X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Fsimulate.py;h=cdf6d86add47fafbcc842b37baf600b014a3cf0d;hb=9de8fe1e1b7f8148cbaf850c5fa8dd1082f2353a;hp=13a20fa6ca31f786dc3998ee7706c748848ace8f;hpb=e9a8105a8f22404f4ac550d79954eaa6b7f5d8ff;p=progcomp10.git diff --git a/src/simulate.py b/src/simulate.py index 13a20fa..cdf6d86 100755 --- a/src/simulate.py +++ b/src/simulate.py @@ -5,22 +5,18 @@ Written by Luke Williams for the UCC Programming Competiti Licensed under an MIT-style license: see the LICENSE file for details. ''' -# Import and add your agents here: -from djaAgents import BOFH -from SampleAgents import Angel, Lucifer, Dummy, Frenchie, Streetfighter -Agents = [Angel, Lucifer, Frenchie, Streetfighter, BOFH] +# this is the default arena. To chose a different one - for example to run your +# own bots - use -a arenaName on the command line, or change this variable. +arenaName = "PythonSampleAgents" #################################### # Developers only past this point! # #################################### import sys +from conf import * from uccProgComp import Supervisor -maxIterations = 150 -startingPopulations = 10 -verbose = False -trials = 1 usage = "Usage: rps [-v] [-i iterations=150] [-n starting_populations=10] [-t trials=1]" for i in range (1,len(sys.argv)): if sys.argv[i] == "-i": @@ -47,25 +43,32 @@ for i in range (1,len(sys.argv)): except: print usage sys.exit(1) - elif sys.argv[i] == "-v": - verbose = True + VERBOSE = True + elif sys.argv[i] == "-a": + arenaName = sys.argv[i+1] + i += 1 + +#import the arena - NOTE THAT THIS IS A POTENTIAL SECURITY HOLE, +# AS INPUT IS NOT SANITY CHECKED! +importString = "from arenas." + arenaName + " import arena" +exec importString iteration = 0 trial = 0 winners = {} -while trial < trials: +while trial < TRIALS: sup = Supervisor () - for Agent in Agents: sup.RegisterAgent (Agent) - sup.GeneratePopulation (startingPopulations) + for Agent in arena.Agents: sup.RegisterAgent (Agent) + sup.GeneratePopulation (STARTING_POPULATION) trial += 1 iteration = 0 - while iteration < maxIterations and not sup.IsGameOver (): + while iteration < MAX_ITERATIONS and not sup.IsGameOver (): iteration += 1 sup.Iterate () - if not verbose: continue + if not VERBOSE: continue print "Iteration %d:" % iteration for key, value in sup.GetStats ().iteritems(): print "%s: Population=%d, Newborns=%d, Deaths=%d" % (key, value[0], value[1], value[2])