5 * Created by Daniel Axtens on 19/04/10.
\r
6 * Licensed under an MIT-style license: see the LICENSE file for details.
\r
16 /* You don't need to read this file.
\r
17 All you have to do is implement the bot functions defined in <c_link.h>
\r
18 This file sets up the I/O for you, as well as some utility functions and tables.
\r
21 char ITEMNAMES[3][MAXITEMLEN] = {"Rock", "Paper", "Scissors"};
\r
23 /* rock-rock rock-paper rock-scissors
\r
24 paper-rock paper-paper paper-scissors
\r
25 scissors-rock scissors-paper scissors-scissors */
\r
27 RESULTTYPE RESULTOF[3][3] = { { tie, defender, attacker },
\r
28 { attacker, tie, defender },
\r
29 { defender, attacker, tie } };
\r
31 ITEMTYPE RandomAttack() {
\r
32 return (ITEMTYPE)rand()%3;
\r
35 ITEMTYPE stringToItem( char * str ) {
\r
36 if (strcasecmp( str, "Rock" ) == 0) return rock;
\r
37 if (strcasecmp( str, "Paper" ) == 0) return paper;
\r
38 if (strcasecmp( str, "Scissors" ) == 0) return scissors;
\r
39 /* If we reach this point, we've got real problems. */
\r
40 fprintf( stderr, "Attempt to convert invalid string \"%s\" into an ITEMTYPE! Aborting.\n", str );
\r
46 RESULTTYPE stringToResult( char * str ) {
\r
47 if (strcasecmp( str, "Attacker" ) == 0) return attacker;
\r
48 if (strcasecmp( str, "Defender" ) == 0) return defender;
\r
49 if (strcasecmp( str, "Tie" ) == 0) return tie;
\r
50 /* If we reach this point, we've got real problems. */
\r
51 fprintf( stderr, "Attempt to convert invalid string \"%s\" into an ITEMTYPE! Aborting.\n", str );
\r
56 int main( int argc, char * argv[] ) {
\r
57 srand( time( NULL ) );
\r
59 char command[MAXCOMMANDLEN];
\r
60 char foeName[MAXFOENAMELEN];
\r
61 char attItem[MAXITEMLEN], defItem[MAXITEMLEN], bluffItem[MAXITEMLEN];
\r
62 char didYouInstigate[MAXBOOLLEN];
\r
63 char winner[MAXRESULTLEN];
\r
70 /* generate a random id for this bot. Hopefully it's unique
\r
71 I can't use the UUID, because python doesn't pass it to me! */
\r
74 // TODO: Get the UUID passed by python
\r
75 // Currently, just pass an empty string to the initialise function
\r
76 thisInstance = Initialise( "" );
\r
78 scanf( "%s", command );
\r
80 while (strcasecmp("BYE",command) != 0) {
\r
82 if (strcasecmp("ATTACK", command) == 0) {
\r
83 scanf( "%s", foeName );
\r
84 attack = Attack( thisInstance, foeName );
\r
85 printf("ATTACKING %s %s\n", ITEMNAMES[attack.realAttack], ITEMNAMES[attack.promisedAttack]);
\r
87 } else if (strcasecmp("DEFEND", command) == 0) {
\r
88 scanf( "%s %s", foeName, bluffItem );
\r
89 defence = Defend(thisInstance, foeName, stringToItem(bluffItem));
\r
90 printf("DEFENDING %s\n", ITEMNAMES[defence]);
\r
92 } else if (strcasecmp("RESULTS", command) == 0) {
\r
93 /* (foeName, isInstigatedByYou, winner, attItem, defItem, bluffItem, pointDelta) */
\r
94 scanf( "%s %s %s %s %s %s %d", foeName, didYouInstigate, winner, attItem, defItem, bluffItem, &pointChange );
\r
95 Results(thisInstance, foeName, (strcasecmp("True",didYouInstigate)==0), stringToResult(winner),
\r
96 stringToItem(attItem), stringToItem(defItem), stringToItem(bluffItem), pointChange);
\r
103 // read the next command!
\r
104 scanf( "%s", command );
\r
107 Cleanup(thisInstance);
\r