int checkCutpurseCard(int p, struct gameState *post) { struct gameState pre; post->whoseTurn = p; memcpy (&pre, post, sizeof(struct gameState)); int i, j, r; int handPos = rand() % pre.handCount[p]; r = cutpurseCard(post, handPos); updateCoins(p, &pre, 2); printf("After gaining 2 coins, tester coinCount: %d\n", pre.coins); printf("After gaining 2 coins, testee coinCount: %d\n", post->coins); for (i = 0; i < pre.numPlayers; i++) { if (i != p) { for (j = 0; j < pre.handCount[i]; j++) { if (pre.hand[i][j] == copper) { discardCard(j, i, &pre, 0); break; } if (j == pre.handCount[i]) { int revealedCard = rand () % pre.handCount[i]; printf("Player %d reveals card number %d\n", i, pre.hand[i][revealedCard]); break; } } } } assert (r == 0); discardCard(handPos, p, &pre, 0); if (memcmp(&pre, post, sizeof(struct gameState)) == 0) { printf("cutpurseCard() function unit test passed for player %d!\n", p); } else { printf("cutpurseCard() function unit test failed for player %d\n", p); } return 0; }
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) { int currentPlayer = whoseTurn(state); int nextPlayer = currentPlayer + 1; int tributeRevealedCards[2] = {-1, -1}; int temphand[MAX_HAND];// moved above the if statement int drawntreasure=0; int cardDrawn; int z = 0;// this is the counter for the temp hand if (nextPlayer > (state->numPlayers - 1)) { nextPlayer = 0; } switch( card ) { case adventurer: return adventurerCard(&drawntreasure, state, &cardDrawn, ¤tPlayer, temphand, &z); case council_room: return council_roomCard(¤tPlayer, state, &handPos); case feast: return feastCard(state, temphand, ¤tPlayer, &choice1); case gardens: return -1; case mine: return mineCard(state, ¤tPlayer, &choice1, &choice2, &handPos); case remodel: return remodelCard(state, ¤tPlayer, &choice1, &choice2, &handPos); case smithy: return smithyCard(state, ¤tPlayer, &handPos); case village: return villageCard(state, ¤tPlayer, &handPos); case baron: return baronCard(state, ¤tPlayer, &choice1); case great_hall: return great_hallCard(state, ¤tPlayer, &handPos); case minion: return minionCard(state, ¤tPlayer, &handPos, &choice1, &choice2); case steward: return stewardCard(state, ¤tPlayer, &handPos, &choice1, &choice2, &choice3); case tribute: return tributeCard(state, ¤tPlayer, &handPos, &nextPlayer, tributeRevealedCards); case ambassador: return ambassadorCard(state, ¤tPlayer, &handPos, &choice1, &choice2); case cutpurse: return cutpurseCard(state, ¤tPlayer, &handPos); case embargo: return embargoCard(state, ¤tPlayer, &handPos, &choice1); case outpost: return outpostCard(state, ¤tPlayer, &handPos); case salvager: return salvagerCard(state, ¤tPlayer, &handPos, &choice1); case sea_hag: return sea_hagCard(state, ¤tPlayer); case treasure_map: return treasure_mapCard(state, ¤tPlayer, &handPos); } return -1; }