// compare the pre/post conditions of adventurer void checkAdventureCard(struct gameState *post, int p) { printf("checking adventure card\n"); struct gameState pre; // pre function call game state memcpy (&pre, post, sizeof(struct gameState)); // copy the game state // compareState(&pre, post, p); printf("using adventurer card\n"); int r = cardAdventurer(post, p); // call the function /******************************************* * initial tests before changing parameters *******************************************/ /* printf("initial tests\n"); int handDif = pre.handCount[p] - post->handCount[p]; int discDif = pre.discardCount[p] - post->discardCount[p]; int deckDif = post->deckCount[p] - pre.deckCount[p]; assert((handDif + discDif) == deckDif); // cards should come out of the deck into the hand/discard */ /******************************************** * set expected values and test ********************************************/ /* printf("setting values\n"); // get the number of treasure cards in the player's pre-hand // before the function call int treasure = countTreasure(&pre, p); // set the pre deck to what we expect pre.handCount[p] += 2; // should have 2 more cards in hand than we did // copy some things we can't predict (specific cards in decks) */ memcpy(pre.hand[p], post->hand[p], sizeof(int) * pre.handCount[p]); // copy hand pre.handCount[p] = post->handCount[p]; // copy handcount memcpy(pre.deck[p], post->deck[p], sizeof(int) * pre.deckCount[p]); // copy deck pre.deckCount[p] = post->deckCount[p]; // copy deck count memcpy(pre.discard[p], post->discard[p], sizeof(int) * pre.discardCount[p]); // copy discard pre.discardCount[p] = post->discardCount[p];// copy discard count /******************************************** * perform asserts ********************************************/ /* printf("performing asserts\n"); assert (r == 0); assert((treasure+2) == countTreasure(post, p)); // the player should have 2 more treasure cards */ assert(memcmp(&pre, post, sizeof(struct gameState)) == 0); // compareState(&pre, post, p); }
int main () { int i, n, r, p, players, player, deckCount, discardCount, handCount, seed, handPos; int cardDrawn, drawntreasure, tempcoins, card; int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall}; struct gameState game1; printf ("RANDOM TESTS.\n"); for (n = 0; n < MAX_TESTS; n++) { //random players players = rand() % 4; seed = rand(); //initialize player initializeGame(players, k, seed, &game1); player = game1.whoseTurn; for(i = 0; i< 500; i++) { drawntreasure = rand() % 9; tempcoins = game1.coins; card = cardAdventurer(&game1); if(tempcoins > game1.coins) { printf("error: tempcoins %d game1.coins %d\n", tempcoins, game1.coins); } } } printf("All Tests ok\n"); 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 *temphand = malloc(sizeof(int)*MAX_HAND); 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: return cardAdventurer(card,drawntreasure,z,cardDrawn,state,temphand,currentPlayer); case council_room: return cardCouncilRoom(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 cardMine(j, state, choice1, currentPlayer, choice2, treasure_map,handPos); case remodel: return cardRemodel(j,state,currentPlayer,choice1,choice2,handPos); case smithy: //+3 Cards for (i = 0; i < 3; i++) { drawCard(currentPlayer, state); } //discard card from hand discardCard(handPos, currentPlayer, state, 0); 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: 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: return cardMinion(state,currentPlayer,handPos,choice1,choice2,j); 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, p, d, h, g, r;// p is numPlayer (player), d is deckSize, h is handSize, g position of great_hall, r is to initialize new game int seed = 1000; int numPlayer = 2; int maxBonus = 10; int bonus; int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall}; struct gameState G; struct gameState D; int deckSize = 5; int testHandSize = 5; // arrays of all coppers, silvers, and golds int coppers[MAX_HAND]; int silvers[MAX_HAND]; int golds[MAX_HAND]; int temphand[MAX_HAND]; int mixed[MAX_DECK]; int allTreasure[MAX_DECK]; int noTreasure[MAX_DECK]; int z = 0; //fill test deck for (i = 0; i < MAX_DECK; i++) { allTreasure[i] = copper; noTreasure[i] = k[6]; if(i%2 == 0) mixed[i] = copper; else mixed[i] = k[6]; } printf ("Testing cardGreat_Hall():\n"); for (p = 0; p < numPlayer; p++) { for (d = 0; d < deckSize; d++){ for (h = 0; h < testHandSize; h++){ for (g = 0; g < testHandSize; g++){ #if (NOISY_TEST == 1) printf("Test player = %d with deck size= %d hand= %d and position Great_Hall = %d.\n", p, d, h, g); #endif memset(&G, 23, sizeof(struct gameState)); // clear the game state r = initializeGame(numPlayer, k, seed, &G); // initialize a new game G.deckCount[p] = d; memcpy(G.deck[p], mixed, sizeof(int) * MAX_DECK); memcpy(G.hand[p], allTreasure, sizeof(int) * MAX_HAND); G.handCount[p] = h; G.hand[p][g]= great_hall; D = G; #if (NOISY_TEST == 1) printf("Testing treasure deck and action deck\n"); #endif cardAdventurer(&G); #if (NOISY_TEST == 1) // if deck size is less than 3 if(d < 1) printf("Hand size = %d, expected = %d\n", G.handCount[p], D.handCount[p] - 1 + d); else printf("Hand size = %d, expected = %d\n", G.handCount[p], D.handCount[p]); #endif //core dump // //if the deck size is less than 3 then handcount is equal to previous -1 plus the decksize // if(d < 1) // assert(G.handCount[p] == D.handCount[p] - 1 + d); // else //else the handcount is equal to previous plus 2 // assert(G.handCount[p] == D.handCount[p]); #if (NOISY_TEST == 1) if(d < 1) printf("Deck + Discard + Played = %d, Expected = %d\n", G.discardCount[p] + G.playedCardCount + G.deckCount[p], D.discardCount[p] + D.playedCardCount + D.deckCount[p] + 1); else printf("Deck + Discard + Played = %d, Expected = %d\n", G.discardCount[p] + G.playedCardCount + G.deckCount[p], D.discardCount[p] + D.playedCardCount + D.deckCount[p]); #endif // core dump // if(d < 1) // assert(G.discardCount[p] + G.playedCardCount + G.deckCount[p] == D.discardCount[p] + D.playedCardCount + D.deckCount[p] + 1); // else // assert(G.discardCount[p] + G.playedCardCount + G.deckCount[p] == D.discardCount[p] + D.playedCardCount + D.deckCount[p]); #if (NOISY_TEST == 1) printf("Actions = %d expected = %d \n", G.numActions, D.numActions + 1); #endif //core dump assert(G.numActions == D.numActions + 1); } } } } printf("Tests passed.\n"); 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 index; int currentPlayer = whoseTurn(state); int nextPlayer = currentPlayer + 1; if (nextPlayer > (state->numPlayers - 1)){ nextPlayer = 0; } //uses switch to select card and perform actions switch( card ) { case adventurer: //code was moved into cardAdventurer return cardAdventurer(state, currentPlayer); case council_room: //+4 Cards for (i = 0; i < 4; i++) { drawCard(currentPlayer, state); } //+1 Buy state->numBuys++; //Each other player draws a card for (i = 0; i < state->numPlayers; i++) { if ( i != currentPlayer ) { drawCard(i, state); } } //put played card in played card pile discardCard(handPos, currentPlayer, state, 0); return 0; case feast: //code was moved into cardFeast return cardFeast(state, choice1, currentPlayer); case gardens: return -1; case mine: //code was moved into cardMine return cardMine(state, currentPlayer, choice1, choice2, handPos); 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: //+3 Cards for (i = 0; i < 3; i++) { drawCard(currentPlayer, state); } //discard card from hand discardCard(handPos, currentPlayer, state, 0); 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: //code was moved into cardBaron return cardBaron(state, choice1, currentPlayer); 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: //code was moved into cardTribute return cardTribute(state, nextPlayer, currentPlayer); case ambassador: j = 0; //used to check if player has enough cards to discard printf("choice 1: %i\n", choice1); 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; }
void testAdventurer(struct gameState *G1, struct gameState *G2){ int res1; int d1, d2; int h1, h2; int b1, c1; printf("\n*********************\n"); printf("Testing Adventurer card effect\n"); printf("*********************\n\n"); //Record number of cards in initial discard (should be 0) d1 = G1->discardCount[0]; d2 = G2->discardCount[0]; //Record number of coins and buys b1 = G1->numBuys; c1 = G1->coins; //Add an adventurer card to Payer 1's hand in two games G1->hand[0][G1->handCount[0]] = adventurer; G1->handCount[0]++; G2->hand[0][G2->handCount[0]] = adventurer; G2->handCount[0]++; //Record number of cards in each hand (should be 6) h1 = G1->handCount[0]; h2 = G2->handCount[0]; //Play the smithy in Game 1, Player 1 res1 = cardAdventurer(G1->whoseTurn, G1); //Test to see if 2 cards were added to the hand if(G1->handCount[0] == (h1 + 2)){ printf("Test Passed, 2 cards were added to the hand. \n"); } else { printf("Test Failed, something else happened; 2 cards were not added to the hand. \n"); } //Test to see if both cards that were added to the hand are treasure cards if(G1->hand[0][G1->handCount[0] - 2] == copper || G1->hand[0][G1->handCount[0] - 2] == silver || G1->hand[0][G1->handCount[0] - 2] == gold){ printf("Test Passed, first card added was a treasure card. \n"); } else { printf("Test Failed, first card added was not a treasure card. \n"); } if(G1->hand[0][G1->handCount[0] - 1] == copper || G1->hand[0][G1->handCount[0] - 1] == silver || G1->hand[0][G1->handCount[0] - 1] == gold){ printf("Test Passed, second card added was a treasure card. \n"); } else { printf("Test Failed, second card added was not a treasure card. \n"); } //Test to see if other cards were discarded. if(G1->discardCount[0] > (d1)){ printf("Test Passed, At least 1 card was added to the discard. \n"); } else { printf("Test Failed, something else happened; At least 1 card was not added to the discard. \n"); } //Test to see if number of coins was altered (shouldn't be) if(G1->coins == c1){ printf("Test Passed, Coins were not altered. \n"); } else { printf("Test Failed, Number of coins changed after adventurer was played. \n"); } //Test to see if number of buys was altered (shouldn't be) if(G1->numBuys == b1){ printf("Test Passed, Buys were not altered. \n"); } else { printf("Test Failed, Number of buys changed after adventurer was played. \n"); } //Test to see if the deck still had the same total number of cards as the Game 2 Player 1 deck. if(G1->deckCount[0] == G2->deckCount[0]){ printf("Test Passed, Player 1 from both games have the same size deck. \n"); } else { printf("Test Failed, something else happened; Player 1 from both games do not have the same size deck. \n"); } printf("\n"); return; }
int main() { int i; int cards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall}; int testCount = 100; printf("*-------\nBegin Adventurer Card Random Testing\n-------*\n"); //Set up the random number generator int seed = 12125; SelectStream(1); PutSeed((long)seed); for(i = 0; i < testCount; ++i) { int j, pos, preTreasure = 0, postTreasure = 0, err = 0; //Build a gamestate to test with struct gameState *state = malloc(sizeof(struct gameState)); struct gameState *prev = malloc(sizeof(struct gameState)); seed = floor((Random() * 12125) + 1); int numPlayer = floor((Random() * 3) + 2); initializeGame(numPlayer, cards, seed, state); state->whoseTurn = floor(Random() * numPlayer); state->handCount[state->whoseTurn] = floor(Random() * (MAX_HAND / 3)); state->deckCount[state->whoseTurn] = floor(Random() * (MAX_DECK / 3)); state->discardCount[state->whoseTurn] = floor(Random() * (MAX_DECK / 3)); state->playedCardCount = floor(Random() * 5); //Fill the hand with random cards 0 - 17 for(j = 0; j < state->handCount[state->whoseTurn]; ++j) { state->hand[state->whoseTurn][j] = floor(Random() * 17); } //Fill the deck with random cards 0 - 17 for(j = 0; j < state->deckCount[state->whoseTurn]; ++j) { state->deck[state->whoseTurn][j] = floor(Random() * 17); } //Fill the discard pile with random cards 0 - 17 for(j = 0; j < state->discardCount[state->whoseTurn]; ++j) { state->discard[state->whoseTurn][j] = floor(Random() * 17); } //Randomly select a position, set that card to adventurer for our use pos = floor(Random() * state->handCount[state->whoseTurn]); state->hand[state->whoseTurn][pos] = adventurer; printf("\nPre-State:\nhandCount: %i\ndeckCount: %i\ndiscardCount: %i\n", state->handCount[state->whoseTurn], state->deckCount[state->whoseTurn], state->discardCount[state->whoseTurn]); printf("Cardpos: %i\nPlayer: %i\nplayedCardCount: %i\n", pos, state->whoseTurn, state->playedCardCount); //Copy the gamestate memcpy(prev, state, sizeof(struct gameState)); //Call the adventurer card cardAdventurer(state->whoseTurn, state); //Count up the treasure cards in the players hand before playing the adventurer for(j = 0; j < prev->handCount[prev->whoseTurn]; ++j) { if(prev->hand[prev->whoseTurn][j] == copper || prev->hand[prev->whoseTurn][j] == silver || prev->hand[prev->whoseTurn][j] == gold) { ++preTreasure; } } //Count up the treasure cards in the players hand after playing the adventurer for(j = 0; j < state->handCount[state->whoseTurn]; ++j) { if(state->hand[state->whoseTurn][j] == copper || state->hand[state->whoseTurn][j] == silver || state->hand[state->whoseTurn][j] == gold) { ++postTreasure; } } if((prev->deckCount[prev->whoseTurn] + prev->discardCount[prev->whoseTurn] - 2) != (state->deckCount[state->whoseTurn] + state->discardCount[state->whoseTurn])) { printf("FAILURE: The total number of cards in the deck and discard are incorrect.\n"); printf("Prev: %i, Post: %i, Seed: %i\n", prev->deckCount[prev->whoseTurn] + prev->discardCount[prev->whoseTurn], state->deckCount[state->whoseTurn] + state->discardCount[state->whoseTurn], seed); err = 1; } if((prev->playedCardCount + 1) != state->playedCardCount) { printf("FAILURE: The total number of played cards was not properly incremented.\n"); printf("Prev: %i, Post: %i, Seed: %i\n", prev->playedCardCount, state->playedCardCount, seed); err = 2; } if((preTreasure + 2) != postTreasure) { printf("FAILURE: The number of treasure cards in the players hand is incorrect.\n"); printf("Prev: %i, Post: %i, Seed: %i\n", preTreasure + 2, postTreasure, seed); err = 3; } if(prev->handCount[prev->whoseTurn] + 2 != state->handCount[state->whoseTurn]) { printf("FAILURE: The handCount was not properly incremented.\n"); printf("Prev: %i, Post: %i, Seed: %i\n", prev->handCount[prev->whoseTurn], state->handCount[state->whoseTurn], seed); err = 4; } if(err == 0) { printf("PASSED.\n"); } } printf("*-------\nEnd Adventurer Card Random Testing\n-------*\n"); return 0; }