5 * Created by Daniel Axtens on 19/04/10.
6 * Licensed under an MIT-style license: see the LICENSE file for details.
16 /* You don't need to read this file.
17 This merely sets up the I/O for you, so all you have to do is define the bot
18 functions defined in <c_link.h>
21 char ITEMNAMES[3][MAXITEMLEN] = {"Rock", "Paper", "Scissors"};
24 ITEMTYPE RandomAttack() {
25 return (ITEMTYPE)rand()%3;
28 ITEMTYPE stringToItem( char * str ) {
29 if (strcasecmp( str, "Rock" ) == 0) return rock;
30 if (strcasecmp( str, "Paper" ) == 0) return paper;
31 if (strcasecmp( str, "Scissors" ) == 0) return scissors;
32 /* If we reach this point, we've got real problems. */
33 fprintf( stderr, "Attempt to convert invalid string \"%s\" into an ITEMTYPE! Aborting.\n", str );
39 int main( int argc, char * argv[] ) {
40 srand( time( NULL ) );
42 char command[MAXCOMMANDLEN];
43 char foeName[MAXFOENAMELEN];
44 char yourItem[MAXITEMLEN], theirItem[MAXITEMLEN], promisedItem[MAXITEMLEN];
45 char didYouInstigate[MAXBOOLLEN], childSpawned[MAXBOOLLEN];
51 scanf( "%s", command );
53 while (strcasecmp("BYE",command) != 0) {
55 if (strcasecmp("ATTACK", command) == 0) {
56 scanf( "%s", foeName );
57 attack = Attack( foeName );
58 printf("ATTACKING %s %s\n", ITEMNAMES[attack.realAttack], ITEMNAMES[attack.promisedAttack]);
60 } else if (strcasecmp("DEFEND", command) == 0) {
61 scanf( "%s %s", foeName, promisedItem );
62 defence = Defend(foeName, stringToItem(promisedItem));
63 printf("DEFENDING %s\n", ITEMNAMES[defence]);
65 } else if (strcasecmp("RESULTS", command) == 0) {
66 scanf( "%s %s %s %s %s %d %s", foeName, didYouInstigate, yourItem, theirItem, promisedItem, &pointChange, childSpawned );
67 Results(foeName, (strcasecmp("False",didYouInstigate)==0),
68 stringToItem(yourItem), stringToItem(theirItem), stringToItem(promisedItem));
72 // read the next command!
73 scanf( "%s", command );