} int main(int argc, char** argv){ struct gameState *G; int numplayers, money, handpos, rseed, rcard, choice1, choice2, choice3, coinflip, i, numtests,r; int *k; int players[4]; numtests=1; for(i=0; i<numtests; i++){ G=newGame(); rseed=atoi(argv[1]); k = malloc(sizeof(int)*10); numplayers=rand()%3+2; chooseKingdomCards(k); initializeGame(numplayers, k, rseed, G); printf("FOR SEED %d\n", rseed); if(isGameOver(G)){ printf("game creation error\n"); printf("test %d failed\n",i); } else{ while(!isGameOver(G)){ printf("player %d turn start\n", whoseTurn(G)); handpos=-1; coinflip=rand()%10; rcard=chooseHandCard(G, k, &handpos); choice1=rand()%2; choice2=0; if(choice1==0){ choice2=1; } choice3=rand()%2; if(rcard!=-1 || rcard==curse){ r=playCard(handpos, choice1,choice2,choice3,G); printf("player %d played ", whoseTurn(G)); printCard(rcard, r); } money=countMoney(G); printf("money: %d\n", money); rcard=randomBuyCard(G, money, k); if(coinflip!=9){ //small chance to not buy anything r=buyCard(rcard, G); printf("player %d bought ", whoseTurn(G)); printCard(rcard, r); } printf("player %d hand\n", whoseTurn(G)); printhand(G); printf("player %d score: %d\n", whoseTurn(G), scoreFor(whoseTurn(G),G)); printf("player %d turn ending\n", whoseTurn(G)); endTurn(G); if(isGameOver(G)){ printf("game over player %d won\n", getWinners(players, G)); } } free(k); free(G); printf("test %d passed\n", i); } }
int usermove(void) { int n; const char *const *p; char buf[256]; (void)printf("\nYour hand is:"); printhand(userhand); for (;;) { (void)printf("You ask me for: "); (void)fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) exit(0); if (buf[0] == '\0') continue; if (buf[0] == '\n') { (void)printf("%d cards in my hand, %d in the pool.\n", countcards(comphand), curcard); (void)printf("My books:"); (void)countbooks(comphand); continue; } buf[strlen(buf) - 1] = '\0'; if (!strcasecmp(buf, "p") && !promode) { promode = 1; (void)printf("Entering pro mode.\n"); continue; } if (!strcasecmp(buf, "quit")) exit(0); for (p = cards; *p; ++p) if (!strcasecmp(*p, buf)) break; if (!*p) { (void)printf("I don't understand!\n"); continue; } n = p - cards; if (userhand[n]) { userasked[n] = 1; return(n); } if (nrandom(3) == 1) (void)printf("You don't have any of those!\n"); else (void)printf("You don't have any %s's!\n", cards[n]); if (nrandom(4) == 1) (void)printf("No cheating!\n"); (void)printf("Guess again.\n"); } /* NOTREACHED */ }