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 # Import and add your agents here:
9 #from link.C.c_agents import c_angel, c_lucifer, c_streetfighter, c_frenchie
11 from SampleAgents import Angel, Lucifer, Dummy, Frenchie, Streetfighter
12 Agents = [Angel,Lucifer,Streetfighter,Frenchie]
14 ####################################
15 # Developers only past this point! #
16 ####################################
20 from uccProgComp import Supervisor
22 usage = "Usage: rps [-v] [-i iterations=150] [-n starting_populations=10] [-t trials=1]"
23 for i in range (1,len(sys.argv)):
24 if sys.argv[i] == "-i":
26 maxIterations = int(sys.argv[i+1])
32 elif sys.argv[i] == "-n":
34 startingPopulations = int(sys.argv[i+1])
40 elif sys.argv[i] == "-t":
42 trials = int(sys.argv[i+1])
49 elif sys.argv[i] == "-v":
58 for Agent in Agents: sup.RegisterAgent (Agent)
59 sup.GeneratePopulation (STARTING_POPULATION)
63 while iteration < MAX_ITERATIONS and not sup.IsGameOver ():
66 if not VERBOSE: continue
67 print "Iteration %d:" % iteration
68 for key, value in sup.GetStats ().iteritems():
69 print "%s: Population=%d, Newborns=%d, Deaths=%d" % (key, value[0], value[1], value[2])
70 winner = ("Error", -1)
71 for key, value in sup.GetStats ().iteritems ():
73 if value[0] > winner[1]:
74 winner = (key, value[0])
75 if winner[0] in winners: winners[winner[0]] += 1
76 else: winners[winner[0]] = 1
77 #print "Winner: %s" % winner[0]
79 print "SCOREBOARD OVER %d TRIALS OF %d ROUNDS EACH" % (trials, maxIterations)
80 rawscoreboard = sorted ( [(score,player) for (player,score) in winners.items ()] , reverse=True )
82 for score, player in rawscoreboard:
83 print "%s: %s" % (player, score)