2 '''simulate.py - Runs a full simulation of the UCC Programming Competition with the provided agents.
3 Written by Luke Williams <
[email protected]> for the UCC Programming Competition in 2008.
5 Licensed under an MIT-style license: see the LICENSE file for details.
8 # this is the default arena. To chose a different one - for example to run your
9 # own bots - use -a arenaName on the command line, or change this variable.
10 arenaName = "PythonSampleAgents"
12 ####################################
13 # Developers only past this point! #
14 ####################################
18 from uccProgComp import Supervisor
20 usage = "Usage: rps [-v] [-i iterations=150] [-n starting_populations=10] [-t trials=1]"
21 for i in range (1,len(sys.argv)):
22 if sys.argv[i] == "-i":
24 maxIterations = int(sys.argv[i+1])
30 elif sys.argv[i] == "-n":
32 startingPopulations = int(sys.argv[i+1])
38 elif sys.argv[i] == "-t":
40 trials = int(sys.argv[i+1])
46 elif sys.argv[i] == "-v":
48 elif sys.argv[i] == "-a":
49 arenaName = sys.argv[i+1]
53 #import the arena - NOTE THAT THIS IS A POTENTIAL SECURITY HOLE,
54 # AS INPUT IS NOT SANITY CHECKED!
55 importString = "from arenas." + arenaName + " import arena"
63 for Agent in arena.Agents: sup.RegisterAgent (Agent)
64 sup.GeneratePopulation (STARTING_POPULATION)
68 while iteration < MAX_ITERATIONS and not sup.IsGameOver ():
71 if not VERBOSE: continue
72 print "Iteration %d:" % iteration
73 for key, value in sup.GetStats ().iteritems():
74 print "%s: Population=%d, Newborns=%d, Deaths=%d" % (key, value[0], value[1], value[2])
75 winner = ("Error", -1)
76 for key, value in sup.GetStats ().iteritems ():
78 if value[0] > winner[1]:
79 winner = (key, value[0])
80 if winner[0] in winners: winners[winner[0]] += 1
81 else: winners[winner[0]] = 1
82 #print "Winner: %s" % winner[0]
84 print "SCOREBOARD OVER %d TRIALS OF %d ROUNDS EACH" % (trials, maxIterations)
85 rawscoreboard = sorted ( [(score,player) for (player,score) in winners.items ()] , reverse=True )
87 for score, player in rawscoreboard:
88 print "%s: %s" % (player, score)