int main() { int i, j; int z = 0; int newCards = 3; int discarded = 1; int shuffledCards = 0; int cardDrawn = 0; int handpos = 0; int seed = 1000; int numPlayers = 2; int thisPlayer = 0; int currentPlayer; int drawntreasure = 0; int temphand[MAX_HAND]; struct gameState G, testG; int k[10] = {adventurer, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy, council_room}; // initialize a game state and player cards initializeGame(numPlayers, k, seed, &G); //copy the game state to a test case memcpy(&testG, &G, sizeof(struct gameState)); printf("Testing Card: %s \n", TESTCARD); //calls the adventurer card function and asserts cards are discarded and not trashed adventurer_card(drawntreasure, thisPlayer, cardDrawn, temphand, z, &testG); printf("discard count = %d, expected = %d\n", testG.discardCount[thisPlayer], G.discardCount[thisPlayer]); //assert(z == 0); if(z == 0){ printf("Treasure test PASSED!\n"); }else{ printf("Treasure test FAILED!\n"); } printf("%s card finished all tests.\n", TESTCARD); return 0; }
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) { int i; int j; int k; int x; int index; 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; } //uses switch to select card and perform actions switch( card ) { case adventurer: adventurer_card(drawntreasure, state, currentPlayer, cardDrawn, temphand); return 0; case council_room: council_room_card(currentPlayer, state, handPos); case feast: //gain card with cost up to 5 //Backup hand for (i = 0; i <= state->handCount[currentPlayer]; i++){ temphand[i] = state->hand[currentPlayer][i];//Backup card state->hand[currentPlayer][i] = -1;//Set to nothing } //Backup hand //Update Coins for Buy updateCoins(currentPlayer, state, 5); x = 1;//Condition to loop on while( x == 1) {//Buy one card if (supplyCount(choice1, state) <= 0){ if (DEBUG) printf("None of that card left, sorry!\n"); if (DEBUG){ printf("Cards Left: %d\n", supplyCount(choice1, state)); } } else if (state->coins < getCost(choice1)){ printf("That card is too expensive!\n"); if (DEBUG){ printf("Coins: %d < %d\n", state->coins, getCost(choice1)); } } else{ if (DEBUG){ printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); } gainCard(choice1, state, 0, currentPlayer);//Gain the card x = 0;//No more buying cards if (DEBUG){ printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); } } } //Reset Hand for (i = 0; i <= state->handCount[currentPlayer]; i++){ state->hand[currentPlayer][i] = temphand[i]; temphand[i] = -1; } //Reset Hand return 0; case gardens: return -1; case mine: return mine_card(currentPlayer, state, choice1, choice2, handPos); case remodel: return remodel_card(currentPlayer, state, choice1, choice2, handPos); case smithy: return smithy_card(currentPlayer, state, handPos); case village: //+1 Card drawCard(currentPlayer, state); //+2 Actions state->numActions = state->numActions + 2; //discard played card from hand discardCard(handPos, currentPlayer, state, 0); return 0; case baron: state->numBuys++;//Increase buys by 1! if (choice1 > 0){//Boolean true or going to discard an estate int p = 0;//Iterator for hand! int card_not_discarded = 1;//Flag for discard set! while(card_not_discarded){ if (state->hand[currentPlayer][p] == estate){//Found an estate card! state->coins += 4;//Add 4 coins to the amount of coins state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; state->discardCount[currentPlayer]++; for (;p < state->handCount[currentPlayer]; p++){ state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1]; } state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; state->handCount[currentPlayer]--; card_not_discarded = 0;//Exit the loop } else if (p > state->handCount[currentPlayer]){ if(DEBUG) { printf("No estate cards in your hand, invalid choice\n"); printf("Must gain an estate if there are any\n"); } if (supplyCount(estate, state) > 0){ gainCard(estate, state, 0, currentPlayer); state->supplyCount[estate]--;//Decrement estates if (supplyCount(estate, state) == 0){ isGameOver(state); } } card_not_discarded = 0;//Exit the loop } else{ p++;//Next card } } } else{ if (supplyCount(estate, state) > 0){ gainCard(estate, state, 0, currentPlayer);//Gain an estate state->supplyCount[estate]--;//Decrement Estates if (supplyCount(estate, state) == 0){ isGameOver(state); } } } return 0; case great_hall: //+1 Card drawCard(currentPlayer, state); //+1 Actions state->numActions++; //discard card from hand discardCard(handPos, currentPlayer, state, 0); return 0; case minion: //+1 action state->numActions++; //discard card from hand discardCard(handPos, currentPlayer, state, 0); if (choice1) //+2 coins { state->coins = state->coins + 2; } else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 { //discard hand while(numHandCards(state) > 0) { discardCard(handPos, currentPlayer, state, 0); } //draw 4 for (i = 0; i < 4; i++) { drawCard(currentPlayer, state); } //other players discard hand and redraw if hand size > 4 for (i = 0; i < state->numPlayers; i++) { if (i != currentPlayer) { if ( state->handCount[i] > 4 ) { //discard hand while( state->handCount[i] > 0 ) { discardCard(handPos, i, state, 0); } //draw 4 for (j = 0; j < 4; j++) { drawCard(i, state); } } } } } return 0; case steward: if (choice1 == 1) { //+2 cards drawCard(currentPlayer, state); drawCard(currentPlayer, state); } else if (choice1 == 2) { //+2 coins state->coins = state->coins + 2; } else { //trash 2 cards in hand discardCard(choice2, currentPlayer, state, 1); discardCard(choice3, currentPlayer, state, 1); } //discard card from hand discardCard(handPos, currentPlayer, state, 0); return 0; case tribute: if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1){ if (state->deckCount[nextPlayer] > 0){ tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; state->deckCount[nextPlayer]--; } else if (state->discardCount[nextPlayer] > 0){ tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1]; state->discardCount[nextPlayer]--; } else{ //No Card to Reveal if (DEBUG){ printf("No cards to reveal\n"); } } } else{ if (state->deckCount[nextPlayer] == 0){ for (i = 0; i < state->discardCount[nextPlayer]; i++){ state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck state->deckCount[nextPlayer]++; state->discard[nextPlayer][i] = -1; state->discardCount[nextPlayer]--; } shuffle(nextPlayer,state);//Shuffle the deck } tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; state->deckCount[nextPlayer]--; tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; state->deckCount[nextPlayer]--; } if (tributeRevealedCards[0] == tributeRevealedCards[1]){//If we have a duplicate card, just drop one state->playedCards[state->playedCardCount] = tributeRevealedCards[1]; state->playedCardCount++; tributeRevealedCards[1] = -1; } for (i = 0; i <= 2; i ++){ if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold){//Treasure cards state->coins += 2; } else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall){//Victory Card Found drawCard(currentPlayer, state); drawCard(currentPlayer, state); } else{//Action Card state->numActions = state->numActions + 2; } } return 0; case ambassador: j = 0; //used to check if player has enough cards to discard if (choice2 > 2 || choice2 < 0) { return -1; } if (choice1 == handPos) { return -1; } for (i = 0; i < state->handCount[currentPlayer]; i++) { if (i != handPos && i == state->hand[currentPlayer][choice1] && i != choice1) { j++; } } if (j < choice2) { return -1; } if (DEBUG) printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]); //increase supply count for choosen card by amount being discarded state->supplyCount[state->hand[currentPlayer][choice1]] += choice2; //each other player gains a copy of revealed card for (i = 0; i < state->numPlayers; i++) { if (i != currentPlayer) { gainCard(state->hand[currentPlayer][choice1], state, 0, i); } } //discard played card from hand discardCard(handPos, currentPlayer, state, 0); //trash copies of cards returned to supply for (j = 0; j < choice2; j++) { for (i = 0; i < state->handCount[currentPlayer]; i++) { if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1]) { discardCard(i, currentPlayer, state, 1); break; } } } return 0; case cutpurse: updateCoins(currentPlayer, state, 2); for (i = 0; i < state->numPlayers; i++) { if (i != currentPlayer) { for (j = 0; j < state->handCount[i]; j++) { if (state->hand[i][j] == copper) { discardCard(j, i, state, 0); break; } if (j == state->handCount[i]) { for (k = 0; k < state->handCount[i]; k++) { if (DEBUG) printf("Player %d reveals card number %d\n", i, state->hand[i][k]); } break; } } } } //discard played card from hand discardCard(handPos, currentPlayer, state, 0); return 0; case embargo: //+2 Coins state->coins = state->coins + 2; //see if selected pile is in play if ( state->supplyCount[choice1] == -1 ) { return -1; } //add embargo token to selected supply pile state->embargoTokens[choice1]++; //trash card discardCard(handPos, currentPlayer, state, 1); return 0; case outpost: //set outpost flag state->outpostPlayed++; //discard card discardCard(handPos, currentPlayer, state, 0); return 0; case salvager: //+1 buy state->numBuys++; if (choice1) { //gain coins equal to trashed card state->coins = state->coins + getCost( handCard(choice1, state) ); //trash card discardCard(choice1, currentPlayer, state, 1); } //discard card discardCard(handPos, currentPlayer, state, 0); return 0; case sea_hag: for (i = 0; i < state->numPlayers; i++){ if (i != currentPlayer){ state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; state->deckCount[i]--; state->discardCount[i]++; state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse } } return 0; case treasure_map: //search hand for another treasure_map index = -1; for (i = 0; i < state->handCount[currentPlayer]; i++) { if (state->hand[currentPlayer][i] == treasure_map && i != handPos) { index = i; break; } } if (index > -1) { //trash both treasure cards discardCard(handPos, currentPlayer, state, 1); discardCard(index, currentPlayer, state, 1); //gain 4 Gold cards for (i = 0; i < 4; i++) { gainCard(gold, state, 1, currentPlayer); } //return success return 1; } //no second treasure_map found in hand return -1; } return -1; }
int main() { int i; int seed = 1000; int numPlayer =2; int maxBonus = 10; int p, r, handCount; int bonus; int k[10] = {adventurer, council_room, feast, gardens, mine , remodel, smithy, village, baron, great_hall}; struct gameState G; int maxHandCount = 5; // arrays of all coppers, silvers, and golds int coppers[MAX_HAND]; int silvers[MAX_HAND]; int golds[MAX_HAND]; for (i = 0; i < MAX_HAND; i++) { coppers[i] = copper; silvers[i] = silver; golds[i] = gold; } printf ("TESTING adventurer_card():\n"); for (p = 2; p >= numPlayer; p++){ memset(&G, 23, sizeof(struct gameState)); // clear the game state r = initializeGame(numPlayer, k, seed, &G); // initialize a new game G.handCount[1] = 5; G.discardCount[1] = 0; G.deckCount[1] = 5; G.deck[1][0] = copper; G.deck[1][1] = gold; G.deck[1][2] = smithy; G.deck[1][3] = silver; G.deck[1][4] = copper; G.hand[1][0] = copper; G.hand[1][1] = 0; G.hand[1][2] = adventurer; G.hand[1][3] = copper; G.hand[1][4] = 0; G.handCount[0] = 5; G.discardCount[0] = 5; G.deckCount[0] = 5; int temphand[MAX_HAND]; adventurer_card(1, -1, 0, 0, temphand, &G); updateCoins(1, &G, 0); printf("Expected coin count = 5, Actual coin count = %d\n", G.coins); if (G.coins == 5) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected handCount = 6, Actual handCount = %d\n", G.handCount[1]); if (G.handCount[1] == 6) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected discardCount = 1, Actual discardCount = %d\n", G.discardCount[1]); if (G.discardCount[1] == 1) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected deckCount = 3, Actual deckCount = %d\n", G.deckCount[1]); if (G.deckCount[1] == 3) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected other player's handCount = 5, Actual other player's handCount = %d\n", G.handCount[0]); if (G.handCount[0] == 5) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected other player's discardCount = 5, Actual other player's discardCount = %d\n", G.discardCount[0]); if (G.discardCount[0] == 5) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected deckCount = 5, Actual deckCount = %d\n", G.deckCount[0]); if (G.deckCount[0] == 5) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } G.handCount[1] = 5; G.discardCount[1] = 0; G.deckCount[1] = 5; G.deck[1][0] = smithy; G.deck[1][1] = estate; G.deck[1][2] = smithy; G.deck[1][3] = 0; G.deck[1][4] = province; G.hand[1][0] = copper; G.hand[1][1] = 0; G.hand[1][2] = adventurer; G.hand[1][3] = copper; G.hand[1][4] = 0; G.handCount[0] = 5; G.discardCount[0] = 5; G.deckCount[0] = 5; adventurer_card(1, -1, 0, 0, temphand, &G); updateCoins(1, &G, 0); printf("Expected coin count = 2, Actual coin count = %d\n", G.coins); if (G.coins == 2) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected handCount = 4, Actual handCount = %d\n", G.handCount[1]); if (G.handCount[1] == 4) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected discardCount = 6, Actual discardCount = %d\n", G.discardCount[1]); if (G.discardCount[1] == 6) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected deckCount = 0, Actual deckCount = %d\n", G.deckCount[1]); if (G.deckCount[1] == 0) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected other player's handCount = 5, Actual other player's handCount = %d\n", G.handCount[0]); if (G.handCount[0] == 5) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected other player's discardCount = 5, Actual other player's discardCount = %d\n", G.discardCount[0]); if (G.discardCount[0] == 5) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected deckCount = 5, Actual deckCount = %d\n", G.deckCount[0]); if (G.deckCount[0] == 5) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } G.handCount[1] = 5; G.discardCount[1] = 0; G.deckCount[1] = 5; G.deck[1][0] = smithy; G.deck[1][1] = silver; G.deck[1][2] = smithy; G.deck[1][3] = copper; G.deck[1][4] = province; G.hand[1][0] = copper; G.hand[1][1] = 0; G.hand[1][2] = adventurer; G.hand[1][3] = copper; G.hand[1][4] = 0; G.handCount[0] = 5; G.discardCount[0] = 5; G.deckCount[0] = 5; adventurer_card(1, -1, 0, 0, temphand, &G); updateCoins(1, &G, 0); printf("Expected coin count = 5, Actual coin count = %d\n", G.coins); if (G.coins == 5) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected handCount = 6, Actual handCount = %d\n", G.handCount[1]); if (G.handCount[1] == 6) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected discardCount = 3, Actual discardCount = %d\n", G.discardCount[1]); if (G.discardCount[1] == 3) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected deckCount = 1, Actual deckCount = %d\n", G.deckCount[1]); if (G.deckCount[1] == 1) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected other player's handCount = 5, Actual other player's handCount = %d\n", G.handCount[0]); if (G.handCount[0] == 5) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected other player's discardCount = 5, Actual other player's discardCount = %d\n", G.discardCount[0]); if (G.discardCount[0] == 5) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } printf("Expected deckCount = 5, Actual deckCount = %d\n", G.deckCount[0]); if (G.deckCount[0] == 5) { printf("TEST PASSED\n\n"); } else { printf("TEST FAILED\n\n"); } return 0; } }
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) { int i = 0; int j; int k; int x; int index; 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; } //uses switch to select card and perform actions switch( card ) { case adventurer: adventurer_card(drawntreasure, currentPlayer, state, cardDrawn, temphand[MAX_HAND], z); return 0; case council_room: council_room_card(i, currentPlayer, state, handPos); return 0; case feast: //gain card with cost up to 5 //Backup hand for (i = 0; i <= state->handCount[currentPlayer]; i++){ temphand[i] = state->hand[currentPlayer][i];//Backup card state->hand[currentPlayer][i] = -1;//Set to nothing } //Backup hand //Update Coins for Buy updateCoins(currentPlayer, state, 5); x = 1;//Condition to loop on while( x == 1) {//Buy one card if (supplyCount(choice1, state) <= 0){ if (DEBUG) printf("None of that card left, sorry!\n"); if (DEBUG){ printf("Cards Left: %d\n", supplyCount(choice1, state)); } } else if (state->coins < getCost(choice1)){ printf("That card is too expensive!\n"); if (DEBUG){ printf("Coins: %d < %d\n", state->coins, getCost(choice1)); } } else{ if (DEBUG){ printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); } gainCard(choice1, state, 0, currentPlayer);//Gain the card x = 0;//No more buying cards if (DEBUG){ printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); } } } //Reset Hand for (i = 0; i <= state->handCount[currentPlayer]; i++){ state->hand[currentPlayer][i] = temphand[i]; temphand[i] = -1; } //Reset Hand return 0; case gardens: return -1; case mine: j = state->hand[currentPlayer][choice1]; //store card we will trash if (state->hand[currentPlayer][choice1] < copper || state->hand[currentPlayer][choice1] > gold) { return -1; } if (choice2 > treasure_map || choice2 < curse) { return -1; } if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) ) { return -1; } gainCard(choice2, state, 2, currentPlayer); //discard card from hand discardCard(handPos, currentPlayer, state, 0); //discard trashed card for (i = 0; i < state->handCount[currentPlayer]; i++) { if (state->hand[currentPlayer][i] == j) { discardCard(i, currentPlayer, state, 0); break; } } return 0; case remodel: j = state->hand[currentPlayer][choice1]; //store card we will trash if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) ) { return -1; } gainCard(choice2, state, 0, currentPlayer); //discard card from hand discardCard(handPos, currentPlayer, state, 0); //discard trashed card for (i = 0; i < state->handCount[currentPlayer]; i++) { if (state->hand[currentPlayer][i] == j) { discardCard(i, currentPlayer, state, 0); break; } } return 0; case smithy: smithy_card(i, currentPlayer, handPos, state); return 0; case village: //+1 Card drawCard(currentPlayer, state); //+2 Actions state->numActions = state->numActions + 2; //discard played card from hand discardCard(handPos, currentPlayer, state, 0); return 0; case baron: baron_card(state, choice1, currentPlayer); return 0; case great_hall: //+1 Card drawCard(currentPlayer, state); //+1 Actions state->numActions++; //discard card from hand discardCard(handPos, currentPlayer, state, 0); return 0; case minion: //+1 action state->numActions++; //discard card from hand discardCard(handPos, currentPlayer, state, 0); if (choice1) //+2 coins { state->coins = state->coins + 2; } else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 { //discard hand while(numHandCards(state) > 0) { discardCard(handPos, currentPlayer, state, 0); } //draw 4 for (i = 0; i < 4; i++) { drawCard(currentPlayer, state); } //other players discard hand and redraw if hand size > 4 for (i = 0; i < state->numPlayers; i++) { if (i != currentPlayer) { if ( state->handCount[i] > 4 ) { //discard hand while( state->handCount[i] > 0 ) { discardCard(handPos, i, state, 0); } //draw 4 for (j = 0; j < 4; j++) { drawCard(i, state); } } } } } return 0; case steward: if (choice1 == 1) { //+2 cards drawCard(currentPlayer, state); drawCard(currentPlayer, state); } else if (choice1 == 2) { //+2 coins state->coins = state->coins + 2; } else { //trash 2 cards in hand discardCard(choice2, currentPlayer, state, 1); discardCard(choice3, currentPlayer, state, 1); } //discard card from hand discardCard(handPos, currentPlayer, state, 0); return 0; case tribute: tribute_card(state, nextPlayer, currentPlayer, i, tributeRevealedCards[2]); case ambassador: j = 0; //used to check if player has enough cards to discard if (choice2 > 2 || choice2 < 0) { return -1; } if (choice1 == handPos) { return -1; } for (i = 0; i < state->handCount[currentPlayer]; i++) { if (i != handPos && i == state->hand[currentPlayer][choice1] && i != choice1) { j++; } } if (j < choice2) { return -1; } if (DEBUG) printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]); //increase supply count for choosen card by amount being discarded state->supplyCount[state->hand[currentPlayer][choice1]] += choice2; //each other player gains a copy of revealed card for (i = 0; i < state->numPlayers; i++) { if (i != currentPlayer) { gainCard(state->hand[currentPlayer][choice1], state, 0, i); } } //discard played card from hand discardCard(handPos, currentPlayer, state, 0); //trash copies of cards returned to supply for (j = 0; j < choice2; j++) { for (i = 0; i < state->handCount[currentPlayer]; i++) { if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1]) { discardCard(i, currentPlayer, state, 1); break; } } } return 0; case cutpurse: updateCoins(currentPlayer, state, 2); for (i = 0; i < state->numPlayers; i++) { if (i != currentPlayer) { for (j = 0; j < state->handCount[i]; j++) { if (state->hand[i][j] == copper) { discardCard(j, i, state, 0); break; } if (j == state->handCount[i]) { for (k = 0; k < state->handCount[i]; k++) { if (DEBUG) printf("Player %d reveals card number %d\n", i, state->hand[i][k]); } break; } } } } //discard played card from hand discardCard(handPos, currentPlayer, state, 0); return 0; case embargo: //+2 Coins state->coins = state->coins + 2; //see if selected pile is in play if ( state->supplyCount[choice1] == -1 ) { return -1; } //add embargo token to selected supply pile state->embargoTokens[choice1]++; //trash card discardCard(handPos, currentPlayer, state, 1); return 0; case outpost: //set outpost flag state->outpostPlayed++; //discard card discardCard(handPos, currentPlayer, state, 0); return 0; case salvager: //+1 buy state->numBuys++; if (choice1) { //gain coins equal to trashed card state->coins = state->coins + getCost( handCard(choice1, state) ); //trash card discardCard(choice1, currentPlayer, state, 1); } //discard card discardCard(handPos, currentPlayer, state, 0); return 0; case sea_hag: for (i = 0; i < state->numPlayers; i++){ if (i != currentPlayer){ state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; state->deckCount[i]--; state->discardCount[i]++; state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse } } return 0; case treasure_map: //search hand for another treasure_map index = -1; for (i = 0; i < state->handCount[currentPlayer]; i++) { if (state->hand[currentPlayer][i] == treasure_map && i != handPos) { index = i; break; } } if (index > -1) { //trash both treasure cards discardCard(handPos, currentPlayer, state, 1); discardCard(index, currentPlayer, state, 1); //gain 4 Gold cards for (i = 0; i < 4; i++) { gainCard(gold, state, 1, currentPlayer); } //return success return 1; } //no second treasure_map found in hand return -1; } return -1; }
/*Adventurer card unit tests*/ void testAdventurerCard() { int seed = 1000; /*Used for initializeGame parameter for setting up random # generator*/ int numPlayer = 2; /*number of players in game. Maximum # of players is 4*/ int p = 1; /*holds the value of the player, example player 0, player 1.*/ int handCount = 5; /*Number of cards player starts with*/ /*Kingdom cards used in this game*/ int k[10] = {adventurer, council_room, feast, gardens, mine , remodel, smithy, village, baron, great_hall }; struct gameState G; /*start a new game*/ /*create a custom hand to give to player */ int custom_hand[handCount]; custom_hand[0] = smithy; custom_hand[1] = village; custom_hand[2] = gardens; custom_hand[3] = adventurer; custom_hand[4] = mine; char name[20]; /*Holds card name when converting card number to string*/ int inhand = 0; /*Determines if Adventurer card is in player's hand or not.*/ int z = 0; /*counter for temp hand*/ int cardDrawn = 0; /*gets card value of card drawn to put in temp hand*/ int drawnTreasure = 0; /*Number of treasure cards drawn*/ int temphand[MAX_HAND];/*Temp hand to put drawn cards in to later discard*/ printf ("\nTESTING adventurer_card():\n"); printf("Test player %d with %d card(s) with 1 card being an Adventurer card.\n", p, handCount); initializeGame(numPlayer, k, seed, &G); /*initialize a new game*/ G.handCount[p] = handCount; /*set the number of cards in hand*/ memcpy(G.hand[p], custom_hand, sizeof(int) * handCount); /*Populate hand with cards*/ G.deckCount[p] = 0; /*set player's deck count to 0 so shuffle needs to occur*/ /*Print the cards in player's hand*/ int i; for(i = 0; i < G.handCount[p]; i++) { cardNumToName(G.hand[p][i], name); /*Convert card number to cards name*/ printf("%s%s", name, ", "); if(strcmp(name, "Adventurer") == 0) { inhand = 1; /*Adventurer card is in player's hand*/ } } if (inhand == 1) { printf ("\nPASS - Adventurer card is in player's hand\n"); } else { printf ("\nFAIL - Adventurer card is NOT in player's hand\n"); } inhand = 0; /*reset value*/ printf("Player's deck count is %d and must be shuffled\n", G.deckCount[p]); printf ("Using Adventurer card...\n"); adventurer_card(p, cardDrawn, drawnTreasure, z, temphand, &G); if(G.deckCount[p] == 0) { printf ("FAIL - deckCount still %d, did not shuffle\n", G.deckCount[p]); } else { printf ("PASS - deckCount now %d, deck was shuffled\n", G.deckCount[p]); } /*checks if 2 treasure cards added, 6 if card was discard and 7 if card was not discarded*/ if(G.handCount[p] == 6 || G.handCount[p] == 7) { printf ("PASS - Player %d has received 2 cards.\n", p); } else { printf ("FAIL - Player %d has not received the proper amount of cards.\n", p); } for(i = 0; i < G.handCount[p]; i++) { cardNumToName(G.hand[p][i], name); /*Convert card number to cards name*/ printf("%s%s", name, ", "); if(strcmp(name, "Adventurer") == 0) { inhand = 0; /*Adventurer card is not in player's hand*/ } if(strcmp(name, "Copper") == 0 || strcmp(name, "Silver") == 0 || strcmp(name, "Gold") == 0) { drawnTreasure++; /*Treasure card drawn.*/ } } if (inhand == 0) { printf ("PASS - Adventurer card was discarded from hand.\n"); } else { printf ("FAIL - Adventurer card was NOT discarded hand.\n"); } if (drawnTreasure == 2) { printf ("PASS - Only two treasure cards were added to hand.\n"); } else { printf ("FAIL - Two treasure cards were NOT added to hand.\n"); } }