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..36086a89b8c33976f2f78ba08f73d090bc34b1b5 100644 Binary files a/src/progcomp.xcodeproj/project.pbxproj and b/src/progcomp.xcodeproj/project.pbxproj differ