c-link written
authorDaniel Axtens <[email protected]>
Wed, 21 Apr 2010 08:01:08 +0000 (16:01 +0800)
committerDaniel Axtens <[email protected]>
Wed, 21 Apr 2010 08:01:08 +0000 (16:01 +0800)
17 files changed:
.gitignore
link/C/Link/c-link-lib/Makefile [deleted file]
link/C/Link/c-link-lib/c-link-lib.xcodeproj/project.pbxproj [deleted file]
link/C/Link/c-link-lib/c-link.c [deleted file]
link/C/Link/c-link-lib/c-link.h [deleted file]
link/C/Link/c-link-lib/link.o [deleted file]
link/C/Link/c-link-lib/sample-agents/c-angel.c [deleted file]
link/C/Link/c-link-lib/sample-agents/c-lucifer.c [deleted file]
link/C/Link/c-link-lib/sample-agents/c-streetfighter.c [deleted file]
link/C/c-link-lib/.gitignore [new file with mode: 0644]
link/C/c-link-lib/Makefile [new file with mode: 0644]
link/C/c-link-lib/agents/c-angel.c [new file with mode: 0644]
link/C/c-link-lib/agents/c-lucifer.c [new file with mode: 0644]
link/C/c-link-lib/agents/c-streetfighter.c [new file with mode: 0644]
link/C/c-link-lib/c-link-lib.xcodeproj/project.pbxproj [new file with mode: 0644]
link/C/c-link-lib/c_link.c [new file with mode: 0644]
link/C/c-link-lib/c_link.h [new file with mode: 0644]

index c2668d6..483ef52 100644 (file)
@@ -4,6 +4,7 @@ build/
 *.mode1v3
 
 *.o
+*.a
 
 # old skool
 .svn
diff --git a/link/C/Link/c-link-lib/Makefile b/link/C/Link/c-link-lib/Makefile
deleted file mode 100644 (file)
index 86d085d..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-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 $@
diff --git a/link/C/Link/c-link-lib/c-link-lib.xcodeproj/project.pbxproj b/link/C/Link/c-link-lib/c-link-lib.xcodeproj/project.pbxproj
deleted file mode 100644 (file)
index 97722b7..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-// !$*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 */;
-}
diff --git a/link/C/Link/c-link-lib/c-link.c b/link/C/Link/c-link-lib/c-link.c
deleted file mode 100644 (file)
index 0b8af58..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- *  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
diff --git a/link/C/Link/c-link-lib/c-link.h b/link/C/Link/c-link-lib/c-link.h
deleted file mode 100644 (file)
index a369ea8..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- *  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
diff --git a/link/C/Link/c-link-lib/link.o b/link/C/Link/c-link-lib/link.o
deleted file mode 100644 (file)
index facc4cb..0000000
Binary files a/link/C/Link/c-link-lib/link.o and /dev/null differ
diff --git a/link/C/Link/c-link-lib/sample-agents/c-angel.c b/link/C/Link/c-link-lib/sample-agents/c-angel.c
deleted file mode 100644 (file)
index 1efaa80..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- *  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
diff --git a/link/C/Link/c-link-lib/sample-agents/c-lucifer.c b/link/C/Link/c-link-lib/sample-agents/c-lucifer.c
deleted file mode 100644 (file)
index 2b9da08..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- *  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
diff --git a/link/C/Link/c-link-lib/sample-agents/c-streetfighter.c b/link/C/Link/c-link-lib/sample-agents/c-streetfighter.c
deleted file mode 100644 (file)
index 2841f43..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- *  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. */
-}
diff --git a/link/C/c-link-lib/.gitignore b/link/C/c-link-lib/.gitignore
new file mode 100644 (file)
index 0000000..fbde527
--- /dev/null
@@ -0,0 +1,2 @@
+agents/
+!agents/*.c
diff --git a/link/C/c-link-lib/Makefile b/link/C/c-link-lib/Makefile
new file mode 100644 (file)
index 0000000..c10ef62
--- /dev/null
@@ -0,0 +1,30 @@
+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
diff --git a/link/C/c-link-lib/agents/c-angel.c b/link/C/c-link-lib/agents/c-angel.c
new file mode 100644 (file)
index 0000000..c628ade
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ *  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
diff --git a/link/C/c-link-lib/agents/c-lucifer.c b/link/C/c-link-lib/agents/c-lucifer.c
new file mode 100644 (file)
index 0000000..adfb2ba
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ *  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
diff --git a/link/C/c-link-lib/agents/c-streetfighter.c b/link/C/c-link-lib/agents/c-streetfighter.c
new file mode 100644 (file)
index 0000000..9a1d6ce
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ *  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. */
+}
diff --git a/link/C/c-link-lib/c-link-lib.xcodeproj/project.pbxproj b/link/C/c-link-lib/c-link-lib.xcodeproj/project.pbxproj
new file mode 100644 (file)
index 0000000..467b386
--- /dev/null
@@ -0,0 +1,148 @@
+// !$*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 */;
+}
diff --git a/link/C/c-link-lib/c_link.c b/link/C/c-link-lib/c_link.c
new file mode 100644 (file)
index 0000000..e75997f
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ *  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
diff --git a/link/C/c-link-lib/c_link.h b/link/C/c-link-lib/c_link.h
new file mode 100644 (file)
index 0000000..08cdb63
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ *  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

UCC git Repository :: git.ucc.asn.au