int main (){ struct gameState state; int hand1[5] = {copper,copper,copper,copper,copper}; int hand2[5] = {silver,silver,silver,silver,silver}; int hand3[5] = {gold,gold,gold,gold,gold}; int hand4[4] = {copper,copper,gold,silver}; int hand5[1] = {copper}; int hand6[0] = {}; int hand7[10] = {copper,silver,silver,copper,gold,silver,gold,gold,copper,copper}; int hand8[5] = {baron,mine,province,province,curse}; int hand9[7] = {embargo,gold,remodel,salvager,copper,silver,gold}; int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy}; initializeGame(2,k,1000,&state); checkCoins(hand1, &state,5,0,5); checkCoins(hand2, &state,5,0,10); checkCoins(hand3, &state,5,0,15); checkCoins(hand4, &state,4,0,7); checkCoins(hand5, &state,1,0,1); checkCoins(hand6, &state,0,0,0); checkCoins(hand7, &state,10,0,19); checkCoins(hand8, &state,5,0,0); checkCoins(hand9, &state,7,0,9); checkCoins(hand3, &state,5,-3,12); checkCoins(hand4, &state,4,2,9); return 0; }
int main () { int i, j; //loop controls int result; //return value for function calls int failed; //flags for tests struct gameState *g = malloc(sizeof(struct gameState)); //working game state struct gameState *pre = malloc(sizeof(struct gameState)); //reference game state; stored before functions run int selectedCards[10] = {adventurer, council_room, feast, gardens, mine, smithy, village, tribute, salvager, sea_hag}; int seed = 10; int choice1, choice2, choice3; //choices for card effect int coin_bonus; //coins added by card //---Test smithy (all choices = -1, no bonus) /*---Expected result: - Game and turn settings are unchanged - Other player's cards (hand, deck, discard) are unchanged - Current player's discard is unchanged - Played card count increased by 1 - Smithy card added to played pile (in last position) - Smithy card removed from hand - Last 3 cards of current player's deck moved to hand - Current player's deckCount is decreased by 3 - Current player's handCount is increased by 2 (+3 new cards, -1 smithy) - No bonus coins */ printf("*** Testing valid smithy ***\n"); printf("Errors: "); //Setup card options choice1 = -1; choice2 = -1; choice3 = -1; coin_bonus = 0; //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted.\n"); return -1; } //Set deck to 5 copper cards g->deckCount[whoseTurn(g)] = 5; for (i = 0; i < 5; i++){ g->deck[whoseTurn(g)][i] = copper; } //Set test position in hand to test card g->hand[whoseTurn(g)][TEST_POS] = TEST_CARD; //Save current state memcpy(pre, g, sizeof(struct gameState)); //Attempt to execute card result = cardEffect(TEST_CARD, choice1, choice2, choice3, g, TEST_POS, &coin_bonus); failed = 0; if (result != 0){ printf("\nReturn value: %d, Expected: %d\n", result, 0); failed = 1; } //Check game/turn settings if (checkNumPlayers(pre, g) < 0){ printf("\nNumPlayers: %d, Expected: %d\n", g->numPlayers, pre->numPlayers); failed = 1; } result = checkSupply(pre, g); if (result != 0){ printf("\nSupply count for card %d: %d, Expected: %d\n", result, g->supplyCount[result], pre->supplyCount[result]); failed = 1; } result = checkEmbargo(pre, g); if (result != 0){ printf("\nEmbargo for card %d: %d, Expected: %d\n", result, g->embargoTokens[result], pre->embargoTokens[result]); failed = 1; } if (checkOutpost(pre, g) < 0){ printf("\noutpostPlayed: %d, Expected: %d\n", g->outpostPlayed, pre->outpostPlayed); printf("\noutpostTurn: %d, Expected: %d\n", g->outpostTurn, pre->outpostTurn); failed = 1; } if (checkTurn(pre, g) < 0){ printf("\nwhoseTurn: %d, Expected: %d\n", g->whoseTurn, pre->whoseTurn); failed = 1; } if (checkPhase(pre, g) < 0){ printf("\nphase: %d, Expected: %d\n", g->phase, pre->phase); failed = 1; } if (checkNumActions(pre, g) < 0){ printf("\nnumActions: %d, Expected: %d\n", g->numActions, pre->numActions); failed = 1; } if (checkCoins(pre, g) < 0){ printf("\ncoins: %d, Expected: %d\n", g->coins, pre->coins); failed = 1; } if (checkNumBuys(pre, g) < 0){ printf("\nnumBuys: %d, Expected: %d\n", g->numBuys, pre->numBuys); failed = 1; } //Check all player's discard unchanged if (checkDiscards(pre, g) < 0){ printf("\nDiscards changed after smithy\n"); //Print expected and actual discards for each player for (i = 0; i < NUM_PLAYERS; i++){ printf(" Discard pile for player %d:\n", i); printf(" Count: %d, Expected: %d\n", g->discardCount[i], pre->discardCount[i]); if (g->discardCount[i] > 0){ printf(" Actual Cards: "); for (j = 0; j < g->discardCount[i]; j++){ printf("%d ", g->discard[i][j]); } printf("\n Expected Cards: "); for (j = 0; j < pre->discardCount[i]; j++){ printf("%d ", pre->discard[i][j]); } } } failed = 1; } //Check deck unchanged for other players for (i = 0; i < g->numPlayers; i++){ //skip if current player if (i == whoseTurn(g)){ continue; } if (pre->deckCount[i] != g->deckCount[i]){ printf("\nPlayer %d's deckCount: %d, Expected: %d", i, g->deckCount[i], pre->deckCount[i]); failed = 1; } else { //check each card for (j = 0; j < g->deckCount[i]; j++){ if (pre->deck[i][j] != g->deck[i][j]){ printf("\nPlayer %d's deck[%d]: %d, Expected: %d", i, j, g->deck[i][j], pre->deck[i][j]); failed = 1; } } } } //Check hand unchanged for other players for (i = 0; i < g->numPlayers; i++){ //skip if current player if (i == whoseTurn(g)){ continue; } if (pre->handCount[i] != g->handCount[i]){ printf("\nPlayer %d's handCount: %d, Expected: %d", i, g->handCount[i], pre->handCount[i]); failed = 1; } else { //check each card for (j = 0; j < g->handCount[i]; j++){ if (pre->hand[i][j] != g->hand[i][j]){ printf("\nPlayer %d's hand[%d]: %d, Expected: %d", i, j, g->hand[i][j], pre->hand[i][j]); failed = 1; } } } } //Check smithy added to played pile if (g->playedCardCount != pre->playedCardCount + 1){ printf("\nPlayed card count: %d, Expected: %d", g->playedCardCount, pre->playedCardCount + 1); failed = 1; } else if (g->playedCards[g->playedCardCount - 1] != TEST_CARD){ printf("\nLast played card: %d, Expected: %d", g->playedCards[g->playedCardCount - 1], TEST_CARD); failed = 1; } //Check 3 cards added to hand and smithy removed if (g->handCount[whoseTurn(g)] != pre->handCount[whoseTurn(g)] + 2){ printf("\nCurrent player's hand count: %d, Expected: %d", g->handCount[whoseTurn(g)], pre->handCount[whoseTurn(g)] + 2); failed = 1; } //Check 3 cards removed from deck if (g->deckCount[whoseTurn(g)] != pre->deckCount[whoseTurn(g)] - 3){ printf("\nCurrent player's deck count: %d, Expected: %d", g->deckCount[whoseTurn(g)], pre->deckCount[whoseTurn(g)] - 3); failed = 1; } //Check cards removed from deck = cards added to hand (last 2 cards, plus position 0...last card replaces test card when discarded) if (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1] != pre->deck[whoseTurn(g)][pre->deckCount[whoseTurn(g)] - 1]){ printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 1, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1], pre->deck[whoseTurn(g)][pre->deckCount[whoseTurn(g)] - 1]); failed = 1; } if (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 2] != pre->deck[whoseTurn(g)][pre->deckCount[whoseTurn(g)] - 2]){ printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 2, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 2], pre->deck[whoseTurn(g)][pre->deckCount[whoseTurn(g)] - 2]); failed = 1; } if (g->hand[whoseTurn(g)][0] != pre->deck[whoseTurn(g)][pre->deckCount[whoseTurn(g)] - 3]){ printf("\nCurrent player's hand[0]: %d, Expected: %d", g->hand[whoseTurn(g)][0], pre->deck[whoseTurn(g)][pre->deckCount[whoseTurn(g)] - 3]); failed = 1; } //Check no bonus coins added if (coin_bonus != 0){ printf("\nCoin bonus after smithy: %d, Expected: %d", coin_bonus, 0); failed = 1; } //Final check if (failed){ printf("\nResult: FAIL\n"); } else { printf("none"); printf("\nResult: PASS\n"); } return 0; }
int main () { int i, j; int result; //return value for function calls int failed, changed; //flags for tests int cardsBefore[treasure_map]; //cards in hand before shuffle int cardsAfter[treasure_map]; //cards in hand after shuffle struct gameState *g = malloc(sizeof(struct gameState)); //working game state struct gameState *pre = malloc(sizeof(struct gameState)); //reference game state; stored before functions run int selectedCards[10] = {adventurer, council_room, feast, gardens, mine, smithy, village, tribute, salvager, sea_hag}; int seed = 10; //---Test deckCount = 0 //---Expected result: error printf("*** Testing deckCount = 0 ***\n"); printf("Errors: "); //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted."); return -1; } //Draw all cards in deck while (g->deckCount[whoseTurn(g)] > 0){ drawCard(whoseTurn(g), g); } //Save current state memcpy(pre, g, sizeof(struct gameState)); //Attempt to shuffle result = shuffle(whoseTurn(g), g); failed = 0; if (result != -1){ printf("\nReturn value: %d, Expected: %d", result, -1); failed = 1; } //Check game state is unchanged if (checkGameState(pre, g) < 0){ printf("\ngameState changed"); failed = 1; } //Final check if (failed){ printf("\nResult: FAIL\n\n"); } else { printf("none"); printf("\nResult: PASS\n\n"); } //---Test deckCount = 1 //---Expected result: gameState is unchanged printf("*** Testing deckCount = 1 ***\n"); printf("Errors: "); //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted."); return -1; } //Draw all cards but 1 in deck while (g->deckCount[whoseTurn(g)] > 1){ drawCard(whoseTurn(g), g); } //Save current state memcpy(pre, g, sizeof(struct gameState)); //Run shuffle and check results failed = 0; result = shuffle(whoseTurn(g), g); if (result == -1){ printf("\nReturn value: %d, Expected: %d", result, 0); failed = 1; } //Check game state is unchanged if (checkGameState(pre, g) < 0){ printf("\ngameState changed"); failed = 1; } //Final check if (failed){ printf("\nResult: FAIL\n\n"); } else { printf("none"); printf("\nResult: PASS\n\n"); } //---Test deckCount > 1 /*---Expected results: - Game and turn settings are unchanged - Other player's cards (hand, deck, discard) are unchanged - Current player's hand and discard are unchanged - Played cards are unchanged - Current player's deck Count is unchanged - Current player's deck contains same cards as before shuffle - Current player's deck cards are in different order than before shuffle */ printf("*** Testing deckCount > 1 ***\n"); printf("Errors: "); //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted."); return -1; } //Confirm deckCount > 1 if (g->deckCount[whoseTurn(g)] <= 1){ printf("\nCould not create suitable game. Testing aborted."); return -1; } //Save current state memcpy(pre, g, sizeof(struct gameState)); //Initialize card count arrays for (i = 0; i < treasure_map; i++){ cardsAfter[i] = 0; cardsBefore[i] = 0; } //Get before deck card counts for (i = 0; i < g->deckCount[(whoseTurn(g))]; i++){ cardsBefore[g->deck[whoseTurn(g)][i]]++; } //Run shuffle and check results failed = 0; result = shuffle(whoseTurn(g), g); if (result == -1){ printf("\nReturn value: %d, Expected: %d", result, 0); failed = 1; } //Check game/turn settings if (checkNumPlayers(pre, g) < 0){ printf("\nNumPlayers: %d, Expected: %d", g->numPlayers, pre->numPlayers); failed = 1; } result = checkSupply(pre, g); if (result != 0){ printf("\nSupply count for card %d: %d, Expected: %d", result, g->supplyCount[result], pre->supplyCount[result]); failed = 1; } result = checkEmbargo(pre, g); if (result != 0){ printf("\nEmbargo for card %d: %d, Expected: %d", result, g->embargoTokens[result], pre->embargoTokens[result]); failed = 1; } if (checkOutpost(pre, g) < 0){ printf("\noutpostPlayed: %d, Expected: %d", g->outpostPlayed, pre->outpostPlayed); printf("\noutpostTurn: %d, Expected: %d", g->outpostTurn, pre->outpostTurn); failed = 1; } if (checkTurn(pre, g) < 0){ printf("\nwhoseTurn: %d, Expected: %d", g->whoseTurn, pre->whoseTurn); failed = 1; } if (checkPhase(pre, g) < 0){ printf("\nphase: %d, Expected: %d", g->phase, pre->phase); failed = 1; } if (checkNumActions(pre, g) < 0){ printf("\nnumActions: %d, Expected: %d", g->numActions, pre->numActions); failed = 1; } if (checkCoins(pre, g) < 0){ printf("\ncoins: %d, Expected: %d", g->coins, pre->coins); failed = 1; } if (checkNumBuys(pre, g) < 0){ printf("\nnumBuys: %d, Expected: %d", g->numBuys, pre->numBuys); failed = 1; } //Check all hand, discard, play cards unchanged if (checkHands(pre, g) < 0){ printf("\nHands changed after shuffle\n"); //Print expected and actual hand for each player for (i = 0; i < NUM_PLAYERS; i++){ printf(" Hand for player %d:\n", i); printf(" Count: %d, Expected: %d\n", g->handCount[i], pre->handCount[i]); if (g->handCount[i] > 0){ printf(" Actual Cards: "); for (j = 0; j < g->handCount[i]; j++){ printf("%d ", g->hand[i][j]); } printf("\n Expected Cards: "); for (j = 0; j < pre->handCount[i]; j++){ printf("%d ", pre->hand[i][j]); } } } failed = 1; } if (checkDiscards(pre, g) < 0){ printf("\nDiscards changed after shuffle\n"); //Print expected and actual discards for each player for (i = 0; i < NUM_PLAYERS; i++){ printf(" Discard pile for player %d:\n", i); printf(" Count: %d, Expected: %d\n", g->discardCount[i], pre->discardCount[i]); if (g->discardCount[i] > 0){ printf(" Actual Cards: "); for (j = 0; j < g->discardCount[i]; j++){ printf("%d ", g->discard[i][j]); } printf("\n Expected Cards: "); for (j = 0; j < pre->discardCount[i]; j++){ printf("%d ", pre->discard[i][j]); } } } failed = 1; } if (checkPlayed(pre, g) < 0){ printf("\nPlayed cards changed after shuffle\n"); //Print expected and actual discards for each player printf(" Played count: %d, Expected: %d\n", g->playedCardCount, pre->playedCardCount); if (g->playedCardCount > 0){ printf(" Actual Cards: "); for (i = 0; i < g->playedCardCount; i++){ printf("%d ", g->playedCards[i]); } printf("\n Expected Cards: "); for (i = 0; i < pre->playedCardCount; i++){ printf("%d ", pre->playedCards[i]); } } failed = 1; } //Check deck unchanged for other players for (i = 0; i < g->numPlayers; i++){ //skip if current player if (i == whoseTurn(g)){ continue; } if (pre->deckCount[i] != g->deckCount[i]){ printf("\nPlayer %d's deckCount: %d, Expected: %d", i, g->deckCount[i], pre->deckCount[i]); failed = 1; } else { //check each card for (j = 0; j < g->deckCount[i]; j++){ if (pre->deck[i][j] != g->deck[i][j]){ printf("\nPlayer %d's deck[%d]: %d, Expected: %d", i, j, g->deck[i][j], pre->deck[i][j]); failed = 1; } } } } //Check current player's deck is same size if (pre->deckCount[whoseTurn(g)] != g->deckCount[whoseTurn(g)]){ printf("\nCurrent player's deckCount: %d, Expected: %d", g->deckCount[whoseTurn(g)], pre->deckCount[whoseTurn(g)]); failed = 1; } //Check current player's deck contains same cards as before for (i = 0; i < g->deckCount[(whoseTurn(g))]; i++){ cardsAfter[g->deck[whoseTurn(g)][i]]++; } for (i = 0; i < treasure_map; i++){ if (cardsBefore[i] != cardsAfter[i]){ printf("\nCount for card %d in deck: %d, Expected: %d", i, cardsAfter[i], cardsBefore[i]); failed = 1; break; } } //Check current player's deck has cards in different order than before if (pre->deckCount[whoseTurn(g)] == g->deckCount[whoseTurn(g)]){ changed = 0; for (i = 0; i < g->deckCount[whoseTurn(g)]; i++){ if (pre->deck[whoseTurn(g)][i] != g->deck[whoseTurn(g)][i]){ changed = 1; break; } } if (!changed){ printf("\nCards in current player's deck not shuffled"); failed = 1; } } //Final check if (failed){ printf("\nResult: FAIL\n"); } else { printf("none"); printf("\nResult: PASS\n"); } return 0; }
int main () { int i, j; //loop controls int result; //return value for function calls int failed; //flags for tests struct gameState *g = malloc(sizeof(struct gameState)); //working game state struct gameState *pre = malloc(sizeof(struct gameState)); //reference game state; stored before functions run int selectedCards[10] = {adventurer, council_room, feast, gardens, mine, smithy, village, tribute, salvager, sea_hag}; int seed = 10; int choice1, choice2, choice3; //choices for card effect int coin_bonus; //coins added by card //---Test adventurer with 2 treasure cards in deck //---(all choices = -1, no bonus) /*---Expected result: - Game and turn settings are unchanged - Other player's cards (hand, deck, discard) are unchanged - Played card count increased by 1 - Adventurer card added to played pile (in last position) - Adventurer card removed from hand - Current player's deck count decreased by 2 treasures + extras - Other cards in player's deck unchanged - Current player's discard count increased by extras - Current player's hand count increased by 1 (+2 treasures, -1 adventurer) - Cards added to player's hand are treasure - Cards added to player's discard are extras - No bonus coins */ printf("*** Testing 2 treasure cards in deck ***\n"); printf("Errors: "); //Setup card options choice1 = -1; choice2 = -1; choice3 = -1; coin_bonus = 0; //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted.\n"); return -1; } //Set deck to 5 extras - 2 treasures - 5 extras g->deckCount[whoseTurn(g)] = 0; for (i = 1; i <= EXTRA_COUNT; i++){ g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = EXTRA_CARD; g->deckCount[whoseTurn(g)]++; } for (i = 1; i <= 2; i++){ g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = TREASURE; g->deckCount[whoseTurn(g)]++; } for (i = 1; i <= EXTRA_COUNT; i++){ g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = EXTRA_CARD; g->deckCount[whoseTurn(g)]++; } //Set test position in hand to test card g->hand[whoseTurn(g)][TEST_POS] = TEST_CARD; //Save current state memcpy(pre, g, sizeof(struct gameState)); //Attempt to execute card result = cardEffect(TEST_CARD, choice1, choice2, choice3, g, TEST_POS, &coin_bonus); failed = 0; if (result != 0){ printf("\nReturn value: %d, Expected: %d", result, 0); failed = 1; } //Check game/turn settings if (checkNumPlayers(pre, g) < 0){ printf("\nNumPlayers: %d, Expected: %d", g->numPlayers, pre->numPlayers); failed = 1; } result = checkSupply(pre, g); if (result != 0){ printf("\nSupply count for card %d: %d, Expected: %d", result, g->supplyCount[result], pre->supplyCount[result]); failed = 1; } result = checkEmbargo(pre, g); if (result != 0){ printf("\nEmbargo for card %d: %d, Expected: %d", result, g->embargoTokens[result], pre->embargoTokens[result]); failed = 1; } if (checkOutpost(pre, g) < 0){ printf("\noutpostPlayed: %d, Expected: %d", g->outpostPlayed, pre->outpostPlayed); printf("\noutpostTurn: %d, Expected: %d", g->outpostTurn, pre->outpostTurn); failed = 1; } if (checkTurn(pre, g) < 0){ printf("\nwhoseTurn: %d, Expected: %d", g->whoseTurn, pre->whoseTurn); failed = 1; } if (checkPhase(pre, g) < 0){ printf("\nphase: %d, Expected: %d", g->phase, pre->phase); failed = 1; } if (checkNumActions(pre, g) < 0){ printf("\nnumActions: %d, Expected: %d", g->numActions, pre->numActions); failed = 1; } if (checkCoins(pre, g) < 0){ printf("\ncoins: %d, Expected: %d", g->coins, pre->coins); failed = 1; } if (checkNumBuys(pre, g) < 0){ printf("\nnumBuys: %d, Expected: %d", g->numBuys, pre->numBuys); failed = 1; } //Check discard unchanged for other players for (i = 0; i < g->numPlayers; i++){ //skip if current player if (i == whoseTurn(g)){ continue; } if (pre->discardCount[i] != g->discardCount[i]){ printf("\nPlayer %d's discardCount: %d, Expected: %d", i, g->discardCount[i], pre->discardCount[i]); failed = 1; } else { //check each card for (j = 0; j < g->discardCount[i]; j++){ if (pre->discard[i][j] != g->discard[i][j]){ printf("\nPlayer %d's discard[%d]: %d, Expected: %d", i, j, g->discard[i][j], pre->discard[i][j]); failed = 1; } } } } //Check deck unchanged for other players for (i = 0; i < g->numPlayers; i++){ //skip if current player if (i == whoseTurn(g)){ continue; } if (pre->deckCount[i] != g->deckCount[i]){ printf("\nPlayer %d's deckCount: %d, Expected: %d", i, g->deckCount[i], pre->deckCount[i]); failed = 1; } else { //check each card for (j = 0; j < g->deckCount[i]; j++){ if (pre->deck[i][j] != g->deck[i][j]){ printf("\nPlayer %d's deck[%d]: %d, Expected: %d", i, j, g->deck[i][j], pre->deck[i][j]); failed = 1; } } } } //Check hand unchanged for other players for (i = 0; i < g->numPlayers; i++){ //skip if current player if (i == whoseTurn(g)){ continue; } if (pre->handCount[i] != g->handCount[i]){ printf("\nPlayer %d's handCount: %d, Expected: %d", i, g->handCount[i], pre->handCount[i]); failed = 1; } else { //check each card for (j = 0; j < g->handCount[i]; j++){ if (pre->hand[i][j] != g->hand[i][j]){ printf("\nPlayer %d's hand[%d]: %d, Expected: %d", i, j, g->hand[i][j], pre->hand[i][j]); failed = 1; } } } } //Check adventurer added to played pile if (g->playedCardCount != pre->playedCardCount + 1){ printf("\nPlayed card count: %d, Expected: %d", g->playedCardCount, pre->playedCardCount + 1); failed = 1; } else if (g->playedCards[g->playedCardCount - 1] != TEST_CARD){ printf("\nLast played card: %d, Expected: %d", g->playedCards[g->playedCardCount - 1], TEST_CARD); failed = 1; } //Check 2 treasures + extras removed from deck; other cards remain if (g->deckCount[whoseTurn(g)] != pre->deckCount[whoseTurn(g)] - EXTRA_COUNT - 2){ printf("\nCurrent player's deck count: %d, Expected: %d", g->deckCount[whoseTurn(g)], pre->deckCount[whoseTurn(g)] - EXTRA_COUNT - 2); failed = 1; } for (i = 0; i < g->deckCount[whoseTurn(g)]; i++){ if (g->deck[whoseTurn(g)][i] != EXTRA_CARD){ printf("\nCurrent player's deck[%d]: %d, Expected: %d", i, g->deck[whoseTurn(g)][i], EXTRA_CARD); failed = 1; } } //Check 2 treasure cards added to hand, adventurer removed if (g->handCount[whoseTurn(g)] != pre->handCount[whoseTurn(g)] + 1){ printf("\nCurrent player's hand count: %d, Expected: %d", g->handCount[whoseTurn(g)], pre->handCount[whoseTurn(g)] + 1); failed = 1; } if ( (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1] != TREASURE) && (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 2] != TREASURE) ){ printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 1, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1], TREASURE); printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 2, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 2], TREASURE); failed = 1; } //Check extra cards added to discard if (g->discardCount[whoseTurn(g)] != pre->discardCount[whoseTurn(g)] + EXTRA_COUNT){ printf("\nCurrent player's discard count: %d, Expected: %d", g->discardCount[whoseTurn(g)], pre->discardCount[whoseTurn(g)] + EXTRA_COUNT); failed = 1; } for (i = 1; i <= EXTRA_COUNT; i++){ if (g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)] - i] != EXTRA_CARD){ printf("\nCurrent player's discard[%d]: %d, Expected: %d", g->discardCount[whoseTurn(g)] - i, g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)] - i], EXTRA_CARD); failed = 1; } } //Check no bonus coins added if (coin_bonus != 0){ printf("\nCoin bonus after adventurer: %d, Expected: %d", coin_bonus, 0); failed = 1; } //Final check if (failed){ printf("\nResult: FAIL\n\n"); } else { printf("none"); printf("\nResult: PASS\n\n"); } //---Test adventurer with 1 treasure card in deck, 1 in discard //---(all choices = -1, no bonus) /*---Expected result: - Game and turn settings are unchanged - Other player's cards (hand, deck, discard) are unchanged - Played card count increased by 1 - Adventurer card added to played pile (in last position) - Adventurer card removed from hand - Current player's deck count decreased by 1 treasure + extras - Current player's discard count increased by extras, decreased by 1 treasure - Current player's hand count increased by 1 (+2 treasures, -1 adventurer) - Cards added to player's hand are treasure - Cards added to player's discard are extras - No bonus coins ------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- NOTICE: Test disabled because of bug in current code causing infinite loop. When deck is empty, adventurer code does not add discard pile to deck before shuffle. ------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- */ printf("*** Testing 1 treasure in deck + 1 in discard ***\n"); //printf("Errors: "); printf("Test disabled because of infinite loop\n"); printf("Result: FAIL\n\n"); /* //Setup card options choice1 = -1; choice2 = -1; choice3 = -1; coin_bonus = 0; //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted.\n"); return -1; } //Set deck to 1 treasure - 5 extras g->deckCount[whoseTurn(g)] = 0; g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = TREASURE; g->deckCount[whoseTurn(g)]++; for (i = 1; i <= EXTRA_COUNT; i++){ g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = EXTRA_CARD; g->deckCount[whoseTurn(g)]++; } //Set discard to 1 treasure g->discardCount[whoseTurn(g)] = 0; g->discard[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = TREASURE; g->discardCount[whoseTurn(g)]++; //Set test position in hand to test card g->hand[whoseTurn(g)][TEST_POS] = TEST_CARD; //Save current state memcpy(pre, g, sizeof(struct gameState)); //Attempt to execute card result = cardEffect(TEST_CARD, choice1, choice2, choice3, g, TEST_POS, &coin_bonus); failed = 0; if (result != 0){ printf("\nReturn value: %d, Expected: %d", result, 0); failed = 1; } //Check game/turn settings if (checkNumPlayers(pre, g) < 0){ printf("\nNumPlayers: %d, Expected: %d", g->numPlayers, pre->numPlayers); failed = 1; } result = checkSupply(pre, g); if (result != 0){ printf("\nSupply count for card %d: %d, Expected: %d", result, g->supplyCount[result], pre->supplyCount[result]); failed = 1; } result = checkEmbargo(pre, g); if (result != 0){ printf("\nEmbargo for card %d: %d, Expected: %d", result, g->embargoTokens[result], pre->embargoTokens[result]); failed = 1; } if (checkOutpost(pre, g) < 0){ printf("\noutpostPlayed: %d, Expected: %d", g->outpostPlayed, pre->outpostPlayed); printf("\noutpostTurn: %d, Expected: %d", g->outpostTurn, pre->outpostTurn); failed = 1; } if (checkTurn(pre, g) < 0){ printf("\nwhoseTurn: %d, Expected: %d", g->whoseTurn, pre->whoseTurn); failed = 1; } if (checkPhase(pre, g) < 0){ printf("\nphase: %d, Expected: %d", g->phase, pre->phase); failed = 1; } if (checkNumActions(pre, g) < 0){ printf("\nnumActions: %d, Expected: %d", g->numActions, pre->numActions); failed = 1; } if (checkCoins(pre, g) < 0){ printf("\ncoins: %d, Expected: %d", g->coins, pre->coins); failed = 1; } if (checkNumBuys(pre, g) < 0){ printf("\nnumBuys: %d, Expected: %d", g->numBuys, pre->numBuys); failed = 1; } //Check discard unchanged for other players for (i = 0; i < g->numPlayers; i++){ //skip if current player if (i == whoseTurn(g)){ continue; } if (pre->discardCount[i] != g->discardCount[i]){ printf("\nPlayer %d's discardCount: %d, Expected: %d", i, g->discardCount[i], pre->discardCount[i]); failed = 1; } else { //check each card for (j = 0; j < g->discardCount[i]; j++){ if (pre->discard[i][j] != g->discard[i][j]){ printf("\nPlayer %d's discard[%d]: %d, Expected: %d", i, j, g->discard[i][j], pre->discard[i][j]); failed = 1; } } } } //Check deck unchanged for other players for (i = 0; i < g->numPlayers; i++){ //skip if current player if (i == whoseTurn(g)){ continue; } if (pre->deckCount[i] != g->deckCount[i]){ printf("\nPlayer %d's deckCount: %d, Expected: %d", i, g->deckCount[i], pre->deckCount[i]); failed = 1; } else { //check each card for (j = 0; j < g->deckCount[i]; j++){ if (pre->deck[i][j] != g->deck[i][j]){ printf("\nPlayer %d's deck[%d]: %d, Expected: %d", i, j, g->deck[i][j], pre->deck[i][j]); failed = 1; } } } } //Check hand unchanged for other players for (i = 0; i < g->numPlayers; i++){ //skip if current player if (i == whoseTurn(g)){ continue; } if (pre->handCount[i] != g->handCount[i]){ printf("\nPlayer %d's handCount: %d, Expected: %d", i, g->handCount[i], pre->handCount[i]); failed = 1; } else { //check each card for (j = 0; j < g->handCount[i]; j++){ if (pre->hand[i][j] != g->hand[i][j]){ printf("\nPlayer %d's hand[%d]: %d, Expected: %d", i, j, g->hand[i][j], pre->hand[i][j]); failed = 1; } } } } //Check adventurer added to played pile if (g->playedCardCount != pre->playedCardCount + 1){ printf("\nPlayed card count: %d, Expected: %d", g->playedCardCount, pre->playedCardCount + 1); failed = 1; } else if (g->playedCards[g->playedCardCount - 1] != TEST_CARD){ printf("\nLast played card: %d, Expected: %d", g->playedCards[g->playedCardCount - 1], TEST_CARD); failed = 1; } //Check 1 treasure + extras removed from deck if (g->deckCount[whoseTurn(g)] != pre->deckCount[whoseTurn(g)] - EXTRA_COUNT - 1){ printf("\nCurrent player's deck count: %d, Expected: %d", g->deckCount[whoseTurn(g)], pre->deckCount[whoseTurn(g)] - EXTRA_COUNT - 1); failed = 1; } //Check 2 treasure cards added to hand, adventurer removed if (g->handCount[whoseTurn(g)] != pre->handCount[whoseTurn(g)] + 1){ printf("\nCurrent player's hand count: %d, Expected: %d", g->handCount[whoseTurn(g)], pre->handCount[whoseTurn(g)] + 1); failed = 1; } if ( (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1] != TREASURE) && (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 2] != TREASURE) ){ printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 1, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1], TREASURE); printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 2, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 2], TREASURE); failed = 1; } //Check extra cards added to discard and treasure removed if (g->discardCount[whoseTurn(g)] != pre->discardCount[whoseTurn(g)] + EXTRA_COUNT - 1){ printf("\nCurrent player's discard count: %d, Expected: %d", g->discardCount[whoseTurn(g)], pre->discardCount[whoseTurn(g)] + EXTRA_COUNT - 1); failed = 1; } for (i = 1; i <= EXTRA_COUNT; i++){ if (g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)] - i] != EXTRA_CARD){ printf("\nCurrent player's discard[%d]: %d, Expected: %d", g->discardCount[whoseTurn(g)] - i, g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)] - i], EXTRA_CARD); failed = 1; } } //Check no bonus coins added if (coin_bonus != 0){ printf("\nCoin bonus after adventurer: %d, Expected: %d", coin_bonus, 0); failed = 1; } //Final check if (failed){ printf("\nResult: FAIL\n\n"); } else { printf("none"); printf("\nResult: PASS\n\n"); } */ //---Test adventurer with 1 treasure card in deck (only 1 treasure total) //---(all choices = -1, no bonus) /*---Expected result: - Game and turn settings are unchanged - Other player's cards (hand, deck, discard) are unchanged - Played card count increased by 1 - Adventurer card added to played pile (in last position) - Adventurer removed from hand - Current player's deck count decreased by 1 treasure + extras - Other cards in player's deck unchanged - Current player's discard count increased by extras - Current player's hand count is unchanged (+1 treasure, -1 adventurer) - Card added to player's hand is treasure - Cards added to player's discard are extras - No bonus coins ------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- NOTICE: Test disabled because of bug in current code causing infinite loop. While loop does not have exit condition for case when only 1 treasure exists. ------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- */ printf("*** Testing 1 treasure card in deck ***\n"); //printf("Errors: "); printf("Test disabled because of infinite loop\n"); printf("Result: FAIL\n"); /* //Setup card options choice1 = -1; choice2 = -1; choice3 = -1; coin_bonus = 0; //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted.\n"); return -1; } //Set deck to 5 extras - 1 treasure - 5 extras g->deckCount[whoseTurn(g)] = 0; for (i = 1; i <= EXTRA_COUNT; i++){ g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = EXTRA_CARD; g->deckCount[whoseTurn(g)]++; } g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = TREASURE; g->deckCount[whoseTurn(g)]++; for (i = 1; i <= EXTRA_COUNT; i++){ g->deck[whoseTurn(g)][g->deckCount[whoseTurn(g)]] = EXTRA_CARD; g->deckCount[whoseTurn(g)]++; } //Set test position in hand to test card g->hand[whoseTurn(g)][TEST_POS] = TEST_CARD; //Save current state memcpy(pre, g, sizeof(struct gameState)); //Attempt to execute card result = cardEffect(TEST_CARD, choice1, choice2, choice3, g, TEST_POS, &coin_bonus); failed = 0; if (result != 0){ printf("\nReturn value: %d, Expected: %d", result, 0); failed = 1; } //Check game/turn settings if (checkNumPlayers(pre, g) < 0){ printf("\nNumPlayers: %d, Expected: %d", g->numPlayers, pre->numPlayers); failed = 1; } result = checkSupply(pre, g); if (result != 0){ printf("\nSupply count for card %d: %d, Expected: %d", result, g->supplyCount[result], pre->supplyCount[result]); failed = 1; } result = checkEmbargo(pre, g); if (result != 0){ printf("\nEmbargo for card %d: %d, Expected: %d", result, g->embargoTokens[result], pre->embargoTokens[result]); failed = 1; } if (checkOutpost(pre, g) < 0){ printf("\noutpostPlayed: %d, Expected: %d", g->outpostPlayed, pre->outpostPlayed); printf("\noutpostTurn: %d, Expected: %d", g->outpostTurn, pre->outpostTurn); failed = 1; } if (checkTurn(pre, g) < 0){ printf("\nwhoseTurn: %d, Expected: %d", g->whoseTurn, pre->whoseTurn); failed = 1; } if (checkPhase(pre, g) < 0){ printf("\nphase: %d, Expected: %d", g->phase, pre->phase); failed = 1; } if (checkNumActions(pre, g) < 0){ printf("\nnumActions: %d, Expected: %d", g->numActions, pre->numActions); failed = 1; } if (checkCoins(pre, g) < 0){ printf("\ncoins: %d, Expected: %d", g->coins, pre->coins); failed = 1; } if (checkNumBuys(pre, g) < 0){ printf("\nnumBuys: %d, Expected: %d", g->numBuys, pre->numBuys); failed = 1; } //Check discard unchanged for other players for (i = 0; i < g->numPlayers; i++){ //skip if current player if (i == whoseTurn(g)){ continue; } if (pre->discardCount[i] != g->discardCount[i]){ printf("\nPlayer %d's discardCount: %d, Expected: %d", i, g->discardCount[i], pre->discardCount[i]); failed = 1; } else { //check each card for (j = 0; j < g->discardCount[i]; j++){ if (pre->discard[i][j] != g->discard[i][j]){ printf("\nPlayer %d's discard[%d]: %d, Expected: %d", i, j, g->discard[i][j], pre->discard[i][j]); failed = 1; } } } } //Check deck unchanged for other players for (i = 0; i < g->numPlayers; i++){ //skip if current player if (i == whoseTurn(g)){ continue; } if (pre->deckCount[i] != g->deckCount[i]){ printf("\nPlayer %d's deckCount: %d, Expected: %d", i, g->deckCount[i], pre->deckCount[i]); failed = 1; } else { //check each card for (j = 0; j < g->deckCount[i]; j++){ if (pre->deck[i][j] != g->deck[i][j]){ printf("\nPlayer %d's deck[%d]: %d, Expected: %d", i, j, g->deck[i][j], pre->deck[i][j]); failed = 1; } } } } //Check hand unchanged for other players for (i = 0; i < g->numPlayers; i++){ //skip if current player if (i == whoseTurn(g)){ continue; } if (pre->handCount[i] != g->handCount[i]){ printf("\nPlayer %d's handCount: %d, Expected: %d", i, g->handCount[i], pre->handCount[i]); failed = 1; } else { //check each card for (j = 0; j < g->handCount[i]; j++){ if (pre->hand[i][j] != g->hand[i][j]){ printf("\nPlayer %d's hand[%d]: %d, Expected: %d", i, j, g->hand[i][j], pre->hand[i][j]); failed = 1; } } } } //Check adventurer added to played pile if (g->playedCardCount != pre->playedCardCount + 1){ printf("\nPlayed card count: %d, Expected: %d", g->playedCardCount, pre->playedCardCount + 1); failed = 1; } else if (g->playedCards[g->playedCardCount - 1] != TEST_CARD){ printf("\nLast played card: %d, Expected: %d", g->playedCards[g->playedCardCount - 1], TEST_CARD); failed = 1; } //Check 1 treasure + extras removed from deck; other cards remain if (g->deckCount[whoseTurn(g)] != pre->deckCount[whoseTurn(g)] - EXTRA_COUNT - 1){ printf("\nCurrent player's deck count: %d, Expected: %d", g->deckCount[whoseTurn(g)], pre->deckCount[whoseTurn(g)] - EXTRA_COUNT - 1); failed = 1; } for (i = 0; i < g->deckCount[whoseTurn(g)]; i++){ if (g->deck[whoseTurn(g)][i] != EXTRA_CARD){ printf("\nCurrent player's deck[%d]: %d, Expected: %d", i, g->deck[whoseTurn(g)][i], EXTRA_CARD); failed = 1; } } //Check 1 treasure card added to hand, adventurer removed if (g->handCount[whoseTurn(g)] != pre->handCount[whoseTurn(g)]){ printf("\nCurrent player's hand count: %d, Expected: %d", g->handCount[whoseTurn(g)], pre->handCount[whoseTurn(g)]); failed = 1; } if (g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1] != TREASURE){ printf("\nCurrent player's hand[%d]: %d, Expected: %d", g->handCount[whoseTurn(g)] - 1, g->hand[whoseTurn(g)][g->handCount[whoseTurn(g)] - 1], TREASURE); failed = 1; } //Check extra cards added to discard if (g->discardCount[whoseTurn(g)] != pre->discardCount[whoseTurn(g)] + EXTRA_COUNT){ printf("\nCurrent player's discard count: %d, Expected: %d", g->discardCount[whoseTurn(g)], pre->discardCount[whoseTurn(g)] + EXTRA_COUNT); failed = 1; } for (i = 1; i <= EXTRA_COUNT; i++){ if (g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)] - i] != EXTRA_CARD){ printf("\nCurrent player's discard[%d]: %d, Expected: %d", g->discardCount[whoseTurn(g)] - i, g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)] - i], EXTRA_CARD); failed = 1; } } //Check no bonus coins added if (coin_bonus != 0){ printf("\nCoin bonus after adventurer: %d, Expected: %d", coin_bonus, 0); failed = 1; } //Final check if (failed){ printf("\nResult: FAIL\n"); } else { printf("none"); printf("\nResult: PASS\n"); } */ return 0; }