int main (int argc, char** argv) { struct gameState G; int i; int *k; // int king_cards[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy}; // int post_check_array[10]; // for(i=0; i<10; i++){ // post_check_array[i] = king_cards[0]; // } printf ("Starting Unit Test 1: KingdomCards\n"); // int *did_it_work = kingdomCards(king_cards[0], king_cards[1], king_cards[2], king_cards[3], king_cards[4], king_cards[5], king_cards[6], king_cards[7], king_cards[8], king_cards[9]); // int r = initializeGame(2, king_cards, 4903, &G); // assert (r == 0); // for (i = 0; i < 10; i++){ // assert(did_it_work[i] == post_check_array[i]); // } int king[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy}; k = kingdomCards(king[0], king[1], king[2], king[3], king[4], king[5], king[6], king[7], king[8], king[9]); for (i = 0; i < 10; i++) { assert(k[i] == king[i]); } printf("End of Unit Test 1\n"); return 0; }
int main () { int passes = 0; int fails = 0; // keeps track of case results //The test int cases = 1000; //how many random numbers will be tested for(int i=0; i<cases; i++){ int testK[10]; for(int i=0;i<10;i++){testK[i]=(rand()%19+7);} int* kings=kingdomCards((testK[0]),testK[1],testK[2],testK[3],testK[4],testK[5],testK[6],testK[7],testK[8],testK[9]); for(int i = 0; i<10;i++ ){ if(testK[i]!=kings[i]){fails++; break;} else if(testK[i]==kings[i] && i==9){passes++;} //printf("\n %d %d ", testK[i],kings[i]); } //printf("\n\n"); } printf("\n\nPasses: %d Fails: %d\n\n",passes,fails); return 0; }
int main() { struct gameState* testState = newGame(); int* myKingdomCards = kingdomCards(7, 8, 9, 10, 11, 12, 13, 14, 15, 16); initializeGame(2, myKingdomCards, 3, testState); testState->hand[0][0] = remodel; assert(testState->coins == 3); assert(testState->handCount[0] == 5); playCard(0, copper, estate, 0, testState); assert(testState->coins == 2); assert(testState->handCount[0] == 3); assert(testState->discardCount[0] == 1); assert(testState->discard[0][0] == estate); endTurn(testState); assert(testState->discardCount[0] == 5); assert(testState->discard[0][0] == remodel); return 0; }
int main() { srand(time(NULL)); int k1=rand(); int k2=rand(); int k3=rand(); int k4=rand(); int k5=rand(); int k6=rand(); int k7=rand(); int k8=rand(); int k9=rand(); int k10=rand(); int* k = malloc(10 * sizeof(int)); k=kingdomCards(k1, k2, k3, k4, k5, k6, k7, k8, k9, k10); assertEqu(k1,k[0]); assertEqu(k2,k[1]); assertEqu(k3,k[2]); assertEqu(k4,k[3]); assertEqu(k5,k[4]); assertEqu(k6,k[5]); assertEqu(k7,k[6]); assertEqu(k8,k[7]); assertEqu(k9,k[8]); assertEqu(k10,k[9]); checkasserts(); return 0; }
int main() { printf("\nTESTING kingdomCards() method.\n\n"); srand(time(NULL)); int number; int* original = malloc(sizeof(int) * 10); int* returned = malloc(sizeof(int) * 10); int* random = malloc(sizeof(int) * 10); for (int i = 0; i < 10; i++) { number = rand(); original[i] = number; random[i] = number; } returned = kingdomCards(random[0], random[1], random[2], random[3], random[4], random[5], random[6], random[7], random[8], random[9]); for (int i = 0; i < 10; i++) { printf("Checking if content in array position %d is the same in both arrays", i); assertTrue(EQ(original[i], returned[i]), ""); } printf("\n"); return 0; }
int main (){ struct gameState g; int *k; printf("--------------------unit test 2 for kingdomCards( start) -------------------------------------- \n"); k = kingdomCards(1,2,3,4,5,6,7,8,9,10); if ( k[0]== 1&& k[1] == 2&&k[2] == 3 &&k[3]== 4&&k[4] == 5&& k[5]== 6&&k[6]==7&&k[7]==8&&k[8]==9&&k[9]==10){ printf(" the test pass and return is correct\n"); } else{ printf("it have some bugs \n"); } printf("---------------unit test 2 for kingdomCards( end) -------------------------------------- \n"); return 0; }
int main(int argc, char** argv) { printf("\nStarting Unit Test 4 (drawCard)\n"); int *tempKC = kingdomCards(council_room, feast, mine, great_hall, cutpurse, treasure_map, outpost, smithy, gardens, embargo); G = newGame(); initializeGame(4, tempKC, 4, G); printf("\n**********************Before Draw**************************\n"); displayState(4); int *tempDeck = malloc(MAX_DECK * sizeof(int)); memcpy(tempDeck, G->deck[0], MAX_DECK); int tmpDeckCount = G->deckCount[0]; int c; c = G->deck[0][tmpDeckCount - 1]; drawCard(0, G); printf("\n**********************After Draw**************************\n"); displayState(4); printf("\n************************************************\n"); printf("\nTop of deck: "); printCardName(c); printf("\nNew Card in Hand: "); printCardName(G->deck[0][G->deckCount[0]]); printf("\n\n*********************************************************\n"); printf("Successfully finished Unit Test 4\n"); printf("*********************************************************\n\n"); return 0; }
int main(int argc, char** argv) { printf("\nStarting Card Test 3 (baron)\n"); tempKC = kingdomCards(council_room, feast, mine, great_hall, cutpurse, treasure_map, outpost, smithy, gardens, embargo); G = newGame(); initializeGame(2, tempKC, 4, G); testNoDiscard(); free(G); G = newGame(); initializeGame(2, tempKC, 4, G); testDiscard(); free(G); G = newGame(); initializeGame(2, tempKC, 4, G); testDiscardFail(); printf("\n*********************************************************\n"); printf("*********Successfully finished Card Test 3***********\n"); printf("*********************************************************\n\n"); return 0; }
int main(){ printf("\n\n Unit Test 2 ----------------"); struct gameState* game = newGame(); initializeGame(2,kingdomCards(7,8,9,10,11,12,13,14,15,16),20,game); assertPrint(supplyCount(0,game)==10, "PASSED: supplyCount gave an accurate count after initialization", "FAILED: supplyCount failed to give an accurate count after initialization"); game->supplyCount[0]-=3; assertPrint(supplyCount(0,game)==7, "PASSED: supplyCount gave an accurate count after modification of supply", "FAILED: supplyCount failed to give an accurate count after modification of supply"); assertPrint(supplyCount(-1,game)==-1, "PASSED: supplyCount gave an error code when negative index is supplied", "FAILED: supplyCount failed to give an error code when negative index is supplied"); assertPrint(supplyCount(99999,game)==-1, "PASSED: supplyCount gave an error code when an overly large index is supplied", "FAILED: supplyCount failed to give an error code when an overly large index is supplied"); return 0; }
int main() { int k1 = 0; int k2 = 1; int k3 = 2; int k4 = 3; int k5 = 4; int k6 = 5; int k7 = 6; int k8 = 7; int k9 = 8; int k10 = 9; int i = 0; int* kingdomCardsTest; printf ("TESTING kingdomCards():\n"); kingdomCardsTest = kingdomCards(k1, k2, k3, k4, k5, k6, k7, k8, k9, k10); for (i = 0; i < 10; i++) { #if (NOISY_TEST == 1) printf("Test value of k%d\n", i + 1); printf("k%d = %d, expected = %d\n", i + 1, kingdomCardsTest[i], i); printf("\n"); #endif assert(kingdomCardsTest[i] == i); } printf("All tests passed.\n"); return 0; }
int main() { struct gameState* testState = newGame(); int* myKingdomCards = kingdomCards(7, 8, 9, 10, 11, 12, 13, 14, 15, 16); initializeGame(2, myKingdomCards, 3, testState); testState->hand[0][0] = smithy; playCard(0, 0, 0, 0, testState); printf("Begin assert statements\n"); assert(testState->numActions == 0); assert(testState->playedCardCount == 1); assert(testState->playedCards[0] == smithy); assert(testState->handCount[0] == 7); assert(testState->deckCount[0] == 2); assert(testState->discardCount[0] == 0); endTurn(testState); assert(testState->discardCount[0] == 6); assert(testState->discard[0][0] == smithy); printf("Test complete\n"); return 0; }
int main() { printf("%sTesting Village Card...%s\n", YELLOW, CLEAR); struct gameState state; int i = 0; int game; printf("%s\nSetting up game...%s\n", YELLOW, CLEAR); game = initializeGame(2, kingdomCards(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 5, &state); assertTrue(game == 0, "Game is initialized"); printf("%s\nSetting card to village...%s\n", YELLOW, CLEAR); state.hand[0][0] = 14; assertTrue(state.hand[0][0] == 14, "Test card is village"); printf("%s\nSaving initial hand count...%s\n", YELLOW, CLEAR); int currentHandCount = state.handCount[0]; printf("%s\nSetting initial actions...%s\n", YELLOW, CLEAR); state.numActions = 0; int currentActionCount = 2; //+2 actions for village card printf("%s\nCalling village card...%s\n", YELLOW, CLEAR); cardEffect(14, 0, 0, 0, &state, i, NULL); assertTrue(state.handCount[0] == currentHandCount, "Discard player card from hand"); assertTrue(state.numActions == currentActionCount, "+2 actions"); return 0; }
int main() { int i; int* result = kingdomCards(1,2,3,4,5,6,7,8,9,10); for(i=0; i<10; i++){ newassert(result[i] == i+1); } return 0; }
int main(void) { int *k, k1=1, k2=2, k3=3, k4=4, k5=5, k6=6, k7=7, k8=8, k9=9, k10=10, i; int data[10]= {k1,k2,k3,k4,k5,k6,k7,k8,k9,k10}; k=kingdomCards(k1,k2,k3,k4,k5,k6,k7,k8,k9,k10); for (i=0 ; i<10; i++) { assert(k[i]==data[i]); } return 0; }
int main(void){ //testig great_hallEffect struct gameState G; initializeGame(2, kingdomCards(1,2,3,4,5,6,7,8,9,10), 10, &G); int bonus; G.hand[0][0]=16; int currentHandNum=G.handCount[0], actionNum=G.numActions; cardEffect(16, 2, 2, 3, &G, 0, &bonus); assert(G.handCount[0]==currentHandNum && G.numActions==actionNum+1); //get one new card and discard the played smithycard -> +0 AND one more action }
int main(){ struct gameState *state=newGame(); int *kc = kingdomCards(adventurer,council_room,feast,gardens,mine,remodel,smithy,village,baron,great_hall); int results = initializeGame(4, kc,1,state); printf("Playing council room\n"); councilEffect(0,state); printf("Hand count 9? %d %s\n",state->handCount[0],(state->handCount[0]==9)?"YES":"NO"); printf("Other hand counts increased by 1? %s\n",(state->handCount[1]==1 && state->handCount[2]==1)?"YES":"NO"); return 0; }
int main(){ struct gameState G; int *k = kingdomCards(gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy, great_hall); initializeGame(2, k, 1, &G); int i; int g[10] = {gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy, great_hall}; printf("######################################################f4\n"); printf("Testing kingdomCards() functionality.\n"); printf("Before test:\n"); printf(" Intended list of cards: %d %d %d %d %d %d %d %d %d %d\n", gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy, great_hall); printf(" Saved list of cards: "); for(i = 0; i < 10; i++){ printf("%d ", k[i]); } for(i = 0; i < 10; i++){ if(g[i] != k[i]) printf("Bug!: at location %d, %d != %d", i, g[i], k[i]); } k = kingdomCards(great_hall, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy); int h[10] = {great_hall, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy}; printf("\nAfter test 1: rerun function with a new list.\n"); printf(" Intended list of cards: %d %d %d %d %d %d %d %d %d %d\n", great_hall, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy); printf(" Saved list of cards: "); for(i = 0; i < 10; i++){ printf("%d ", k[i]); } for(i = 0; i < 10; i++){ if(h[i] != k[i]) printf("Bug!: at location %d, %d != %d", i, h[i], k[i]); } printf("\n"); printf("----------------------------------------------------------------\n"); printf("\n"); return 0; }
int main(int argc, char *argv[]) { srand(time(NULL)); struct gameState *game = newGame(); int* kingdom_cards = kingdomCards(adventurer, council_room, feast, gardens, mine, smithy, remodel, village, minion, great_hall); initializeGame(3, kingdom_cards, 5, game); int choices = rand() % 10; int choice1 = 0; int choice2 = 0; if(choices > 5) { choice1 = 1; } else { choice2 = 1; } int numbuys = game->numBuys; int coins = game->coins; cardEffect(baron, choice1, choice2, 0, game, 0, 0); int numbuys2 = game->numBuys; int coins2 = game->coins; int hand2 = game->handCount[0]; if(numbuys != numbuys2 - 1) { printf("1"); exit(EXIT_SUCCESS); } if(choice1 == 1) { if(coins != coins2 - 2) { printf("1"); exit(EXIT_SUCCESS); } } if(choice2 == 1) { if(hand2 != 4) { printf("1"); exit(EXIT_SUCCESS); } } return 0; }
int main(void){ //testing steward struct gameState G, G2, G3; int bonus=0; initializeGame(2, kingdomCards(1,2,3,4,5,6,7,8,9,10), 10, &G); initializeGame(2, kingdomCards(1,2,3,4,5,6,7,8,9,10), 10, &G2); initializeGame(2, kingdomCards(1,2,3,4,5,6,7,8,9,10), 10, &G3); G.hand[0][0]=18; G2.hand[0][0]=18; G3.hand[0][0]=18; int currentHandNum=G.handCount[0]; cardEffect(18, 1, 2, 3, &G, 0, &bonus); assert(G.handCount[0]==currentHandNum+1); //if choice1==1, get two new cards and discard the played steward -> +1 int coins=G2.coins; cardEffect(18, 2, 2, 3, &G2, 0, &bonus); assert(G2.coins==coins+2); //if choice==2, get two coins currentHandNum=G3.handCount[0]; cardEffect(18, 3, 2, 3, &G3, 0, &bonus); assert(G3.handCount[0]==currentHandNum-3); //if choice is neither 1 nor 2, lose two cards and discard the played steward -> -3 }
int* randSupplyCards(){ //going to randomly choose supplyCards with fisher-yates shuffle //first 10 will be in supply(Kingdom Cards) //dont forget to free pointer that we return int supplyCards[20] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall, minion, steward, tribute, ambassador, cutpurse, embargo, outpost, salvager, sea_hag, treasure_map}; for(int i = 0; i < 10; i++) { int j = rand() % 20; int temp = supplyCards[j]; supplyCards[j] = supplyCards[i]; supplyCards[i] = temp; } return kingdomCards(supplyCards[0],supplyCards[1],supplyCards[2], supplyCards[3], supplyCards[4], supplyCards[5], supplyCards[6], supplyCards[7], supplyCards[8], supplyCards[9]); }
int main(int argc, char** argv) { printf("\nStarting Card Test 4 (gardens)\n"); tempKC = kingdomCards(council_room, feast, mine, great_hall, cutpurse, treasure_map, outpost, smithy, gardens, embargo); G = newGame(); initializeGame(2, tempKC, 4, G); int turn1 = G->whoseTurn; int turn2 = turn1 + 1; //Assign first hand draw (deck must be identifiable) G->hand[turn1][0] = estate; G->hand[turn1][1] = baron; G->hand[turn1][2] = copper; G->hand[turn1][3] = gardens; G->hand[turn1][4] = copper; //Each Deck position should be different (identification) G->deck[turn1][0] = estate; G->deck[turn1][1] = silver; G->deck[turn1][2] = gold; G->deck[turn1][3] = village; G->deck[turn1][4] = minion; //Set 2nd player to keep deck identifiable G->deck[turn2][0] = estate; G->deck[turn2][1] = estate; G->deck[turn2][2] = copper; G->deck[turn2][3] = copper; G->deck[turn2][4] = copper; G->deck[turn2][5] = tribute; G->deck[turn2][6] = salvager; G->deck[turn2][7] = adventurer; G->deck[turn2][8] = baron; G->deck[turn2][9] = remodel; printf("\n*********Before card effect***********\n"); displayState(2); int result = cardEffect(gardens, 0, 0, 0, G, 0, 0); printf("\n*********After card effect***********\n"); displayState(2); printf("cardEffect returns: %i\n", result); printf("\n*********************************************************\n"); printf("*********Successfully finished Card Test 4***********\n"); printf("*********************************************************\n\n"); return 0; }
// Tests kingdomCards() in dominion.c int main(int argc, char **argv) { printf("TESTING kingdomCards().\n"); printf("RANDOM TESTS\n"); srand(time(NULL)); int numtests = 1000; for(int i = 0; i < numtests; i++){ int j[10] = { rand(), rand(), rand(), rand(), rand(), rand(), rand(), rand(), rand(), rand() }; int *k = kingdomCards(j[0], j[1], j[2], j[3], j[4], j[5], j[6], j[7], j[8], j[9]); for(int ii = 0; i < 10; i++){ assert(j[ii] == k[ii]); } } printf("ALL TESTS OK\n\n"); }
int main(){ printf("--------------------TESTING kingdomCards-----------------\n"); srand(time(NULL)); int* test1 = malloc(10 * sizeof(int)); int* test2 = malloc(10 * sizeof(int)); int i; for(i = 0; i<10; i++){ test1[i] = rand(); } test2 = kingdomCards(test1[0],test1[1],test1[2],test1[3],test1[4],test1[5],test1[6],test1[7],test1[8],test1[9]); for(i = 0; i<10; i++){ assert(test1[i]==test2[i]); } printf("--------------------TEST PASSED---------------\n"); return 0; }
int main() { printf("-------------------------------------\n"); printf("START of the unittest2 - KingdomCards\n"); printf("-------------------------------------\n"); int i; int k1[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall}; int *k2 = kingdomCards(adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall); for(i = 0; i < 10; i++) { int ret = compare(&k1[i], & k2[i]); if(ret != 0) printf("FAIL: return val should be 0, got %d\n", ret); assert(ret == 0); } printf("PASS: kingdom cards allocated correctly\n"); return 0; }
int main() { int ret, i; struct gameState G; int *mahKingdomCards = kingdomCards(1,2,3,4,5,6,7,8,9,10); initializeGame(3, mahKingdomCards, 20, &G); // check with new game ret = isGameOver(&G); assert(ret == 0); // check empty stack of Province cards G.supplyCount[province] = 0; ret = isGameOver(&G); assert(ret == 1); // check with various supply piles // try all at 10 for (i = 0; i < 25; i++) { G.supplyCount[i] = 10; } ret = isGameOver(&G); assert(ret == 0); // empty 2 piles and test G.supplyCount[15] = 0; G.supplyCount[9] = 0; ret = isGameOver(&G); assert(ret == 0); // empty more piles and verify it stays over for (i = 0; i < 25; i++) { G.supplyCount[i] = 0; assert(isGameOver(&G) == 1); } return 0; }
int main() { struct gameState* testState = newGame(); int* myKingdomCards = kingdomCards(7, 8, 9, 10, 11, 12, 13, 14, 15, 16); initializeGame(2, myKingdomCards, 3, testState); testState->hand[0][0] = village; playCard(0, 0, 0, 0, testState); assert(testState->numActions == 2); assert(testState->playedCardCount == 1); assert(testState->playedCards[0] == village); assert(testState->handCount[0] == 5); assert(testState->deckCount[0] == 4); assert(testState->discardCount[0] == 0); endTurn(testState); assert(testState->discardCount[0] == 6); assert(testState->discard[0][0] == village); return 0; }
int main() { printf("%sTesting Smithy Card...%s\n", YELLOW, CLEAR); int i = 0; struct gameState state; int game; printf("%s\nSetting up game...%s\n", YELLOW, CLEAR); game = initializeGame(2, kingdomCards(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 5, &state); assertTrue(game == 0, "Game is initialized"); printf("%s\nSetting card to smithy...%s\n", YELLOW, CLEAR); state.hand[0][0] = 13; assertTrue(state.hand[0][0] == 13, "Test card is smithy"); printf("%s\nSaving initial hand count...%s\n", YELLOW, CLEAR); int currentHandNum = state.handCount[0]; printf("%s\nCalling smithy card...%s\n", YELLOW, CLEAR); cardEffect(13, 0, 0, 0, &state, i, NULL); assertTrue(state.handCount[0] == currentHandNum+2, "+3 cards, discard 1"); return 0; }
int main() { int w; int x; int b[10]; int *k; int m; int n; int temp; int temp2; int pos; int i, j, d[4], dis[4], p[4], status, status2, players, player, handCount, expectedHandSize, deckCount, priorDeckCount, oldDiscardCount, seed, draw1, draw2; struct gameState *state; int money; int numViolated = 0; int winners[MAX_PLAYERS]; srand(1317); printf("Running Random Dominion Test\n"); for (i = 0; i < MAX_TESTS; i++) { fprintf(stderr, "STARTING A GAME~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); state = newGame(); // Random number of players between 2 and 4 players = rand() % 3 + 2; seed = rand(); for (j = 0; j < 10; j++) b[j] = -1; // Random kingdom cards for (j = 0; j < 10; j++) { m = rand() % 20 + 7; temp = 0; for (n = 0; n < j; n++) { if (b[n] == m) { temp = 1; } } if (temp) { j -= 1; continue; } else { b[j] = m; } } k = kingdomCards(b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9]); status = initializeGame(players, k, seed, state); //initialize Gamestate if (myassert(status != -1, "Failed to initialize game", &numViolated)) fprintf(stderr, "Initialize failed\n"); // Run the game/test while (!isGameOver(state)) { fprintf(stderr, "And so a turn begins\n"); player = whoseTurn(state); money = 0; pos = -1; for (j = 0; j < numHandCards(state); j++) { fprintf(stderr, "In money loop\n"); if (handCard(j, state) == copper) money++; else if (handCard(j, state) == silver) money = money + 2; else if (handCard(j, state) == gold) money = money + 3; else pos = j; } temp = handCard(pos, state); if (DEBUG) fprintf(stderr, "Playing card of type %d\n", temp); w = 0; x = 0; if (temp == 9) { status = 0; while(!status) { if (supplyCount(w, state) > 0 && getCost(w) <= state->coins) status = 1; else w++; } } else if (temp == 15) { if (rand() % 2) w = 1; } else if (temp == 17) { status = rand() % 3; if (status == 0) w = 1; else if (status == 1) x = 1; } else if (temp == 24) { status = 0; while(!status) { if (w != pos) status = 1; else w++; } } status = playCard(pos, w, x, 0, state); //myassert(status != -1, "playCard failed", &numViolated); if (status != -1 && DEBUG) fprintf(stderr, "%d: Card of type %d played\n", player, temp); temp2 = 0; while (!temp2) { fprintf(stderr, "In loop prior to buy card\n"); temp = rand() % 27; if (supplyCount(temp, state) >= 0 ) temp2 = 1; } if (DEBUG) fprintf(stderr, "Buying card\n"); status = buyCard(temp, state); //myassert(status != -1, "buyCard failed", &numViolated); if (DEBUG && status != -1) fprintf(stderr, "%d: bought card of type %d\n", player, temp); if (DEBUG) fprintf(stderr, "Ending turn\n"); status = endTurn(state); myassert( status != -1, "endTurn failed", &numViolated); /* // Error info if (status2 && DEBUG) { printf(" Current player info:\n"); printf(" old DeckCount: %d\n", priorDeckCount); printf(" new DeckCount: %d\n", state->deckCount[player]); printf(" old DiscardCount: %d\n", oldDiscardCount); printf(" new discardCount: %d\n", state->discardCount[player]); printf(" old handCount: %d\n", handCount); printf(" new handCount: %d\n", state->handCount[player]); } */ } status = getWinners(winners, state); myassert(status != -1, "getWinners failed to run", &numViolated); for(j = 0; j < players; j++) { status = scoreFor(j, state); myassert(status != -1, "scoreFor failed", &numViolated); } free(k); } printf("%d Tests Completed\n", MAX_TESTS); printf("Failed %d times\n", numViolated); return 0; }
int* getUniqueCards() { return kingdomCards(5, 6, 7, 8, 9, 10, 11, 12, 13, 14); }
int main(int argc, char *argv[]){ //make sure correct number of arguments are provided if(argc > 2){ printf("Too many arguments, only one expected.\n"); return -1; } if(argc < 2){ printf("Not enough arguments, need a random seed.\n"); return -1; } //setup game int testSeed = argv[1]; struct gameState game; srand(testSeed); //get 10 random kingdom cards int allKingCards[20] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall, minion, steward, tribute, ambassador, cutpurse, embargo, outpost, salvager, sea_hag, treasure_map}; kingShuffle(allKingCards, 20); int k[10]; for(int i = 0; i < 10; i++){ k[i] = allKingCards[i]; } kingdomCards(k[0], k[1], k[2], k[3], k[4], k[5], k[6], k[7], k[8], k[9]); //get random number of players between 2 and MAX_PLAYERS int players = (rand() % MAX_PLAYERS); if(players < 2){ players = players + 2; } srand(testSeed); int gameSeed = rand(); //initialize game initializeGame(players, k, gameSeed, &game); //loop until game is finished while(!isGameOver(&game)){ int currentPlayer = whoseTurn(&game); printf("player: %d begins their turn\n",currentPlayer ); //action phase int playResult = 0; while(game.numActions > 0){ int numActionCards = 0; //make sure there is an action card in hand for(int i=0; i <numHandCards(&game); i++){ if(game.hand[currentPlayer][i] >= adventurer && game.hand[currentPlayer][i] <= treasure_map){ numActionCards++; } } //if no action cards in hand break loop if(numActionCards == 0){ printf("no action cards in hand\n"); break; } int handPos = rand() % game.handCount[currentPlayer]; int cardPlay = game.hand[currentPlayer][handPos]; //check if selected card is kingdom card if(cardPlay >= adventurer && cardPlay <= treasure_map){ playResult = playCard(handPos,0,0,0,&game); } //check result of playCard if(playResult != 0){ printf("Could not play card\n"); } else printf("Card was successfully played\n"); //1 in 10 chance to not use an action if(rand() % 10 == 0) break; } //buy phase while(game.numBuys > 0){ //count the value of treasure in player's hand updateCoins(currentPlayer, &game, 0); int treasureAvailable = HandTreasure(&game, currentPlayer); //for buying cards, I seperated possible cards to buy into tiers based on cost //this is less about game strategy and more about trying to get good coverage of cards if(treasureAvailable >= 8){ customBuy(province, &game); treasureAvailable = HandTreasure(&game, currentPlayer); } if(treasureAvailable >= 6){ if(rand() % 1) customBuy(gold, &game); else customBuy(adventurer, &game); treasureAvailable = HandTreasure(&game, currentPlayer); } if(treasureAvailable >= 5){ switch(rand() % 6){ case 4: customBuy(minion, &game); break; case 3: customBuy(mine, &game); break; case 2: customBuy(council_room, &game); break; case 1: customBuy(duchy, &game); break; case 0: customBuy(outpost, &game); break; default: customBuy(tribute, &game); break; } treasureAvailable = HandTreasure(&game, currentPlayer); } if(treasureAvailable >= 4){ switch(rand() % 9){ case 7: customBuy(feast, &game); break; case 6: customBuy(gardens, &game); break; case 5: customBuy(salvager, &game); break; case 4: customBuy(treasure_map, &game); break; case 3: customBuy(sea_hag, &game); break; case 2: customBuy(cutpurse, &game); case 1: customBuy(remodel, &game); break; case 0: customBuy(smithy, &game); break; default: customBuy(baron, &game); break; } treasureAvailable = HandTreasure(&game, currentPlayer); } if(treasureAvailable >= 3){ switch(rand() % 5){ case 3: customBuy(steward, &game); break; case 2: customBuy(ambassador, &game); break; case 1: customBuy(great_hall, &game); break; case 0: customBuy(silver, &game); break; default: customBuy(village, &game); break; } treasureAvailable = HandTreasure(&game, currentPlayer); } if(treasureAvailable >= 2){ if(rand() % 1) customBuy(estate, &game); else customBuy(embargo, &game); treasureAvailable = HandTreasure(&game, currentPlayer); } else customBuy(copper, &game); break; }//end buy loop //cleanup phase printf("player: %d ends their turn\n",currentPlayer ); endTurn(&game); }//game loop printf("game is finished.\n"); printf("Game results:\n"); for(int i = 0; i < players; i++){ printf("Player: %d Score: %d\n",i,scoreFor(i, &game)); } int winners[5]; getWinners(winners, &game); return 1; }