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 All you have to do is implement the bot functions defined in <c_link.h>
18 This file sets up the I/O for you, as well as some utility functions and tables.
21 char ITEMNAMES[3][MAXITEMLEN] = {"Rock", "Paper", "Scissors"};
23 /* rock-rock rock-paper rock-scissors
24 paper-rock paper-paper paper-scissors
25 scissors-rock scissors-paper scissors-scissors */
27 RESULTTYPE RESULTOF[3][3] = { { tie, lose, win },
32 ITEMTYPE RandomAttack() {
33 return (ITEMTYPE)rand()%3;
36 ITEMTYPE stringToItem( char * str ) {
37 if (strcasecmp( str, "Rock" ) == 0) return rock;
38 if (strcasecmp( str, "Paper" ) == 0) return paper;
39 if (strcasecmp( str, "Scissors" ) == 0) return scissors;
40 /* If we reach this point, we've got real problems. */
41 fprintf( stderr, "Attempt to convert invalid string \"%s\" into an ITEMTYPE! Aborting.\n", str );
47 int main( int argc, char * argv[] ) {
48 srand( time( NULL ) );
50 char command[MAXCOMMANDLEN];
51 char foeName[MAXFOENAMELEN];
52 char yourItem[MAXITEMLEN], theirItem[MAXITEMLEN], promisedItem[MAXITEMLEN];
53 char didYouInstigate[MAXBOOLLEN], childSpawned[MAXBOOLLEN];
59 scanf( "%s", command );
61 while (strcasecmp("BYE",command) != 0) {
63 if (strcasecmp("ATTACK", command) == 0) {
64 scanf( "%s", foeName );
65 attack = Attack( foeName );
66 printf("ATTACKING %s %s\n", ITEMNAMES[attack.realAttack], ITEMNAMES[attack.promisedAttack]);
68 } else if (strcasecmp("DEFEND", command) == 0) {
69 scanf( "%s %s", foeName, promisedItem );
70 defence = Defend(foeName, stringToItem(promisedItem));
71 printf("DEFENDING %s\n", ITEMNAMES[defence]);
73 } else if (strcasecmp("RESULTS", command) == 0) {
74 scanf( "%s %s %s %s %s %d %s", foeName, didYouInstigate, yourItem, theirItem, promisedItem, &pointChange, childSpawned );
75 Results(foeName, (strcasecmp("False",didYouInstigate)==0),
76 stringToItem(yourItem), stringToItem(theirItem), stringToItem(promisedItem));
80 // read the next command!
81 scanf( "%s", command );