Pulling out magic numbers into conf.py.
[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.C.c_agents import c_angel, c_lucifer, c_streetfighter, c_frenchie
10
11 from SampleAgents import Angel, Lucifer, Dummy, Frenchie, Streetfighter
12 Agents =  [Angel,Lucifer,Streetfighter,Frenchie]
13
14 ####################################
15 # Developers only past this point! #
16 ####################################
17
18 import sys
19 from conf import *
20 from uccProgComp import Supervisor
21
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":
25                 try:
26                         maxIterations = int(sys.argv[i+1])
27                         i += 1
28                         continue
29                 except:
30                         print usage
31                         sys.exit(1)
32         elif sys.argv[i] == "-n":
33                 try:
34                         startingPopulations = int(sys.argv[i+1])
35                         i += 1
36                         continue
37                 except:
38                         print usage
39                         sys.exit(1)
40         elif sys.argv[i] == "-t":
41                 try:
42                         trials = int(sys.argv[i+1])
43                         i += 1
44                         continue
45                 except:
46                         print usage
47                         sys.exit(1)
48
49         elif sys.argv[i] == "-v":
50                 VERBOSE = True
51
52
53 iteration = 0
54 trial = 0
55 winners = {}
56 while trial < TRIALS:
57         sup = Supervisor ()
58         for Agent in Agents: sup.RegisterAgent (Agent)
59         sup.GeneratePopulation (STARTING_POPULATION)
60
61         trial += 1
62         iteration = 0
63         while iteration < MAX_ITERATIONS and not sup.IsGameOver ():
64                 iteration += 1
65                 sup.Iterate ()
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 ():
72                 #print key, value
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]
78
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 )
81 scoreboard = []
82 for score, player in rawscoreboard:
83         print "%s: %s" % (player, score)
84

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