int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, struct gameState *state) { int i; int j; int it; //set up random number generator SelectStream(1); PutSeed((long)randomSeed); //check number of players if (numPlayers > MAX_PLAYERS || numPlayers < 2) { return -1; } //set number of players state->numPlayers = numPlayers; //check selected kingdom cards are different for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { if (j != i && kingdomCards[j] == kingdomCards[i]) { return -1; } } } //initialize supply /////////////////////////////// //set number of Curse cards if (numPlayers == 2) { state->supplyCount[curse] = 10; } else if (numPlayers == 3) { state->supplyCount[curse] = 20; } else { state->supplyCount[curse] = 30; } //set number of Victory cards if (numPlayers == 2) { state->supplyCount[estate] = 8; state->supplyCount[duchy] = 8; state->supplyCount[province] = 8; } else { state->supplyCount[estate] = 12; state->supplyCount[duchy] = 12; state->supplyCount[province] = 12; } //set number of Treasure cards state->supplyCount[copper] = 60 - (7 * numPlayers); state->supplyCount[silver] = 40; state->supplyCount[gold] = 30; //set number of Kingdom cards for (i = adventurer; i <= treasure_map; i++) //loop all cards { for (j = 0; j < 10; j++) //loop chosen cards { if (kingdomCards[j] == i) { //check if card is a 'Victory' Kingdom card if (kingdomCards[j] == great_hall || kingdomCards[j] == gardens) { if (numPlayers == 2) { state->supplyCount[i] = 8; } else{ state->supplyCount[i] = 12; } } else { state->supplyCount[i] = 10; } break; } else //card is not in the set choosen for the game { state->supplyCount[i] = -1; } } } //////////////////////// //supply intilization complete //set player decks for (i = 0; i < numPlayers; i++) { state->deckCount[i] = 0; for (j = 0; j < 3; j++) { state->deck[i][j] = estate; state->deckCount[i]++; } for (j = 3; j < 10; j++) { state->deck[i][j] = copper; state->deckCount[i]++; } } //shuffle player decks for (i = 0; i < numPlayers; i++) { if ( shuffle(i, state) < 0 ) { return -1; } } //draw player hands for (i = 0; i < numPlayers; i++) { //initialize hand size to zero state->handCount[i] = 0; state->discardCount[i] = 0; //draw 5 cards // for (j = 0; j < 5; j++) // { // drawCard(i, state); // } } //set embargo tokens to 0 for all supply piles for (i = 0; i <= treasure_map; i++) { state->embargoTokens[i] = 0; } //initialize first player's turn state->outpostPlayed = 0; state->phase = 0; state->numActions = 1; state->numBuys = 1; state->playedCardCount = 0; state->whoseTurn = 0; state->handCount[state->whoseTurn] = 0; //int it; move to top //Moved draw cards to here, only drawing at the start of a turn for (it = 0; it < 5; it++) { drawCard(state->whoseTurn, state); } updateCoins(state->whoseTurn, state, 0); return 0; }
int main () { int i, j, n, r, p, deckCount, discardCount, handCount, handPos, randomCard, randomHandCount; int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall}; struct gameState G; printf ("Testing CARD SMITHY.\n"); SelectStream(2); PutSeed(3); for (n = 0; n < 1; n++) { for (i = 0; i < sizeof(struct gameState); i++) { ((char*)&G)[i] = floor(Random() * 256); } p = floor(Random() * 2); randomHandCount = floor(Random() * MAX_HAND); G.deckCount[p] = floor(Random() * MAX_DECK); G.discardCount[p] = floor(Random() * MAX_DECK); G.handCount[p] = randomHandCount; /* initialize hand */ // give the player real cards for ( j=0; j< randomHandCount; j++) { G.hand[p][j] = 0; randomCard = floor(Random() * 3); switch (randomCard) { case 0: G.hand[p][j] = copper; break; case 1: G.hand[p][j] = silver; break; case 2: G.hand[p][j] = gold; break; } } /* player two now has real cards */ for ( j=0; j< randomHandCount; j++) { G.hand[1-p][j] = 0; randomCard = floor(Random() * 3); switch (randomCard) { case 0: G.hand[1-p][j] = copper; break; case 1: G.hand[1-p][j] = silver; break; case 2: G.hand[1-p][j] = gold; break; } } G.whoseTurn = 0; handPos = 0; handPos = 5; G.deckCount[p] = 40; G.discardCount[p] = 10; G.handCount[p] = 8; G.discard[p][G.discardCount[p]] = 100; G.playedCardCount = 3; G.playedCards[ G.playedCardCount ] = G.hand[p][handPos-1]; r = checkSmithy(&G, handPos, p); } printf ("ALL TESTS OK FOR SMITHY \n\n"); exit(0); return 0; }
int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, struct gameState *state) { int i; int j; int it; //set up random number generator SelectStream(1); PutSeed((long)randomSeed); //check number of players if (numPlayers > MAX_PLAYERS || numPlayers < 2) { return -1; } //set number of players state->numPlayers = numPlayers; //check selected kingdom cards are different for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { if (j != i && kingdomCards[j] == kingdomCards[i]) { return -1; } } } //initialize supply /////////////////////////////// //set number of Curse cards if (numPlayers == 2) { state->supplyCount[curse] = 10; } else if (numPlayers == 3) { state->supplyCount[curse] = 20; } else { state->supplyCount[curse] = 30; } //set number of Victory cards if (numPlayers == 2) { state->supplyCount[estate] = 8; state->supplyCount[duchy] = 8; state->supplyCount[province] = 8; } else { state->supplyCount[estate] = 12; state->supplyCount[duchy] = 12; state->supplyCount[province] = 12; } //set number of Treasure cards state->supplyCount[copper] = 60 - (7 * numPlayers); state->supplyCount[silver] = 40; state->supplyCount[gold] = 30; //set number of Kingdom cards for (i = adventurer; i <= treasure_map; i++) //loop all cards { for (j = 0; j < 10; j++) //loop chosen cards { if (kingdomCards[j] == i) { //check if card is a 'Victory' Kingdom card if (kingdomCards[j] == great_hall || kingdomCards[j] == gardens) { if (numPlayers == 2){ state->supplyCount[i] = 8; } else{ state->supplyCount[i] = 12; } } else { state->supplyCount[i] = 10; } break; } else //card is not in the set choosen for the game { state->supplyCount[i] = -1; } } } //////////////////////// //supply intilization complete //set player decks for (i = 0; i < numPlayers; i++) { state->deckCount[i] = 0; for (j = 0; j < 3; j++) { state->deck[i][j] = estate; state->deckCount[i]++; } for (j = 3; j < 10; j++) { state->deck[i][j] = copper; state->deckCount[i]++; } } //shuffle player decks for (i = 0; i < numPlayers; i++) { if ( shuffle(i, state) < 0 ) /* MUTANT (rep_op) */ if ( shuffle(i, state) != 0 ) return -1; } }
int main() { int totalFail = 0; int totalPass = 0; int seed = -1; struct gameState G; int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy}; int NUM_TEST_CARDS = 3; int testCards[NUM_TEST_CARDS]; int i, x; int priorSupply, postSupply; int priorHand, postHand; int priorDeck, postDeck; int priorDiscard, postDiscard; SelectStream(1); PutSeed(-1); Random(); for (i = 0; i < NUM_TEST_CARDS; i++) { testCards[i] = k[(int)floor(Random() * 10)]; } initializeGame(2, k, seed, &G); //Begin testing-------------------------------------------------------------- printf("------------------------------------------------------------\n"); printf("-----------------BEGIN TESTING FOR gainCard()---------------\n"); printf("------------------------------------------------------------\n"); //Test out of bounds input for card to get ie. card that does not exist if (gainCard(treasure_map + 2, &G, 0, 0) == -1) { printf("gainCard(): PASS -> handles non existent card.\n\n"); totalPass++; } else { printf("gainCard(): FAIL -> does not handle non existent card.\n\n"); totalFail++; } //test empty supply pile ie. all cards are gone of that type G.supplyCount[curse] = 0; if (gainCard(curse, &G, 0, 0) == -1) { printf("gainCard(): PASS -> handles empty supply pile.\n\n"); totalPass++; } else { printf("gainCard(): FAIL -> does not handle empty supply pile.\n\n"); totalFail++; } //Test for out of bounds player if (gainCard(copper, &G, 0, MAX_PLAYERS + 1) == -1) { printf("gainCard(): PASS -> handles out of bounds player.\n\n"); totalPass++; } else { printf("gainCard(): FAIL -> does not exit on out of bounds player.\n\n"); totalFail++; } //Test to make sure anything other than 1 or 2 adds card to discard pile priorSupply = G.supplyCount[copper]; priorDiscard = G.discardCount[0]; gainCard(copper, &G, 3, 0); postSupply = G.supplyCount[copper]; postDiscard = G.discardCount[0]; if (postSupply == (priorSupply - 1)) { printf("gainCard(): PASS -> decrements supply count on flag not equal to 1 or 2.\n\n"); totalPass++; } else { printf("gainCard(): FAIL -> does not decrement supply count on flag not equal to 1 or 2.\n\n"); totalFail++; } if ( postDiscard == (priorDiscard + 1) && G.discard[0][postDiscard - 1] == copper ) { printf("gainCard(): PASS -> correctly discards card on flag not equal to 1 or 2.\n\n"); totalPass++; } else { printf("gainCard(): FAIL -> did not discard card on flag not equal to 1 or 2.\n\n"); totalFail++; } //Test scenario of adding card to the discard pile //test scenario of adding card to the deck //test scenario of adding card to the hand //The following uses NUM_TEST_CARDS number of random cards to test to make //sure that the cards are gained in either the discard, deck or hand for (x = 0; x < NUM_TEST_CARDS; x++) { //testing gaining card x and adding it to the deck priorSupply = G.supplyCount[testCards[x]]; priorDeck = G.deckCount[0]; gainCard(testCards[x], &G, 1, 0); //add card to deck postSupply = G.supplyCount[testCards[x]]; postDeck = G.deckCount[0]; if ( postDeck == (priorDeck + 1) ) { if ( G.deck[0][postDeck - 1] == testCards[x] ) { printf("gainCard(): PASS -> Test card %d gained correctly to deck.\n\n", testCards[x]); totalPass++; } else { printf("gainCard(): FAIL -> Test card %d incremented deck count but was not correctly added to deck.\n\n", testCards[x]); totalFail++; } } else { if ( G.deck[0][postDeck - 1] == testCards[x] ) { printf("gainCard(): FAIL -> Test card %d was added to deck but did not increment deck count.\n\n", testCards[x]); totalFail++; } else { printf("gainCard(): FAIL -> Test card %d was not added to deck and did not increment deck count.\n\n", testCards[x]); totalFail++; } } if ( postSupply == (priorSupply - 1) ) { printf("gainCard(): PASS -> Test card %d decreased supply pile after added to deck.\n\n", testCards[x]); totalPass++; } else { printf("gainCard(): FAIL -> Test card %d did not decrease supply pile after added to deck.\n\n", testCards[x]); totalFail++; } //testing gaining card x and adding it to the hand priorSupply = G.supplyCount[testCards[x]]; priorHand = G.handCount[0]; gainCard(testCards[x], &G, 2, 0); //add card to hand postSupply = G.supplyCount[testCards[x]]; postHand = G.handCount[0]; if ( postHand == (priorHand + 1) ) { if ( G.hand[0][postHand - 1] == testCards[x] ) { printf("gainCard(): PASS -> Test card %d gained correctly to hand.\n\n", testCards[x]); totalPass++; } else { printf("gainCard(): FAIL -> Test card %d incremented hand count but was not correctly added to hand.\n\n", testCards[x]); totalFail++; } } else { if ( G.hand[0][postHand - 1] == testCards[x] ) { printf("gainCard(): FAIL -> Test card %d was added to hand but did not increment hand count.\n\n", testCards[x]); totalFail++; } else { printf("gainCard(): FAIL -> Test card %d was not added to hand and did not increment hand count.\n\n", testCards[x]); totalFail++; } } if ( postSupply == (priorSupply - 1) ) { printf("gainCard(): PASS -> Test card %d decreased supply pile after added to hand.\n\n", testCards[x]); totalPass++; } else { printf("gainCard(): FAIL -> Test card %d did not decrease supply pile after added to deck.\n\n", testCards[x]); totalFail++; } //testing gaining card x and adding it to discard priorSupply = G.supplyCount[testCards[x]]; priorDiscard = G.discardCount[0]; gainCard(testCards[x], &G, 0, 0); //add card to discard postSupply = G.supplyCount[testCards[x]]; postDiscard = G.discardCount[0]; if ( postDiscard == (priorDiscard + 1) ) { if ( G.discard[0][postDiscard - 1] == testCards[x] ) { printf("gainCard(): PASS -> Test card %d gained correctly to discard.\n\n", testCards[x]); totalPass++; } else { printf("gainCard(): FAIL -> Test card %d incremented discard count but was not correctly added to discard.\n\n", testCards[x]); totalFail++; } } else { if ( G.discard[0][postDiscard - 1] == testCards[x] ) { printf("gainCard(): FAIL -> Test card %d was added to discard but did not increment discard count.\n\n", testCards[x]); totalFail++; } else { printf("gainCard(): FAIL -> Test card %d was not added to discard and did not increment discard count.\n\n", testCards[x]); totalFail++; } } if ( postSupply == (priorSupply - 1) ) { printf("gainCard(): PASS -> Test card %d decreased supply pile after added to discard.\n\n", testCards[x]); totalPass++; } else { printf("gainCard(): FAIL -> Test card %d did not decrease supply pile after added to deck.\n\n", testCards[x]); totalFail++; } } printf("------------------------------------------------------------\n"); printf("----------------RESULTS of gainCard() testing---------------\n"); printf("Tests Passed: %d\tTests Failed: %d\n", totalPass, totalFail); printf("------------------------------------------------------------\n"); return 0; }
int main(int argc, char* argv[]){ int x; int player = 0; //player 1 = 0; initialize to something, will change later struct gameState *state = newGame(); int i, j; int myHandCount; int myDeckCount; int myPlayCount; printf("Testing SMITHY Card Function:\n"); srand(time(NULL)); //initialize hands for 2 players initGameState(state); for(i = 0; i < 2000; i++){ //start with 5 for testing SelectStream(2); PutSeed(2); player = rand() % 2; state->whoseTurn = player; state->deckCount[player] = rand() % MAX_DECK; state->playedCardCount = rand() % MAX_DECK; state->handCount[player] = rand() % MAX_HAND; //put smithy card in the player's hand state->hand[player][0] = smithy; //randomize rest of the cards in the player's hand for(j = 1; j < state->handCount[player] - 1; j++){ state->hand[player][j] = rand() %27; } //randomize cards in the discard pile for(j = 0; j < state->playedCardCount; j++){ state->discard[player][j] = rand() % 27; } //randomize cards in the deck for(j = 0; j < state->deckCount[player]; j++){ state->discard[player][j] = rand() % 27; } //initialize values of players deck counts //save teh details of what the state was before playing the smithy card. //This is used to track my expectations of how the card SHOULD play because the state is going to change as the card is played myHandCount = state->handCount[player]; myDeckCount = state->deckCount[player]; myPlayCount = state->playedCardCount; printf("Starting handCount = %d\n", myHandCount); printf("Starting deckCount = %d\n", myDeckCount); printf("Starting playedCardCount = %d\n", myPlayCount); //play the smithy card smithyCard(player, state, 0); /******************************************************************* * TESTING HAND, DECK, DISCARD AND PLAY *******************************************************************/ //myHandCount should now = original handCount + 3 -1 x = myHandCount + 3 - 1; if(state->handCount[player] == x){ printf("Testing myHandCount: TEST PASSED\n"); } else{ printf("Testing myHandCount: TEST FAILED: expected: %d, actual: %d\n", x, state->handCount[player]); } //myDeckCount should now = original deckCount + 1 x = myDeckCount - 3;//because 3 were taken from my deck and added to my hand if(state->deckCount[player] == x) {//if it is correct printf("Testing myDeckCount: TEST PASSED\n"); } else { printf("Testing myDeckCount: TEST FAILED: expected %d, actual %d\n", x, state->deckCount[player]); } //myPlayCount should now = original playCount + 1 x = myPlayCount + 1; if(state->playedCardCount == x) {//if it is correct printf("Testing myPlayCount: TEST PASSED\n"); } else { printf("Testing myPlayCount: TEST FAILED: expected %d, actual %d\n", x, state->playedCardCount); } } //end of for loop return 0; }
int main () { int n, p, i; struct gameState G; time_t t; srand((unsigned)time(&t)); printf ("Testing Adventurer.\n"); printf ("RANDOM TESTS.\n"); SelectStream(2); PutSeed(3); for (n = 0; n < 2000; n++) { int* k=kingdomCards(1,2,3,4,5,6,7,8,9,10); G.numPlayers=rand() % 3+1; initializeGame(G.numPlayers,k,1000,&G); p = rand() % 2+1; G.numPlayers=rand() % 3+1; G.deckCount[p] = rand() % MAX_DECK; G.discardCount[p] = rand() % MAX_DECK; G.handCount[p] = rand() % MAX_HAND; G.supplyCount[adventurer]=rand()%10; testAdventurer(&G,p); } printf ("Fixed tests for adventurer():\n"); for (i=0;i<50;i++) { int* k=kingdomCards(1,2,3,4,5,6,7,8,9,10); memset(&G, 23, sizeof(struct gameState)); // clear the game state initializeGame(2, k, 1000, &G); // initialize a new game G.handCount[0]=0; #if (NOISY_TEST == 1) printf ("Playing adventurer card 1 time\n"); #endif adventurerCard(1,&G); #if (NOISY_TEST == 1) printf("Handcount: %d\n", G.handCount[0]); printf("Number of Cards Played = %d, expected = 0", G.playedCardCount); if (G.playedCardCount==0) { printf("....PASS\n"); } else{ printf("....FAIL\n"); } printf ("Playing adventurer card another time\n"); #endif adventurerCard(1,&G); #if (NOISY_TEST == 1) printf("Handcount: %d\n", G.handCount[0]); printf("Number of Cards Played = %d, expected = 0", G.playedCardCount); if (G.playedCardCount==0) { printf("....PASS\n"); } else{ printf("....FAIL\n"); } printf ("Playing adventurer card another time\n"); #endif adventurerCard(1,&G); #if (NOISY_TEST == 1) printf("Handcount: %d\n", G.handCount[0]); printf("Number of Cards Played = %d, expected = 0", G.playedCardCount); if (G.playedCardCount==0) { printf("....PASS\n"); } else{ printf("....FAIL\n"); } printf ("Playing adventurer card another time\n"); #endif adventurerCard(1,&G); #if (NOISY_TEST == 1) printf("Handcount: %d\n", G.handCount[0]); printf("Number of Cards Played = %d, expected = 0", G.playedCardCount); if (G.playedCardCount==0) { printf("....PASS\n"); } else{ printf("....FAIL\n"); } printf ("Playing adventurer card another time\n"); #endif adventurerCard(1,&G); #if (NOISY_TEST == 1) printf("Handcount: %d\n", G.handCount[0]); printf("Number of Cards Played = %d, expected = 0", G.playedCardCount); if (G.playedCardCount==0) { printf("....PASS\n"); } else{ printf("....FAIL\n"); } printf ("Playing adventurer card another time\n"); #endif adventurerCard(1,&G); #if (NOISY_TEST == 1) printf("Handcount: %d\n", G.handCount[0]); printf("Number of Cards Played = %d, expected = 0", G.playedCardCount); if (G.playedCardCount==0) { printf("....PASS\n"); } else{ printf("....FAIL\n"); } printf ("Playing adventurer card another time*\n"); #endif adventurerCard(1,&G); #if (NOISY_TEST == 1) printf("Handcount: %d\n", G.handCount[0]); printf("Number of Cards Played = %d, expected = 0", G.playedCardCount); if (G.playedCardCount==0) { printf("....PASS\n\n"); } else{ printf("....FAIL\n\n"); } #endif endTurn(&G); #if (NOISY_TEST == 1) printf("Testing other player's hand\n"); printf("Number of Cards Played = %d, expected = 0", G.playedCardCount); if (G.playedCardCount==0) { printf("....PASS\n"); } else{ printf("....FAIL\n"); } printf("Hand Count = %d, expected = 0", G.handCount[0]); if (G.handCount[0]==0) { printf("....PASS\n\n"); } else{ printf("....FAIL\n\n"); } #endif } printf ("ALL TESTS COMPLETE\n"); return 0; }
int main(){ SelectStream(2); PutSeed(time(NULL)); int num_tests = 5000; struct gameState state, previous; #if(NOISY_TEST == 1) printf("Testing Adventurer against %d random gamestates\n", num_tests); #endif for(int test = 0; test < num_tests; test++){ for(int p = 0; p < MAX_PLAYERS; p++){ //start adventurer specific counters int drawnTreasure = 0; int cardDrawn = 0; int tempHand[MAX_HAND]; int z = 0; //end adventurer specific counters int treasures_in_deck = 0; int treasures_in_hand = 0; int prev; random_gamestate(&state); int adventurer_pos = (int)(Random()*state.handCount[p]); //random adventurer position state.hand[p][adventurer_pos] = adventurer; int d = state.deckCount[p]; previous = state; //count treasures in deck for(int i = 0; i < state.deckCount[p]; i++) if(state.deck[p][i] == copper || state.deck[p][i] == silver || state.deck[p][i] == gold) treasures_in_deck+=1; #if(NOISY_TEST == 1) printf("Randomly generated deck contains %d treasure cards\n", treasures_in_deck); #endif //count treasures in hand for(int i = 0; i < state.handCount[p]; i++) if(state.hand[p][i] == copper || state.hand[p][i] == silver || state.hand[p][i] == gold) treasures_in_hand+=1; #if(NOISY_TEST == 1) printf("Randomly generated hand contains %d treasure cards\n", treasures_in_hand); #endif zzzadventurercardplay(drawnTreasure, p, cardDrawn, tempHand, z, &state); //check hand size if(d<2){ if(treasures_in_deck >= d){ #if(NOISY_TEST == 1) printf("Hand Size: %d, Expected: %d\n", state.handCount[p], previous.handCount[p] -1 + d); #endif #if(ASSERTS == 1) assert(state.handCount[p] == previous.handCount[p] - 1 + d); #endif }else{ #if(NOISY_TEST == 1) printf("Hand Size: %d, Expected: %d\n", state.handCount[p], previous.handCount[p] -1 + treasures_in_deck); #endif #if(ASSERTS == 1) assert(state.handCount[p] == previous.handCount[p] - 1 + treasures_in_deck); #endif }} else{ if(treasures_in_deck < 2){ #if(NOISY_TEST == 1) printf("Hand Size: %d, Expected: %d\n", state.handCount[p], previous.handCount[p] -1 + treasures_in_deck); #endif #if(ASSERTS == 1) assert(state.handCount[p] == previous.handCount[p] -1 + treasures_in_deck); #endif }else{ #if(NOISY_TEST == 1) printf("Hand Size: %d, Expected: %d\n", state.handCount[p], previous.handCount[p] +1); #endif #if(ASSERTS == 1) assert(state.handCount[p] == previous.handCount[p] +1); #endif }} //check deck size if(d<2){ if(treasures_in_deck >= d){ #if(NOISY_TEST == 1) printf("Deck + Discard + Played: %d, Expected: %d\n", state.discardCount[p] + state.playedCardCount + state.deckCount[p], previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] + 1 - d ); #endif #if(ASSERTS == 1) assert(state.discardCount[p] + state.playedCardCount + state.deckCount[p] == previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] + 1 - d); #endif }else{ #if(NOISY_TEST == 1) printf("Deck + Discard + Played: %d, Expected: %d\n", state.discardCount[p] + state.playedCardCount + state.deckCount[p], previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] + 1 - treasures_in_deck ); #endif #if(ASSERTS == 1) assert(state.discardCount[p] + state.playedCardCount + state.deckCount[p] == previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] + 1 - treasures_in_deck); #endif }} else{ if(treasures_in_deck < 2){ #if(NOISY_TEST == 1) printf("Deck + Discard + Played: %d, Expected: %d\n", state.discardCount[p] + state.playedCardCount + state.deckCount[p], previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] + 1 - treasures_in_deck); #endif #if(ASSERTS == 1) assert(state.discardCount[p] + state.playedCardCount + state.deckCount[p] == previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] + 1 - treasures_in_deck); #endif }else{ #if(NOISY_TEST == 1) printf("Deck + Discard + Played: %d, Expected: %d\n", state.discardCount[p] + state.playedCardCount + state.deckCount[p], previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] -1); #endif #if(ASSERTS == 1) assert(state.discardCount[p] + state.playedCardCount + state.deckCount[p] == previous.discardCount[p] + previous.playedCardCount + previous.deckCount[p] -1); #endif }} //check treasures in hand prev = treasures_in_hand; treasures_in_hand = 0; for(int i = 0; i < state.handCount[p]; i++) if(state.hand[p][i] == copper || state.hand[p][i] == silver || state.hand[p][i] == gold) treasures_in_hand++; if(d<2){ if(treasures_in_deck >= d){ #if(NOISY_TEST == 1) printf("Treasures in Hand: %d, Expected: %d\n", treasures_in_hand, prev + d); #endif #if(ASSERTS == 1) assert(treasures_in_hand == prev + d); #endif }else{ #if(NOISY_TEST == 1) printf("Treasures in Hand: %d, Expected: %d\n", treasures_in_hand, prev + treasures_in_deck); #endif #if(ASSERTS == 1) assert(treasures_in_hand == prev+treasures_in_deck); #endif }} else{ if(treasures_in_deck < 2){ #if(NOISY_TEST == 1) printf("Treasures in Hand: %d, Expected: %d\n", treasures_in_hand, prev + treasures_in_deck); #endif #if(ASSERTS == 1) assert(treasures_in_hand == prev+treasures_in_deck); #endif }else{ #if(NOISY_TEST == 1) printf("Treasures in Hand: %d, Expected: %d\n", treasures_in_hand, prev + 2); #endif #if(ASSERTS == 1) assert(treasures_in_hand == prev + 2); #endif }} }//end players loop }//end tests loop #if(NOISY_TEST == 1) printf("Finished testing adventurer on %d random gamestates\n", num_tests); #endif #if(ASSERTS == 1) printf("Tests passed.\n"); #endif }//end main
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; }