git.ucc.asn.au
/
progcomp10.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
1740df9
)
More work on C sample agents. Learning agents are a pain.
author
Daniel Axtens
<
[email protected]
>
Thu, 22 Apr 2010 16:54:45 +0000
(
00:54
+0800)
committer
Daniel Axtens
<
[email protected]
>
Thu, 22 Apr 2010 16:54:45 +0000
(
00:54
+0800)
link/C/c-link-lib/Makefile
patch
|
blob
|
history
link/C/c-link-lib/agents/c-angel.c
patch
|
blob
|
history
link/C/c-link-lib/agents/c-lucifer.c
patch
|
blob
|
history
link/C/c-link-lib/agents/c-streetfighter.c
patch
|
blob
|
history
link/C/c-link-lib/c-link-lib.xcodeproj/project.pbxproj
patch
|
blob
|
history
link/C/c-link-lib/c_link.c
patch
|
blob
|
history
link/C/c-link-lib/c_link.h
patch
|
blob
|
history
diff --git
a/link/C/c-link-lib/Makefile
b/link/C/c-link-lib/Makefile
index
c10ef62
..
10e306b
100644
(file)
--- a/
link/C/c-link-lib/Makefile
+++ b/
link/C/c-link-lib/Makefile
@@
-11,8
+11,6
@@
LINKLIB=libc_link.a
AGENTSRCS=$(wildcard agents/*.c)
AGENTS=$(AGENTSRCS:.c=)
AGENTSRCS=$(wildcard agents/*.c)
AGENTS=$(AGENTSRCS:.c=)
-EXECUTABLE=rps-c
-
all: $(LINKSRCS) $(LINKLIB) $(AGENTS)
$(LINKLIB): $(LINKOBJS)
all: $(LINKSRCS) $(LINKLIB) $(AGENTS)
$(LINKLIB): $(LINKOBJS)
@@
-27,4
+25,4
@@
$(AGENTS): $(AGENTSRCS)
.PHONY : clean
clean:
.PHONY : clean
clean:
- rm $(LINKOBJS) $(LINKLIB) $(AGENTS)
\ No newline at end of file
+ rm $(LINKOBJS) $(LINKLIB) $(AGENTS)
diff --git
a/link/C/c-link-lib/agents/c-angel.c
b/link/C/c-link-lib/agents/c-angel.c
index
c628ade
..
c6c8687
100644
(file)
--- a/
link/C/c-link-lib/agents/c-angel.c
+++ b/
link/C/c-link-lib/agents/c-angel.c
@@
-31,4
+31,10
@@
void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem,
ITEMTYPE theirItem, ITEMTYPE promisedItem) {
return; /* Ignore whatever just happened. */
ITEMTYPE theirItem, ITEMTYPE promisedItem) {
return; /* Ignore whatever just happened. */
+}
+
+/* same for Cleanup() */
+
+void Cleanup() {
+ return;
}
\ No newline at end of file
}
\ 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
index
adfb2ba
..
1dabc34
100644
(file)
--- a/
link/C/c-link-lib/agents/c-lucifer.c
+++ b/
link/C/c-link-lib/agents/c-lucifer.c
@@
-57,4
+57,10
@@
void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem,
ITEMTYPE theirItem, ITEMTYPE promisedItem) {
return; /* Ignore whatever just happened. */
ITEMTYPE theirItem, ITEMTYPE promisedItem) {
return; /* Ignore whatever just happened. */
+}
+
+/* same for Cleanup() */
+
+void Cleanup() {
+ return;
}
\ No newline at end of file
}
\ 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
index
9a1d6ce
..
c63939d
100644
(file)
--- a/
link/C/c-link-lib/agents/c-streetfighter.c
+++ b/
link/C/c-link-lib/agents/c-streetfighter.c
@@
-17,35
+17,33
@@
ATTACKTYPE Attack( char * foe_name ) {
attack.realAttack = RandomAttack();
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:
switch (attack.realAttack) {
case rock:
result.promisedAttack = paper;
break;
case paper:
- result.promisedAttack =
rock
;
+ result.promisedAttack =
scissors
;
break;
default: /* attack = scissors */
break;
default: /* attack = scissors */
- result.promisedAttack =
paper
;
+ result.promisedAttack =
rock
;
break;
}
break;
}
- attack.promisedAttack = result.realAttack; /* Tells the truth for its bluff */
-
return attack;
}
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:
ITEMTYPE Defend( char * foeName, ITEMTYPE foePromisedAttack ) {
ITEMTYPE defence;
switch (foePromisedAttack) {
case rock:
- defence =
paper
;
+ defence =
scissors
;
break;
case paper:
break;
case paper:
- defence =
scissors
;
+ defence =
rock
;
break;
default:
break;
default:
- defence =
rock
;
+ defence =
paper
;
break;
}
}
break;
}
}
@@
-57,3
+55,9
@@
void Results( char * foeName, int isInstigatedByYou, ITEMTYPE yourItem,
return; /* Ignore whatever just happened. */
}
return; /* Ignore whatever just happened. */
}
+
+/* same for Cleanup() */
+
+void Cleanup() {
+ return;
+}
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
index
467b386
..
80d9803
100644
(file)
--- a/
link/C/c-link-lib/c-link-lib.xcodeproj/project.pbxproj
+++ b/
link/C/c-link-lib/c-link-lib.xcodeproj/project.pbxproj
@@
-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>"; };
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 */
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 */,
2291A1BD117EE3FD00854CBE /* c-angel.c */,
2291A1BE117EE3FD00854CBE /* c-lucifer.c */,
2291A1BF117EE3FD00854CBE /* c-streetfighter.c */,
+ 2291A1EC117FF85D00854CBE /* c-frechie.c */,
);
path = agents;
sourceTree = "<group>";
);
path = agents;
sourceTree = "<group>";
diff --git
a/link/C/c-link-lib/c_link.c
b/link/C/c-link-lib/c_link.c
index
e75997f
..
680450e
100644
(file)
--- a/
link/C/c-link-lib/c_link.c
+++ b/
link/C/c-link-lib/c_link.c
@@
-14,12
+14,20
@@
#include <time.h>
/* You don't need to read this 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"};
*/
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;
ITEMTYPE RandomAttack() {
return (ITEMTYPE)rand()%3;
@@
-73,5
+81,7
@@
int main( int argc, char * argv[] ) {
scanf( "%s", command );
}
scanf( "%s", command );
}
+ Cleanup();
+
return 0;
}
\ No newline at end of file
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
index
08cdb63
..
84e9bce
100644
(file)
--- a/
link/C/c-link-lib/c_link.h
+++ b/
link/C/c-link-lib/c_link.h
@@
-7,6
+7,8
@@
*
*/
*
*/
+#include <stdio.h>
+
#define MAXCOMMANDLEN 15
#define MAXFOENAMELEN 50
#define MAXITEMLEN 10
#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;
/* 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 {
/* 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 */
/********** 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();
/* Returns a random item */
ITEMTYPE RandomAttack();
@@
-37,6
+49,10
@@
ITEMTYPE RandomAttack();
extern char ITEMNAMES[3][MAXITEMLEN];
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 */
/********** 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,
*/
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