X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Fsimulate.py;h=438a49e4672782b52b1f1d588dd66a5a4e87c364;hb=580f670dd7bea442c8f478ef2f2efa4c9974c47f;hp=d3afdf930b840c567a312d9e9aec03e76bb8294a;hpb=bde6a9634c116c190cb631e962ccda551503a5c5;p=progcomp10.git diff --git a/src/simulate.py b/src/simulate.py index d3afdf9..438a49e 100755 --- a/src/simulate.py +++ b/src/simulate.py @@ -5,11 +5,9 @@ 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 link.C.c_agents import c_angel, c_lucifer, c_streetfighter, c_frenchie - -from SampleAgents import Angel, Lucifer, Dummy, Frenchie, Streetfighter -Agents = [Angel,Lucifer,Streetfighter,Frenchie] +# 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! # @@ -23,7 +21,7 @@ usage = "Usage: rps [-v] [-i iterations=150] [-n starting_populations=10] [-t tr for i in range (1,len(sys.argv)): if sys.argv[i] == "-i": try: - maxIterations = int(sys.argv[i+1]) + MAX_ITERATIONS = int(sys.argv[i+1]) i += 1 continue except: @@ -39,23 +37,30 @@ for i in range (1,len(sys.argv)): sys.exit(1) elif sys.argv[i] == "-t": try: - trials = int(sys.argv[i+1]) + TRIALS = int(sys.argv[i+1]) i += 1 continue except: print usage sys.exit(1) - elif sys.argv[i] == "-v": 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: sup = Supervisor () - for Agent in Agents: sup.RegisterAgent (Agent) + for Agent in arena.Agents: sup.RegisterAgent (Agent) sup.GeneratePopulation (STARTING_POPULATION) trial += 1 @@ -76,7 +81,7 @@ while trial < TRIALS: else: winners[winner[0]] = 1 #print "Winner: %s" % winner[0] -print "SCOREBOARD OVER %d TRIALS OF %d ROUNDS EACH" % (trials, maxIterations) +print "SCOREBOARD OVER %d TRIALS OF %d ROUNDS EACH" % (TRIALS, MAX_ITERATIONS) rawscoreboard = sorted ( [(score,player) for (player,score) in winners.items ()] , reverse=True ) scoreboard = [] for score, player in rawscoreboard: