-/*
- * 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
+/*\r
+ * c_angel.c\r
+ * c-link-lib\r
+ *\r
+ * Created by Daniel Axtens on 20/04/10.\r
+ * Licensed under an MIT-style license: see the LICENSE file for details.\r
+ *\r
+ */\r
+\r
+#include <c_link.h>\r
+\r
+void * Initialise( char * me ) {\r
+ return NULL;\r
+}\r
+\r
+/* Implement the angel bot, which always tells the truth\r
+ and expects others to do the same */\r
+\r
+ATTACKTYPE Attack( void * this, char * foe_name ) {\r
+ ATTACKTYPE attack;\r
+ \r
+ attack.realAttack = RandomAttack(); /* Chooses randomly from Rock, Paper, Scissors */ \r
+ attack.promisedAttack = attack.realAttack; /* Tells the truth for its bluff */\r
+\r
+ return attack;\r
+}\r
+\r
+ITEMTYPE Defend( void * this, char * foeName, ITEMTYPE foePromisedAttack ) {\r
+ return foePromisedAttack; /* Trusts them to be going for a tie */\r
+}\r
+\r
+/* You need to define a results function, even if it isn't used\r
+ (otherwise the linker will complain) */\r
+void Results( void * this, char * foeName, int isInstigatedByYou, RESULTTYPE winner,\r
+ ITEMTYPE attItem, ITEMTYPE defItem, ITEMTYPE bluffItem,\r
+ int pointDelta ) {\r
+ \r
+ return; /* Ignore whatever just happened. */\r
+}\r
+\r
+/* same for Cleanup() */\r
+\r
+void Cleanup( void * this ) {\r
+ return;\r
+}\r
-/*
- * 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
+/*\r
+ * c_lucifer.c\r
+ * c-link-lib\r
+ *\r
+ * Created by Daniel Axtens on 20/04/10.\r
+ * Licensed under an MIT-style license: see the LICENSE file for details.\r
+ *\r
+ */\r
+\r
+\r
+#include <c_link.h>\r
+\r
+/* Implement the lucifer bot, which always lies expecting people to be good\r
+ and always goes for the kill */\r
+\r
+void * Initialise( char * myName ) {\r
+ return NULL;\r
+}\r
+\r
+ATTACKTYPE Attack( void * this, char * foe_name ) {\r
+ ATTACKTYPE attack;\r
+ \r
+ attack.realAttack = RandomAttack();\r
+ \r
+ /* Here we choose the thing that will hurt them if they go for a tie */\r
+ switch (attack.realAttack) {\r
+ case rock:\r
+ attack.promisedAttack = scissors;\r
+ break;\r
+ case paper:\r
+ attack.promisedAttack = rock;\r
+ break;\r
+ default: /* attack = scissors */\r
+ attack.promisedAttack = paper;\r
+ break;\r
+ }\r
+ \r
+ return attack;\r
+}\r
+\r
+/* Here we trust that they are telling the truth. And we try to kill them. */\r
+ITEMTYPE Defend( void * this, char * foeName, ITEMTYPE foePromisedAttack ) {\r
+ ITEMTYPE defence;\r
+ switch (foePromisedAttack) {\r
+ case rock:\r
+ defence = paper;\r
+ break;\r
+ case paper:\r
+ defence = scissors;\r
+ break;\r
+ default:\r
+ defence = rock;\r
+ break;\r
+ }\r
+ return defence;\r
+}\r
+\r
+/* You need to define a results function, even if it isn't used\r
+ (otherwise the linker will complain) */\r
+void Results( void * this, char * foeName, int isInstigatedByYou, RESULTTYPE winner,\r
+ ITEMTYPE attItem, ITEMTYPE defItem, ITEMTYPE bluffItem,\r
+ int pointDelta ) {\r
+ \r
+ return; /* Ignore whatever just happened. */\r
+}\r
+\r
+/* same for Cleanup() */\r
+\r
+void Cleanup( void * this ) {\r
+ return;\r
+}\r
-/*
- * 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;
-}
+/*\r
+ * c_streetfighter.c\r
+ * c-link-lib\r
+ *\r
+ * Created by Daniel Axtens on 20/04/10.\r
+ * Licensed under an MIT-style license: see the LICENSE file for details.\r
+ *\r
+ */\r
+\r
+\r
+#include <c_link.h>\r
+\r
+/* Implement the streetfighter bot, which thinks everyone has it in for him. */\r
+\r
+void * Initialise( char * myName ) {\r
+ return NULL;\r
+}\r
+\r
+ATTACKTYPE Attack( void * this, char * foe_name ) {\r
+ ATTACKTYPE attack;\r
+ \r
+ attack.realAttack = RandomAttack();\r
+ \r
+ /* Here we choose the thing that will hurt them if they go for the kill */\r
+ switch (attack.realAttack) {\r
+ case rock:\r
+ attack.promisedAttack = paper;\r
+ break;\r
+ case paper:\r
+ attack.promisedAttack = scissors;\r
+ break;\r
+ default: /* attack = scissors */\r
+ attack.promisedAttack = rock;\r
+ break;\r
+ }\r
+ return attack;\r
+}\r
+\r
+/* Here we assume they are lying, trying to kill us. And we try to kill them. */\r
+ITEMTYPE Defend( void * this, char * foeName, ITEMTYPE foePromisedAttack ) {\r
+ ITEMTYPE defence;\r
+ switch (foePromisedAttack) {\r
+ case rock:\r
+ defence = scissors;\r
+ break;\r
+ case paper:\r
+ defence = rock;\r
+ break;\r
+ default:\r
+ defence = paper;\r
+ break;\r
+ }\r
+ return defence;\r
+}\r
+\r
+/* You need to define a results function, even if it isn't used\r
+ (otherwise the linker will complain) */\r
+void Results( void * this, char * foeName, int isInstigatedByYou, RESULTTYPE winner,\r
+ ITEMTYPE attItem, ITEMTYPE defItem, ITEMTYPE bluffItem,\r
+ int pointDelta ) {\r
+ \r
+ return; /* Ignore whatever just happened. */\r
+}\r
+\r
+/* same for Cleanup() */\r
+\r
+void Cleanup( void * this ) {\r
+ return;\r
+}\r
--- /dev/null
+/*
+ * c_frechie.c
+ * c-link-lib
+ *
+ * Created by Daniel Axtens on 22/04/10.
+ * Licensed under an MIT-style license: see the LICENSE file for details.
+ *
+ */
+
+#include <c_link.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Implement the wash agent, that is by default nice but will
+ permanently turn against any agent that betrays it.
+ This is trickier in C than in any other language, for a number of reasons:
+ - there's no classes in C, so we can't just write a generic learning agent
+ and subclass it.
+ - your agent has no idea how many agents it's going to battle, or how many
+ battles it is going to fight, so you've got to do dynamic memory allocation.
+ (anyone who tries to read the source of the supervisor to find out is liable
+ to have their program break unexpectedly)
+ */
+
+/* To simplify things, we just look at whether we have lost to a particular agent.
+ Unlike in the Python version, we don't keep a generic list
+ This is also done in a inefficient (O(bot-cout)) way.
+ Implementing a faster version is left as an exercise to the DSA student. */
+
+/* Our guess at the number of agents I'm going to fight in my lifetime
+ (note that this is only a guess, not an upper limit. Do *not* take it as
+ gospel on the number of agents you're going to see. */
+#define NUMBEROFAGENTSGUESS 100
+
+/* data for each instance of my agent */
+typedef struct {
+ /* The name of the n-th foe who has beaten us */
+ char (*defeatingFoes)[MAXFOENAMELEN];
+
+ /* The length of the array, and how far we are along it */
+ size_t foesLen;
+ unsigned int foesCount;
+} wash_data;
+
+
+/* an internal function - have I lost to a given foe? */
+int haveLostTo( wash_data * me, char * foeName ) {
+
+ int foe;
+
+ /* check every foe we know to have defeated us */
+ for (foe=0; foe<me->foesCount; foe++) {
+ if (strncmp( me->defeatingFoes[foe], foeName, MAXFOENAMELEN) == 0) {
+ //debugmsg( "%d\thaveLostTo( %s ) -> Yes\n", me, foeName );
+ return 1;
+ }
+ }
+
+ /* this foe not found */
+ return 0;
+}
+
+/* set up myself */
+void * Initialise( char * myName ) {
+ wash_data * me = malloc( sizeof( wash_data ) );
+
+ me->defeatingFoes = calloc( NUMBEROFAGENTSGUESS, sizeof( MAXFOENAMELEN*sizeof(char) ) );
+ me->foesLen = NUMBEROFAGENTSGUESS;
+ me->foesCount = 0;
+
+ return (void *) me;
+}
+
+/* Attack */
+ATTACKTYPE Attack( void * this, char * foeName ) {
+ wash_data * me = (wash_data *)this;
+
+ ATTACKTYPE attack;
+
+ attack.realAttack = RandomAttack();
+
+ /* have I lost to this foe? */
+ if ( haveLostTo(me, foeName) ) {
+ /* Assume they are lying */
+ switch (attack.realAttack) {
+ case rock:
+ attack.promisedAttack = scissors;
+ break;
+ case paper:
+ attack.promisedAttack = rock;
+ break;
+ default: /* attack = scissors */
+ attack.promisedAttack = paper;
+ break;
+ }
+ } else {
+ /* be nice! */
+ attack.promisedAttack = attack.realAttack;
+ }
+
+
+ return attack;
+}
+
+/* defend */
+ITEMTYPE Defend( void * this, char * foeName, ITEMTYPE foePromisedAttack ) {
+ wash_data * me = (wash_data *)this;
+
+ ITEMTYPE defence;
+
+ if (haveLostTo(me, foeName)) {
+ /* They've screwed us in the past, assume they're lying and go for the
+ kill. */
+ switch (foePromisedAttack) {
+ case rock:
+ defence = scissors;
+ break;
+ case paper:
+ defence = rock;
+ break;
+ default:
+ defence = paper;
+ break;
+ }
+ } else {
+ /* be nice! */
+ defence = foePromisedAttack;
+ }
+
+ return defence;
+}
+
+/* This is so much less fun in C */
+void Results( void * this, char * foeName, int isInstigatedByYou,
+ RESULTTYPE winner, ITEMTYPE attItem, ITEMTYPE defItem,
+ ITEMTYPE bluffItem, int pointDelta ) {
+
+ wash_data * me = (wash_data *)this;
+
+ int foe;
+
+ /* figure out if we lost, which is the only thing we care about
+ if we didn't, move on. */
+ if ((winner == tie) ||
+ (winner==attacker && isInstigatedByYou) ||
+ (winner==defender && !isInstigatedByYou) ) return;
+
+ //fprintf( stderr, "%d\tsaving loss from %s\n", me, foeName );
+
+ /* if we've already lost the foe, don't store again */
+ for (foe=0; foe<me->foesCount; foe++) {
+ if (strncmp( me->defeatingFoes[foe], foeName, MAXFOENAMELEN ) == 0) {
+ /* we've found it! */
+ return;
+ }
+ }
+
+ /* we haven't found the foe. add it, expanding the array if needed */
+ if (me->foesCount==me->foesLen) {
+ /* double the array size. This should error check, but doesn't */
+ me->defeatingFoes = realloc( me->defeatingFoes,
+ me->foesLen*2*sizeof( MAXFOENAMELEN*sizeof(char) ) );
+ me->foesLen *= 2;
+ }
+
+ strncpy( me->defeatingFoes[me->foesCount], foeName, MAXFOENAMELEN );
+ me->foesCount++;
+
+ return;
+}
+
+/* Cleanup */
+void Cleanup( void * this ) {
+ wash_data * me = (wash_data *) this;
+ free(me->defeatingFoes);
+ free(me);
+}
\ No newline at end of file
-/*
- * 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
+/*\r
+ * c_link.c\r
+ * c-link-lib\r
+ *\r
+ * Created by Daniel Axtens on 19/04/10.\r
+ * Licensed under an MIT-style license: see the LICENSE file for details.\r
+ *\r
+ */\r
+\r
+#include "c_link.h"\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <stdio.h>\r
+#include <time.h>\r
+\r
+/* You don't need to read this file.\r
+ All you have to do is implement the bot functions defined in <c_link.h>\r
+ This file sets up the I/O for you, as well as some utility functions and tables. \r
+ */\r
+\r
+char ITEMNAMES[3][MAXITEMLEN] = {"Rock", "Paper", "Scissors"};\r
+\r
+/* rock-rock rock-paper rock-scissors \r
+ paper-rock paper-paper paper-scissors\r
+ scissors-rock scissors-paper scissors-scissors */ \r
+ \r
+RESULTTYPE RESULTOF[3][3] = { { tie, defender, attacker },\r
+ { attacker, tie, defender },\r
+ { defender, attacker, tie } };\r
+\r
+ITEMTYPE RandomAttack() {\r
+ return (ITEMTYPE)rand()%3;\r
+}\r
+\r
+ITEMTYPE stringToItem( char * str ) {\r
+ if (strcasecmp( str, "Rock" ) == 0) return rock;\r
+ if (strcasecmp( str, "Paper" ) == 0) return paper;\r
+ if (strcasecmp( str, "Scissors" ) == 0) return scissors;\r
+ /* If we reach this point, we've got real problems. */\r
+ fprintf( stderr, "Attempt to convert invalid string \"%s\" into an ITEMTYPE! Aborting.\n", str );\r
+ exit(EXIT_FAILURE);\r
+ return -1;\r
+}\r
+ \r
+\r
+RESULTTYPE stringToResult( char * str ) {\r
+ if (strcasecmp( str, "Attacker" ) == 0) return attacker;\r
+ if (strcasecmp( str, "Defender" ) == 0) return defender;\r
+ if (strcasecmp( str, "Tie" ) == 0) return tie;\r
+ /* If we reach this point, we've got real problems. */\r
+ fprintf( stderr, "Attempt to convert invalid string \"%s\" into an ITEMTYPE! Aborting.\n", str );\r
+ exit(EXIT_FAILURE);\r
+ return -1;\r
+}\r
+\r
+int main( int argc, char * argv[] ) {\r
+ srand( time( NULL ) );\r
+ \r
+ char command[MAXCOMMANDLEN];\r
+ char foeName[MAXFOENAMELEN];\r
+ char attItem[MAXITEMLEN], defItem[MAXITEMLEN], bluffItem[MAXITEMLEN];\r
+ char didYouInstigate[MAXBOOLLEN];\r
+ char winner[MAXRESULTLEN];\r
+ int pointChange;\r
+ void *thisInstance;\r
+\r
+ ATTACKTYPE attack;\r
+ ITEMTYPE defence;\r
+ \r
+ /* generate a random id for this bot. Hopefully it's unique\r
+ I can't use the UUID, because python doesn't pass it to me! */\r
+ me = rand();\r
+ \r
+ // TODO: Get the UUID passed by python\r
+ // Currently, just pass an empty string to the initialise function\r
+ thisInstance = Initialise( "" );\r
+ \r
+ scanf( "%s", command );\r
+ \r
+ while (strcasecmp("BYE",command) != 0) {\r
+ \r
+ if (strcasecmp("ATTACK", command) == 0) {\r
+ scanf( "%s", foeName );\r
+ attack = Attack( thisInstance, foeName );\r
+ printf("ATTACKING %s %s\n", ITEMNAMES[attack.realAttack], ITEMNAMES[attack.promisedAttack]);\r
+ \r
+ } else if (strcasecmp("DEFEND", command) == 0) {\r
+ scanf( "%s %s", foeName, bluffItem );\r
+ defence = Defend(thisInstance, foeName, stringToItem(bluffItem));\r
+ printf("DEFENDING %s\n", ITEMNAMES[defence]);\r
+ \r
+ } else if (strcasecmp("RESULTS", command) == 0) {\r
+ /* (foeName, isInstigatedByYou, winner, attItem, defItem, bluffItem, pointDelta) */\r
+ scanf( "%s %s %s %s %s %s %d", foeName, didYouInstigate, winner, attItem, defItem, bluffItem, &pointChange );\r
+ Results(thisInstance, foeName, (strcasecmp("True",didYouInstigate)==0), stringToResult(winner),\r
+ stringToItem(attItem), stringToItem(defItem), stringToItem(bluffItem), pointChange);\r
+ printf("OK\n");\r
+ }\r
+ \r
+ fflush(stdout);\r
+ fflush(stderr);\r
+ \r
+ // read the next command!\r
+ scanf( "%s", command );\r
+ }\r
+ \r
+ Cleanup(thisInstance);\r
+ \r
+ return 0;\r
+}\r
-/*
- * 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
+/*\r
+ * c_link.h\r
+ * c-link-lib\r
+ *\r
+ * Created by Daniel Axtens on 19/04/10.\r
+ * Licensed under an MIT-style license: see the LICENSE file for details.\r
+ *\r
+ */\r
+\r
+#include <stdio.h>\r
+\r
+#define MAXCOMMANDLEN 15\r
+#define MAXFOENAMELEN 50\r
+#define MAXITEMLEN 10\r
+#define MAXRESULTLEN 10\r
+#define MAXBOOLLEN 6\r
+\r
+/********** Type definitions **********/\r
+\r
+/* The type of item used in an attack or defence */\r
+typedef enum {rock, paper, scissors} ITEMTYPE;\r
+\r
+/* A result of a battle, in terms of who won */\r
+typedef enum {attacker, defender, tie} RESULTTYPE;\r
+\r
+\r
+/* An attack, consisting of the real attack and the attack promised */\r
+typedef struct {\r
+ ITEMTYPE realAttack;\r
+ ITEMTYPE promisedAttack;\r
+} ATTACKTYPE;\r
+\r
+\r
+/********** Utility Function definitions **********/\r
+/* These are implemented in c-link.c, and automagically linked in */\r
+\r
+/* prints a debug message. Same arguments as printf().\r
+ (you can't use printf because it is used to talk between\r
+ the agent and supervisor) \r
+ */\r
+\r
+#define debugmsg(x...) fprintf(stderr, x)\r
+\r
+/* A (hopefully) unique identifier for this particular instance of your agent,\r
+ to help with debugging */\r
+int me;\r
+\r
+\r
+/* Returns a random item */\r
+\r
+ITEMTYPE RandomAttack();\r
+\r
+/* A useful translation table\r
+ eg debugmsg( "I use %s.\n", ITEMNAMES[rock] ); */\r
+\r
+extern char ITEMNAMES[3][MAXITEMLEN];\r
+\r
+/* Another useful table - who's the victor given an \r
+ attacker with first item vs defender with the second item? */\r
+extern RESULTTYPE RESULTOF[3][3];\r
+\r
+/********** Bot Function definitions **********/\r
+/* You need to provide implementations for these to create a bot */\r
+\r
+/* Initialise( yourName : string - name of this instance (you)\r
+ ) : void * - A data pointer to represent this instance\r
+ \r
+ Called to create a new instance of this agent\r
+\r
+ */\r
+void *Initialise( char * yourName );\r
+\r
+/* Defend( this : pointer - value returned from Initialise();\r
+ foeName : string - the name of your foe;\r
+ foePromisedAttack : ITEMTYPE - the item your foe promised to use\r
+ ) : ITEMTYPE - the item you wish to use to defend;\r
+ \r
+ Called when your agent needs to defend itself.\r
+ \r
+ */\r
+ITEMTYPE Defend( void * this, char * foeName, ITEMTYPE foePromisedAttack );\r
+\r
+\r
+/* Attack( this: pointer - value returned from Initialise();\r
+ foeName : string - the name of your foe\r
+ ) : ATTACKTYPE - the real and promised attack you wish to use\r
+\r
+ Called when your agent needs to attack another agent.\r
+ \r
+ */\r
+ATTACKTYPE Attack( void * this, char * foeName );\r
+\r
+\r
+/* Results( this : pointer - value returned from Initialise();\r
+ foeName : string - the name of your foe;\r
+ isInstigatedByYou : 0=you defended/1=you attacked;\r
+ winner : RESULTTYPE - who won\r
+ attItem : ITEMTYPE - the item used to attack;\r
+ defItem : ITEMTYPE - the item used to defend;\r
+ bluffItem : ITEMTYPE - the item that was promised\r
+ pointDelta : integer - how your points were affected.\r
+ );\r
+\r
+ Called after your agent battles another agent, to tell you how the battle goes.\r
+ \r
+ */\r
+void Results( void * this, char * foeName, int isInstigatedByYou, RESULTTYPE winner,\r
+ ITEMTYPE attItem, ITEMTYPE defItem, ITEMTYPE bluffItem,\r
+ int pointDelta );\r
+\r
+/* Cleanup( this: pointer - value returned from Initialise()\r
+ );\r
+\r
+ Called when your agent is no longer needed, either due to the round ending\r
+ or due to your agent being eliminated.\r
+\r
+ */\r
+void Cleanup( void * this );\r