643dad0a58a25de36d2d2de9fa0599d5c6787577
[progcomp10.git] / src / simulate.py
1 #!/usr/bin/python2.5
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.
4
5 Licensed under an MIT-style license: see the LICENSE file for details.
6 '''
7
8 # Import and add your agents here:
9 from link.cangel import CAngel
10
11 from SampleAgents import Angel, Lucifer, Dummy, Frenchie, Streetfighter
12 Agents = [Lucifer, Frenchie, Streetfighter, CAngel]
13
14 ####################################
15 # Developers only past this point! #
16 ####################################
17
18 import sys
19 from uccProgComp import Supervisor
20
21 maxIterations = 150
22 startingPopulations = 10
23 verbose = False
24 trials = 1
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":
28                 try:
29                         maxIterations = int(sys.argv[i+1])
30                         i += 1
31                         continue
32                 except:
33                         print usage
34                         sys.exit(1)
35         elif sys.argv[i] == "-n":
36                 try:
37                         startingPopulations = int(sys.argv[i+1])
38                         i += 1
39                         continue
40                 except:
41                         print usage
42                         sys.exit(1)
43         elif sys.argv[i] == "-t":
44                 try:
45                         trials = int(sys.argv[i+1])
46                         i += 1
47                         continue
48                 except:
49                         print usage
50                         sys.exit(1)
51
52         elif sys.argv[i] == "-v":
53                 verbose = True
54
55
56 iteration = 0
57 trial = 0
58 winners = {}
59 while trial < trials:
60         sup = Supervisor ()
61         for Agent in Agents: sup.RegisterAgent (Agent)
62         sup.GeneratePopulation (startingPopulations)
63
64         trial += 1
65         iteration = 0
66         while iteration < maxIterations and not sup.IsGameOver ():
67                 iteration += 1
68                 sup.Iterate ()
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 ():
75                 #print key, value
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]
81
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 )
84 scoreboard = []
85 for score, player in rawscoreboard:
86         print "%s: %s" % (player, score)
87

UCC git Repository :: git.ucc.asn.au