AGENTSRCS=$(wildcard agents/*.c)
AGENTS=$(AGENTSRCS:.c=)
-EXECUTABLE=rps-c
-
all: $(LINKSRCS) $(LINKLIB) $(AGENTS)
$(LINKLIB): $(LINKOBJS)
.PHONY : clean
clean:
- rm $(LINKOBJS) $(LINKLIB) $(AGENTS)
\ No newline at end of file
+ rm $(LINKOBJS) $(LINKLIB) $(AGENTS)
ITEMTYPE theirItem, ITEMTYPE promisedItem) {
return; /* Ignore whatever just happened. */
+}
+
+/* same for Cleanup() */
+
+void Cleanup() {
+ return;
}
\ No newline at end of file
ITEMTYPE theirItem, ITEMTYPE promisedItem) {
return; /* Ignore whatever just happened. */
+}
+
+/* same for Cleanup() */
+
+void Cleanup() {
+ return;
}
\ No newline at end of file
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;
}
}
return; /* Ignore whatever just happened. */
}
+
+/* same for Cleanup() */
+
+void Cleanup() {
+ return;
+}
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 */
2291A1BD117EE3FD00854CBE /* c-angel.c */,
2291A1BE117EE3FD00854CBE /* c-lucifer.c */,
2291A1BF117EE3FD00854CBE /* c-streetfighter.c */,
+ 2291A1EC117FF85D00854CBE /* c-frechie.c */,
);
path = agents;
sourceTree = "<group>";
#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;
scanf( "%s", command );
}
+ Cleanup();
+
return 0;
}
\ No newline at end of file
*
*/
+#include <stdio.h>
+
#define MAXCOMMANDLEN 15
#define MAXFOENAMELEN 50
#define MAXITEMLEN 10
/* 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 {
/********** 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();
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 */
*/
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