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 djaAgents import BOFH
10 from SampleAgents import Angel, Lucifer, Dummy, Frenchie, Streetfighter
11 Agents = [Angel, Lucifer, Frenchie, Streetfighter, BOFH]
13 ####################################
14 # Developers only past this point! #
15 ####################################
18 from uccProgComp import Supervisor
21 startingPopulations = 10
24 usage = "Usage: rps [-v] [-i iterations=150] [-n starting_populations=10] [-t trials=1]"
25 for i in range (1,len(sys.argv)):
26 if sys.argv[i] == "-i":
28 maxIterations = int(sys.argv[i+1])
34 elif sys.argv[i] == "-n":
36 startingPopulations = int(sys.argv[i+1])
42 elif sys.argv[i] == "-t":
44 trials = int(sys.argv[i+1])
51 elif sys.argv[i] == "-v":
60 for Agent in Agents: sup.RegisterAgent (Agent)
61 sup.GeneratePopulation (startingPopulations)
65 while iteration < maxIterations and not sup.IsGameOver ():
68 if not verbose: continue
69 print "Iteration %d:" % iteration
70 for key, value in sup.GetStats ().iteritems():
71 print "%s: Population=%d, Newborns=%d, Deaths=%d" % (key, value[0], value[1], value[2])
72 winner = ("Error", -1)
73 for key, value in sup.GetStats ().iteritems ():
75 if value[0] > winner[1]:
76 winner = (key, value[0])
77 if winner[0] in winners: winners[winner[0]] += 1
78 else: winners[winner[0]] = 1
79 #print "Winner: %s" % winner[0]
81 print "SCOREBOARD OVER %d TRIALS OF %d ROUNDS EACH" % (trials, maxIterations)
82 rawscoreboard = sorted ( [(score,player) for (player,score) in winners.items ()] , reverse=True )
84 for score, player in rawscoreboard:
85 print "%s: %s" % (player, score)