X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=link%2FC%2Fc-link-lib%2Fc_link.c;fp=link%2FC%2Fc-link-lib%2Fc_link.c;h=e75997f9b9e37d9026cffa47d0ceb27f821df158;hb=1740df9314f3dc49c6d44378c5915674aa1ab75f;hp=0000000000000000000000000000000000000000;hpb=fac40599d3ae604872ce34f3546a6c634183148f;p=progcomp10.git diff --git a/link/C/c-link-lib/c_link.c b/link/C/c-link-lib/c_link.c new file mode 100644 index 0000000..e75997f --- /dev/null +++ b/link/C/c-link-lib/c_link.c @@ -0,0 +1,77 @@ +/* + * c_link.c + * c-link-lib + * + * Created by Daniel Axtens on 19/04/10. + * Licensed under an MIT-style license: see the LICENSE file for details. + * + */ + +#include "c_link.h" +#include +#include +#include +#include + +/* 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 + */ + +char ITEMNAMES[3][MAXITEMLEN] = {"Rock", "Paper", "Scissors"}; + + +ITEMTYPE RandomAttack() { + return (ITEMTYPE)rand()%3; +} + +ITEMTYPE stringToItem( char * str ) { + if (strcasecmp( str, "Rock" ) == 0) return rock; + if (strcasecmp( str, "Paper" ) == 0) return paper; + if (strcasecmp( str, "Scissors" ) == 0) return scissors; + /* If we reach this point, we've got real problems. */ + fprintf( stderr, "Attempt to convert invalid string \"%s\" into an ITEMTYPE! Aborting.\n", str ); + exit(EXIT_FAILURE); + return -1; +} + + +int main( int argc, char * argv[] ) { + srand( time( NULL ) ); + + char command[MAXCOMMANDLEN]; + char foeName[MAXFOENAMELEN]; + char yourItem[MAXITEMLEN], theirItem[MAXITEMLEN], promisedItem[MAXITEMLEN]; + char didYouInstigate[MAXBOOLLEN], childSpawned[MAXBOOLLEN]; + int pointChange; + + ATTACKTYPE attack; + ITEMTYPE defence; + + scanf( "%s", command ); + + while (strcasecmp("BYE",command) != 0) { + + if (strcasecmp("ATTACK", command) == 0) { + scanf( "%s", foeName ); + attack = Attack( foeName ); + printf("ATTACKING %s %s\n", ITEMNAMES[attack.realAttack], ITEMNAMES[attack.promisedAttack]); + + } else if (strcasecmp("DEFEND", command) == 0) { + scanf( "%s %s", foeName, promisedItem ); + defence = Defend(foeName, stringToItem(promisedItem)); + printf("DEFENDING %s\n", ITEMNAMES[defence]); + + } else if (strcasecmp("RESULTS", command) == 0) { + scanf( "%s %s %s %s %s %d %s", foeName, didYouInstigate, yourItem, theirItem, promisedItem, &pointChange, childSpawned ); + Results(foeName, (strcasecmp("False",didYouInstigate)==0), + stringToItem(yourItem), stringToItem(theirItem), stringToItem(promisedItem)); + printf("OK\n"); + } + + // read the next command! + scanf( "%s", command ); + } + + return 0; +} \ No newline at end of file