5 * Created by Daniel Axtens on 19/04/10.
6 * Licensed under an MIT-style license: see the LICENSE file for details.
15 /* If you just want to write a bot, you don't need to read this file.
16 This merely sets up the I/O for you, so all you have to do is define the bot
17 functions defined in <c-link.h>
19 The only reason you would care about this info is if you want to use pointChange
20 and/or childSpawned parameters from the RESULTS call, which are otherwise discarded.
23 char ITEMNAMES[3][MAXITEMLEN] = {"Rock", "Paper", "Scissors"};
26 ITEMTYPE RandomAttack() {
27 return (ITEMTYPE)rand()%3;
30 ITEMTYPE stringToItem( char * str ) {
31 if (strcasecmp( str, "Rock" ) == 0) return rock;
32 if (strcasecmp( str, "Paper" ) == 0) return paper;
33 if (strcasecmp( str, "Scissors" ) == 0) return scissors;
34 /* If we reach this point, we've got real problems. */
35 fprintf( stderr, "Attempt to convert invalid string \"%s\" into an ITEMTYPE! Aborting.\n", str );
41 int main( int argc, char * argv[] ) {
42 srand( time( NULL ) );
44 char command[MAXCOMMANDLEN];
45 char foeName[MAXFOENAMELEN];
46 char yourItem[MAXITEMLEN], theirItem[MAXITEMLEN], promisedItem[MAXITEMLEN];
47 char didYouInstigate[MAXBOOLLEN], childSpawned[MAXBOOLLEN];
53 scanf( "%s", command );
55 while (strcasecmp("BYE",command) != 0) {
57 if (strcasecmp("ATTACK", command) == 0) {
58 scanf( "%s", foeName );
59 attack = Attack( foeName );
60 printf("ATTACKING %s %s\n", ITEMNAMES[attack.realAttack], ITEMNAMES[attack.promisedAttack]);
62 } else if (strcasecmp("DEFEND", command) == 0) {
63 scanf( "%s %s", foeName, promisedItem );
64 defence = Defend(foeName, stringToItem(promisedItem));
65 printf("DEFENDING %s\n", ITEMNAMES[defence]);
67 } else if (strcasecmp("RESULTS", command) == 0) {
68 scanf( "%s %s %s %s %s %d %s", foeName, didYouInstigate, yourItem, theirItem, promisedItem, &pointChange, childSpawned );
69 Results(foeName, (strcasecmp("False",didYouInstigate)==0),
70 stringToItem(yourItem), stringToItem(theirItem), stringToItem(promisedItem));
74 // read the next command!
75 scanf( "%s", command );