diff --git a/src/arenas/CSampleAgents.py b/src/arenas/CSampleAgents.py new file mode 100644 index 0000000000000000000000000000000000000000..a49d6dfc29870962e61f8c4343746a0f35ee164c --- /dev/null +++ b/src/arenas/CSampleAgents.py @@ -0,0 +1,11 @@ +'''CSampleAgents.py +An areana that runs the sample bots in C. +Written by Daniel Axtens <dja@ucc.asn.au> for the UCC Programming Competition in 2010. + +Licensed under an MIT-style license: see the LICENSE file for details. +''' + +from link.C.c_agents import c_angel, c_lucifer, c_streetfighter, c_frenchie + +class arena: + Agents = [c_angel,c_lucifer,c_streetfighter,c_frenchie] diff --git a/src/arenas/PythonSampleAgents.py b/src/arenas/PythonSampleAgents.py new file mode 100755 index 0000000000000000000000000000000000000000..c0c1134fb0c172438a2103f99b6a9d43041b47d5 --- /dev/null +++ b/src/arenas/PythonSampleAgents.py @@ -0,0 +1,14 @@ +#!/usr/bin/python2.5 +'''PythonSampleAgentsArena.py +An areana that runs the sample bots in python. +Written by Daniel Axtens <dja@ucc.asn.au> for the UCC Programming Competition in 2010. + +Licensed under an MIT-style license: see the LICENSE file for details. +''' + +from SampleAgents import Angel, Lucifer, Dummy, Frenchie, Streetfighter + + +# Import and add your agents here: +class PythonSampleAgentsArena: + Agents = [Angel,Lucifer,Streetfighter,Frenchie] \ No newline at end of file diff --git a/src/arenas/__init__.py b/src/arenas/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/conf.py b/src/conf.py index 8ffbb2f2502ab8c5a164bbaf9f5732b358f45ab0..aabd7171395fe9f6214462284223594833b3241b 100644 --- a/src/conf.py +++ b/src/conf.py @@ -6,7 +6,7 @@ from rpsconst import * VERBOSE = True # Enable for even more verbose output. -DEBUG = True +DEBUG = False # How many iterations to run before quitting. MAX_ITERATIONS = 150 diff --git a/src/link/C/README b/src/link/C/README index 7f0a970f1efd9717742ebbae80ad30f6a12b739c..9afcc16778ad09b0f1bdb896c0391580033beb4a 100644 --- a/src/link/C/README +++ b/src/link/C/README @@ -1,5 +1,7 @@ Welcome to the C SDK and link library. +If you want to enter in C, you've come to the right place. + == Compiling and testing the sample bots == Run "make" in this directory. To include them in the @@ -7,6 +9,9 @@ Run "make" in this directory. To include them in the == Making your own agent == See wiki page. +Also, use the link/bundle-agent.sh shell script - it will take your agent file +and make a python module that you can include. + = Testing your own agent = Edit src/simulate.py. Your agents live in link.C.c_agents diff --git a/src/link/C/c_agents.py b/src/link/C/c_agents.py index ae6441045f7068abb99be068eb59634f17c75b49..dfc1393678e1b09437dac4368e40cf50a1358b7d 100644 --- a/src/link/C/c_agents.py +++ b/src/link/C/c_agents.py @@ -1,20 +1,20 @@ # add your agents to this file by copying the definition and adjusting # you then need to modify simulate.py -from link.externAgent import externAgent +from link.cAgent import cAgent -class c_angel (externAgent): +class c_angel (cAgent): def __init__ (self): - externAgent.__init__(self, "./link/C/agents/c_angel") + cAgent.__init__(self, "./link/C/agents/c_angel") -class c_lucifer (externAgent): +class c_lucifer (cAgent): def __init__ (self): - externAgent.__init__(self, "./link/C/agents/c_lucifer") + cAgent.__init__(self, "./link/C/agents/c_lucifer") -class c_streetfighter (externAgent): +class c_streetfighter (cAgent): def __init__ (self): - externAgent.__init__(self, "./link/C/agents/c_streetfighter") + cAgent.__init__(self, "./link/C/agents/c_streetfighter") -class c_frenchie (externAgent): +class c_frenchie (cAgent): def __init__ (self): - externAgent.__init__(self, "./link/C/agents/c_frenchie") + cAgent.__init__(self, "./link/C/agents/c_frenchie") diff --git a/src/link/bundle-agent.sh b/src/link/bundle-agent.sh new file mode 100755 index 0000000000000000000000000000000000000000..edf55ee04e3beda48915b4774f33994d17d36041 --- /dev/null +++ b/src/link/bundle-agent.sh @@ -0,0 +1,120 @@ +#!/bin/bash + +# bundle-agent.sh +# progcomp +# +# Written by Daniel Axtens <dja@ucc.asn.au> for the UCC Programming Competition in 2010. +# Licensed under an MIT-style license: see the LICENSE file for details. + +# a candidate for porting to python. + +# put ourselves in SRCROOT - src/ +# this assumes we are in the src/link directory. +cd `dirname $0`/.. + +# begin script +cat << __EOF__ +This script takes the code that you have written for UCC::ProgComp 2010 and +bundles it up as an agent that you can test. This script is not needed for code +written in Python. +__EOF__ + + +# select language +lang=0 + +while ([ $lang != 1 ] && [ $lang != 2 ]) do { + + cat << __EOF__ +Is your agent written in: +(1) C +(2) another language (UNSUPPORTED) +__EOF__ + + read -p "Enter 1 or 2: " lang + +} done; + +# C bots +if ([ $lang == 1 ]) then + echo + echo "Preparing a C bot." + echo + + echo "Where is your .c file?" + echo "Provide the full path, including the agent file and the .c" + echo "Give paths relative to the src/ directory." + echo "WARNING: will overwrite \'agent name\'.py if it exists" + + read -p "Path: " path + + location=`dirname $path` + name=`basename $path .c` + + cat > ${location}/${name}.py << __EOF__ +# ${name}.py - a C bot shell generated by `basename $0` for UCC::ProgComp 2010 + +from link.cAgent import cAgent + +class ${name} (cAgent): + def __init__ (self): + cAgent.__init__(self, "${location}/${name}") +__EOF__ + + + +# Custom bots +elif ([ $lang == 2 ]) then + echo + echo "Preparing a custom bot." + echo + + echo "What is the name of your bot?" + + read -p "Name: " name + + echo + echo "Enter the command required to spawn your bot." + echo "Give paths relative to the src/ directory." + + read -p "Command: " cmd + + echo + echo "Into which directory should I put the resultant python module?" + echo "(again, give paths relative to src/)" + echo "WARNING: will overwrite ${name}.py if it exists" + + read -p "Location: " location + + cat > ${location}/${name}.py << __EOF__ +# ${name}.py - a custom bot shell generated by `basename $0` for UCC::ProgComp 2010 +# calls "${cmd}" to invoke the bot + +from link.externAgent import externAgent + +class ${name} (externAgent): + def __init__ (self): + externAgent.__init__(self, "${cmd}") +__EOF__ + + +fi + +### Finish up +echo +echo "${name}.py created." +echo +echo "Include your bot with:" + +#there must be a nicer way to do this. possibly by using python +#part of the horror is trying to deal with location possibly having a trailing +#slash, and possibly not having one. *sigh* +pythonpath=`sed 's:/:.:g' << __EOF__ +$(dirname ${location}/${name}).${name} +__EOF__ +` + +echo " from ${pythonpath} import ${name}" +echo "Then make sure the Agents list includes ${name}" +echo +echo "Good luck!" \ No newline at end of file diff --git a/src/link/cAgent.py b/src/link/cAgent.py new file mode 100644 index 0000000000000000000000000000000000000000..5d445aa0db608abbc00da0feac6a207320b8d7a3 --- /dev/null +++ b/src/link/cAgent.py @@ -0,0 +1,17 @@ +'''cAgent.py - a bot shell for talking to C bots. +Written by Daniel Axtens <dja@ucc.asn.au> for the UCC Programming Competition in 2010. + +This is a separate class to externAgent so that changes can be made +without requiring C agents to have their wrapper scripts rewritten. + +Licensed under an MIT-style license: see the LICENSE file for details. +''' + +from link.externAgent import externAgent + +class cAgent (externAgent): + """A class for handling agents in C. + A subclass of externAgent so that changes can be made to how all external + agents are handled, or how all C agents are handled, without requiring C + agents to have their wrapper scripts rewritten. Use this in preference to + externAgent for C agents.""" \ No newline at end of file diff --git a/src/progcomp.xcodeproj/project.pbxproj b/src/progcomp.xcodeproj/project.pbxproj index eaf32afd5b00e17c2acbe4d1f2d48c4b8d236e9c..ca03935b7fd30746c09daa114d84eb2dbd8f8238 100644 Binary files a/src/progcomp.xcodeproj/project.pbxproj and b/src/progcomp.xcodeproj/project.pbxproj differ diff --git a/src/simulate.py b/src/simulate.py index d3afdf930b840c567a312d9e9aec03e76bb8294a..cdf6d86add47fafbcc842b37baf600b014a3cf0d 100755 --- a/src/simulate.py +++ b/src/simulate.py @@ -5,11 +5,9 @@ Written by Luke Williams <shmookey@ucc.asn.au> 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! # @@ -45,17 +43,24 @@ for i in range (1,len(sys.argv)): 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