The full documentation is in the "doc" directory. Alternatively, if you
want to dive straight into the code, see the "src" directory.
+
+This version only supports Python.
+Other languages are coming soon.
- SampleAgents.py : the sample agents.
- agents/ : where you put your agent.
- arenas/ : arenas define which agents play against which, and some other parameters.
- - link/ : Other languages belong here.
- conf.py : has various useful things like the ability to turn on debug support.
The rest of the files are probably not useful to you, but just for completeness:
- uccProgComp.py : the guts of the competition.
- rpsconst.py : various constants, such as the points table.
-Ignore anything else. :P
\ No newline at end of file
+Ignore anything else. :P
+++ /dev/null
-!agents/*.c
-agents/*
+++ /dev/null
-CC=gcc
-AR=ar
-
-myCFLAGS=$(CFLAGS) -Wall -I.
-myLDFLAGS=-lc_link -L.
-
-LINKSRCS=c_link.c
-LINKOBJS=$(LINKSRCS:.c=.o)
-LINKLIB=libc_link.a
-
-AGENTSRCS=$(wildcard agents/*.c)
-AGENTS=$(AGENTSRCS:.c=)
-
-all: $(LINKSRCS) $(LINKLIB) $(AGENTS)
-
-$(LINKLIB): $(LINKOBJS)
- $(AR) rcs $(LINKLIB) $(LINKOBJS)
-
-$(AGENTS): $(AGENTSRCS) $(LINKLIB)
- @echo Building $@
-
-.c.o: c_link.h
- $(CC) -c $(myCFLAGS) $< -o $@
-
-.PHONY : clean
-clean:
- rm $(LINKOBJS) $(LINKLIB) $(AGENTS)
+++ /dev/null
-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
-
-== 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
-Add them to Agents to get them to do battle.
-
-For example, this code imports c_angel, c_lucifer, c_streetfighter and
-c_wash, as well as the python sample agents, and then battles c_lucifer,
-python Wash, c_streetfighter and c_angel. It goes at the top of simulate.py.
-
-# Import and add your agents here:
-from link.C.c_agents import c_angel, c_lucifer, c_streetfighter, c_wash
-
-from SampleAgents import Angel, Lucifer, Dummy, Wash, Streetfighter
-Agents = [c_lucifer, Wash, c_streetfighter, c_angel]
-
+++ /dev/null
-/*
- * c_angel.c
- * c-link-lib
- *
- * Created by Daniel Axtens on 20/04/10.
- * Licensed under an MIT-style license: see the LICENSE file for details.
- *
- */
-
-#include <c_link.h>
-
-/* Implement the angel bot, which always tells the truth
- and expects others to do the same */
-
-ATTACKTYPE Attack( char * foe_name ) {
- ATTACKTYPE attack;
-
- attack.realAttack = RandomAttack(); /* Chooses randomly from Rock, Paper, Scissors */
- attack.promisedAttack = attack.realAttack; /* Tells the truth for its bluff */
-
- return attack;
-}
-
-ITEMTYPE Defend( char * foeName, ITEMTYPE foePromisedAttack ) {
- return foePromisedAttack; /* Trusts them to be going for a tie */
-}
-
-/* You need to define a results function, even if it isn't used
- (otherwise the linker will complain) */
-void Results( char * foeName, int isInstigatedByYou, RESULTTYPE winner,
- ITEMTYPE attItem, ITEMTYPE defItem, ITEMTYPE bluffItem,
- int pointDelta ) {
-
- return; /* Ignore whatever just happened. */
-}
-
-/* same for Cleanup() */
-
-void Cleanup() {
- return;
-}
\ No newline at end of file
+++ /dev/null
-/*
- * c_lucifer.c
- * c-link-lib
- *
- * Created by Daniel Axtens on 20/04/10.
- * Licensed under an MIT-style license: see the LICENSE file for details.
- *
- */
-
-
-#include <c_link.h>
-
-/* Implement the lucifer bot, which always lies expecting people to be good
- and always goes for the kill */
-
-ATTACKTYPE Attack( char * foe_name ) {
- ATTACKTYPE attack;
-
- attack.realAttack = RandomAttack();
-
- /* Here we choose the thing that will hurt them if they go for a tie */
- switch (attack.realAttack) {
- case rock:
- attack.promisedAttack = scissors;
- break;
- case paper:
- attack.promisedAttack = rock;
- break;
- default: /* attack = scissors */
- attack.promisedAttack = paper;
- break;
- }
-
- return attack;
-}
-
-/* Here we trust that they are telling the truth. And we try to kill them. */
-ITEMTYPE Defend( char * foeName, ITEMTYPE foePromisedAttack ) {
- ITEMTYPE defence;
- switch (foePromisedAttack) {
- case rock:
- defence = paper;
- break;
- case paper:
- defence = scissors;
- break;
- default:
- defence = rock;
- break;
- }
- return defence;
-}
-
-/* You need to define a results function, even if it isn't used
- (otherwise the linker will complain) */
-void Results( char * foeName, int isInstigatedByYou, RESULTTYPE winner,
- ITEMTYPE attItem, ITEMTYPE defItem, ITEMTYPE bluffItem,
- int pointDelta ) {
-
- return; /* Ignore whatever just happened. */
-}
-
-/* same for Cleanup() */
-
-void Cleanup() {
- return;
-}
\ No newline at end of file
+++ /dev/null
-/*
- * c_streetfighter.c
- * c-link-lib
- *
- * Created by Daniel Axtens on 20/04/10.
- * Licensed under an MIT-style license: see the LICENSE file for details.
- *
- */
-
-
-#include <c_link.h>
-
-/* Implement the streetfighter bot, which thinks everyone has it in for him. */
-
-ATTACKTYPE Attack( char * foe_name ) {
- ATTACKTYPE attack;
-
- attack.realAttack = RandomAttack();
-
- /* Here we choose the thing that will hurt them if they go for the kill */
- switch (attack.realAttack) {
- case rock:
- attack.promisedAttack = paper;
- break;
- case paper:
- attack.promisedAttack = scissors;
- break;
- default: /* attack = scissors */
- attack.promisedAttack = rock;
- break;
- }
- return attack;
-}
-
-/* Here we assume they are lying, trying to kill us. And we try to kill them. */
-ITEMTYPE Defend( char * foeName, ITEMTYPE foePromisedAttack ) {
- ITEMTYPE defence;
- switch (foePromisedAttack) {
- case rock:
- defence = scissors;
- break;
- case paper:
- defence = rock;
- break;
- default:
- defence = paper;
- break;
- }
- return defence;
-}
-
-/* You need to define a results function, even if it isn't used
- (otherwise the linker will complain) */
-void Results( char * foeName, int isInstigatedByYou, RESULTTYPE winner,
- ITEMTYPE attItem, ITEMTYPE defItem, ITEMTYPE bluffItem,
- int pointDelta ) {
-
- return; /* Ignore whatever just happened. */
-}
-
-/* same for Cleanup() */
-
-void Cleanup() {
- return;
-}
+++ /dev/null
-// !$*UTF8*$!
-{
- archiveVersion = 1;
- classes = {
- };
- objectVersion = 45;
- objects = {
-
-/* Begin PBXFileReference section */
- 2208AFE6118F28D800770C92 /* c_wash.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = c_wash.c; sourceTree = "<group>"; };
- 2208AFE7118F28F400770C92 /* c_agents.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = c_agents.py; sourceTree = "<group>"; };
- 2291A1BB117EDB9600854CBE /* c_link.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = c_link.c; sourceTree = "<group>"; };
- 2291A1BD117EE3FD00854CBE /* c_angel.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = c_angel.c; sourceTree = "<group>"; };
- 2291A1BE117EE3FD00854CBE /* c_lucifer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = c_lucifer.c; sourceTree = "<group>"; };
- 2291A1BF117EE3FD00854CBE /* c_streetfighter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = c_streetfighter.c; sourceTree = "<group>"; };
- 22CAFECF11D48750001ECDEF /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
- 22F652F5117C679300A3793D /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
- 22F652F6117C6C9500A3793D /* c_link.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = c_link.h; sourceTree = "<group>"; };
-/* End PBXFileReference section */
-
-/* Begin PBXGroup section */
- 08FB7794FE84155DC02AAC07 /* c-link-lib */ = {
- isa = PBXGroup;
- children = (
- 22CAFECF11D48750001ECDEF /* README */,
- 2208AFE7118F28F400770C92 /* c_agents.py */,
- 2291A1BC117EE3FD00854CBE /* agents */,
- 22F652F6117C6C9500A3793D /* c_link.h */,
- 2291A1BB117EDB9600854CBE /* c_link.c */,
- 22F652F5117C679300A3793D /* Makefile */,
- );
- name = "c-link-lib";
- sourceTree = "<group>";
- };
- 2291A1BC117EE3FD00854CBE /* agents */ = {
- isa = PBXGroup;
- children = (
- 2291A1BD117EE3FD00854CBE /* c_angel.c */,
- 2291A1BE117EE3FD00854CBE /* c_lucifer.c */,
- 2291A1BF117EE3FD00854CBE /* c_streetfighter.c */,
- 2208AFE6118F28D800770C92 /* c_wash.c */,
- );
- path = agents;
- sourceTree = "<group>";
- };
-/* End PBXGroup section */
-
-/* Begin PBXLegacyTarget section */
- D28A88AD04BDD90700651E21 /* c-link-lib */ = {
- isa = PBXLegacyTarget;
- buildArgumentsString = "$(ACTION)";
- buildConfigurationList = 1DEB918F08733D9F0010E9CD /* Build configuration list for PBXLegacyTarget "c-link-lib" */;
- buildPhases = (
- );
- buildToolPath = /usr/bin/make;
- buildWorkingDirectory = "";
- dependencies = (
- );
- name = "c-link-lib";
- passBuildSettingsInEnvironment = 1;
- productName = "c-link-lib";
- };
-/* End PBXLegacyTarget section */
-
-/* Begin PBXProject section */
- 08FB7793FE84155DC02AAC07 /* Project object */ = {
- isa = PBXProject;
- buildConfigurationList = 1DEB919308733D9F0010E9CD /* Build configuration list for PBXProject "c-link-lib" */;
- compatibilityVersion = "Xcode 3.1";
- hasScannedForEncodings = 1;
- mainGroup = 08FB7794FE84155DC02AAC07 /* c-link-lib */;
- projectDirPath = "";
- projectRoot = "";
- targets = (
- D28A88AD04BDD90700651E21 /* c-link-lib */,
- );
- };
-/* End PBXProject section */
-
-/* Begin XCBuildConfiguration section */
- 1DEB919008733D9F0010E9CD /* Debug */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- COPY_PHASE_STRIP = NO;
- DEBUGGING_SYMBOLS = YES;
- GCC_DYNAMIC_NO_PIC = NO;
- GCC_ENABLE_FIX_AND_CONTINUE = YES;
- GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
- GCC_OPTIMIZATION_LEVEL = 0;
- OTHER_CFLAGS = "";
- OTHER_LDFLAGS = "";
- PRODUCT_NAME = "c-link-lib";
- };
- name = Debug;
- };
- 1DEB919108733D9F0010E9CD /* Release */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- COPY_PHASE_STRIP = YES;
- GCC_ENABLE_FIX_AND_CONTINUE = NO;
- OTHER_CFLAGS = "";
- OTHER_LDFLAGS = "";
- PRODUCT_NAME = "c-link-lib";
- };
- name = Release;
- };
- 1DEB919408733D9F0010E9CD /* Debug */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- GCC_WARN_ABOUT_RETURN_TYPE = YES;
- GCC_WARN_UNUSED_VARIABLE = YES;
- ONLY_ACTIVE_ARCH = YES;
- PREBINDING = NO;
- SDKROOT = macosx10.6;
- };
- name = Debug;
- };
- 1DEB919508733D9F0010E9CD /* Release */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- GCC_WARN_ABOUT_RETURN_TYPE = YES;
- GCC_WARN_UNUSED_VARIABLE = YES;
- PREBINDING = NO;
- SDKROOT = macosx10.6;
- };
- name = Release;
- };
-/* End XCBuildConfiguration section */
-
-/* Begin XCConfigurationList section */
- 1DEB918F08733D9F0010E9CD /* Build configuration list for PBXLegacyTarget "c-link-lib" */ = {
- isa = XCConfigurationList;
- buildConfigurations = (
- 1DEB919008733D9F0010E9CD /* Debug */,
- 1DEB919108733D9F0010E9CD /* Release */,
- );
- defaultConfigurationIsVisible = 0;
- defaultConfigurationName = Release;
- };
- 1DEB919308733D9F0010E9CD /* Build configuration list for PBXProject "c-link-lib" */ = {
- isa = XCConfigurationList;
- buildConfigurations = (
- 1DEB919408733D9F0010E9CD /* Debug */,
- 1DEB919508733D9F0010E9CD /* Release */,
- );
- defaultConfigurationIsVisible = 0;
- defaultConfigurationName = Release;
- };
-/* End XCConfigurationList section */
- };
- rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
-}
+++ /dev/null
-# add your agents to this file by copying the definition and adjusting
-# you then need to modify simulate.py
-
-from link.cAgent import cAgent
-
-class c_angel (cAgent):
- def __init__ (self):
- cAgent.__init__(self, "./link/C/agents/c_angel")
-
-class c_lucifer (cAgent):
- def __init__ (self):
- cAgent.__init__(self, "./link/C/agents/c_lucifer")
-
-class c_streetfighter (cAgent):
- def __init__ (self):
- cAgent.__init__(self, "./link/C/agents/c_streetfighter")
-
-class c_wash (cAgent):
- def __init__ (self):
- cAgent.__init__(self, "./link/C/agents/c_wash")
+++ /dev/null
-/*
- * c_link.c
- * c-link-lib
- *
- * Created by Daniel Axtens on 19/04/10.
- * Licensed under an MIT-style license: see the LICENSE file for details.
- *
- */
-
-#include "c_link.h"
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <time.h>
-
-/* You don't need to read this file.
- All you have to do is implement the bot functions defined in <c_link.h>
- This file sets up the I/O for you, as well as some utility functions and tables.
- */
-
-char ITEMNAMES[3][MAXITEMLEN] = {"Rock", "Paper", "Scissors"};
-
-/* rock-rock rock-paper rock-scissors
- paper-rock paper-paper paper-scissors
- scissors-rock scissors-paper scissors-scissors */
-
-RESULTTYPE RESULTOF[3][3] = { { tie, defender, attacker },
- { attacker, tie, defender },
- { defender, attacker, tie } };
-
-
-ITEMTYPE RandomAttack() {
- return (ITEMTYPE)rand()%3;
-}
-
-ITEMTYPE stringToItem( char * str ) {
- if (strcasecmp( str, "Rock" ) == 0) return rock;
- if (strcasecmp( str, "Paper" ) == 0) return paper;
- if (strcasecmp( str, "Scissors" ) == 0) return scissors;
- /* If we reach this point, we've got real problems. */
- fprintf( stderr, "Attempt to convert invalid string \"%s\" into an ITEMTYPE! Aborting.\n", str );
- exit(EXIT_FAILURE);
- return -1;
-}
-
-
-RESULTTYPE stringToResult( char * str ) {
- if (strcasecmp( str, "Attacker" ) == 0) return attacker;
- if (strcasecmp( str, "Defender" ) == 0) return defender;
- if (strcasecmp( str, "Tie" ) == 0) return tie;
- /* If we reach this point, we've got real problems. */
- fprintf( stderr, "Attempt to convert invalid string \"%s\" into an ITEMTYPE! Aborting.\n", str );
- exit(EXIT_FAILURE);
- return -1;
-}
-
-int main( int argc, char * argv[] ) {
- srand( time( NULL ) );
-
- char command[MAXCOMMANDLEN];
- char foeName[MAXFOENAMELEN];
- char attItem[MAXITEMLEN], defItem[MAXITEMLEN], bluffItem[MAXITEMLEN];
- char didYouInstigate[MAXBOOLLEN];
- char winner[MAXRESULTLEN];
- int pointChange;
-
- ATTACKTYPE attack;
- ITEMTYPE defence;
-
- /* generate a random id for this bot. Hopefully it's unique
- I can't use the UUID, because python doesn't pass it to me! */
- me = rand();
-
-
- scanf( "%s", command );
-
- while (strcasecmp("BYE",command) != 0) {
-
- if (strcasecmp("ATTACK", command) == 0) {
- scanf( "%s", foeName );
- attack = Attack( foeName );
- printf("ATTACKING %s %s\n", ITEMNAMES[attack.realAttack], ITEMNAMES[attack.promisedAttack]);
-
- } else if (strcasecmp("DEFEND", command) == 0) {
- scanf( "%s %s", foeName, bluffItem );
- defence = Defend(foeName, stringToItem(bluffItem));
- printf("DEFENDING %s\n", ITEMNAMES[defence]);
-
- } else if (strcasecmp("RESULTS", command) == 0) {
- /* (foeName, isInstigatedByYou, winner, attItem, defItem, bluffItem, pointDelta) */
- scanf( "%s %s %s %s %s %s %d", foeName, didYouInstigate, winner, attItem, defItem, bluffItem, &pointChange );
- Results(foeName, (strcasecmp("True",didYouInstigate)==0), stringToResult(winner),
- stringToItem(attItem), stringToItem(defItem), stringToItem(bluffItem), pointChange);
- printf("OK\n");
- }
-
- fflush(stdout);
- fflush(stderr);
-
- // read the next command!
- scanf( "%s", command );
- }
-
- Cleanup();
-
- return 0;
-}
\ No newline at end of file
+++ /dev/null
-/*
- * c_link.h
- * c-link-lib
- *
- * Created by Daniel Axtens on 19/04/10.
- * Licensed under an MIT-style license: see the LICENSE file for details.
- *
- */
-
-#include <stdio.h>
-
-#define MAXCOMMANDLEN 15
-#define MAXFOENAMELEN 50
-#define MAXITEMLEN 10
-#define MAXRESULTLEN 10
-#define MAXBOOLLEN 6
-
-/********** Type definitions **********/
-
-/* The type of item used in an attack or defence */
-typedef enum {rock, paper, scissors} ITEMTYPE;
-
-/* A result of a battle, in terms of who won */
-typedef enum {attacker, defender, tie} RESULTTYPE;
-
-
-/* An attack, consisting of the real attack and the attack promised */
-typedef struct {
- ITEMTYPE realAttack;
- ITEMTYPE promisedAttack;
-} ATTACKTYPE;
-
-
-/********** Utility Function definitions **********/
-/* These are implemented in c-link.c, and automagically linked in */
-
-/* prints a debug message. Same arguments as printf().
- (you can't use printf because it is used to talk between
- the agent and supervisor)
- */
-
-#define debugmsg(x...) fprintf(stderr, x)
-
-/* A (hopefully) unique identifier for this particular instance of your agent,
- to help with debugging */
-int me;
-
-
-/* Returns a random item */
-
-ITEMTYPE RandomAttack();
-
-/* A useful translation table
- eg debugmsg( "I use %s.\n", ITEMNAMES[rock] ); */
-
-extern char ITEMNAMES[3][MAXITEMLEN];
-
-/* Another useful table - who's the victor given an
- attacker with first item vs defender with the second item? */
-extern RESULTTYPE RESULTOF[3][3];
-
-/********** Bot Function definitions **********/
-/* You need to provide implementations for these to create a bot */
-
-/* Defend( foeName : string - the name of your foe;
- foePromisedAttack : ITEMTYPE - the item your foe promised to use
- ) : ITEMTYPE - the item you wish to use to defend;
-
- Called when your agent needs to defend itself.
-
- */
-ITEMTYPE Defend( char * foeName, ITEMTYPE foePromisedAttack );
-
-
-/* Attack( foeName : string - the name of your foe
- ) : ATTACKTYPE - the real and promised attack you wish to use
-
- Called when your agent needs to attack another agent.
-
- */
-ATTACKTYPE Attack( char * foeName );
-
-
-/* Results( foeName : string - the name of your foe;
- isInstigatedByYou : 0=you defended/1=you attacked;
- winner : RESULTTYPE - who won
- attItem : ITEMTYPE - the item used to attack;
- defItem : ITEMTYPE - the item used to defend;
- bluffItem : ITEMTYPE - the item that was promised
- pointDelta : integer - how your points were affected.
- );
-
- Called after your agent battles another agent, to tell you how the battle goes.
-
- */
-void Results( char * foeName, int isInstigatedByYou, RESULTTYPE winner,
- ITEMTYPE attItem, ITEMTYPE defItem, ITEMTYPE bluffItem,
- int pointDelta );
-
-/* Cleanup();
-
- Called when your agent is no longer needed, either due to the round ending
- or due to your agent being eliminated.
-
- */
-void Cleanup();
\ No newline at end of file
+++ /dev/null
-#!/bin/bash
-
-# bundle-agent.sh
-# progcomp
-#
-# Written by Daniel Axtens <
[email protected]> 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
+++ /dev/null
-'''cAgent.py - a bot shell for talking to C bots.
-Written by Daniel Axtens <
[email protected]> 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
+++ /dev/null
-'''externAgent.py - a bot shell for talking to external I/O bots.
-Written by Daniel Axtens <
[email protected]> for the UCC Programming Competition in 2010.
-
-Licensed under an MIT-style license: see the LICENSE file for details.
-'''
-
-from uccProgComp import BaseAgent, LearningAgent, RandomAttack
-from rpsconst import *
-#from pexpect import pexpect
-
-import sys, subprocess
-
-class externAgent (BaseAgent):
-
- def __init__ (self, externName):
- BaseAgent.__init__(self)
- try:
- self.process = subprocess.Popen(externName, stdin=subprocess.PIPE,
- stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- universal_newlines=True)
- except Exception, e:
- print ("Error spawning \"%s\": " % externName), e
-
- def stringToItem( self, str ):
- if str == "Rock":
- return Rock
- elif str == "Paper":
- return Paper
- elif str == "Scissors":
- return Scissors
- else:
- # Something has gone wrong!
- print "Error: tried to convert \"%s\" into an item!" % str
- raise ValueError( "tried to convert \"%s\" into an item!" % str );
- return None
-
- def itemToString( self, item ):
- return rpsStrings[item]
-
- #if item == Rock:
- # return "Rock"
- #elif item == Paper:
- # return "Paper"
- #elif item == Scissors:
- # return "Scissors"
- #else:
- # # Something has gone wrong!
- # print "Error: tried to convert '%d' to Rock/Paper/Scissors string!" % item
- # # raise an exception
- # raise ValueError("tried to convert '%d' to Rock/Paper/Scissors string!" % item)
-
- def resultToString( self, result ):
- return adtStrings[result]
-
- #if result == Attacker:
- # return "Attacker"
- #elif result == Defender:
- # return "Defender"
- #elif result == Tie:
- # return "Tie"
- #else:
- # # Something has gone wrong!
- # print "Error: tried to convert '%d' to Attacker/Defender/Tie string!" % result
- # # raise an exception
- # raise ValueError("tried to convert '%d' to Attacker/Defender/Tie string!" % result)
-
- def Attack (self, foe):
- self.process.stdin.write ( ' '.join( ["ATTACK", repr(foe), "\r\n"] ) )
- #print >>sys.stderr, self.process.stderr.readlines()
- result = self.process.stdout.readline().split()
- try:
- attack, bluff = self.stringToItem( result[1] ), self.stringToItem( result[2] )
- return attack, bluff
- except:
- #agent is insane
- print "Agent is insane:", self
- pass
-
- def Defend (self, foe, bluff ):
- self.process.stdin.write ( ' '.join( ["DEFEND", repr(foe), self.itemToString( bluff ), "\r\n"] ) )
- #print >>sys.stderr, self.process.stderr.readlines()
- result = self.process.stdout.readline().split()
- try:
- defence = self.stringToItem( result[1] )
- return defence
- except:
- #agent is insane
- print "Agent is insane:", self
- pass
-
- def Results (self, foe, isInstigatedByYou, winner, attItem, defItem, bluffItem, pointDelta):
-
- BaseAgent.Results (self, foe, isInstigatedByYou, winner, attItem,
- defItem, bluffItem, pointDelta)
-
- string = ' '.join( [ "RESULTS", repr(foe), repr(isInstigatedByYou),
- self.resultToString(winner),
- self.itemToString( attItem ),
- self.itemToString( defItem ),
- self.itemToString( bluffItem ), repr(pointDelta),
- "\r\n" ] )
-
- #string = "RESULTS %s %s %s %s %s %s %d\r\n" % (foe, isInstigatedByYou,
- # self.resultToString(winner),
- # self.itemToString( attItem ),
- # self.itemToString( defItem ),
- # self.itemToString( bluffItem ), pointDelta)
- #print string
-
- self.process.stdin.write ( string )
- self.process.stdout.readline() # read and discard (should be "OK")
-
- def __del__(self):
- try:
- self.process.communicate( "BYE\r\n" )
- except Exception, e:
- print "Error in BYE:", self, ":", e
-
- try:
- self.process.kill()
- except:
- None
\ No newline at end of file
+++ /dev/null
-// !$*UTF8*$!
-{
- archiveVersion = 1;
- classes = {
- };
- objectVersion = 45;
- objects = {
-
-/* Begin PBXFileReference section */
- 228D541011DB3CEB00258478 /* PythonSampleAgents.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = PythonSampleAgents.py; sourceTree = "<group>"; };
- 228D541311DB443B00258478 /* CSampleAgents.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = CSampleAgents.py; sourceTree = "<group>"; };
- 22CA010611D9BD51001ECDEF /* bundle-agent.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = "bundle-agent.sh"; path = "link/bundle-agent.sh"; sourceTree = "<group>"; };
- 22CA010711D9C52B001ECDEF /* cAgent.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; name = cAgent.py; path = link/cAgent.py; sourceTree = "<group>"; };
- 22CAFEEB11D84076001ECDEF /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
- 22CAFEEC11D84076001ECDEF /* rpsconst.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = rpsconst.py; sourceTree = "<group>"; };
- 22CAFEED11D84076001ECDEF /* SampleAgents.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = SampleAgents.py; sourceTree = "<group>"; };
- 22CAFEEE11D84076001ECDEF /* selectAlgorithms.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = selectAlgorithms.py; sourceTree = "<group>"; };
- 22CAFEEF11D84076001ECDEF /* simulate.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = simulate.py; sourceTree = "<group>"; };
- 22CAFEF011D84076001ECDEF /* uccProgComp.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = uccProgComp.py; sourceTree = "<group>"; };
- 22CAFF7B11D840E3001ECDEF /* __init__.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; name = __init__.py; path = link/__init__.py; sourceTree = "<group>"; };
- 22CAFF7C11D840E3001ECDEF /* externAgent.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; name = externAgent.py; path = link/externAgent.py; sourceTree = "<group>"; };
- 22DB7DF31223BAF700E04CAB /* conf.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = conf.py; sourceTree = "<group>"; };
-/* End PBXFileReference section */
-
-/* Begin PBXGroup section */
- 08FB7794FE84155DC02AAC07 /* progcomp */ = {
- isa = PBXGroup;
- children = (
- 22CAFF7711D840CB001ECDEF /* link */,
- 22CAFEEB11D84076001ECDEF /* README */,
- 22CAFEEC11D84076001ECDEF /* rpsconst.py */,
- 22CAFEED11D84076001ECDEF /* SampleAgents.py */,
- 22DB7DF31223BAF700E04CAB /* conf.py */,
- 22CAFEEE11D84076001ECDEF /* selectAlgorithms.py */,
- 22CAFEEF11D84076001ECDEF /* simulate.py */,
- 22CAFEF011D84076001ECDEF /* uccProgComp.py */,
- 228D540F11DB3CEB00258478 /* arenas */,
- );
- name = progcomp;
- sourceTree = "<group>";
- };
- 228D540F11DB3CEB00258478 /* arenas */ = {
- isa = PBXGroup;
- children = (
- 228D541011DB3CEB00258478 /* PythonSampleAgents.py */,
- 228D541311DB443B00258478 /* CSampleAgents.py */,
- );
- path = arenas;
- sourceTree = "<group>";
- };
- 22CAFF7711D840CB001ECDEF /* link */ = {
- isa = PBXGroup;
- children = (
- 22CA010711D9C52B001ECDEF /* cAgent.py */,
- 22CAFF7B11D840E3001ECDEF /* __init__.py */,
- 22CAFF7C11D840E3001ECDEF /* externAgent.py */,
- 22CA010611D9BD51001ECDEF /* bundle-agent.sh */,
- );
- name = link;
- sourceTree = "<group>";
- };
-/* End PBXGroup section */
-
-/* Begin PBXLegacyTarget section */
- D28A88AD04BDD90700651E21 /* progcomp */ = {
- isa = PBXLegacyTarget;
- buildArgumentsString = "$(ACTION)";
- buildConfigurationList = 1DEB918F08733D9F0010E9CD /* Build configuration list for PBXLegacyTarget "progcomp" */;
- buildPhases = (
- );
- buildToolPath = /usr/bin/make;
- dependencies = (
- );
- name = progcomp;
- passBuildSettingsInEnvironment = 1;
- productName = progcomp;
- };
-/* End PBXLegacyTarget section */
-
-/* Begin PBXProject section */
- 08FB7793FE84155DC02AAC07 /* Project object */ = {
- isa = PBXProject;
- buildConfigurationList = 1DEB919308733D9F0010E9CD /* Build configuration list for PBXProject "progcomp" */;
- compatibilityVersion = "Xcode 3.1";
- hasScannedForEncodings = 1;
- mainGroup = 08FB7794FE84155DC02AAC07 /* progcomp */;
- projectDirPath = "";
- projectRoot = "";
- targets = (
- D28A88AD04BDD90700651E21 /* progcomp */,
- );
- };
-/* End PBXProject section */
-
-/* Begin XCBuildConfiguration section */
- 1DEB919008733D9F0010E9CD /* Debug */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- COPY_PHASE_STRIP = NO;
- DEBUGGING_SYMBOLS = YES;
- GCC_DYNAMIC_NO_PIC = NO;
- GCC_ENABLE_FIX_AND_CONTINUE = YES;
- GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
- GCC_OPTIMIZATION_LEVEL = 0;
- OTHER_CFLAGS = "";
- OTHER_LDFLAGS = "";
- PRODUCT_NAME = progcomp;
- };
- name = Debug;
- };
- 1DEB919108733D9F0010E9CD /* Release */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- COPY_PHASE_STRIP = YES;
- GCC_ENABLE_FIX_AND_CONTINUE = NO;
- OTHER_CFLAGS = "";
- OTHER_LDFLAGS = "";
- PRODUCT_NAME = progcomp;
- };
- name = Release;
- };
- 1DEB919408733D9F0010E9CD /* Debug */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- GCC_WARN_ABOUT_RETURN_TYPE = YES;
- GCC_WARN_UNUSED_VARIABLE = YES;
- ONLY_ACTIVE_ARCH = YES;
- PREBINDING = NO;
- SDKROOT = macosx10.6;
- };
- name = Debug;
- };
- 1DEB919508733D9F0010E9CD /* Release */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- GCC_WARN_ABOUT_RETURN_TYPE = YES;
- GCC_WARN_UNUSED_VARIABLE = YES;
- PREBINDING = NO;
- SDKROOT = macosx10.6;
- };
- name = Release;
- };
-/* End XCBuildConfiguration section */
-
-/* Begin XCConfigurationList section */
- 1DEB918F08733D9F0010E9CD /* Build configuration list for PBXLegacyTarget "progcomp" */ = {
- isa = XCConfigurationList;
- buildConfigurations = (
- 1DEB919008733D9F0010E9CD /* Debug */,
- 1DEB919108733D9F0010E9CD /* Release */,
- );
- defaultConfigurationIsVisible = 0;
- defaultConfigurationName = Release;
- };
- 1DEB919308733D9F0010E9CD /* Build configuration list for PBXProject "progcomp" */ = {
- isa = XCConfigurationList;
- buildConfigurations = (
- 1DEB919408733D9F0010E9CD /* Debug */,
- 1DEB919508733D9F0010E9CD /* Release */,
- );
- defaultConfigurationIsVisible = 0;
- defaultConfigurationName = Release;
- };
-/* End XCConfigurationList section */
- };
- rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
-}