int main(void) { int k[10] = {adventurer, ambassador, village, remodel, baron, mine, gardens, feast, minion, steward}; struct gameState G; printf("Beginning unit testing of Village...\n\n"); //Initialize game for testing initializeGame(2, k, 1111, &G); printf("Printing initial state...\n"); printf("Hand count player 0: %d\n", G.handCount[0]); printf("Number of actions: %d\n\n", G.numActions); //Case: Player 1 plays Village printf("Testing case: Player 1 plays Village.\n"); playVillage(0, 5, &G); check(G.handCount[0] == 5); check(G.numActions == 2); printf("\nPrinting final state...\n"); printf("Hand count player 0: %d\n", G.handCount[0]); printf("Number of actions: %d\n", G.numActions); return 0; }
int main() { struct gameState G; int r, oldActions, oldHandCount; int player = 0; int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall}; printf("\nTesting Village Card\n"); r = initializeGame(2, k, 1, &G); printf("initializeGame() returned %d, Expected %d\n", r, 0); check(r == 0); oldHandCount = G.handCount[player]; //store hand count oldActions = G.numActions; G.hand[player][0] = village; r = playVillage(&G, 0); printf("\nplayVillage() returned %d, Expected %d\n", r, 0); //check playVillage check(r == 0); printf("\nG.handCount = %d, Expected %d\n\n", G.handCount[player], oldHandCount + 1); //check hand count check(G.handCount[player] == oldHandCount + 1); printf("G.numActions = %d, Expected %d\n\n", G.numActions, oldActions + 2); //check number of actions check(G.numActions == oldActions + 2); printf("G.discardCount= %d, Expected %d\n\n", G.discardCount[player], 1); //check discard count check(G.discardCount[player] == 1); return 0; }
int main () { int pass = 0; int fail = 0; int r; int p; int index; int handPos; struct gameState post, pre; printf ("Unit Test: cardtest4.c\n"); printf (" Target: Village Card\n"); for(p=0; p<4; p++) { for(index=0; index<20; index++) { for(handPos=0; handPos<5; handPos++) { reset(&post, p, index, handPos); memcpy (&pre, &post, sizeof(struct gameState)); set(&pre, p, handPos); playVillage(&post, handPos); r = mycompare(&pre, &post, p); if (r == 0) { pass++; } else { fail++; if(VERBOSE){ printf("\nFailed Test: p:%d index:%d handPos:%d\n", p, index, handPos); printf("ORACLE\n"); myprint(&pre, p); printf("RESULTS\n"); myprint(&post, p); printf("\n"); } } } } } if (fail) printf (" Status: FAILED\n"); else printf (" Status: PASSED\n"); printf (" Passed: %d\n", pass); printf (" Failed: %d\n", fail); return 0; }
int unitTest(int handPos, struct gameState *post, int p) { struct gameState pre; memcpy(&pre, post, sizeof(struct gameState)); int failedTests = 0; int p2 = 1; // player 2 int r, j, victoryCount, victoryCount2, kingdomCount, kingdomCount2; // run fucntion playVillage(handPos, post); // cardEffect(village, 0, 0, 0, post, handPos, 0); // count victory cards post function call victoryCount = getVictoryCount(&pre); victoryCount2 = getVictoryCount(post); // count all kingdom cards post function call kingdomCount2 = getKingdomCount(post); kingdomCount = getKingdomCount(&pre); r = checkCounts(&pre, post, 0, victoryCount, victoryCount2, kingdomCount, kingdomCount2); if (r > 0 ) { failedTests++; } // card should be a silver because of our stacked deck/hand if(post->hand[p][4] != copper) { printf("FAIL: added card isn't copper. Actual: %d\n", post->hand[p][4]); failedTests++; } // check player 2 state printf("Checking Player %d: \n", p2+1); j = checkPlayer2(&pre, post, p2, victoryCount, victoryCount2, kingdomCount, kingdomCount2); if(j > 0 ) { failedTests++; // check player 2 counts before and after function call otherPlayerState(&pre, post, 0, 1, victoryCount, victoryCount2, kingdomCount, kingdomCount2); printf("\nERROR: PLAYER 2 STATE HAS CHANGED \n"); } return failedTests; }
int main() { int seed = 1000; int numPlayer = 2; int p, r, handCount, initActions, initPlayedCount, initHandCount; int k[10] = {adventurer, council_room, feast, gardens, mine , remodel, smithy, village, baron, great_hall}; struct gameState G; int maxHandCount = 5; printf ("TESTING playVillage():\n"); p = 0; // set player 0 memset(&G, 23, sizeof(struct gameState)); // clear the game state r = initializeGame(numPlayer, k, seed, &G); // initialize a new game r = gainCard(village, &G, 2, p); // add village to player 0s hand initPlayedCount = G.playedCardCount; initHandCount = G.handCount[p]; initActions = G.numActions; r = playVillage(&G, 0, initHandCount - 1); //Draw +1 card Discard Village - Net 0 Change printf("G.handCount[p] = %d, expected = %d\n", G.handCount[p], initHandCount); assert(G.handCount[p] == initHandCount); // check if the handcount is correct //+2 actions printf("G.numActions = %d, expected = %d\n", G.numActions, initActions + 2); assert(G.numActions == initActions + 2); // check if the num actions is correct //+1 played card count printf("G.playedCardCount = %d, expected = %d\n", G.playedCardCount, initPlayedCount + 1); assert(G.playedCardCount == initPlayedCount + 1); // check if the played card count is correct printf("All tests passed!\n"); return 0; }
int checkRandomVillage(int p, struct gameState *postTest, int handPos) { int fail = 0; struct gameState preTest; memset(&preTest, 23, sizeof(struct gameState)); memcpy(&preTest, postTest, sizeof(struct gameState)); playVillage(p, postTest, handPos); //ensure the hand is the correct size if (preTest.handCount[p] != postTest->handCount[p]) { printFailure(p, preTest.handCount[p], handPos, __LINE__); fail++; } //ensure the number of actions are correct if (postTest->numActions != preTest.numActions + 2) { printFailure(p, preTest.handCount[p], handPos, __LINE__); fail++; } //ensure a card is discarded if (postTest->discardCount[p] != preTest.discardCount[p] + 1) { printFailure(p, preTest.handCount[p], handPos, __LINE__); fail++; } //ensure the correct card is discarded if (postTest->discard[p][postTest->discardCount[p] - 1] != village) { printFailure(p, preTest.handCount[p], handPos, __LINE__); fail++; } return fail; }
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: return playAdventurer(state); 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: //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: //+3 Cards return playSmithy(state, handPos); case village: return playVillage(state, handPos); 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: return playSteward(state, choice1, choice2, choice3, handPos); 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: return playSalvager(state, handPos, choice1); 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 handPos, choice1, choice2, choice3, bonus, player; handPos = choice1 = choice2 = choice3 = bonus = player = 0; int seed = 1000; int numPlayers = 4; int k[10] = {adventurer, council_room, steward, gardens, mine, remodel, smithy, village, baron, great_hall}; struct gameState state, controlState; initializeGame(numPlayers, k, seed, &state); state.hand[player][0] = village; //Set control state for comparison, call cardEffect memcpy(&controlState, &state, sizeof(struct gameState)); //cardEffect(village, choice1, choice2, choice3, &state, handPos, &bonus); playVillage(&state, player, handPos); printf("\nTESTING Village cardEffect\n"); //************** Test hand count ************** printf("Testing Hand Count\n"); if(state.handCount[player] == controlState.handCount[player]) { printf("PASS: Expected Value: %d Actual Value: %d\n", controlState.handCount[player], state.handCount[player]); } else { printf("FAIL: Expected Value: %d Actual Value: %d\n", controlState.handCount[player], state.handCount[player]); } //************** Test deck + discard count ************** printf("Testing Discard and Deck Counts\n"); if((state.deckCount[player] + state.discardCount[player]) == (controlState.deckCount[player] + controlState.discardCount[player] - 1)) { printf("PASS: Expected Value: %d Actual Value: %d\n", state.deckCount[player] + state.discardCount[player], controlState.deckCount[player] + controlState.discardCount[player] - 1); } else { printf("FAIL: Expected Value: %d Actual Value: %d\n", state.deckCount[player] + state.discardCount[player], controlState.deckCount[player] + controlState.discardCount[player] - 1); } //************** Test actions count ************** printf("Testing Actions Count\n"); if(state.numActions == controlState.numActions + 1) { printf("PASS: Expected Value: %d Actual Value: %d\n", controlState.numActions + 1, state.numActions); } else { printf("FAIL: Expected Value: %d Actual Value: %d\n", controlState.numActions + 1, state.numActions); } //************** Test other players' deck / discard / hand ************** printf("Testing other players' deck / discard / hand counts\n"); for(i = 1; i < numPlayers; i++) { assert(state.deckCount[i] == controlState.deckCount[i]); assert(state.discardCount[i] == controlState.discardCount[i]); assert(state.handCount[i] == controlState.handCount[i]); } printf("PASS: Other players' states unchanged\n"); //************** Test supply piles ************** printf("Test Supply Counts\n"); for(i = 0; i < 25; i++) { assert(state.supplyCount[i] == controlState.supplyCount[i]); } printf("PASS: All supply counts unchanged.\n"); return 0; }
int main() { int r; int player; int numPlayer = 2; int seed = 1000; int k[10] = { adventurer, council_room, feast, gardens, mine , remodel, smithy, village, baron, great_hall }; #if (NOISY_TEST == 1) const char* cards[] = //All 27 cards in game { "curse", "estate", "duchy", "province", "copper", "silver", "gold", "adventurer", "council_room", "feast", "gardens", "mine", "remodel", "smithy", "village", "baron", "great_hall", "minion", "steward", "tribute", "ambassador", "cutpurse", "embargo", "outpost", "salvager", "sea_hag", "treasure_map" }; #endif struct gameState prevState; //untouched game state to compare with after running tests struct gameState postState; //game state that will be used for tests int testResult; int numTests = 1; //how many test iterations to run. int failedTests = 0; int passedTests = 0; printf("==============================================\r\n"); printf(" Beginning testing for playVillage()\r\n"); printf("==============================================\r\n"); int i; for (i = 0; i < numTests; i++) { memset(&prevState, 23, sizeof(struct gameState)); // clear the game state r = initializeGame(numPlayer, k, seed, &prevState); // initialize a new game for (player = 0; player < numPlayer; player++) { prevState.handCount[player] = 1; // set the number of cards on hand int villageHand[1]; villageHand[0] = village; memcpy(prevState.hand[player], villageHand, sizeof(int)); prevState.deckCount[player] = 5; // set the number of cards in deck int mixedDeck[5]; mixedDeck[0] = copper; mixedDeck[1] = silver; mixedDeck[2] = gold; mixedDeck[3] = gardens; mixedDeck[4] = tribute; memcpy(prevState.deck[player], mixedDeck, sizeof(int) * 5); memcpy(&postState, &prevState, sizeof(struct gameState)); //create clone of game state to run tests on playVillage(player, &postState, 0); //Check that exactly 1 card was indeed added to current player's hand by comparing handCount value #if (NOISY_TEST == 1) printf("---------------------------------------------------------------------------------------------------------------------------\r\n"); printf("Testing that player[%d] handCount is still the same...\r\n", player); #endif testResult = postState.handCount[player]; if (testResult == prevState.handCount[player]) //due to village needing being discarded, handCount should still be the same { passedTests++; } else//failed { failedTests++; } #if (NOISY_TEST == 1) printf("handCount = %d, Expected = %d\r\n", testResult, prevState.handCount[player]); printf("Testing that player[%d] playedCardCount has increased by 1..\r\n", player); #endif //Check that playedCardCount increased by 1 testResult = postState.playedCardCount; if (testResult == prevState.playedCardCount + 1) //passed { passedTests++; } else//failed { failedTests++; } #if (NOISY_TEST == 1) printf("playedCardCount = %d, Expected = %d\r\n", testResult, prevState.playedCardCount + 1); printf("Checking that the village card was added to the played cards pile...\r\n"); #endif //Check that the village card was added to the played cards pile testResult = findCard(player, &postState, village, 0); if (testResult == -1) //failed, if variable is still -1, village was not found { failedTests++; } else//passed { passedTests++; } #if (NOISY_TEST == 1) if (testResult == -1) //failed { printf("Failed! village card was not found in played cards pile!\r\n"); } else//passed { printf("Passed! village card was found in played cards pile at position %d!\r\n", testResult); } printf("Checking that village card is not in player[%d]'s hand...\r\n", player); #endif //Check that village card is not in player's hand testResult = findCard(player, &postState, village, 1); if (testResult == -1) //passed, if variable is still -1, village was not found { passedTests++; } else//failed { failedTests++; } #if (NOISY_TEST == 1) if (testResult == -1) //passed { printf("Passsed! village card was not found in the player's hand!\r\n"); } else//failed { printf("Failed! village card was found in player's hand at position %d!\r\n", testResult); } printf("Checking that the card added came from the player's own deck...\r\n"); #endif //Check that the 1 card added came from the player's own deck //debug //int y; //for (y = 0; y < postState.handCount[player]; y++) //{ //printf("%s Card at position %d \r\n", cards[postState.hand[player][y]], y); // } int card; int cardCount = 0; int foundCards[MAX_DECK]; int j; for (j = 0; j < 5; j++) { if (j == 0) { card = copper; } if (j == 1) { card = silver; } if (j == 2) { card = gold; } if (j == 3) { card = gardens; } if (j == 4) { card = tribute; } testResult = findCard(player, &postState, card, 1); if (testResult != -1) //card found { cardCount++; foundCards[cardCount - 1] = card; #if (NOISY_TEST == 1) printf("Found %s card in player[%d]'s hand at position %d! Number of cards found: %d\r\n", cards[card], player, testResult, cardCount); #endif } } if (cardCount == 1) //passed { passedTests++; } else//failed { failedTests++; } #if (NOISY_TEST == 1) printf("cardCount = %d, Expected = 1\r\n", cardCount); #endif //check that the found cards are not in the deck anymore for (j = 0; j < cardCount; j++) { testResult = findCard(player, &postState, foundCards[j], 2); if (testResult == -1) //card not found { passedTests++; } else { failedTests++; #if (NOISY_TEST == 1) printf("Found %s card in player[%d]'s deck at position %d\r\n", cards[card], player, testResult); #endif } } #if (NOISY_TEST == 1) printf("Testing that player[%d] deckCount has decreased by 1..\r\n", player); #endif //Check that deckCount decreased by 1 testResult = postState.deckCount[player]; if (testResult == prevState.deckCount[player] - 1) //passed { passedTests++; } else//failed { failedTests++; } #if (NOISY_TEST == 1) printf("deckCount = %d, Expected = %d\r\n", testResult, prevState.deckCount[player] - 1); printf("Checking that the the number of actions have increased by 2...\r\n"); #endif //Check that number of actions have increased by 2 testResult = postState.numActions; if (testResult == prevState.numActions + 2) //passed { passedTests++; } else//failed { failedTests++; } #if (NOISY_TEST == 1) printf("numActions = %d, Expected = %d\r\n", testResult, prevState.numActions + 2); printf("---------------------------------------------------------------------------------------------------------------------------\r\n"); #endif } } printf("%d out of %d tests passed!\r\n", passedTests, passedTests + failedTests); printf("%d out of %d tests failed!\r\n", failedTests, passedTests + failedTests); return 0; }
int main() { int i, j, currentPlayer; int handPos, choice1, choice2, choice3, bonus; int failFlag; choice1 = choice2 = choice3 = bonus = 0; struct gameState state, controlState; srand(time(NULL)); printf("Beginning Village Random Testing\n\n"); //Test Expected Results for(i = 0; i < NUM_TESTS; i++) { //Generate randomized game state, copy to a control, and call cardEffect handPos = generateState(&state); memcpy(&controlState, &state, sizeof(struct gameState)); //cardEffect(village, choice1, choice2, choice3, &state, handPos, &bonus); currentPlayer = state.whoseTurn; playVillage(&state, currentPlayer, handPos); failFlag = 0; printf("------------ %d ------------\n", i); //Test hand count //Expected: unchanged if(state.handCount[currentPlayer] != controlState.handCount[currentPlayer]) { failFlag = 1; printf("FAIL: Hand Count | Expected: %d | Actual: %d\n", controlState.handCount[currentPlayer], state.handCount[currentPlayer]); } //Test deck count //Expected: decrement by one if(controlState.deckCount[currentPlayer] - 1 < state.deckCount[currentPlayer]) { failFlag = 1; printf("FAIL: Deck Count | Expected: %d or less | Actual: %d\n", controlState.handCount[currentPlayer] - 1, state.deckCount[currentPlayer]); } //Test action count //Expected: increment by one if(controlState.numActions + 1 != state.numActions) { failFlag = 1; printf("FAIL: Action count | Expected: %d | Actual: %d\n", controlState.numActions + 1, state.numActions); } //Test other players' hand count and deck count //Expected: unchanged for(j = 0; j < state.numPlayers; j++) { if(j != currentPlayer) { if(state.handCount[j] != controlState.handCount[j]) { failFlag = 1; printf("FAIL: Player %d's Hand Count | Expected: %d | Actual: %d\n", j, controlState.handCount[j], state.handCount[j]); } if(state.deckCount[j] != controlState.deckCount[j]) { failFlag = 1; printf("FAIL: Player %d's Deck Count | Expected: %d | Actual: %d\n", j, controlState.deckCount[j], state.deckCount[j]); } } } //Test supply piles //Expected: unchanged for(j = 0; j < 25; j++) { if(state.supplyCount[j] != controlState.supplyCount[j]) { failFlag = 1; printf("FAIL: Supply Count %d | Expected: %d | Actual: %d\n", j, controlState.supplyCount[j], state.supplyCount[j]); } } //Print out the inputs that lead to a failure if(failFlag == 1) { printf("Inputs: \n numPlayers %d\n current player %d\n numActions %d\n handCount %d\n deckCount %d\n discardCount %d\n", state.numPlayers, currentPlayer, state.numActions, state.handCount[currentPlayer], state.deckCount[currentPlayer], state.discardCount[currentPlayer]); } else { printf("All tests passed!\n"); } printf("\n"); } printf("Village tests complete.\n"); return 0; }
int main(){ //Initialize Game int init; int k[10] = {adventurer, smithy, remodel, gardens, minion, steward, tribute, ambassador, baron, mine}; struct gameState G; init = initializeGame(2, k, 1, &G); printf("\n--------------------------------\n"); printf("Testing Card: Villages\n"); printf("--------------------------------\n\n"); //Setup the cards for user 1 G.deckCount[0] = 5; G.handCount[0] = 5; G.discardCount[0] = 0; G.hand[0][0] = 1; //estate G.hand[0][1] = 1; //estate G.hand[0][2] = 4; //copper G.hand[0][3] = 4; //copper G.hand[0][4] = 14; //villages G.deck[0][0] = 1; //estate G.deck[0][1] = 2; //duchy G.deck[0][2] = 4; //copper G.deck[0][3] = 5; //silver G.deck[0][4] = 6; //gold printf("Top card in deck: %d\n", G.deck[0][G.deckCount[0] - 1]); printf("\nHand prior to playing Village\n"); printHand(&G); //Get the number of actions prior to playing the Village card int numActionsprior = G.numActions; printf("\nNumber of actions prior to playing Village: %d\n", numActionsprior); //Run test #1 int test1 = playVillage(0, 4, &G); if(test1 != 0){ printf("Test #1 Failed to run."); } printf("\nHand after playing Village\n"); printHand(&G); int numActionsafter = G.numActions; printf("\nNumber of actions after playing Village: %d\n\n", numActionsafter); printf("Test #1: Village card removed.\n"); if(G.hand[0][4]!= 14){ printf("Result: Pass\n\n"); }else{ printf("Result: Fail\n\n"); } printf("Test #2: Added card is the top card of the deck.\n"); if(G.hand[0][4] == 6){ printf("Result: Pass\n\n"); }else{ printf("Result: Fail\n\n"); } printf("Test #3: More than 1 card is added.\n"); if(G.hand[0][5] == -1){ printf("Result: Pass\n\n"); }else{ printf("Result: Fail\n\n"); } printf("Test #4: Actions should be incremented by 2.\n"); if(numActionsafter == numActionsprior+2){ printf("Result: Pass\n\n"); }else{ printf("Result: Fail\n\n"); } }
int main() { printf("Testing playVillage()...\n"); struct gameState* state = newGame(); int player = 0; state->numActions = 1; state->numPlayers = 4; state->playedCardCount = 0; int failCount = 0; // set hand to a known state state->handCount[player] = 3; state->hand[player][0] = copper; state->hand[player][1] = village; state->hand[player][2] = estate; // set deck to a known state state->deckCount[player] = 3; state->deck[player][0] = copper; state->deck[player][1] = gold; state->deck[player][2] = copper; // set other players' cards to a known state int i; for (i = 1; i < state->numPlayers; i++) { state->handCount[i] = 0; state->deckCount[i] = 0; state->discardCount[i] = 0; } // call the function being tested playVillage(state, 1, player); // check that handCount has not changed (1 card added, 1 discarded) if (state->handCount[player] != 3) { printf("Error: handCount is %d instead of 3\n", state->handCount[player]); failCount++; } // check that numActions has increased by 2 if (state->numActions != 3) { printf("Error: numActions is %d instead of 3\n", state->numActions); failCount++; } // check that deck has had a card removed if (state->deckCount[player] != 2) { printf("Error: deckCount is %d instead of 2\n", state->deckCount[player]); failCount++; } // check that village card is no longer in the player's hand for (i = 0; i < state->handCount[player]; i++) { if (state->hand[player][i] == village) { printf("Error: village card not discarded\n"); failCount++; } } // check that the played card count has incremented if (state->playedCardCount != 1) { printf("Error: playedCardCount is %d instead of 1\n", state->playedCardCount); failCount++; } // check that the other players' cards were not modified for (i = 1; i < state->numPlayers; i++) { if (state->handCount[i] != 0) { printf("Error: player %d's handCount is %d instead of 0\n", i + 1, state->handCount[i]); failCount++; } if (state->deckCount[i] != 0) { printf("Error: player %d's deckCount is %d instead of 0\n", i + 1, state->deckCount[i]); failCount++; } if (state->discardCount[i] != 0) { printf("Error: player %d's discardCount is %d instead of 0\n", i + 1, state->discardCount[i]); failCount++; } } printf("Testing complete!\n%d errors found.\n", failCount); return 0; }
int main() { srand(time(NULL)); int i; int numPlayers = 2, thisPlayer = 0, handPos = 0; int seed = rand() % 65535; int k[10] = { adventurer, smithy, village, great_hall, council_room, salvager, sea_hag, gardens, remodel, ambassador }; int totalSuccesses, totalFailures, numTests = 1000; int successBool; // Assume all tests pass unless otherwise specified. totalSuccesses = numTests; struct gameState state, testState; initializeGame(numPlayers, k, seed, &state); totalFailures = 0; printf("GENERATING CARD TEST FOR %s\n", TESTCARD); for(i = 0; i < numTests; i++) { successBool = 1; printf("\nITERATION %d\n", i+1); memcpy(&testState, &state, sizeof(struct gameState)); state.hand[thisPlayer][0] = rand() % 27; state.hand[thisPlayer][1] = rand() % 27; state.hand[thisPlayer][2] = rand() % 27; state.hand[thisPlayer][3] = rand() % 27; state.hand[thisPlayer][4] = rand() % 27; state.hand[thisPlayer+1][0] = rand() % 27; state.hand[thisPlayer+1][1] = rand() % 27; state.hand[thisPlayer+1][2] = rand() % 27; state.hand[thisPlayer+1][3] = rand() % 27; state.hand[thisPlayer+1][4] = rand() % 27; state.deck[thisPlayer][0] = rand() % 27; state.deck[thisPlayer][1] = rand() % 27; state.deck[thisPlayer][2] = rand() % 27; state.deck[thisPlayer][3] = rand() % 27; state.deck[thisPlayer][4] = rand() % 27; state.deck[thisPlayer+1][0] = rand() % 27; state.deck[thisPlayer+1][1] = rand() % 27; state.deck[thisPlayer+1][2] = rand() % 27; state.deck[thisPlayer+1][3] = rand() % 27; state.deck[thisPlayer+1][4] = rand() % 27; memcpy(&testState, &state, sizeof(struct gameState)); //testState.hand[thisPlayer][0] = rand() % 27; //testState.hand[thisPlayer][1] = rand() % 27; //testState.hand[thisPlayer][2] = rand() % 27; //testState.hand[thisPlayer][3] = rand() % 27; //testState.hand[thisPlayer][4] = rand() % 27; // Make sure we have all of the victory cards are in order. /* if(testState.supplyCount[estate] != 8 || testState.supplyCount[duchy] != 8 || testState.supplyCount[province] != 8) { printf("\nFailed Test: Victory card supplies are incorrect.\n"); successBool = 0; } if(testState.supplyCount[copper] != 46 || testState.supplyCount[silver] != 40 || testState.supplyCount[gold] != 30) { printf("\nFailed Test: Treasure Card supplies are not correct\n"); successBool = 0; } if(testState.supplyCount[copper] + testState.supplyCount[silver] + testState.supplyCount[gold] != 116); { printf("\nFailed Test: Treasure Card Totals Do Not Equal 116\n"); successBool = 0; } */ playVillage(&testState, thisPlayer, handPos); if(testState.deckCount[thisPlayer] != state.deckCount[thisPlayer] - 1) { printf("\nFailed Test: Player did not pick up extra card properly.\n"); printf("Deck Count: %d, Pre-Deck Count: %d\n", testState.deckCount[thisPlayer], state.deckCount[thisPlayer] - 1); totalFailures++; successBool = 0; } if(testState.numActions != state.numActions + 2) { printf("\nFailed Test: Number of actions did not increase properly for Player 1.\n"); totalFailures++; successBool = 0; } if(testState.discardCount[thisPlayer] != state.discardCount[thisPlayer] + 1) // should fail { printf("\nFailed Test: Number of cards discarded did not increase properly for Player 1.\n"); printf("Deck Count: %d, Pre-Deck Count: %d\n", testState.discardCount[thisPlayer], state.discardCount[thisPlayer] + 1); totalFailures++; successBool = 0; } endTurn(&testState); // Player 2 playVillage(&testState, thisPlayer, handPos); if(testState.deckCount[thisPlayer] != state.deckCount[thisPlayer] - 1) { printf("\nFailed Test: Player 2 did not pick up extra card properly.\n"); printf("Deck Count: %d, Pre-Deck Count: %d\n", testState.deckCount[thisPlayer], state.deckCount[thisPlayer] - 1); totalFailures++; successBool = 0; } if(testState.numActions != state.numActions + 2) { printf("\nFailed Test: Number of actions did not increase properly for Player 2.\n"); totalFailures++; successBool = 0; } if(testState.discardCount[thisPlayer] != state.discardCount[thisPlayer] - 6) { printf("\nFailed Test: Number of cards discarded did not increase properly for Player 2.\n"); printf("Deck Count: %d, Pre-Deck Count: %d\n", testState.discardCount[thisPlayer], state.discardCount[thisPlayer] + 1); totalFailures++; successBool = 0; } } printf("Testing complete for %s.\n", TESTCARD); printf("Total Tests: %d\n", numTests); printf("Total Successful: %d\n", (numTests * 6) - totalFailures); printf("Total Unsuccessful: %d\n", totalFailures); return 0; }
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) { //uses switch to select card and perform actions switch( card ) { case adventurer: return (playAdventurer(state)); case council_room: return (playCouncil_Room(state, handPos)); case feast: return(playFeast(state, choice1)); case gardens: return -1; case smithy: return (playSmithy(state, handPos)); case village: return (playVillage(state, handPos)); case mine: return(playMine(state, choice1, choice2, handPos)); case remodel: return(playRemodel(state, choice1, choice2, handPos)); case baron: return(playBaron(state, choice1, choice2, handPos)); case great_hall: return(playGreat_hall(state, handPos)); case minion: return(playMinion(state, choice1, choice2, handPos)); case steward: return(playSteward(state, choice1, choice2, choice3, handPos)); case tribute: return(playTribute(state)); case ambassador: return(playAmbassador(state,choice1, choice2, handPos)); case cutpurse: return(playCutpurse(state, handPos)); case embargo: return(playEmbargo(state, choice1, handPos)); case outpost: return(playOutpost(state, handPos)); case salvager: return(playSalvager(state, choice1, handPos)); case sea_hag: return(playSea_hag(state)); case treasure_map: return(playTreasure_map(state, handPos)); } return -1; }
int main(int argc, char const *argv[]) { printf("Testing playVillage().\n"); int i, p, r, j; int k[10] = {adventurer, council_room, feast, gardens, mine, smithy, village, baron, great_hall, tribute}; int fail = 0; int tempHand[5]; int tempDeck[20]; int handSize = 5; int deckSize = 20; struct gameState G; for (i = 0; i < handSize; ++i) { tempHand[i] = village; } for (i = 0; i < deckSize; ++i) { if (i % 2 == 0) { tempDeck[i] = copper; }else if (i % 3 == 0) { tempDeck[i] = silver; }else if (i % 7 == 0) { tempDeck[i] = estate; }else { tempDeck[i] = gold; } } /*set up the game*/ memset(&G, 0, sizeof(struct gameState)); r = initializeGame(NUM_PLAYERS, k, SEED_NUMBER, &G); for (p = 0; p < NUM_PLAYERS; ++p) { memcpy(G.hand[p], tempHand, sizeof(int) * handSize); memcpy(G.deck[p], tempDeck, sizeof(int) * deckSize); G.handCount[p] = handSize; G.deckCount[p] = deckSize; for ( j = handSize -1; j >= 0; --j) { int oldHandCount = G.handCount[p]; int oldDiscardCount = G.discardCount[p]; int oldNumActions = G.numActions; playVillage(p, &G, j); //ensure the hand is the correct size if (oldHandCount != G.handCount[p]) { printFailure(p, j, oldHandCount); ID_LINE; fail++; } //ensure the number of actions are correct if (G.numActions != oldNumActions + 2) { printFailure(p, j, oldHandCount); ID_LINE; fail++; } //ensure a card is discarded if (G.discardCount[p] != oldDiscardCount + 1) { printFailure(p, j, oldHandCount); ID_LINE; fail++; } //ensure the correct card is discarded if (G.discard[p][G.discardCount[p] - 1] != village) { printFailure(p, j, oldHandCount); ID_LINE; fail++; } } } if (fail > 0) { printf("%d tests failed.\n", fail); }else { printf("ALL TESTS PASSED!\n"); } return 0; }