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 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() { 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; }
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 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++) /* MUTANT (rep_const) */ for (j = ((3)-1); j < 10; j++) state->deck[i][j] = copper; state->deckCount[i]++; } }