From 13eb5cad5dedf0cc7a01f7f8d50812b14288e71d Mon Sep 17 00:00:00 2001
From: Daniel Axtens <dja@ucc.asn.au>
Date: Tue, 29 Jun 2010 17:08:21 +0800
Subject: [PATCH] split off c agents into cAgent.py. created a script to churn
 out a python module for an external agent.

---
 src/link/C/README                      |   5 ++
 src/link/C/c_agents.py                 |  18 ++--
 src/link/bundle-agent.sh               | 120 +++++++++++++++++++++++++
 src/link/cAgent.py                     |  17 ++++
 src/progcomp.xcodeproj/project.pbxproj | Bin 16649 -> 6211 bytes
 5 files changed, 151 insertions(+), 9 deletions(-)
 create mode 100755 src/link/bundle-agent.sh
 create mode 100644 src/link/cAgent.py

diff --git a/src/link/C/README b/src/link/C/README
index 7f0a970..9afcc16 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 ae64410..dfc1393 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 0000000..edf55ee
--- /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 0000000..5d445aa
--- /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/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