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 = [c_lucifer, Frenchie, c_streetfighter, c_angel]
14 ####################################
15 # Developers only past this point! #
16 ####################################
19 from uccProgComp import Supervisor
22 startingPopulations = 10
25 usage = "Usage: rps [-v] [-i iterations=150] [-n starting_populations=10] [-t trials=1]"
26 for i in range (1,len(sys.argv)):
27 if sys.argv[i] == "-i":
29 maxIterations = int(sys.argv[i+1])
35 elif sys.argv[i] == "-n":
37 startingPopulations = int(sys.argv[i+1])
43 elif sys.argv[i] == "-t":
45 trials = int(sys.argv[i+1])
52 elif sys.argv[i] == "-v":
61 for Agent in Agents: sup.RegisterAgent (Agent)
62 sup.GeneratePopulation (startingPopulations)
66 while iteration < maxIterations and not sup.IsGameOver ():
69 if not verbose: continue
70 print "Iteration %d:" % iteration
71 for key, value in sup.GetStats ().iteritems():
72 print "%s: Population=%d, Newborns=%d, Deaths=%d" % (key, value[0], value[1], value[2])
73 winner = ("Error", -1)
74 for key, value in sup.GetStats ().iteritems ():
76 if value[0] > winner[1]:
77 winner = (key, value[0])
78 if winner[0] in winners: winners[winner[0]] += 1
79 else: winners[winner[0]] = 1
80 #print "Winner: %s" % winner[0]
82 print "SCOREBOARD OVER %d TRIALS OF %d ROUNDS EACH" % (trials, maxIterations)
83 rawscoreboard = sorted ( [(score,player) for (player,score) in winners.items ()] , reverse=True )
85 for score, player in rawscoreboard:
86 print "%s: %s" % (player, score)