int main(int argc, char ** argv) { createFrame(); createNewBlockBatch(); renderCanvas(); while (inGame) { checkGameState(); checkRowCompletion(); spawnNewBlock(); fetchUserInput(); if(timer++ % 10 == 0 && gameState == 0) { moveDown(); } renderCanvas(); usleep(wait); } endwin(); return 0; }
int dispThread(SceSize args, void *argp) { sceIoChdir(cwd); initBackground(); while (exit_state != EXCEPTION) { if (exit_state) { setFadeMode(&main_fade,FADE_IN,0); if (getFadeState(&main_fade) == FADE_DONE) break; } if (checkGameState(GSQUARE)) { g2dClear(BLACK); dispgSquare(); } if (checkGameState(BANNER)) { g2dClear(BLACK); dispBanner(); } if (checkGameState(MENU)) { drawMovingBackground(); dispMenu(); } if (checkGameState(INGAME)) { drawMovingBackground(); camera(); drawLevel(); drawUI(); } if (checkGameState(LEVEL_TITLE)) { g2dClear(WHITE); intraFontSetStyle(seriffont,1.f,BLACK,0,0,INTRAFONT_ALIGN_CENTER); intraFontPrint(seriffont,G2D_SCR_W/2,G2D_SCR_H/2,lvl.title); } if (checkGameState(END)) { g2dClear(WHITE); g2dBeginRects(img.end); { g2dAdd(); } g2dEnd(); } drawFade(&main_fade); g2dFlip(G2D_VSYNC); } if (exit_state == EXCEPTION) dispException(); return 0; }
int main() { srand(time(NULL)); //new gameState struct gameState * randomState = malloc(sizeof(struct gameState)); int i; int numPlayers; int kingdomCards[10]; int randomSeed; int firstRun = 1; int returnValue; printf("Unit test 1\r\n"); printf("Conducting %d random trials.\r\n", UNITTEST1_TRIALS); int foundErrors = 0; int trials; for (trials = 0; trials < UNITTEST1_TRIALS; trials++ ){ //fuzz the state fuzzState(randomState); //semi-randomize inputs (within reason) numPlayers = randomNumPlayers(); unittest1_initiateKingdomCards(kingdomCards); randomSeed = rand(); //run function and store results returnValue = initializeGame(numPlayers, kingdomCards, randomSeed, randomState); //test outputs: if (firstRun == 1) TestRandom(); if (returnValue != -1) { foundErrors -= checkGameState(randomState, returnValue, numPlayers, kingdomCards); //subtracts a negative to add } firstRun = 0; } printf("Unit Test 1 Complete. I found %d errors\r\n", foundErrors); return 0; }
int main(int argc, char** argv) { srand(time(NULL)); Square** board = randomizeBoard(); int gameOver, gameWon, i; while(1) { printBoard(board); int gameWon = checkGameState(board); if(gameWon == 1) { printf("\nYou won! Congratulations!\n"); return 0; } printf("\n\nEnter the row of the space you want to hit: "); int row; scanf("%d", &row); printf("\nEnter the column of the space you want to hit: "); int column; scanf("%d", &column); gameOver = updateBoard(board, row, column); if(gameOver == 1) { printf("\nYou hit a mine! Game Over"); printUncoveredBoard(board); return 0; } } free(board); for(i = 0; i < SIZE; i++) { free(board[i]); } return (EXIT_SUCCESS); }
//step through one cycle of the game int step(int cycle,Agent agents[],Graph g,int maxCycles){ int i; cycle++; for(i=0;i<=NUM_DETECTIVES;i++){ if(i == THIEF) { //location of thief stored in graph setThiefLocation(g, getCurrentLocation(agents[i])); } Edge nextMove = getNextMove(agents[i],g); makeNextMove(g, agents[i], nextMove); } display(cycle,agents,g); int gameState = checkGameState(agents,g,cycle,maxCycles); if(gameState == CONTINUE){ return cycle; } else { return gameState; } }
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 argc, char * argv[]){ Agent agents[NUM_DETECTIVES+1]; if(argc < 4){ printf("Incorrect usage: please enter filename1 filename2 maxCycles\n"); exit(0); } int maxCycles = atoi(argv[3]); int cycle = 0; int seed = time(NULL); if(argc == 5) seed = atoi(argv[4]); srand(seed); Graph g = readGraph(argv[1]); #ifdef DEBUG show(g); #endif initialiseAgents(argv[2],agents,maxCycles,g); #ifdef DEBUG stats(cycle,agents); #endif char command[MAXLINE]; printf("\nPOLICE ACADEMY 1927"); printf("\n\nRed alert! A thief is on the run.\n"); printf("Agents, to your cars. You have %d hours.\n\n",maxCycles); display(cycle,agents,g); if(checkGameState(agents,g,cycle,maxCycles) != CONTINUE){ freeResources(agents,g); return 0; } printf("Enter command: "); scanf("%s",command); while (strcmp(command,"quit") != 0){ if(strcmp(command,"display") == 0){ display(cycle,agents,g); }else if(strcmp(command,"run") == 0){ cycle = run(cycle,maxCycles,agents,g); }else if(strcmp(command,"step") == 0){ cycle = step(cycle,agents,g,maxCycles); }else if(strcmp(command,"stats") == 0){ stats(cycle,agents); }else if(strcmp(command,"map") == 0){ show(g); printf("\n"); } if(cycle < 0) break; printf("Enter command: "); scanf("%s",command); } freeResources(agents,g); 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; //---Test numBuys = 0 //---Expected result: error printf("*** Testing numBuys = 0 ***\n"); printf("Errors: "); //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted."); return -1; } //Set numBuys to 0 g->numBuys = 0; //Save current state memcpy(pre, g, sizeof(struct gameState)); //Attempt to buy card result = buyCard(TEST_CARD, 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 no supply remaining //---Expected result: error printf("*** Testing supplyCount = 0 ***\n"); printf("Errors: "); //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted."); return -1; } //Set supplyCount for test card to 0 g->supplyCount[TEST_CARD] = 0; //Save current state memcpy(pre, g, sizeof(struct gameState)); //Attempt to buy card result = buyCard(TEST_CARD, 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 insufficient funds //---Expected result: error printf("*** Testing coins < cost ***\n"); printf("Errors: "); //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted."); return -1; } //Set coins to cost of card - 1 g->coins = getCost(TEST_CARD) - 1; //Save current state memcpy(pre, g, sizeof(struct gameState)); //Attempt to buy card result = buyCard(TEST_CARD, 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 invalid supply position //---Expected result: error printf("*** Testing invalid position ***\n"); printf("Errors: "); //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted."); return -1; } //Save current state memcpy(pre, g, sizeof(struct gameState)); //Attempt to buy card at invalid position result = buyCard(treasure_map+1, 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 valid buy /*---Expected results: - Game and turn settings are unchanged except as noted below - Phase set to 1 - numBuys decreased by 1 - coins decreased by card cost - Supply count for other cards are unchanged - Supply count for selected card is decreased by 1 - Other player's cards (hand, deck, discard) are unchanged - Played cards are unchanged - Current player's hand and deck are unchanged - Current player's discardCount is 1 more than before buyCard - Current player's discard is the same except additional card in last position */ printf("*** Testing valid buy ***\n"); printf("Errors: "); //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted."); return -1; } //Add sufficient coins and numBuys g->coins = getCost(TEST_CARD); g->numBuys = 1; //Save current state memcpy(pre, g, sizeof(struct gameState)); //Run buyCard and check results failed = 0; result = buyCard(TEST_CARD, 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 = 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 (checkNumActions(pre, g) < 0){ printf("\nnumActions: %d, Expected: %d", g->numActions, pre->numActions); failed = 1; } //Check phase = 1 if (g->phase != 1){ printf("\nphase: %d, Expected: %d", g->phase, 1); failed = 1; } //Check coins = coins_before - cost of card if (g->coins != pre->coins - getCost(TEST_CARD)){ printf("\ncoins: %d, Expected: %d", g->coins, pre->coins - getCost(TEST_CARD)); failed = 1; } //Check numBuys decreased by 1 if (g->numBuys != pre->numBuys - 1){ printf("\nnumBuys: %d, Expected: %d", g->numBuys, pre->numBuys - 1); failed = 1; } //Check supply for bought card is decreased by 1 if (g->supplyCount[TEST_CARD] != pre->supplyCount[TEST_CARD]-1){ printf("\nSupply count for card %d: %d, Expected: %d", TEST_CARD, g->supplyCount[TEST_CARD], pre->supplyCount[TEST_CARD]-1); failed = 1; } //Check supply for other cards remains the same for (i = 0; i <= treasure_map; i++){ //if test card, skip if (i == TEST_CARD){ continue; } if (pre->supplyCount[i] != g->supplyCount[i]){ printf("\nSupply count for card %d: %d, Expected: %d", i, g->supplyCount[i], pre->supplyCount[i]); failed = 1; } } //Check all hand, deck and played cards unchanged if (checkHands(pre, g) < 0){ printf("\nHands changed after buyCard\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 (checkDecks(pre, g) < 0){ printf("\nDecks changed after buyCard\n"); //Print expected and actual deck for each player for (i = 0; i < NUM_PLAYERS; i++){ printf(" Deck for player %d:\n", i); printf(" Count: %d, Expected: %d\n", g->deckCount[i], pre->deckCount[i]); if (g->deckCount[i] > 0){ printf(" Actual Cards: "); for (j = 0; j < g->deckCount[i]; j++){ printf("%d ", g->deck[i][j]); } printf("\n Expected Cards: "); for (j = 0; j < pre->deckCount[i]; j++){ printf("%d ", pre->deck[i][j]); } } } failed = 1; } if (checkPlayed(pre, g) < 0){ printf("\nPlayed cards changed after buyCard\n"); //Print expected and actual played cards 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 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 current player's discardCount increased by 1 if (g->discardCount[whoseTurn(g)] != pre->discardCount[whoseTurn(g)]+1){ printf("\nCurrent player's discardCount: %d, Expected: %d", g->discardCount[whoseTurn(g)], pre->discardCount[whoseTurn(g)]+1); failed = 1; } //Check current player's discard contains same cards plus new card in last position for (i = 0; i < g->discardCount[whoseTurn(g)]-1; i++){ if (pre->discard[whoseTurn(g)][i] != g->discard[whoseTurn(g)][i]){ printf("\nCurrent player's discard[%d]: %d, Expected: %d", i, g->discard[whoseTurn(g)][i], pre->discard[whoseTurn(g)][i]); failed = 1; } } if (g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)]-1] != TEST_CARD){ printf("\nGained card: %d, Expected: %d", g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)]-1], TEST_CARD); failed = 1; } //Final check if (failed){ printf("\nResult: FAIL\n\n"); } else { printf("none"); printf("\nResult: PASS\n\n"); } //---Test buy with embargo /*---Expected results: - Game and turn settings are unchanged except as noted below - Phase set to 1 - numBuys decreased by 1 - coins decreased by card cost - Supply count for other cards are unchanged - Supply count for selected card is decreased by 1 - Supply count for curse card decreased by 1 - Embargo tokens for other cards are unchanged - Embargo tokens for selected card is decreased by 1 - Other player's cards (hand, deck, discard) are unchanged - Played cards are unchanged - Current player's hand and deck are unchanged - Current player's discardCount is 2 more than before buyCard - Current player's discard is the same except additional card and curse card */ printf("*** Testing valid buy with embargo ***\n"); printf("Errors: "); //Create clean game if (initializeGame(NUM_PLAYERS, selectedCards, seed, g) == -1){ printf("\nCould not initialize game. Testing aborted."); return -1; } //Add sufficient coins and numBuys g->coins = getCost(TEST_CARD); g->numBuys = 1; //Add embargo to test card g->embargoTokens[TEST_CARD] = 1; //Save current state memcpy(pre, g, sizeof(struct gameState)); //Run buyCard and check results failed = 0; result = buyCard(TEST_CARD, 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; } 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 (checkNumActions(pre, g) < 0){ printf("\nnumActions: %d, Expected: %d", g->numActions, pre->numActions); failed = 1; } //Check phase = 1 if (g->phase != 1){ printf("\nphase: %d, Expected: %d", g->phase, 1); failed = 1; } //Check coins = coins_before - cost of card if (g->coins != pre->coins - getCost(TEST_CARD)){ printf("\ncoins: %d, Expected: %d", g->coins, pre->coins - getCost(TEST_CARD)); failed = 1; } //Check numBuys decreased by 1 if (g->numBuys != pre->numBuys - 1){ printf("\nnumBuys: %d, Expected: %d", g->numBuys, pre->numBuys - 1); failed = 1; } //Check supply for bought card is decreased by 1 if (g->supplyCount[TEST_CARD] != pre->supplyCount[TEST_CARD]-1){ printf("\nSupply count for card %d: %d, Expected: %d", TEST_CARD, g->supplyCount[TEST_CARD], pre->supplyCount[TEST_CARD]-1); failed = 1; } //Check supply for curse card is decreased by 1 if (g->supplyCount[0] != pre->supplyCount[0]-1){ printf("\nSupply count for curse card: %d, Expected: %d", g->supplyCount[0], pre->supplyCount[0]-1); failed = 1; } //Check supply for other cards remains the same for (i = 1; i <= treasure_map; i++){ //if test card, skip if (i == TEST_CARD){ continue; } if (pre->supplyCount[i] != g->supplyCount[i]){ printf("\nSupply count for card %d: %d, Expected: %d", i, g->supplyCount[i], pre->supplyCount[i]); failed = 1; } } //Check embargo tokens for bought card is decreased by 1 if (g->embargoTokens[TEST_CARD] != pre->embargoTokens[TEST_CARD]-1){ printf("\nEmbargo tokens for card %d: %d, Expected: %d", TEST_CARD, g->embargoTokens[TEST_CARD], pre->embargoTokens[TEST_CARD]-1); failed = 1; } //Check embargo tokens for other cards remains the same for (i = 0; i <= treasure_map; i++){ //if test card, skip if (i == TEST_CARD){ continue; } if (pre->embargoTokens[i] != g->embargoTokens[i]){ printf("\nEmbargo tokens for card %d: %d, Expected: %d", i, g->embargoTokens[i], pre->embargoTokens[i]); failed = 1; } } //Check all hand, deck and played cards unchanged if (checkHands(pre, g) < 0){ printf("\nHands changed after buyCard\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 (checkDecks(pre, g) < 0){ printf("\nDecks changed after buyCard\n"); //Print expected and actual deck for each player for (i = 0; i < NUM_PLAYERS; i++){ printf(" Deck for player %d:\n", i); printf(" Count: %d, Expected: %d\n", g->deckCount[i], pre->deckCount[i]); if (g->deckCount[i] > 0){ printf(" Actual Cards: "); for (j = 0; j < g->deckCount[i]; j++){ printf("%d ", g->deck[i][j]); } printf("\n Expected Cards: "); for (j = 0; j < pre->deckCount[i]; j++){ printf("%d ", pre->deck[i][j]); } } } failed = 1; } if (checkPlayed(pre, g) < 0){ printf("\nPlayed cards changed after buyCard\n"); //Print expected and actual played cards 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 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 current player's discardCount increased by 2 if (g->discardCount[whoseTurn(g)] != pre->discardCount[whoseTurn(g)]+2){ printf("\nCurrent player's discardCount: %d, Expected: %d", g->discardCount[whoseTurn(g)], pre->discardCount[whoseTurn(g)]+2); failed = 1; } //Check current player's discard contains same cards plus new card and curse in last two positions for (i = 0; i < g->discardCount[whoseTurn(g)]-2; i++){ if (pre->discard[whoseTurn(g)][i] != g->discard[whoseTurn(g)][i]){ printf("\nCurrent player's discard[%d]: %d, Expected: %d", i, g->discard[whoseTurn(g)][i], pre->discard[whoseTurn(g)][i]); failed = 1; } } if (g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)]-1] == TEST_CARD){ if (g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)]-2] != 0){ printf("\nGained card: %d, Expected: %d", g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)]-1], 0); failed = 1; } } else if (g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)]-1] == 0){ if (g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)]-2] != TEST_CARD){ printf("\nGained card: %d, Expected: %d", g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)]-1], TEST_CARD); failed = 1; } } else { printf("\nGained card: %d, Expected: %d or %d", g->discard[whoseTurn(g)][g->discardCount[whoseTurn(g)]-1], TEST_CARD, 0); failed = 1; } //Final check if (failed){ printf("\nResult: FAIL\n"); } else { printf("none"); printf("\nResult: PASS\n"); } return 0; }
void renderCanvas() { clear(); checkGameState(); refresh(); }