More work on C sample agents. Learning agents are a pain.
authorDaniel Axtens <[email protected]>
Thu, 22 Apr 2010 16:54:45 +0000 (00:54 +0800)
committerDaniel Axtens <[email protected]>
Thu, 22 Apr 2010 16:54:45 +0000 (00:54 +0800)
link/C/c-link-lib/Makefile
link/C/c-link-lib/agents/c-angel.c
link/C/c-link-lib/agents/c-lucifer.c
link/C/c-link-lib/agents/c-streetfighter.c
link/C/c-link-lib/c-link-lib.xcodeproj/project.pbxproj
link/C/c-link-lib/c_link.c
link/C/c-link-lib/c_link.h

index c10ef62..10e306b 100644 (file)
@@ -11,8 +11,6 @@ LINKLIB=libc_link.a
 AGENTSRCS=$(wildcard agents/*.c)
 AGENTS=$(AGENTSRCS:.c=)
 
-EXECUTABLE=rps-c
-
 all: $(LINKSRCS) $(LINKLIB) $(AGENTS)
        
 $(LINKLIB): $(LINKOBJS)
@@ -27,4 +25,4 @@ $(AGENTS): $(AGENTSRCS)
 
 .PHONY : clean
 clean:
-       rm $(LINKOBJS) $(LINKLIB) $(AGENTS)
\ No newline at end of file
+       rm $(LINKOBJS) $(LINKLIB) $(AGENTS)
index c628ade..c6c8687 100644 (file)
@@ -31,4 +31,10 @@ void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem,
                         ITEMTYPE theirItem, ITEMTYPE promisedItem) {
        
        return; /* Ignore whatever just happened. */
+}
+
+/* same for Cleanup() */
+
+void Cleanup() {
+       return;
 }
\ No newline at end of file
index adfb2ba..1dabc34 100644 (file)
@@ -57,4 +57,10 @@ void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem,
                         ITEMTYPE theirItem, ITEMTYPE promisedItem) {
        
        return; /* Ignore whatever just happened. */
+}
+
+/* same for Cleanup() */
+
+void Cleanup() {
+       return;
 }
\ No newline at end of file
index 9a1d6ce..c63939d 100644 (file)
@@ -17,35 +17,33 @@ ATTACKTYPE Attack( char * foe_name ) {
        
        attack.realAttack =  RandomAttack();
        
-       /* Here we choose the thing that will hurt them if they go for a tie */
+       /* Here we choose the thing that will hurt them if they go for the kill */
        switch (attack.realAttack) {
                case rock:
                        result.promisedAttack = paper;
                        break;
                case paper:
-                       result.promisedAttack = rock;
+                       result.promisedAttack = scissors;
                        break;
                default: /* attack = scissors */
-                       result.promisedAttack = paper;
+                       result.promisedAttack = rock;
                        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. */
+/* 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 = paper;
+                       defence = scissors;
                        break;
                case paper:
-                       defence = scissors;
+                       defence = rock;
                        break;
                default:
-                       defence = rock;
+                       defence = paper;
                        break;
        }
 }
@@ -57,3 +55,9 @@ void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem,
        
        return; /* Ignore whatever just happened. */
 }
+
+/* same for Cleanup() */
+
+void Cleanup() {
+       return;
+}
index 467b386..80d9803 100644 (file)
@@ -11,6 +11,7 @@
                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>"; };
+               2291A1EC117FF85D00854CBE /* c-frechie.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "c-frechie.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 */
@@ -33,6 +34,7 @@
                                2291A1BD117EE3FD00854CBE /* c-angel.c */,
                                2291A1BE117EE3FD00854CBE /* c-lucifer.c */,
                                2291A1BF117EE3FD00854CBE /* c-streetfighter.c */,
+                               2291A1EC117FF85D00854CBE /* c-frechie.c */,
                        );
                        path = agents;
                        sourceTree = "<group>";
index e75997f..680450e 100644 (file)
 #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>
+   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, lose, win },
+                              { win, tie, lose },
+                              { lose, win, tie } };
+
 
 ITEMTYPE RandomAttack() {
        return (ITEMTYPE)rand()%3;
@@ -73,5 +81,7 @@ int main( int argc, char * argv[] ) {
                scanf( "%s", command );
        }
        
+       Cleanup();
+       
        return 0;
 }
\ No newline at end of file
index 08cdb63..84e9bce 100644 (file)
@@ -7,6 +7,8 @@
  *
  */
 
+#include <stdio.h>
+
 #define MAXCOMMANDLEN  15
 #define MAXFOENAMELEN  50
 #define MAXITEMLEN             10
@@ -17,6 +19,9 @@
 /* The type of item used in an attack or defence */
 typedef enum {rock, paper, scissors} ITEMTYPE;
 
+/* A result of a battle */
+typedef enum {win, lose, tie} RESULTTYPE;
+
 
 /* An attack, consisting of the real attack and the attack promised */
 typedef struct {
@@ -28,6 +33,13 @@ typedef struct {
 /********** 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...) sprintf(stderr, x)
+
 /* Returns a random item */
 
 ITEMTYPE RandomAttack();
@@ -37,6 +49,10 @@ ITEMTYPE RandomAttack();
 
 extern char ITEMNAMES[3][MAXITEMLEN];
 
+/* Another useful table - what's the result of the 
+   first item vs the second item? */
+extern RESULTTYPE RESULTOF[3][3];
+
 /********** Bot Function definitions **********/
 /* You need to provide implementations for these to create a bot */
 
@@ -70,4 +86,12 @@ ATTACKTYPE Attack( char * foeName );
  
  */
 void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem, 
-                         ITEMTYPE theirItem, ITEMTYPE promisedItem);
\ No newline at end of file
+                         ITEMTYPE theirItem, ITEMTYPE promisedItem);
+
+/* 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

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