*.mode1v3
*.o
+*.a
# old skool
.svn
+++ /dev/null
-CC=gcc
-CFLAGS=-c -Wall
-LDFLAGS=
-SOURCES=c-link.c
-OBJECTS=$(SOURCES:.c=.o)
-EXECUTABLE=rps-c
-
-all: $(SOURCES) $(EXECUTABLE)
-
-$(EXECUTABLE): $(OBJECTS)
- $(CC) $(LDFLAGS) $(OBJECTS) -o $@
-
-.c.o:
- $(CC) $(CFLAGS) $< -o $@
+++ /dev/null
-// !$*UTF8*$!
-{
- archiveVersion = 1;
- classes = {
- };
- objectVersion = 45;
- objects = {
-
-/* Begin PBXFileReference section */
- 224F59A1117D6473003D9540 /* c-angel.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "c-angel.c"; path = "sample-agents/c-angel.c"; sourceTree = "<group>"; };
- 224F59B9117D6D88003D9540 /* c-lucifer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "c-lucifer.c"; path = "sample-agents/c-lucifer.c"; sourceTree = "<group>"; };
- 224F59BA117D889A003D9540 /* c-streetfighter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "c-streetfighter.c"; path = "sample-agents/c-streetfighter.c"; 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>"; };
- 22F652F7117C6C9500A3793D /* c-link.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "c-link.c"; sourceTree = "<group>"; };
-/* End PBXFileReference section */
-
-/* Begin PBXGroup section */
- 08FB7794FE84155DC02AAC07 /* c-link-lib */ = {
- isa = PBXGroup;
- children = (
- 224F59A3117D64B4003D9540 /* Sample Agents */,
- 22F652F6117C6C9500A3793D /* c-link.h */,
- 22F652F7117C6C9500A3793D /* c-link.c */,
- 22F652F5117C679300A3793D /* Makefile */,
- );
- name = "c-link-lib";
- sourceTree = "<group>";
- };
- 224F59A3117D64B4003D9540 /* Sample Agents */ = {
- isa = PBXGroup;
- children = (
- 224F59B9117D6D88003D9540 /* c-lucifer.c */,
- 224F59BA117D889A003D9540 /* c-streetfighter.c */,
- 224F59A1117D6473003D9540 /* c-angel.c */,
- );
- name = "Sample 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 = "/Users/dja/Documents/dev/progcomp/link/C/Link/c-link-lib";
- 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
-/*
- * 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>
-
-/* If you just want to write a bot, you don't need to read this file.
- This merely sets up the I/O for you, so all you have to do is define the bot
- functions defined in <c-link.h>
-
- The only reason you would care about this info is if you want to use pointChange
- and/or childSpawned parameters from the RESULTS call, which are otherwise discarded.
- */
-
-char ITEMNAMES[3][MAXITEMLEN] = {"Rock", "Paper", "Scissors"};
-
-
-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;
-}
-
-
-int main( int argc, char * argv[] ) {
- srand( time( NULL ) );
-
- char command[MAXCOMMANDLEN];
- char foeName[MAXFOENAMELEN];
- char yourItem[MAXITEMLEN], theirItem[MAXITEMLEN], promisedItem[MAXITEMLEN];
- char didYouInstigate[MAXBOOLLEN], childSpawned[MAXBOOLLEN];
- int pointChange;
-
- ATTACKTYPE attack;
- ITEMTYPE defence;
-
- 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, promisedItem );
- defence = Defend(foeName, stringToItem(promisedItem));
- printf("DEFENDING %s\n", ITEMNAMES[defence]);
-
- } else if (strcasecmp("RESULTS", command) == 0) {
- scanf( "%s %s %s %s %s %d %s", foeName, didYouInstigate, yourItem, theirItem, promisedItem, &pointChange, childSpawned );
- Results(foeName, (strcasecmp("False",didYouInstigate)==0),
- stringToItem(yourItem), stringToItem(theirItem), stringToItem(promisedItem));
- printf("OK\n");
- }
-
- // read the next command!
- scanf( "%s", command );
- }
-
- 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.
- *
- */
-
-#define MAXCOMMANDLEN 15
-#define MAXFOENAMELEN 50
-#define MAXITEMLEN 10
-#define MAXBOOLLEN 6
-
-/********** Type definitions **********/
-
-/* The type of item used in an attack or defence */
-typedef enum {rock, paper, scissors} ITEMTYPE;
-
-
-/* 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 */
-
-/* Returns a random item */
-
-ITEMTYPE RandomAttack();
-
-/* A useful translation table
- eg printf( "I use %s.\n", ITEMNAMES[rock] ); */
-
-extern char ITEMNAMES[3][MAXITEMLEN];
-
-/********** 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;
- yourItem : ITEMTYPE - the item you used;
- theirItem : ITEMTYPE - the item they used;
- promisedItem : ITEMTYPE - the item that was promised
- );
-
- Called after your agent battles another agent, to tell you how the battle goes.
-
- */
-void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem,
- ITEMTYPE theirItem, ITEMTYPE promisedItem);
\ No newline at end of file
+++ /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, ITEMTYPE yourItem,
- ITEMTYPE theirItem, ITEMTYPE promisedItem) {
-
- return; /* Ignore whatever just happened. */
-}
\ 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:
- result.promisedAttack = scissors;
- break;
- case paper:
- result.promisedAttack = rock;
- break;
- default: /* attack = scissors */
- result.promisedAttack = paper;
- break;
- }
- attack.promisedAttack = result.realAttack; /* Tells the truth for its bluff */
-
- 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;
- }
-}
-
-/* You need to define a results function, even if it isn't used
- (otherwise the linker will complain) */
-void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem,
- ITEMTYPE theirItem, ITEMTYPE promisedItem) {
-
- return; /* Ignore whatever just happened. */
-}
\ 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 a tie */
- switch (attack.realAttack) {
- case rock:
- result.promisedAttack = paper;
- break;
- case paper:
- result.promisedAttack = rock;
- break;
- default: /* attack = scissors */
- result.promisedAttack = paper;
- break;
- }
- attack.promisedAttack = result.realAttack; /* Tells the truth for its bluff */
-
- 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;
- }
-}
-
-/* You need to define a results function, even if it isn't used
- (otherwise the linker will complain) */
-void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem,
- ITEMTYPE theirItem, ITEMTYPE promisedItem) {
-
- return; /* Ignore whatever just happened. */
-}
--- /dev/null
+agents/
+!agents/*.c
--- /dev/null
+CC=gcc
+AR=ar
+
+CFLAGS=-Wall -I.
+LDFLAGS=-lc_link -L.
+
+LINKSRCS=c_link.c
+LINKOBJS=$(LINKSRCS:.c=.o)
+LINKLIB=libc_link.a
+
+AGENTSRCS=$(wildcard agents/*.c)
+AGENTS=$(AGENTSRCS:.c=)
+
+EXECUTABLE=rps-c
+
+all: $(LINKSRCS) $(LINKLIB) $(AGENTS)
+
+$(LINKLIB): $(LINKOBJS)
+ $(AR) rcs $(LINKLIB) $(LINKOBJS)
+
+$(AGENTS): $(AGENTSRCS)
+ @echo Building $<
+ $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
+
+.c.o: c_link.h
+ $(CC) -c $(CFLAGS) $< -o $@
+
+.PHONY : clean
+clean:
+ rm $(LINKOBJS) $(LINKLIB) $(AGENTS)
\ No newline at end of file
--- /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, ITEMTYPE yourItem,
+ ITEMTYPE theirItem, ITEMTYPE promisedItem) {
+
+ return; /* Ignore whatever just happened. */
+}
\ 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:
+ result.promisedAttack = scissors;
+ break;
+ case paper:
+ result.promisedAttack = rock;
+ break;
+ default: /* attack = scissors */
+ result.promisedAttack = paper;
+ break;
+ }
+ attack.promisedAttack = result.realAttack; /* Tells the truth for its bluff */
+
+ 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;
+ }
+}
+
+/* You need to define a results function, even if it isn't used
+ (otherwise the linker will complain) */
+void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem,
+ ITEMTYPE theirItem, ITEMTYPE promisedItem) {
+
+ return; /* Ignore whatever just happened. */
+}
\ 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 a tie */
+ switch (attack.realAttack) {
+ case rock:
+ result.promisedAttack = paper;
+ break;
+ case paper:
+ result.promisedAttack = rock;
+ break;
+ default: /* attack = scissors */
+ result.promisedAttack = paper;
+ break;
+ }
+ attack.promisedAttack = result.realAttack; /* Tells the truth for its bluff */
+
+ 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;
+ }
+}
+
+/* You need to define a results function, even if it isn't used
+ (otherwise the linker will complain) */
+void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem,
+ ITEMTYPE theirItem, ITEMTYPE promisedItem) {
+
+ return; /* Ignore whatever just happened. */
+}
--- /dev/null
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 45;
+ objects = {
+
+/* Begin PBXFileReference section */
+ 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>"; };
+ 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 = (
+ 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 */,
+ );
+ 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
+/*
+ * 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.
+ This merely sets up the I/O for you, so all you have to do is define the bot
+ functions defined in <c_link.h>
+ */
+
+char ITEMNAMES[3][MAXITEMLEN] = {"Rock", "Paper", "Scissors"};
+
+
+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;
+}
+
+
+int main( int argc, char * argv[] ) {
+ srand( time( NULL ) );
+
+ char command[MAXCOMMANDLEN];
+ char foeName[MAXFOENAMELEN];
+ char yourItem[MAXITEMLEN], theirItem[MAXITEMLEN], promisedItem[MAXITEMLEN];
+ char didYouInstigate[MAXBOOLLEN], childSpawned[MAXBOOLLEN];
+ int pointChange;
+
+ ATTACKTYPE attack;
+ ITEMTYPE defence;
+
+ 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, promisedItem );
+ defence = Defend(foeName, stringToItem(promisedItem));
+ printf("DEFENDING %s\n", ITEMNAMES[defence]);
+
+ } else if (strcasecmp("RESULTS", command) == 0) {
+ scanf( "%s %s %s %s %s %d %s", foeName, didYouInstigate, yourItem, theirItem, promisedItem, &pointChange, childSpawned );
+ Results(foeName, (strcasecmp("False",didYouInstigate)==0),
+ stringToItem(yourItem), stringToItem(theirItem), stringToItem(promisedItem));
+ printf("OK\n");
+ }
+
+ // read the next command!
+ scanf( "%s", command );
+ }
+
+ 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.
+ *
+ */
+
+#define MAXCOMMANDLEN 15
+#define MAXFOENAMELEN 50
+#define MAXITEMLEN 10
+#define MAXBOOLLEN 6
+
+/********** Type definitions **********/
+
+/* The type of item used in an attack or defence */
+typedef enum {rock, paper, scissors} ITEMTYPE;
+
+
+/* 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 */
+
+/* Returns a random item */
+
+ITEMTYPE RandomAttack();
+
+/* A useful translation table
+ eg printf( "I use %s.\n", ITEMNAMES[rock] ); */
+
+extern char ITEMNAMES[3][MAXITEMLEN];
+
+/********** 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;
+ yourItem : ITEMTYPE - the item you used;
+ theirItem : ITEMTYPE - the item they used;
+ promisedItem : ITEMTYPE - the item that was promised
+ );
+
+ Called after your agent battles another agent, to tell you how the battle goes.
+
+ */
+void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem,
+ ITEMTYPE theirItem, ITEMTYPE promisedItem);
\ No newline at end of file