initial import, after some monkeying around
[progcomp10.git] / rps / trunk / 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 djaAgents import BOFH
10 from SampleAgents import Angel, Lucifer, Dummy, Frenchie, Streetfighter
11 Agents = [Angel, Lucifer, Frenchie, Streetfighter, BOFH]
12
13 ####################################
14 # Developers only past this point! #
15 ####################################
16
17 import sys
18 from uccProgComp import Supervisor
19
20 maxIterations = 150
21 startingPopulations = 10
22 verbose = False
23 trials = 1
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":
27                 try:
28                         maxIterations = int(sys.argv[i+1])
29                         i += 1
30                         continue
31                 except:
32                         print usage
33                         sys.exit(1)
34         elif sys.argv[i] == "-n":
35                 try:
36                         startingPopulations = int(sys.argv[i+1])
37                         i += 1
38                         continue
39                 except:
40                         print usage
41                         sys.exit(1)
42         elif sys.argv[i] == "-t":
43                 try:
44                         trials = int(sys.argv[i+1])
45                         i += 1
46                         continue
47                 except:
48                         print usage
49                         sys.exit(1)
50
51         elif sys.argv[i] == "-v":
52                 verbose = True
53
54
55 iteration = 0
56 trial = 0
57 winners = {}
58 while trial < trials:
59         sup = Supervisor ()
60         for Agent in Agents: sup.RegisterAgent (Agent)
61         sup.GeneratePopulation (startingPopulations)
62
63         trial += 1
64         iteration = 0
65         while iteration < maxIterations and not sup.IsGameOver ():
66                 iteration += 1
67                 sup.Iterate ()
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 ():
74                 #print key, value
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]
80
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 )
83 scoreboard = []
84 for score, player in rawscoreboard:
85         print "%s: %s" % (player, score)
86

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