diff --git a/dominion/Makefile b/dominion/Makefile index 5541801f3..4a9d67348 100644 --- a/dominion/Makefile +++ b/dominion/Makefile @@ -1,31 +1,68 @@ -CFLAGS= -Wall -fpic -coverage -lm -std=c99 +CFLAGS= -Wall -fpic -coverage -lm -std=c99 -g + +unittestresults: unittest1 unittest2 unittest3 unittest4 unittest5 \ + randomtestcard2 randomtestcard3 runtests + #randomtestcard1 randomtestcard2 randomtestcard3 runtests rngs.o: rngs.h rngs.c - gcc -c rngs.c -g $(CFLAGS) + gcc -c rngs.c $(CFLAGS) dominion.o: dominion.h dominion.c rngs.o - gcc -c dominion.c -g $(CFLAGS) + gcc -c dominion.c $(CFLAGS) + +unittest1: dominion.o rngs.o unittest1.c + gcc -o unittest1 unittest1.c dominion.o rngs.o $(CFLAGS) + #./unittest1 + +unittest2: dominion.o rngs.o unittest2.c + gcc -o unittest2 unittest2.c dominion.o rngs.o $(CFLAGS) + #./unittest2 -playdom: dominion.o playdom.c - gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS) -#To run playdom you need to entere: ./playdom like ./playdom 10*/ +unittest3: dominion.o rngs.o unittest3.c + gcc -o unittest3 unittest3.c dominion.o rngs.o $(CFLAGS) + #./unittest3 -testDrawCard: testDrawCard.c dominion.o rngs.o - gcc -o testDrawCard -g testDrawCard.c dominion.o rngs.o $(CFLAGS) +unittest4: dominion.o rngs.o unittest4.c + gcc -o unittest4 unittest4.c dominion.o rngs.o $(CFLAGS) + #./unittest4 -interface.o: interface.h interface.c - gcc -c interface.c -g $(CFLAGS) +unittest5: dominion.o rngs.o unittest5.c + gcc -o unittest5 unittest5.c dominion.o rngs.o $(CFLAGS) + #./unittest5 -runtests: testDrawCard - ./testDrawCard &> unittestresult.out - gcov dominion.c >> unittestresult.out - cat dominion.c.gcov >> unittestresult.out +randomtestcard1: dominion.o rngs.o randomtestcard1.c + gcc -o randomtestcard1 randomtestcard1.c dominion.o rngs.o $(CFLAGS) + #./randomtestcard1 +randomtestcard2: dominion.o rngs.o randomtestcard2.c + gcc -o randomtestcard2 randomtestcard2.c dominion.o rngs.o $(CFLAGS) + #./randomtestcard2 -player: player.c interface.o - gcc -o player player.c -g dominion.o rngs.o interface.o $(CFLAGS) +randomtestcard3: dominion.o rngs.o randomtestcard3.c + gcc -o randomtestcard3 randomtestcard3.c dominion.o rngs.o $(CFLAGS) + #./randomtestcard3 -all: playdom player +#ifeq (0,1) +runtests: unittest1 unittest2 unittest3 unittest4 unittest5 \ + randomtestcard1 randomtestcard2 randomtestcard3 + ./unittest1 > unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + ./unittest2 >> unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + ./unittest3 >> unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + ./unittest4 >> unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + ./unittest5 >> unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + #./randomtestcard1 >> randomtestresults.out + #gcov -b -f dominion.c >> randomtestresults.out + ./randomtestcard2 >> randomtestresults.out + gcov -b -f dominion.c >> randomtestresults.out + ./randomtestcard3 >> randomtestresults.out + gcov -b -f dominion.c >> randomtestresults.out +#endif clean: - rm -f *.o playdom.exe playdom player player.exe *.gcov *.gcda *.gcno *.so *.out testDrawCard testDrawCard.exe + rm -f *.o unittest1 unittest2 unittest3 unittest4 unittest5 \ + randomtestcard1 randomtestcard2 randomtestcard3 *.gcov *.gcda *.gcno *.out diff --git a/dominion/Makefile old b/dominion/Makefile old new file mode 100644 index 000000000..5541801f3 --- /dev/null +++ b/dominion/Makefile old @@ -0,0 +1,31 @@ +CFLAGS= -Wall -fpic -coverage -lm -std=c99 + +rngs.o: rngs.h rngs.c + gcc -c rngs.c -g $(CFLAGS) + +dominion.o: dominion.h dominion.c rngs.o + gcc -c dominion.c -g $(CFLAGS) + +playdom: dominion.o playdom.c + gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS) +#To run playdom you need to entere: ./playdom like ./playdom 10*/ + +testDrawCard: testDrawCard.c dominion.o rngs.o + gcc -o testDrawCard -g testDrawCard.c dominion.o rngs.o $(CFLAGS) + +interface.o: interface.h interface.c + gcc -c interface.c -g $(CFLAGS) + +runtests: testDrawCard + ./testDrawCard &> unittestresult.out + gcov dominion.c >> unittestresult.out + cat dominion.c.gcov >> unittestresult.out + + +player: player.c interface.o + gcc -o player player.c -g dominion.o rngs.o interface.o $(CFLAGS) + +all: playdom player + +clean: + rm -f *.o playdom.exe playdom player player.exe *.gcov *.gcda *.gcno *.so *.out testDrawCard testDrawCard.exe diff --git a/dominion/Makefile3.mak b/dominion/Makefile3.mak new file mode 100644 index 000000000..377d44b80 --- /dev/null +++ b/dominion/Makefile3.mak @@ -0,0 +1,46 @@ +CFLAGS= -Wall -fpic -coverage -lm -std=c99 + +unittestresults: unittest1 unittest2 unittest3 unittest4 unittest5 runtests + +rngs.o: rngs.h rngs.c + gcc -c rngs.c $(CFLAGS) + +dominion.o: dominion.h dominion.c rngs.o + gcc -c dominion.c $(CFLAGS) + +unittest1: dominion.o rngs.o unittest1.c + gcc -o unittest1 unittest1.c dominion.o rngs.o $(CFLAGS) + #./unittest1 + +unittest2: dominion.o rngs.o unittest2.c + gcc -o unittest2 unittest2.c dominion.o rngs.o $(CFLAGS) + #./unittest2 + +unittest3: dominion.o rngs.o unittest3.c + gcc -o unittest3 unittest3.c dominion.o rngs.o $(CFLAGS) + #./unittest3 + +unittest4: dominion.o rngs.o unittest4.c + gcc -o unittest4 unittest4.c dominion.o rngs.o $(CFLAGS) + #./unittest4 + +unittest5: dominion.o rngs.o unittest5.c + gcc -o unittest5 unittest5.c dominion.o rngs.o $(CFLAGS) + #./unittest5 + +#ifeq (0,1) +runtests: unittest1 unittest2 unittest3 unittest4 unittest5 + ./unittest1 > unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + ./unittest2 >> unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + ./unittest3 >> unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + ./unittest4 >> unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + ./unittest5 >> unittestresults.out + gcov -b -f dominion.c >> unittestresults.out +#endif + +clean: + rm -f *.o unittest1 unittest2 unittest3 unittest4 unittest5 *.gcov *.gcda *.gcno *.out diff --git a/dominion/Makefile_old b/dominion/Makefile_old new file mode 100644 index 000000000..e14ad1e8b --- /dev/null +++ b/dominion/Makefile_old @@ -0,0 +1,31 @@ +CFLAGS= -Wall -fpic -coverage -lm -std=c99 + +rngs.o: rngs.h rngs.c + gcc -c rngs.c -g $(CFLAGS) + +dominion.o: dominion.h dominion.c rngs.o + gcc -c dominion.c -g $(CFLAGS) + +playdom: dominion.o playdom.c + gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS) +#To run playdom you need to entere: ./playdom like ./playdom 10*/ + +testdrawcard: testdrawcard.c dominion.o rngs.o + gcc -o testdrawcard -g testdrawcard.c dominion.o rngs.o $(CFLAGS) + +interface.o: interface.h interface.c + gcc -c interface.c -g $(CFLAGS) + +runtests: testdrawcard + ./testdrawcard &> unittestresult.out + gcov dominion.c >> unittestresult.out + cat dominion.c.gcov >> unittestresult.out + + +player: player.c interface.o + gcc -o player player.c -g dominion.o rngs.o interface.o $(CFLAGS) + +all: playdom player + +clean: + rm -f *.o playdom.exe playdom player player.exe *.gcov *.gcda *.gcno *.so *.out testdrawcard testdrawcard.exe diff --git a/dominion/as3/dominion.c b/dominion/as3/dominion.c new file mode 100644 index 000000000..0c865f97e --- /dev/null +++ b/dominion/as3/dominion.c @@ -0,0 +1,1420 @@ +#include "dominion.h" +#include "dominion_helpers.h" +#include "rngs.h" +#include +#include +#include + +int compare(const void* a, const void* b) { + if (*(int*)a > *(int*)b) + return 1; + if (*(int*)a < *(int*)b) + return -1; + return 0; +} + +struct gameState* newGame() { + struct gameState* g = malloc(sizeof(struct gameState)); + return g; +} + +int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + int k8, int k9, int k10) { + int* k = malloc(10 * sizeof(int)); + k[0] = k1; + k[1] = k2; + k[2] = k3; + k[3] = k4; + k[4] = k5; + k[5] = k6; + k[6] = k7; + k[7] = k8; + k[8] = k9; + k[9] = k10; + return k; +} + +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 shuffle(int player, struct gameState *state) { + + + int newDeck[MAX_DECK]; + int newDeckPos = 0; + int card; + int i; + + if (state->deckCount[player] < 1) + return -1; + qsort ((void*)(state->deck[player]), state->deckCount[player], sizeof(int), compare); + /* SORT CARDS IN DECK TO ENSURE DETERMINISM! */ + + while (state->deckCount[player] > 0) { + card = floor(Random() * state->deckCount[player]); + newDeck[newDeckPos] = state->deck[player][card]; + newDeckPos++; + for (i = card; i < state->deckCount[player]-1; i++) { + state->deck[player][i] = state->deck[player][i+1]; + } + state->deckCount[player]--; + } + for (i = 0; i < newDeckPos; i++) { + state->deck[player][i] = newDeck[i]; + state->deckCount[player]++; + } + + return 0; +} + +int playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state) +{ + int card; + int coin_bonus = 0; //tracks coins gain from actions + + //check if it is the right phase + if (state->phase != 0) + { + return -1; + } + + //check if player has enough actions + if ( state->numActions < 1 ) + { + return -1; + } + + //get card played + card = handCard(handPos, state); + + //check if selected card is an action + if ( card < adventurer || card > treasure_map ) + { + return -1; + } + + //play card + if ( cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0 ) + { + return -1; + } + + //reduce number of actions + state->numActions--; + + //update coins (Treasure cards may be added with card draws) + updateCoins(state->whoseTurn, state, coin_bonus); + + return 0; +} + +int buyCard(int supplyPos, struct gameState *state) { + int who; + if (DEBUG) { + printf("Entering buyCard...\n"); + } + + // I don't know what to do about the phase thing. + + who = state->whoseTurn; + + if (state->numBuys < 1) { + if (DEBUG) + printf("You do not have any buys left\n"); + return -1; + } else if (supplyCount(supplyPos, state) <1) { + if (DEBUG) + printf("There are not any of that type of card left\n"); + return -1; + } else if (state->coins < getCost(supplyPos)) { + if (DEBUG) + printf("You do not have enough money to buy that. You have %d coins.\n", state->coins); + return -1; + } else { + state->phase=1; + //state->supplyCount[supplyPos]--; + gainCard(supplyPos, state, 0, who); //card goes in discard, this might be wrong.. (2 means goes into hand, 0 goes into discard) + + state->coins = (state->coins) - (getCost(supplyPos)); + state->numBuys--; + if (DEBUG) + printf("You bought card number %d for %d coins. You now have %d buys and %d coins.\n", supplyPos, getCost(supplyPos), state->numBuys, state->coins); + } + + //state->discard[who][state->discardCount[who]] = supplyPos; + //state->discardCount[who]++; + + return 0; +} + +int numHandCards(struct gameState *state) { + return state->handCount[ whoseTurn(state) ]; +} + +int handCard(int handPos, struct gameState *state) { + int currentPlayer = whoseTurn(state); + return state->hand[currentPlayer][handPos]; +} + +int supplyCount(int card, struct gameState *state) { + return state->supplyCount[card]; +} + +int fullDeckCount(int player, int card, struct gameState *state) { + int i; + int count = 0; + + for (i = 0; i < state->deckCount[player]; i++) + { + if (state->deck[player][i] == card) count++; + } + + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == card) count++; + } + + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->discard[player][i] == card) count++; + } + + return count; +} + +int whoseTurn(struct gameState *state) { + return state->whoseTurn; +} + +int endTurn(struct gameState *state) { + int k; + int i; + int currentPlayer = whoseTurn(state); + + //Discard hand + for (i = 0; i < state->handCount[currentPlayer]; i++) { + state->discard[currentPlayer][state->discardCount[currentPlayer]++] = state->hand[currentPlayer][i];//Discard + state->hand[currentPlayer][i] = -1;//Set card to -1 + } + state->handCount[currentPlayer] = 0;//Reset hand count + + //Code for determining the player + if (currentPlayer < (state->numPlayers - 1)) { + state->whoseTurn = currentPlayer + 1;//Still safe to increment + } + else { + state->whoseTurn = 0;//Max player has been reached, loop back around to player 1 + } + + state->outpostPlayed = 0; + state->phase = 0; + state->numActions = 1; + state->coins = 0; + state->numBuys = 1; + state->playedCardCount = 0; + state->handCount[state->whoseTurn] = 0; + + //int k; move to top + //Next player draws hand + for (k = 0; k < 5; k++) { + drawCard(state->whoseTurn, state);//Draw a card + } + + //Update money + updateCoins(state->whoseTurn, state, 0); + + return 0; +} + +int isGameOver(struct gameState *state) { + int i; + int j; + + //if stack of Province cards is empty, the game ends + if (state->supplyCount[province] == 0) + { + return 1; + } + + //if three supply pile are at 0, the game ends + j = 0; + for (i = 0; i < 25; i++) + { + if (state->supplyCount[i] == 0) + { + j++; + } + } + if ( j >= 3) + { + return 1; + } + + return 0; +} + +int scoreFor (int player, struct gameState *state) { + + int i; + int score = 0; + //score from hand + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == curse) { + score = score - 1; + }; + if (state->hand[player][i] == estate) { + score = score + 1; + }; + if (state->hand[player][i] == duchy) { + score = score + 3; + }; + if (state->hand[player][i] == province) { + score = score + 6; + }; + if (state->hand[player][i] == great_hall) { + score = score + 1; + }; + if (state->hand[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + //score from discard + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->discard[player][i] == curse) { + score = score - 1; + }; + if (state->discard[player][i] == estate) { + score = score + 1; + }; + if (state->discard[player][i] == duchy) { + score = score + 3; + }; + if (state->discard[player][i] == province) { + score = score + 6; + }; + if (state->discard[player][i] == great_hall) { + score = score + 1; + }; + if (state->discard[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + //score from deck + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->deck[player][i] == curse) { + score = score - 1; + }; + if (state->deck[player][i] == estate) { + score = score + 1; + }; + if (state->deck[player][i] == duchy) { + score = score + 3; + }; + if (state->deck[player][i] == province) { + score = score + 6; + }; + if (state->deck[player][i] == great_hall) { + score = score + 1; + }; + if (state->deck[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + return score; +} + +int getWinners(int players[MAX_PLAYERS], struct gameState *state) { + int i; + int j; + int highScore; + int currentPlayer; + + //get score for each player + for (i = 0; i < MAX_PLAYERS; i++) + { + //set unused player scores to -9999 + if (i >= state->numPlayers) + { + players[i] = -9999; + } + else + { + players[i] = scoreFor (i, state); + } + } + + //find highest score + j = 0; + for (i = 0; i < MAX_PLAYERS; i++) + { + if (players[i] > players[j]) + { + j = i; + } + } + highScore = players[j]; + + //add 1 to players who had less turns + currentPlayer = whoseTurn(state); + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] == highScore && i > currentPlayer ) + { + players[i]++; + } + } + + //find new highest score + j = 0; + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] > players[j] ) + { + j = i; + } + } + highScore = players[j]; + + //set winners in array to 1 and rest to 0 + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] == highScore ) + { + players[i] = 1; + } + else + { + players[i] = 0; + } + } + + return 0; +} + +int drawCard(int player, struct gameState *state) +{ int count; + int deckCounter; + if (state->deckCount[player] <= 0) { //Deck is empty + + //Step 1 Shuffle the discard pile back into a deck + int i; + //Move discard to deck + for (i = 0; i < state->discardCount[player]; i++) { + state->deck[player][i] = state->discard[player][i]; + state->discard[player][i] = -1; + } + + state->deckCount[player] = state->discardCount[player]; + state->discardCount[player] = 0;//Reset discard + + //Shufffle the deck + shuffle(player, state);//Shuffle the deck up and make it so that we can draw + + if (DEBUG) { //Debug statements + printf("Deck count now: %d\n", state->deckCount[player]); + } + + state->discardCount[player] = 0; + + //Step 2 Draw Card + count = state->handCount[player];//Get current player's hand count + + if (DEBUG) { //Debug statements + printf("Current hand count: %d\n", count); + } + + deckCounter = state->deckCount[player];//Create a holder for the deck count + + if (deckCounter == 0) + return -1; + + state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to hand + state->deckCount[player]--; + state->handCount[player]++;//Increment hand count + } + + else { + int count = state->handCount[player];//Get current hand count for player + int deckCounter; + if (DEBUG) { //Debug statements + printf("Current hand count: %d\n", count); + } + + deckCounter = state->deckCount[player];//Create holder for the deck count + state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to the hand + state->deckCount[player]--; + state->handCount[player]++;//Increment hand count + } + + return 0; +} + +int getCost(int cardNumber) +{ + switch( cardNumber ) + { + case curse: + return 0; + case estate: + return 2; + case duchy: + return 5; + case province: + return 8; + case copper: + return 0; + case silver: + return 3; + case gold: + return 6; + case adventurer: + return 6; + case council_room: + return 5; + case feast: + return 4; + case gardens: + return 4; + case mine: + return 5; + case remodel: + return 4; + case smithy: + return 4; + case village: + return 3; + case baron: + return 4; + case great_hall: + return 3; + case minion: + return 5; + case steward: + return 3; + case tribute: + return 5; + case ambassador: + return 3; + case cutpurse: + return 4; + case embargo: + return 2; + case outpost: + return 5; + case salvager: + return 4; + case sea_hag: + return 4; + case treasure_map: + return 4; + } + + return -1; +} + +int doMine(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) +{ + int i; + int j; + + j = state->hand[currentPlayer][choice1]; //store card we will trash + + if (/*state->hand[currentPlayer][choice1] < copper ||*/ state->hand[currentPlayer][choice1] > gold) + { + return -1; + } + + if (choice2 > treasure_map || choice2 < curse) + { + return -1; + } + + if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) ) + { + return -1; + } + + //gainCard(choice2, state, 2, currentPlayer); + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + //discard trashed card + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == j) + { + discardCard(i, currentPlayer, state, 0); + break; + } + } + + return 0; +} + +void getEstateCard(struct gameState *state, int currentPlayer) +{ + if (supplyCount(estate, state) > 0) { + gainCard(estate, state, 0, currentPlayer);//Gain an estate + + state->supplyCount[estate]--;//Decrement Estates + if (supplyCount(estate, state) == 0) { + isGameOver(state); + } + } +} + +void doBaron(int choice1, struct gameState *state, int currentPlayer) +{ + state->numBuys++;//Increase buys by 1! + state->numBuys++;//Increase buys by 1! + if (choice1 > 0) { //Boolean true or going to discard an estate + int p = 1; //0;//Iterator for hand! + int card_not_discarded = 1;//Flag for discard set! + while(card_not_discarded) { + if (state->hand[currentPlayer][p] == estate) { //Found an estate card! + state->coins += 4;//Add 4 coins to the amount of coins + state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; + state->discardCount[currentPlayer]++; + for (; p < state->handCount[currentPlayer]; p++) { + state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1]; + } + state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; + state->handCount[currentPlayer]--; + card_not_discarded = 0;//Exit the loop + } + else if (p > state->handCount[currentPlayer]) { + if(DEBUG) { + printf("No estate cards in your hand, invalid choice\n"); + printf("Must gain an estate if there are any\n"); + } + getEstateCard(state, currentPlayer); + card_not_discarded = 0;//Exit the loop + } + + else { + p++;//Next card + } + } + } + + else { + getEstateCard(state, currentPlayer); + } +} + +void doMinion(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) +{ + int i; + int j; + + //+1 action + state->numActions++; + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + if (choice1) + { + state->coins = state->coins + 2; + } + else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 + { + //discard hand + while(numHandCards(state) > 1 /*0*/) + { + discardCard(handPos, currentPlayer, state, 0); + } + + //draw 4 + for (i = 0; i < 4; i++) + { + drawCard(currentPlayer, state); + } + + //other players discard hand and redraw if hand size > 4 + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + //if ( state->handCount[i] > 4 ) + { + //discard hand + while( state->handCount[i] > 0 ) + { + discardCard(handPos, i, state, 0); + } + + //draw 4 + for (j = 0; j < 4; j++) + { + drawCard(i, state); + } + } + } + } + } +} + +void printDeck(struct gameState *state, int p) { + printf("Deck:"); + for (int i=0; i < state->deckCount[p]; i++) + printf(" %d", state->deck[p][i]); + printf("\n"); +} + +void printHand(struct gameState *state, int p) { + printf("Hand:"); + for (int i=0; i < state->handCount[p]; i++) + printf(" %d", state->hand[p][i]); + printf("\n"); +} + +void doTribute(struct gameState *state, int currentPlayer, int nextPlayer, int tributeRevealedCards[2]) +{ + int i; + + if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) { + if (state->deckCount[nextPlayer] > 0) { + tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + state->deckCount[nextPlayer]--; + } + else if (state->discardCount[nextPlayer] > 0) { + tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1]; + state->discardCount[nextPlayer]--; + } + else { + //No Card to Reveal + if (DEBUG) { + printf("No cards to reveal\n"); + } + } + } + + else { + if (state->deckCount[nextPlayer] == 0) { + for (i = 0; i < state->discardCount[nextPlayer]; i++) { + state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck + state->deckCount[nextPlayer]++; + state->discard[nextPlayer][i] = -1; + state->discardCount[nextPlayer]--; + } + + shuffle(nextPlayer,state);//Shuffle the deck + } + tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + //state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + //state->deckCount[nextPlayer]--; + //tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-2]; + //state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + //state->deckCount[nextPlayer]--; + } + + if (tributeRevealedCards[0] == tributeRevealedCards[1]) { //If we have a duplicate card, just drop one + state->playedCards[state->playedCardCount] = tributeRevealedCards[1]; + state->playedCardCount++; + tributeRevealedCards[1] = -1; + } + + for (i = 0; i < 2; i ++) { + if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) { //Treasure cards + state->numActions = state->numActions + 2; + } + + else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall) { //Victory Card Found + drawCard(currentPlayer, state); + //drawCard(currentPlayer, state); + } + else { //Action Card + state->coins += 2; + } + } +} + +int doAmbassador(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) +{ + int i; + int j; + + j = 0; //used to check if player has enough cards to discard + + if (choice2 > 3 || choice2 < 0) + { + return -1; + } + +/* + if (choice1 == handPos) + { + return -1; + } + */ + + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (i != handPos && state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1] /*&& i != choice1*/) + { + j++; + } + } + if (j < choice2) + { + return -1; + } + + if (DEBUG) + printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]); + + //increase supply count for choosen card by amount being discarded + state->supplyCount[state->hand[currentPlayer][choice1]] += choice2; + + //each other player gains a copy of revealed card + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + gainCard(state->hand[currentPlayer][choice1], state, 0, i); + } + } + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + + //trash copies of cards returned to supply + for (j = 0; j < choice2; j++) + { + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1]) + { + discardCard(i, currentPlayer, state, 1); + break; + } + } + } + + return 0; +} + +int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) +{ + int i; + int j; + int k; + int x; + int index; + int currentPlayer = whoseTurn(state); + int nextPlayer = currentPlayer + 1; + + int tributeRevealedCards[2] = {-1, -1}; + int temphand[MAX_HAND];// moved above the if statement + int drawntreasure=0; + int cardDrawn; + int z = 0;// this is the counter for the temp hand + if (nextPlayer > (state->numPlayers - 1)) { + nextPlayer = 0; + } + + + //uses switch to select card and perform actions + switch( card ) + { + case adventurer: + while(drawntreasure<2) { + if (state->deckCount[currentPlayer] <1) { //if the deck is empty we need to shuffle discard and add to deck + shuffle(currentPlayer, state); + } + drawCard(currentPlayer, state); + cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card. + if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold) + drawntreasure++; + else { + temphand[z]=cardDrawn; + state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one). + z++; + } + } + while(z-1>=0) { + state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn + z=z-1; + } + return 0; + + case council_room: + //+4 Cards + for (i = 0; i < 4; i++) + { + drawCard(currentPlayer, state); + } + + //+1 Buy + state->numBuys++; + + //Each other player draws a card + for (i = 0; i < state->numPlayers; i++) + { + if ( i != currentPlayer ) + { + drawCard(i, state); + } + } + + //put played card in played card pile + discardCard(handPos, currentPlayer, state, 0); + + return 0; + + case feast: + //gain card with cost up to 5 + //Backup hand + for (i = 0; i <= state->handCount[currentPlayer]; i++) { + temphand[i] = state->hand[currentPlayer][i];//Backup card + state->hand[currentPlayer][i] = -1;//Set to nothing + } + //Backup hand + + //Update Coins for Buy + updateCoins(currentPlayer, state, 5); + x = 1;//Condition to loop on + while( x == 1) {//Buy one card + if (supplyCount(choice1, state) <= 0) { + if (DEBUG) + printf("None of that card left, sorry!\n"); + + if (DEBUG) { + printf("Cards Left: %d\n", supplyCount(choice1, state)); + } + } + else if (state->coins < getCost(choice1)) { + printf("That card is too expensive!\n"); + + if (DEBUG) { + printf("Coins: %d < %d\n", state->coins, getCost(choice1)); + } + } + else { + + if (DEBUG) { + printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + } + + gainCard(choice1, state, 0, currentPlayer);//Gain the card + x = 0;//No more buying cards + + if (DEBUG) { + printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + } + + } + } + + //Reset Hand + for (i = 0; i <= state->handCount[currentPlayer]; i++) { + state->hand[currentPlayer][i] = temphand[i]; + temphand[i] = -1; + } + //Reset Hand + + return 0; + + case gardens: + return -1; + + case mine: + return doMine(choice1, choice2, state, handPos, currentPlayer); + + case remodel: + j = state->hand[currentPlayer][choice1]; //store card we will trash + + if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) ) + { + return -1; + } + + gainCard(choice2, state, 0, currentPlayer); + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + //discard trashed card + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == j) + { + discardCard(i, currentPlayer, state, 0); + break; + } + } + + + return 0; + + case smithy: + //+3 Cards + for (i = 0; i < 3; i++) + { + drawCard(currentPlayer, state); + } + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case village: + //+1 Card + drawCard(currentPlayer, state); + + //+2 Actions + state->numActions = state->numActions + 2; + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case baron: + doBaron(choice1, state, currentPlayer); + return 0; + + case great_hall: + //+1 Card + drawCard(currentPlayer, state); + + //+1 Actions + state->numActions++; + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case minion: + doMinion(choice1, choice2, state, handPos, currentPlayer); + return 0; + + case steward: + if (choice1 == 1) + { + //+2 cards + drawCard(currentPlayer, state); + drawCard(currentPlayer, state); + } + else if (choice1 == 2) + { + //+2 coins + state->coins = state->coins + 2; + } + else + { + //trash 2 cards in hand + discardCard(choice2, currentPlayer, state, 1); + discardCard(choice3, currentPlayer, state, 1); + } + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case tribute: + doTribute(state, currentPlayer, nextPlayer, tributeRevealedCards); + return 0; + + case ambassador: + return doAmbassador(choice1, choice2, state, handPos, currentPlayer); + + case cutpurse: + + updateCoins(currentPlayer, state, 2); + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + for (j = 0; j < state->handCount[i]; j++) + { + if (state->hand[i][j] == copper) + { + discardCard(j, i, state, 0); + break; + } + if (j == state->handCount[i]) + { + for (k = 0; k < state->handCount[i]; k++) + { + if (DEBUG) + printf("Player %d reveals card number %d\n", i, state->hand[i][k]); + } + break; + } + } + + } + + } + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + + return 0; + + + case embargo: + //+2 Coins + state->coins = state->coins + 2; + + //see if selected pile is in play + if ( state->supplyCount[choice1] == -1 ) + { + return -1; + } + + //add embargo token to selected supply pile + state->embargoTokens[choice1]++; + + //trash card + discardCard(handPos, currentPlayer, state, 1); + return 0; + + case outpost: + //set outpost flag + state->outpostPlayed++; + + //discard card + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case salvager: + //+1 buy + state->numBuys++; + + if (choice1) + { + //gain coins equal to trashed card + state->coins = state->coins + getCost( handCard(choice1, state) ); + //trash card + discardCard(choice1, currentPlayer, state, 1); + } + + //discard card + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case sea_hag: + for (i = 0; i < state->numPlayers; i++) { + if (i != currentPlayer) { + state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; + state->deckCount[i]--; + state->discardCount[i]++; + state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse + } + } + return 0; + + case treasure_map: + //search hand for another treasure_map + index = -1; + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == treasure_map && i != handPos) + { + index = i; + break; + } + } + if (index > -1) + { + //trash both treasure cards + discardCard(handPos, currentPlayer, state, 1); + discardCard(index, currentPlayer, state, 1); + + //gain 4 Gold cards + for (i = 0; i < 4; i++) + { + gainCard(gold, state, 1, currentPlayer); + } + + //return success + return 1; + } + + //no second treasure_map found in hand + return -1; + } + + return -1; +} + +int discardCard(int handPos, int currentPlayer, struct gameState *state, int trashFlag) +{ + + //if card is not trashed, added to Played pile + if (trashFlag < 1) + { + //add card to played pile + state->playedCards[state->playedCardCount] = state->hand[currentPlayer][handPos]; + state->playedCardCount++; + } + + //set played card to -1 + state->hand[currentPlayer][handPos] = -1; + + //remove card from player's hand + if ( handPos == (state->handCount[currentPlayer] - 1) ) //last card in hand array is played + { + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + else if ( state->handCount[currentPlayer] == 1 ) //only one card in hand + { + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + else + { + //replace discarded card with last card in hand + state->hand[currentPlayer][handPos] = state->hand[currentPlayer][ (state->handCount[currentPlayer] - 1)]; + //set last card to -1 + state->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1; + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + + return 0; +} + +int gainCard(int supplyPos, struct gameState *state, int toFlag, int player) +{ + //Note: supplyPos is enum of choosen card + + //check if supply pile is empty (0) or card is not used in game (-1) + if ( supplyCount(supplyPos, state) < 1 ) + { + return -1; + } + + //added card for [whoseTurn] current player: + // toFlag = 0 : add to discard + // toFlag = 1 : add to deck + // toFlag = 2 : add to hand + + if (toFlag == 1) + { + state->deck[ player ][ state->deckCount[player] ] = supplyPos; + state->deckCount[player]++; + } + else if (toFlag == 2) + { + state->hand[ player ][ state->handCount[player] ] = supplyPos; + state->handCount[player]++; + } + else + { + state->discard[player][ state->discardCount[player] ] = supplyPos; + state->discardCount[player]++; + } + + //decrease number in supply pile + state->supplyCount[supplyPos]--; + + return 0; +} + +int updateCoins(int player, struct gameState *state, int bonus) +{ + int i; + + //reset coin count + state->coins = 0; + + //add coins for each Treasure card in player's hand + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == copper) + { + state->coins += 1; + } + else if (state->hand[player][i] == silver) + { + state->coins += 2; + } + else if (state->hand[player][i] == gold) + { + state->coins += 3; + } + } + + //add bonus + state->coins += bonus; + + return 0; +} + + +//end of dominion.c diff --git a/dominion/as3/dominion.c.gcov b/dominion/as3/dominion.c.gcov new file mode 100644 index 000000000..3292286c4 --- /dev/null +++ b/dominion/as3/dominion.c.gcov @@ -0,0 +1,1961 @@ + -: 0:Source:dominion.c + -: 0:Graph:dominion.gcno + -: 0:Data:dominion.gcda + -: 0:Runs:5 + -: 0:Programs:5 + -: 1:#include "dominion.h" + -: 2:#include "dominion_helpers.h" + -: 3:#include "rngs.h" + -: 4:#include + -: 5:#include + -: 6:#include + -: 7: +function compare called 180 returned 100% blocks executed 83% + 180: 8:int compare(const void* a, const void* b) { + 180: 9: if (*(int*)a > *(int*)b) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + #####: 10: return 1; + 180: 11: if (*(int*)a < *(int*)b) +branch 0 taken 27% (fallthrough) +branch 1 taken 73% + 48: 12: return -1; + 132: 13: return 0; + -: 14:} + -: 15: +function newGame called 0 returned 0% blocks executed 0% + #####: 16:struct gameState* newGame() { + #####: 17: struct gameState* g = malloc(sizeof(struct gameState)); + #####: 18: return g; + -: 19:} + -: 20: +function kingdomCards called 0 returned 0% blocks executed 0% + #####: 21:int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + -: 22: int k8, int k9, int k10) { + #####: 23: int* k = malloc(10 * sizeof(int)); + #####: 24: k[0] = k1; + #####: 25: k[1] = k2; + #####: 26: k[2] = k3; + #####: 27: k[3] = k4; + #####: 28: k[4] = k5; + #####: 29: k[5] = k6; + #####: 30: k[6] = k7; + #####: 31: k[7] = k8; + #####: 32: k[8] = k9; + #####: 33: k[9] = k10; + #####: 34: return k; + -: 35:} + -: 36: +function initializeGame called 5 returned 100% blocks executed 94% + 5: 37:int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, + -: 38: struct gameState *state) { + -: 39: int i; + -: 40: int j; + -: 41: int it; + -: 42: + -: 43: //set up random number generator + 5: 44: SelectStream(1); +call 0 returned 100% + 5: 45: PutSeed((long)randomSeed); +call 0 returned 100% + -: 46: + -: 47: //check number of players + 5: 48: if (numPlayers > MAX_PLAYERS || numPlayers < 2) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 49: { + #####: 50: return -1; + -: 51: } + -: 52: + -: 53: //set number of players + 5: 54: state->numPlayers = numPlayers; + -: 55: + -: 56: //check selected kingdom cards are different + 55: 57: for (i = 0; i < 10; i++) +branch 0 taken 91% +branch 1 taken 9% (fallthrough) + -: 58: { + 550: 59: for (j = 0; j < 10; j++) +branch 0 taken 91% +branch 1 taken 9% (fallthrough) + -: 60: { + 500: 61: if (j != i && kingdomCards[j] == kingdomCards[i]) +branch 0 taken 90% (fallthrough) +branch 1 taken 10% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 62: { + #####: 63: return -1; + -: 64: } + -: 65: } + -: 66: } + -: 67: + -: 68: + -: 69: //initialize supply + -: 70: /////////////////////////////// + -: 71: + -: 72: //set number of Curse cards + 5: 73: if (numPlayers == 2) +branch 0 taken 80% (fallthrough) +branch 1 taken 20% + -: 74: { + 4: 75: state->supplyCount[curse] = 10; + -: 76: } + 1: 77: else if (numPlayers == 3) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 78: { + #####: 79: state->supplyCount[curse] = 20; + -: 80: } + -: 81: else + -: 82: { + 1: 83: state->supplyCount[curse] = 30; + -: 84: } + -: 85: + -: 86: //set number of Victory cards + 5: 87: if (numPlayers == 2) +branch 0 taken 80% (fallthrough) +branch 1 taken 20% + -: 88: { + 4: 89: state->supplyCount[estate] = 8; + 4: 90: state->supplyCount[duchy] = 8; + 4: 91: state->supplyCount[province] = 8; + -: 92: } + -: 93: else + -: 94: { + 1: 95: state->supplyCount[estate] = 12; + 1: 96: state->supplyCount[duchy] = 12; + 1: 97: state->supplyCount[province] = 12; + -: 98: } + -: 99: + -: 100: //set number of Treasure cards + 5: 101: state->supplyCount[copper] = 60 - (7 * numPlayers); + 5: 102: state->supplyCount[silver] = 40; + 5: 103: state->supplyCount[gold] = 30; + -: 104: + -: 105: //set number of Kingdom cards + 105: 106: for (i = adventurer; i <= treasure_map; i++) //loop all cards +branch 0 taken 95% +branch 1 taken 5% (fallthrough) + -: 107: { + 825: 108: for (j = 0; j < 10; j++) //loop chosen cards +branch 0 taken 94% +branch 1 taken 6% (fallthrough) + -: 109: { + 775: 110: if (kingdomCards[j] == i) +branch 0 taken 6% (fallthrough) +branch 1 taken 94% + -: 111: { + -: 112: //check if card is a 'Victory' Kingdom card + 50: 113: if (kingdomCards[j] == great_hall || kingdomCards[j] == gardens) +branch 0 taken 90% (fallthrough) +branch 1 taken 10% +branch 2 taken 11% (fallthrough) +branch 3 taken 89% + -: 114: { + 20: 115: if (numPlayers == 2) { +branch 0 taken 80% (fallthrough) +branch 1 taken 20% + 8: 116: state->supplyCount[i] = 8; + -: 117: } + -: 118: else { + 2: 119: state->supplyCount[i] = 12; + -: 120: } + -: 121: } + -: 122: else + -: 123: { + 40: 124: state->supplyCount[i] = 10; + -: 125: } + 50: 126: break; + -: 127: } + -: 128: else //card is not in the set choosen for the game + -: 129: { + 725: 130: state->supplyCount[i] = -1; + -: 131: } + -: 132: } + -: 133: + -: 134: } + -: 135: + -: 136: //////////////////////// + -: 137: //supply intilization complete + -: 138: + -: 139: //set player decks + 17: 140: for (i = 0; i < numPlayers; i++) +branch 0 taken 71% +branch 1 taken 29% (fallthrough) + -: 141: { + 12: 142: state->deckCount[i] = 0; + 48: 143: for (j = 0; j < 3; j++) +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + -: 144: { + 36: 145: state->deck[i][j] = estate; + 36: 146: state->deckCount[i]++; + -: 147: } + 96: 148: for (j = 3; j < 10; j++) +branch 0 taken 88% +branch 1 taken 13% (fallthrough) + -: 149: { + 84: 150: state->deck[i][j] = copper; + 84: 151: state->deckCount[i]++; + -: 152: } + -: 153: } + -: 154: + -: 155: //shuffle player decks + 17: 156: for (i = 0; i < numPlayers; i++) +branch 0 taken 71% +branch 1 taken 29% (fallthrough) + -: 157: { + 12: 158: if ( shuffle(i, state) < 0 ) +call 0 returned 100% +branch 1 taken 0% (fallthrough) +branch 2 taken 100% + -: 159: { + #####: 160: return -1; + -: 161: } + -: 162: } + -: 163: + -: 164: //draw player hands + 17: 165: for (i = 0; i < numPlayers; i++) +branch 0 taken 71% +branch 1 taken 29% (fallthrough) + -: 166: { + -: 167: //initialize hand size to zero + 12: 168: state->handCount[i] = 0; + 12: 169: state->discardCount[i] = 0; + -: 170: //draw 5 cards + -: 171: // for (j = 0; j < 5; j++) + -: 172: // { + -: 173: // drawCard(i, state); + -: 174: // } + -: 175: } + -: 176: + -: 177: //set embargo tokens to 0 for all supply piles + 140: 178: for (i = 0; i <= treasure_map; i++) +branch 0 taken 96% +branch 1 taken 4% (fallthrough) + -: 179: { + 135: 180: state->embargoTokens[i] = 0; + -: 181: } + -: 182: + -: 183: //initialize first player's turn + 5: 184: state->outpostPlayed = 0; + 5: 185: state->phase = 0; + 5: 186: state->numActions = 1; + 5: 187: state->numBuys = 1; + 5: 188: state->playedCardCount = 0; + 5: 189: state->whoseTurn = 0; + 5: 190: state->handCount[state->whoseTurn] = 0; + -: 191: //int it; move to top + -: 192: + -: 193: //Moved draw cards to here, only drawing at the start of a turn + 30: 194: for (it = 0; it < 5; it++) { +branch 0 taken 83% +branch 1 taken 17% (fallthrough) + 25: 195: drawCard(state->whoseTurn, state); +call 0 returned 100% + -: 196: } + -: 197: + 5: 198: updateCoins(state->whoseTurn, state, 0); +call 0 returned 100% + -: 199: + 5: 200: return 0; + -: 201:} + -: 202: +function shuffle called 13 returned 100% blocks executed 94% + 13: 203:int shuffle(int player, struct gameState *state) { + -: 204: + -: 205: + -: 206: int newDeck[MAX_DECK]; + 13: 207: int newDeckPos = 0; + -: 208: int card; + -: 209: int i; + -: 210: + 13: 211: if (state->deckCount[player] < 1) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + #####: 212: return -1; + 13: 213: qsort ((void*)(state->deck[player]), state->deckCount[player], sizeof(int), compare); +call 0 returned 100% + -: 214: /* SORT CARDS IN DECK TO ENSURE DETERMINISM! */ + -: 215: + 147: 216: while (state->deckCount[player] > 0) { +branch 0 taken 90% +branch 1 taken 10% (fallthrough) + 121: 217: card = floor(Random() * state->deckCount[player]); +call 0 returned 100% + 121: 218: newDeck[newDeckPos] = state->deck[player][card]; + 121: 219: newDeckPos++; + 442: 220: for (i = card; i < state->deckCount[player]-1; i++) { +branch 0 taken 73% +branch 1 taken 27% (fallthrough) + 321: 221: state->deck[player][i] = state->deck[player][i+1]; + -: 222: } + 121: 223: state->deckCount[player]--; + -: 224: } + 134: 225: for (i = 0; i < newDeckPos; i++) { +branch 0 taken 90% +branch 1 taken 10% (fallthrough) + 121: 226: state->deck[player][i] = newDeck[i]; + 121: 227: state->deckCount[player]++; + -: 228: } + -: 229: + 13: 230: return 0; + -: 231:} + -: 232: +function playCard called 0 returned 0% blocks executed 0% + #####: 233:int playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state) + -: 234:{ + -: 235: int card; + #####: 236: int coin_bonus = 0; //tracks coins gain from actions + -: 237: + -: 238: //check if it is the right phase + #####: 239: if (state->phase != 0) +branch 0 never executed +branch 1 never executed + -: 240: { + #####: 241: return -1; + -: 242: } + -: 243: + -: 244: //check if player has enough actions + #####: 245: if ( state->numActions < 1 ) +branch 0 never executed +branch 1 never executed + -: 246: { + #####: 247: return -1; + -: 248: } + -: 249: + -: 250: //get card played + #####: 251: card = handCard(handPos, state); +call 0 never executed + -: 252: + -: 253: //check if selected card is an action + #####: 254: if ( card < adventurer || card > treasure_map ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 255: { + #####: 256: return -1; + -: 257: } + -: 258: + -: 259: //play card + #####: 260: if ( cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0 ) +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 261: { + #####: 262: return -1; + -: 263: } + -: 264: + -: 265: //reduce number of actions + #####: 266: state->numActions--; + -: 267: + -: 268: //update coins (Treasure cards may be added with card draws) + #####: 269: updateCoins(state->whoseTurn, state, coin_bonus); +call 0 never executed + -: 270: + #####: 271: return 0; + -: 272:} + -: 273: +function buyCard called 0 returned 0% blocks executed 0% + #####: 274:int buyCard(int supplyPos, struct gameState *state) { + -: 275: int who; + -: 276: if (DEBUG) { + -: 277: printf("Entering buyCard...\n"); + -: 278: } + -: 279: + -: 280: // I don't know what to do about the phase thing. + -: 281: + #####: 282: who = state->whoseTurn; + -: 283: + #####: 284: if (state->numBuys < 1) { +branch 0 never executed +branch 1 never executed + -: 285: if (DEBUG) + -: 286: printf("You do not have any buys left\n"); + #####: 287: return -1; + #####: 288: } else if (supplyCount(supplyPos, state) <1) { +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 289: if (DEBUG) + -: 290: printf("There are not any of that type of card left\n"); + #####: 291: return -1; + #####: 292: } else if (state->coins < getCost(supplyPos)) { +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 293: if (DEBUG) + -: 294: printf("You do not have enough money to buy that. You have %d coins.\n", state->coins); + #####: 295: return -1; + -: 296: } else { + #####: 297: state->phase=1; + -: 298: //state->supplyCount[supplyPos]--; + #####: 299: gainCard(supplyPos, state, 0, who); //card goes in discard, this might be wrong.. (2 means goes into hand, 0 goes into discard) +call 0 never executed + -: 300: + #####: 301: state->coins = (state->coins) - (getCost(supplyPos)); +call 0 never executed + #####: 302: state->numBuys--; + -: 303: if (DEBUG) + -: 304: printf("You bought card number %d for %d coins. You now have %d buys and %d coins.\n", supplyPos, getCost(supplyPos), state->numBuys, state->coins); + -: 305: } + -: 306: + -: 307: //state->discard[who][state->discardCount[who]] = supplyPos; + -: 308: //state->discardCount[who]++; + -: 309: + #####: 310: return 0; + -: 311:} + -: 312: +function numHandCards called 4 returned 100% blocks executed 100% + 4: 313:int numHandCards(struct gameState *state) { + 4: 314: return state->handCount[ whoseTurn(state) ]; +call 0 returned 100% + -: 315:} + -: 316: +function handCard called 0 returned 0% blocks executed 0% + #####: 317:int handCard(int handPos, struct gameState *state) { + #####: 318: int currentPlayer = whoseTurn(state); +call 0 never executed + #####: 319: return state->hand[currentPlayer][handPos]; + -: 320:} + -: 321: +function supplyCount called 8 returned 100% blocks executed 100% + 8: 322:int supplyCount(int card, struct gameState *state) { + 8: 323: return state->supplyCount[card]; + -: 324:} + -: 325: +function fullDeckCount called 0 returned 0% blocks executed 0% + #####: 326:int fullDeckCount(int player, int card, struct gameState *state) { + -: 327: int i; + #####: 328: int count = 0; + -: 329: + #####: 330: for (i = 0; i < state->deckCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 331: { + #####: 332: if (state->deck[player][i] == card) count++; +branch 0 never executed +branch 1 never executed + -: 333: } + -: 334: + #####: 335: for (i = 0; i < state->handCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 336: { + #####: 337: if (state->hand[player][i] == card) count++; +branch 0 never executed +branch 1 never executed + -: 338: } + -: 339: + #####: 340: for (i = 0; i < state->discardCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 341: { + #####: 342: if (state->discard[player][i] == card) count++; +branch 0 never executed +branch 1 never executed + -: 343: } + -: 344: + #####: 345: return count; + -: 346:} + -: 347: +function whoseTurn called 4 returned 100% blocks executed 100% + 4: 348:int whoseTurn(struct gameState *state) { + 4: 349: return state->whoseTurn; + -: 350:} + -: 351: +function endTurn called 0 returned 0% blocks executed 0% + #####: 352:int endTurn(struct gameState *state) { + -: 353: int k; + -: 354: int i; + #####: 355: int currentPlayer = whoseTurn(state); +call 0 never executed + -: 356: + -: 357: //Discard hand + #####: 358: for (i = 0; i < state->handCount[currentPlayer]; i++) { +branch 0 never executed +branch 1 never executed + #####: 359: state->discard[currentPlayer][state->discardCount[currentPlayer]++] = state->hand[currentPlayer][i];//Discard + #####: 360: state->hand[currentPlayer][i] = -1;//Set card to -1 + -: 361: } + #####: 362: state->handCount[currentPlayer] = 0;//Reset hand count + -: 363: + -: 364: //Code for determining the player + #####: 365: if (currentPlayer < (state->numPlayers - 1)) { +branch 0 never executed +branch 1 never executed + #####: 366: state->whoseTurn = currentPlayer + 1;//Still safe to increment + -: 367: } + -: 368: else { + #####: 369: state->whoseTurn = 0;//Max player has been reached, loop back around to player 1 + -: 370: } + -: 371: + #####: 372: state->outpostPlayed = 0; + #####: 373: state->phase = 0; + #####: 374: state->numActions = 1; + #####: 375: state->coins = 0; + #####: 376: state->numBuys = 1; + #####: 377: state->playedCardCount = 0; + #####: 378: state->handCount[state->whoseTurn] = 0; + -: 379: + -: 380: //int k; move to top + -: 381: //Next player draws hand + #####: 382: for (k = 0; k < 5; k++) { +branch 0 never executed +branch 1 never executed + #####: 383: drawCard(state->whoseTurn, state);//Draw a card +call 0 never executed + -: 384: } + -: 385: + -: 386: //Update money + #####: 387: updateCoins(state->whoseTurn, state, 0); +call 0 never executed + -: 388: + #####: 389: return 0; + -: 390:} + -: 391: +function isGameOver called 0 returned 0% blocks executed 0% + #####: 392:int isGameOver(struct gameState *state) { + -: 393: int i; + -: 394: int j; + -: 395: + -: 396: //if stack of Province cards is empty, the game ends + #####: 397: if (state->supplyCount[province] == 0) +branch 0 never executed +branch 1 never executed + -: 398: { + #####: 399: return 1; + -: 400: } + -: 401: + -: 402: //if three supply pile are at 0, the game ends + #####: 403: j = 0; + #####: 404: for (i = 0; i < 25; i++) +branch 0 never executed +branch 1 never executed + -: 405: { + #####: 406: if (state->supplyCount[i] == 0) +branch 0 never executed +branch 1 never executed + -: 407: { + #####: 408: j++; + -: 409: } + -: 410: } + #####: 411: if ( j >= 3) +branch 0 never executed +branch 1 never executed + -: 412: { + #####: 413: return 1; + -: 414: } + -: 415: + #####: 416: return 0; + -: 417:} + -: 418: +function scoreFor called 0 returned 0% blocks executed 0% + #####: 419:int scoreFor (int player, struct gameState *state) { + -: 420: + -: 421: int i; + #####: 422: int score = 0; + -: 423: //score from hand + #####: 424: for (i = 0; i < state->handCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 425: { + #####: 426: if (state->hand[player][i] == curse) { +branch 0 never executed +branch 1 never executed + #####: 427: score = score - 1; + -: 428: }; + #####: 429: if (state->hand[player][i] == estate) { +branch 0 never executed +branch 1 never executed + #####: 430: score = score + 1; + -: 431: }; + #####: 432: if (state->hand[player][i] == duchy) { +branch 0 never executed +branch 1 never executed + #####: 433: score = score + 3; + -: 434: }; + #####: 435: if (state->hand[player][i] == province) { +branch 0 never executed +branch 1 never executed + #####: 436: score = score + 6; + -: 437: }; + #####: 438: if (state->hand[player][i] == great_hall) { +branch 0 never executed +branch 1 never executed + #####: 439: score = score + 1; + -: 440: }; + #####: 441: if (state->hand[player][i] == gardens) { +branch 0 never executed +branch 1 never executed + #####: 442: score = score + ( fullDeckCount(player, 0, state) / 10 ); +call 0 never executed + -: 443: }; + -: 444: } + -: 445: + -: 446: //score from discard + #####: 447: for (i = 0; i < state->discardCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 448: { + #####: 449: if (state->discard[player][i] == curse) { +branch 0 never executed +branch 1 never executed + #####: 450: score = score - 1; + -: 451: }; + #####: 452: if (state->discard[player][i] == estate) { +branch 0 never executed +branch 1 never executed + #####: 453: score = score + 1; + -: 454: }; + #####: 455: if (state->discard[player][i] == duchy) { +branch 0 never executed +branch 1 never executed + #####: 456: score = score + 3; + -: 457: }; + #####: 458: if (state->discard[player][i] == province) { +branch 0 never executed +branch 1 never executed + #####: 459: score = score + 6; + -: 460: }; + #####: 461: if (state->discard[player][i] == great_hall) { +branch 0 never executed +branch 1 never executed + #####: 462: score = score + 1; + -: 463: }; + #####: 464: if (state->discard[player][i] == gardens) { +branch 0 never executed +branch 1 never executed + #####: 465: score = score + ( fullDeckCount(player, 0, state) / 10 ); +call 0 never executed + -: 466: }; + -: 467: } + -: 468: + -: 469: //score from deck + #####: 470: for (i = 0; i < state->discardCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 471: { + #####: 472: if (state->deck[player][i] == curse) { +branch 0 never executed +branch 1 never executed + #####: 473: score = score - 1; + -: 474: }; + #####: 475: if (state->deck[player][i] == estate) { +branch 0 never executed +branch 1 never executed + #####: 476: score = score + 1; + -: 477: }; + #####: 478: if (state->deck[player][i] == duchy) { +branch 0 never executed +branch 1 never executed + #####: 479: score = score + 3; + -: 480: }; + #####: 481: if (state->deck[player][i] == province) { +branch 0 never executed +branch 1 never executed + #####: 482: score = score + 6; + -: 483: }; + #####: 484: if (state->deck[player][i] == great_hall) { +branch 0 never executed +branch 1 never executed + #####: 485: score = score + 1; + -: 486: }; + #####: 487: if (state->deck[player][i] == gardens) { +branch 0 never executed +branch 1 never executed + #####: 488: score = score + ( fullDeckCount(player, 0, state) / 10 ); +call 0 never executed + -: 489: }; + -: 490: } + -: 491: + #####: 492: return score; + -: 493:} + -: 494: +function getWinners called 0 returned 0% blocks executed 0% + #####: 495:int getWinners(int players[MAX_PLAYERS], struct gameState *state) { + -: 496: int i; + -: 497: int j; + -: 498: int highScore; + -: 499: int currentPlayer; + -: 500: + -: 501: //get score for each player + #####: 502: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 503: { + -: 504: //set unused player scores to -9999 + #####: 505: if (i >= state->numPlayers) +branch 0 never executed +branch 1 never executed + -: 506: { + #####: 507: players[i] = -9999; + -: 508: } + -: 509: else + -: 510: { + #####: 511: players[i] = scoreFor (i, state); +call 0 never executed + -: 512: } + -: 513: } + -: 514: + -: 515: //find highest score + #####: 516: j = 0; + #####: 517: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 518: { + #####: 519: if (players[i] > players[j]) +branch 0 never executed +branch 1 never executed + -: 520: { + #####: 521: j = i; + -: 522: } + -: 523: } + #####: 524: highScore = players[j]; + -: 525: + -: 526: //add 1 to players who had less turns + #####: 527: currentPlayer = whoseTurn(state); +call 0 never executed + #####: 528: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 529: { + #####: 530: if ( players[i] == highScore && i > currentPlayer ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 531: { + #####: 532: players[i]++; + -: 533: } + -: 534: } + -: 535: + -: 536: //find new highest score + #####: 537: j = 0; + #####: 538: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 539: { + #####: 540: if ( players[i] > players[j] ) +branch 0 never executed +branch 1 never executed + -: 541: { + #####: 542: j = i; + -: 543: } + -: 544: } + #####: 545: highScore = players[j]; + -: 546: + -: 547: //set winners in array to 1 and rest to 0 + #####: 548: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 549: { + #####: 550: if ( players[i] == highScore ) +branch 0 never executed +branch 1 never executed + -: 551: { + #####: 552: players[i] = 1; + -: 553: } + -: 554: else + -: 555: { + #####: 556: players[i] = 0; + -: 557: } + -: 558: } + -: 559: + #####: 560: return 0; + -: 561:} + -: 562: +function drawCard called 43 returned 100% blocks executed 38% + 43: 563:int drawCard(int player, struct gameState *state) + -: 564:{ int count; + -: 565: int deckCounter; + 43: 566: if (state->deckCount[player] <= 0) { //Deck is empty +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 567: + -: 568: //Step 1 Shuffle the discard pile back into a deck + -: 569: int i; + -: 570: //Move discard to deck + #####: 571: for (i = 0; i < state->discardCount[player]; i++) { +branch 0 never executed +branch 1 never executed + #####: 572: state->deck[player][i] = state->discard[player][i]; + #####: 573: state->discard[player][i] = -1; + -: 574: } + -: 575: + #####: 576: state->deckCount[player] = state->discardCount[player]; + #####: 577: state->discardCount[player] = 0;//Reset discard + -: 578: + -: 579: //Shufffle the deck + #####: 580: shuffle(player, state);//Shuffle the deck up and make it so that we can draw +call 0 never executed + -: 581: + -: 582: if (DEBUG) { //Debug statements + -: 583: printf("Deck count now: %d\n", state->deckCount[player]); + -: 584: } + -: 585: + #####: 586: state->discardCount[player] = 0; + -: 587: + -: 588: //Step 2 Draw Card + #####: 589: count = state->handCount[player];//Get current player's hand count + -: 590: + -: 591: if (DEBUG) { //Debug statements + -: 592: printf("Current hand count: %d\n", count); + -: 593: } + -: 594: + #####: 595: deckCounter = state->deckCount[player];//Create a holder for the deck count + -: 596: + #####: 597: if (deckCounter == 0) +branch 0 never executed +branch 1 never executed + #####: 598: return -1; + -: 599: + #####: 600: state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to hand + #####: 601: state->deckCount[player]--; + #####: 602: state->handCount[player]++;//Increment hand count + -: 603: } + -: 604: + -: 605: else { + 43: 606: int count = state->handCount[player];//Get current hand count for player + -: 607: int deckCounter; + -: 608: if (DEBUG) { //Debug statements + -: 609: printf("Current hand count: %d\n", count); + -: 610: } + -: 611: + 43: 612: deckCounter = state->deckCount[player];//Create holder for the deck count + 43: 613: state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to the hand + 43: 614: state->deckCount[player]--; + 43: 615: state->handCount[player]++;//Increment hand count + -: 616: } + -: 617: + 43: 618: return 0; + -: 619:} + -: 620: +function getCost called 4 returned 100% blocks executed 17% + 4: 621:int getCost(int cardNumber) + -: 622:{ + 4: 623: switch( cardNumber ) +branch 0 taken 25% +branch 1 taken 0% +branch 2 taken 0% +branch 3 taken 0% +branch 4 taken 25% +branch 5 taken 50% +branch 6 taken 0% +branch 7 taken 0% +branch 8 taken 0% +branch 9 taken 0% +branch 10 taken 0% +branch 11 taken 0% +branch 12 taken 0% +branch 13 taken 0% +branch 14 taken 0% +branch 15 taken 0% +branch 16 taken 0% +branch 17 taken 0% +branch 18 taken 0% +branch 19 taken 0% +branch 20 taken 0% +branch 21 taken 0% +branch 22 taken 0% +branch 23 taken 0% +branch 24 taken 0% +branch 25 taken 0% +branch 26 taken 0% +branch 27 taken 0% + -: 624: { + -: 625: case curse: + 1: 626: return 0; + -: 627: case estate: + #####: 628: return 2; + -: 629: case duchy: + #####: 630: return 5; + -: 631: case province: + #####: 632: return 8; + -: 633: case copper: + 1: 634: return 0; + -: 635: case silver: + 2: 636: return 3; + -: 637: case gold: + #####: 638: return 6; + -: 639: case adventurer: + #####: 640: return 6; + -: 641: case council_room: + #####: 642: return 5; + -: 643: case feast: + #####: 644: return 4; + -: 645: case gardens: + #####: 646: return 4; + -: 647: case mine: + #####: 648: return 5; + -: 649: case remodel: + #####: 650: return 4; + -: 651: case smithy: + #####: 652: return 4; + -: 653: case village: + #####: 654: return 3; + -: 655: case baron: + #####: 656: return 4; + -: 657: case great_hall: + #####: 658: return 3; + -: 659: case minion: + #####: 660: return 5; + -: 661: case steward: + #####: 662: return 3; + -: 663: case tribute: + #####: 664: return 5; + -: 665: case ambassador: + #####: 666: return 3; + -: 667: case cutpurse: + #####: 668: return 4; + -: 669: case embargo: + #####: 670: return 2; + -: 671: case outpost: + #####: 672: return 5; + -: 673: case salvager: + #####: 674: return 4; + -: 675: case sea_hag: + #####: 676: return 4; + -: 677: case treasure_map: + #####: 678: return 4; + -: 679: } + -: 680: + #####: 681: return -1; + -: 682:} + -: 683: +function doMine called 3 returned 100% blocks executed 83% + 3: 684:int doMine(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) + -: 685:{ + -: 686: int i; + -: 687: int j; + -: 688: + 3: 689: j = state->hand[currentPlayer][choice1]; //store card we will trash + -: 690: + 3: 691: if (/*state->hand[currentPlayer][choice1] < copper ||*/ state->hand[currentPlayer][choice1] > gold) +branch 0 taken 33% (fallthrough) +branch 1 taken 67% + -: 692: { + 1: 693: return -1; + -: 694: } + -: 695: + 2: 696: if (choice2 > treasure_map || choice2 < curse) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 697: { + #####: 698: return -1; + -: 699: } + -: 700: + 2: 701: if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) ) +call 0 returned 100% +call 1 returned 100% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 702: { + #####: 703: return -1; + -: 704: } + -: 705: + -: 706: //gainCard(choice2, state, 2, currentPlayer); + -: 707: + -: 708: //discard card from hand + 2: 709: discardCard(handPos, currentPlayer, state, 0); +call 0 returned 100% + -: 710: + -: 711: //discard trashed card + 2: 712: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 taken 100% +branch 1 taken 0% (fallthrough) + -: 713: { + 2: 714: if (state->hand[currentPlayer][i] == j) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% + -: 715: { + 2: 716: discardCard(i, currentPlayer, state, 0); +call 0 returned 100% + 2: 717: break; + -: 718: } + -: 719: } + -: 720: + 2: 721: return 0; + -: 722:} + -: 723: +function getEstateCard called 2 returned 100% blocks executed 86% + 2: 724:void getEstateCard(struct gameState *state, int currentPlayer) + -: 725:{ + 2: 726: if (supplyCount(estate, state) > 0) { +call 0 returned 100% +branch 1 taken 100% (fallthrough) +branch 2 taken 0% + 2: 727: gainCard(estate, state, 0, currentPlayer);//Gain an estate +call 0 returned 100% + -: 728: + 2: 729: state->supplyCount[estate]--;//Decrement Estates + 2: 730: if (supplyCount(estate, state) == 0) { +call 0 returned 100% +branch 1 taken 0% (fallthrough) +branch 2 taken 100% + #####: 731: isGameOver(state); +call 0 never executed + -: 732: } + -: 733: } + 2: 734:} + -: 735: +function doBaron called 3 returned 100% blocks executed 100% + 3: 736:void doBaron(int choice1, struct gameState *state, int currentPlayer) + -: 737:{ + 3: 738: state->numBuys++;//Increase buys by 1! + 3: 739: state->numBuys++;//Increase buys by 1! + 3: 740: if (choice1 > 0) { //Boolean true or going to discard an estate +branch 0 taken 67% (fallthrough) +branch 1 taken 33% + 2: 741: int p = 1; //0;//Iterator for hand! + 2: 742: int card_not_discarded = 1;//Flag for discard set! + 11: 743: while(card_not_discarded) { +branch 0 taken 78% +branch 1 taken 22% (fallthrough) + 7: 744: if (state->hand[currentPlayer][p] == estate) { //Found an estate card! +branch 0 taken 14% (fallthrough) +branch 1 taken 86% + 1: 745: state->coins += 4;//Add 4 coins to the amount of coins + 1: 746: state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; + 1: 747: state->discardCount[currentPlayer]++; + 5: 748: for (; p < state->handCount[currentPlayer]; p++) { +branch 0 taken 80% +branch 1 taken 20% (fallthrough) + 4: 749: state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1]; + -: 750: } + 1: 751: state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; + 1: 752: state->handCount[currentPlayer]--; + 1: 753: card_not_discarded = 0;//Exit the loop + -: 754: } + 6: 755: else if (p > state->handCount[currentPlayer]) { +branch 0 taken 17% (fallthrough) +branch 1 taken 83% + -: 756: if(DEBUG) { + -: 757: printf("No estate cards in your hand, invalid choice\n"); + -: 758: printf("Must gain an estate if there are any\n"); + -: 759: } + 1: 760: getEstateCard(state, currentPlayer); +call 0 returned 100% + 1: 761: card_not_discarded = 0;//Exit the loop + -: 762: } + -: 763: + -: 764: else { + 5: 765: p++;//Next card + -: 766: } + -: 767: } + -: 768: } + -: 769: + -: 770: else { + 1: 771: getEstateCard(state, currentPlayer); +call 0 returned 100% + -: 772: } + 3: 773:} + -: 774: +function doMinion called 2 returned 100% blocks executed 100% + 2: 775:void doMinion(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) + -: 776:{ + -: 777: int i; + -: 778: int j; + -: 779: + -: 780: //+1 action + 2: 781: state->numActions++; + -: 782: + -: 783: //discard card from hand + 2: 784: discardCard(handPos, currentPlayer, state, 0); +call 0 returned 100% + -: 785: + 2: 786: if (choice1) +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + -: 787: { + 1: 788: state->coins = state->coins + 2; + -: 789: } + 1: 790: else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 +branch 0 taken 100% (fallthrough) +branch 1 taken 0% + -: 791: { + -: 792: //discard hand + 5: 793: while(numHandCards(state) > 1 /*0*/) +call 0 returned 100% +branch 1 taken 75% +branch 2 taken 25% (fallthrough) + -: 794: { + 3: 795: discardCard(handPos, currentPlayer, state, 0); +call 0 returned 100% + -: 796: } + -: 797: + -: 798: //draw 4 + 5: 799: for (i = 0; i < 4; i++) +branch 0 taken 80% +branch 1 taken 20% (fallthrough) + -: 800: { + 4: 801: drawCard(currentPlayer, state); +call 0 returned 100% + -: 802: } + -: 803: + -: 804: //other players discard hand and redraw if hand size > 4 + 5: 805: for (i = 0; i < state->numPlayers; i++) +branch 0 taken 80% +branch 1 taken 20% (fallthrough) + -: 806: { + 4: 807: if (i != currentPlayer) +branch 0 taken 75% (fallthrough) +branch 1 taken 25% + -: 808: { + -: 809: //if ( state->handCount[i] > 4 ) + -: 810: { + -: 811: //discard hand + 9: 812: while( state->handCount[i] > 0 ) +branch 0 taken 50% +branch 1 taken 50% (fallthrough) + -: 813: { + 3: 814: discardCard(handPos, i, state, 0); +call 0 returned 100% + -: 815: } + -: 816: + -: 817: //draw 4 + 15: 818: for (j = 0; j < 4; j++) +branch 0 taken 80% +branch 1 taken 20% (fallthrough) + -: 819: { + 12: 820: drawCard(i, state); +call 0 returned 100% + -: 821: } + -: 822: } + -: 823: } + -: 824: } + -: 825: } + 2: 826:} + -: 827: +function printDeck called 0 returned 0% blocks executed 0% + #####: 828:void printDeck(struct gameState *state, int p) { + #####: 829: printf("Deck:"); +call 0 never executed + #####: 830: for (int i=0; i < state->deckCount[p]; i++) +branch 0 never executed +branch 1 never executed + #####: 831: printf(" %d", state->deck[p][i]); +call 0 never executed + #####: 832: printf("\n"); +call 0 never executed + #####: 833:} + -: 834: +function printHand called 0 returned 0% blocks executed 0% + #####: 835:void printHand(struct gameState *state, int p) { + #####: 836: printf("Hand:"); +call 0 never executed + #####: 837: for (int i=0; i < state->handCount[p]; i++) +branch 0 never executed +branch 1 never executed + #####: 838: printf(" %d", state->hand[p][i]); +call 0 never executed + #####: 839: printf("\n"); +call 0 never executed + #####: 840:} + -: 841: +function doTribute called 3 returned 100% blocks executed 93% + 3: 842:void doTribute(struct gameState *state, int currentPlayer, int nextPlayer, int tributeRevealedCards[2]) + -: 843:{ + -: 844: int i; + -: 845: + 3: 846: if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) { +branch 0 taken 33% (fallthrough) +branch 1 taken 67% + 1: 847: if (state->deckCount[nextPlayer] > 0) { +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + #####: 848: tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + #####: 849: state->deckCount[nextPlayer]--; + -: 850: } + 1: 851: else if (state->discardCount[nextPlayer] > 0) { +branch 0 taken 100% (fallthrough) +branch 1 taken 0% + 1: 852: tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1]; + 1: 853: state->discardCount[nextPlayer]--; + -: 854: } + -: 855: else { + -: 856: //No Card to Reveal + -: 857: if (DEBUG) { + -: 858: printf("No cards to reveal\n"); + -: 859: } + -: 860: } + -: 861: } + -: 862: + -: 863: else { + 2: 864: if (state->deckCount[nextPlayer] == 0) { +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + 2: 865: for (i = 0; i < state->discardCount[nextPlayer]; i++) { +branch 0 taken 50% +branch 1 taken 50% (fallthrough) + 1: 866: state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck + 1: 867: state->deckCount[nextPlayer]++; + 1: 868: state->discard[nextPlayer][i] = -1; + 1: 869: state->discardCount[nextPlayer]--; + -: 870: } + -: 871: + 1: 872: shuffle(nextPlayer,state);//Shuffle the deck +call 0 returned 100% + -: 873: } + 2: 874: tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + -: 875: //state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + -: 876: //state->deckCount[nextPlayer]--; + -: 877: //tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + 2: 878: tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-2]; + -: 879: //state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + -: 880: //state->deckCount[nextPlayer]--; + -: 881: } + -: 882: + 3: 883: if (tributeRevealedCards[0] == tributeRevealedCards[1]) { //If we have a duplicate card, just drop one +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + #####: 884: state->playedCards[state->playedCardCount] = tributeRevealedCards[1]; + #####: 885: state->playedCardCount++; + #####: 886: tributeRevealedCards[1] = -1; + -: 887: } + -: 888: + 9: 889: for (i = 0; i < 2; i ++) { +branch 0 taken 67% +branch 1 taken 33% (fallthrough) + 6: 890: if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) { //Treasure cards +branch 0 taken 83% (fallthrough) +branch 1 taken 17% +branch 2 taken 100% (fallthrough) +branch 3 taken 0% +branch 4 taken 0% (fallthrough) +branch 5 taken 100% + 1: 891: state->numActions = state->numActions + 2; + -: 892: } + -: 893: + 5: 894: else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall) { //Victory Card Found +branch 0 taken 60% (fallthrough) +branch 1 taken 40% +branch 2 taken 100% (fallthrough) +branch 3 taken 0% +branch 4 taken 100% (fallthrough) +branch 5 taken 0% +branch 6 taken 100% (fallthrough) +branch 7 taken 0% +branch 8 taken 0% (fallthrough) +branch 9 taken 100% + 2: 895: drawCard(currentPlayer, state); +call 0 returned 100% + -: 896: //drawCard(currentPlayer, state); + -: 897: } + -: 898: else { //Action Card + 3: 899: state->coins += 2; + -: 900: } + -: 901: } + 3: 902:} + -: 903: +function doAmbassador called 2 returned 100% blocks executed 89% + 2: 904:int doAmbassador(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) + -: 905:{ + -: 906: int i; + -: 907: int j; + -: 908: + 2: 909: j = 0; //used to check if player has enough cards to discard + -: 910: + 2: 911: if (choice2 > 3 || choice2 < 0) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 912: { + #####: 913: return -1; + -: 914: } + -: 915: + -: 916:/* + -: 917: if (choice1 == handPos) + -: 918: { + -: 919: return -1; + -: 920: } + -: 921: */ + -: 922: + 12: 923: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 taken 83% +branch 1 taken 17% (fallthrough) + -: 924: { + 10: 925: if (i != handPos && state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1] /*&& i != choice1*/) +branch 0 taken 80% (fallthrough) +branch 1 taken 20% +branch 2 taken 50% (fallthrough) +branch 3 taken 50% + -: 926: { + 4: 927: j++; + -: 928: } + -: 929: } + 2: 930: if (j < choice2) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 931: { + #####: 932: return -1; + -: 933: } + -: 934: + -: 935: if (DEBUG) + -: 936: printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]); + -: 937: + -: 938: //increase supply count for choosen card by amount being discarded + 2: 939: state->supplyCount[state->hand[currentPlayer][choice1]] += choice2; + -: 940: + -: 941: //each other player gains a copy of revealed card + 6: 942: for (i = 0; i < state->numPlayers; i++) +branch 0 taken 67% +branch 1 taken 33% (fallthrough) + -: 943: { + 4: 944: if (i != currentPlayer) +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + -: 945: { + 2: 946: gainCard(state->hand[currentPlayer][choice1], state, 0, i); +call 0 returned 100% + -: 947: } + -: 948: } + -: 949: + -: 950: //discard played card from hand + 2: 951: discardCard(handPos, currentPlayer, state, 0); +call 0 returned 100% + -: 952: + -: 953: //trash copies of cards returned to supply + 6: 954: for (j = 0; j < choice2; j++) +branch 0 taken 67% +branch 1 taken 33% (fallthrough) + -: 955: { + 4: 956: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 taken 100% +branch 1 taken 0% (fallthrough) + -: 957: { + 4: 958: if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1]) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% + -: 959: { + 4: 960: discardCard(i, currentPlayer, state, 1); +call 0 returned 100% + 4: 961: break; + -: 962: } + -: 963: } + -: 964: } + -: 965: + 2: 966: return 0; + -: 967:} + -: 968: +function cardEffect called 0 returned 0% blocks executed 0% + #####: 969:int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) + -: 970:{ + -: 971: int i; + -: 972: int j; + -: 973: int k; + -: 974: int x; + -: 975: int index; + #####: 976: int currentPlayer = whoseTurn(state); +call 0 never executed + #####: 977: int nextPlayer = currentPlayer + 1; + -: 978: + #####: 979: int tributeRevealedCards[2] = {-1, -1}; + -: 980: int temphand[MAX_HAND];// moved above the if statement + #####: 981: int drawntreasure=0; + -: 982: int cardDrawn; + #####: 983: int z = 0;// this is the counter for the temp hand + #####: 984: if (nextPlayer > (state->numPlayers - 1)) { +branch 0 never executed +branch 1 never executed + #####: 985: nextPlayer = 0; + -: 986: } + -: 987: + -: 988: + -: 989: //uses switch to select card and perform actions + #####: 990: switch( card ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed +branch 6 never executed +branch 7 never executed +branch 8 never executed +branch 9 never executed +branch 10 never executed +branch 11 never executed +branch 12 never executed +branch 13 never executed +branch 14 never executed +branch 15 never executed +branch 16 never executed +branch 17 never executed +branch 18 never executed +branch 19 never executed +branch 20 never executed + -: 991: { + -: 992: case adventurer: + #####: 993: while(drawntreasure<2) { +branch 0 never executed +branch 1 never executed + #####: 994: if (state->deckCount[currentPlayer] <1) { //if the deck is empty we need to shuffle discard and add to deck +branch 0 never executed +branch 1 never executed + #####: 995: shuffle(currentPlayer, state); +call 0 never executed + -: 996: } + #####: 997: drawCard(currentPlayer, state); +call 0 never executed + #####: 998: cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card. + #####: 999: if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed + #####: 1000: drawntreasure++; + -: 1001: else { + #####: 1002: temphand[z]=cardDrawn; + #####: 1003: state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one). + #####: 1004: z++; + -: 1005: } + -: 1006: } + #####: 1007: while(z-1>=0) { +branch 0 never executed +branch 1 never executed + #####: 1008: state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn + #####: 1009: z=z-1; + -: 1010: } + #####: 1011: return 0; + -: 1012: + -: 1013: case council_room: + -: 1014: //+4 Cards + #####: 1015: for (i = 0; i < 4; i++) +branch 0 never executed +branch 1 never executed + -: 1016: { + #####: 1017: drawCard(currentPlayer, state); +call 0 never executed + -: 1018: } + -: 1019: + -: 1020: //+1 Buy + #####: 1021: state->numBuys++; + -: 1022: + -: 1023: //Each other player draws a card + #####: 1024: for (i = 0; i < state->numPlayers; i++) +branch 0 never executed +branch 1 never executed + -: 1025: { + #####: 1026: if ( i != currentPlayer ) +branch 0 never executed +branch 1 never executed + -: 1027: { + #####: 1028: drawCard(i, state); +call 0 never executed + -: 1029: } + -: 1030: } + -: 1031: + -: 1032: //put played card in played card pile + #####: 1033: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 1034: + #####: 1035: return 0; + -: 1036: + -: 1037: case feast: + -: 1038: //gain card with cost up to 5 + -: 1039: //Backup hand + #####: 1040: for (i = 0; i <= state->handCount[currentPlayer]; i++) { +branch 0 never executed +branch 1 never executed + #####: 1041: temphand[i] = state->hand[currentPlayer][i];//Backup card + #####: 1042: state->hand[currentPlayer][i] = -1;//Set to nothing + -: 1043: } + -: 1044: //Backup hand + -: 1045: + -: 1046: //Update Coins for Buy + #####: 1047: updateCoins(currentPlayer, state, 5); +call 0 never executed + #####: 1048: x = 1;//Condition to loop on + #####: 1049: while( x == 1) {//Buy one card +branch 0 never executed +branch 1 never executed + #####: 1050: if (supplyCount(choice1, state) <= 0) { +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 1051: if (DEBUG) + -: 1052: printf("None of that card left, sorry!\n"); + -: 1053: + -: 1054: if (DEBUG) { + -: 1055: printf("Cards Left: %d\n", supplyCount(choice1, state)); + -: 1056: } + -: 1057: } + #####: 1058: else if (state->coins < getCost(choice1)) { +call 0 never executed +branch 1 never executed +branch 2 never executed + #####: 1059: printf("That card is too expensive!\n"); +call 0 never executed + -: 1060: + -: 1061: if (DEBUG) { + -: 1062: printf("Coins: %d < %d\n", state->coins, getCost(choice1)); + -: 1063: } + -: 1064: } + -: 1065: else { + -: 1066: + -: 1067: if (DEBUG) { + -: 1068: printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + -: 1069: } + -: 1070: + #####: 1071: gainCard(choice1, state, 0, currentPlayer);//Gain the card +call 0 never executed + #####: 1072: x = 0;//No more buying cards + -: 1073: + -: 1074: if (DEBUG) { + -: 1075: printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + -: 1076: } + -: 1077: + -: 1078: } + -: 1079: } + -: 1080: + -: 1081: //Reset Hand + #####: 1082: for (i = 0; i <= state->handCount[currentPlayer]; i++) { +branch 0 never executed +branch 1 never executed + #####: 1083: state->hand[currentPlayer][i] = temphand[i]; + #####: 1084: temphand[i] = -1; + -: 1085: } + -: 1086: //Reset Hand + -: 1087: + #####: 1088: return 0; + -: 1089: + -: 1090: case gardens: + #####: 1091: return -1; + -: 1092: + -: 1093: case mine: + #####: 1094: return doMine(choice1, choice2, state, handPos, currentPlayer); +call 0 never executed + -: 1095: + -: 1096: case remodel: + #####: 1097: j = state->hand[currentPlayer][choice1]; //store card we will trash + -: 1098: + #####: 1099: if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) ) +call 0 never executed +call 1 never executed +branch 2 never executed +branch 3 never executed + -: 1100: { + #####: 1101: return -1; + -: 1102: } + -: 1103: + #####: 1104: gainCard(choice2, state, 0, currentPlayer); +call 0 never executed + -: 1105: + -: 1106: //discard card from hand + #####: 1107: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 1108: + -: 1109: //discard trashed card + #####: 1110: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 1111: { + #####: 1112: if (state->hand[currentPlayer][i] == j) +branch 0 never executed +branch 1 never executed + -: 1113: { + #####: 1114: discardCard(i, currentPlayer, state, 0); +call 0 never executed + #####: 1115: break; + -: 1116: } + -: 1117: } + -: 1118: + -: 1119: + #####: 1120: return 0; + -: 1121: + -: 1122: case smithy: + -: 1123: //+3 Cards + #####: 1124: for (i = 0; i < 3; i++) +branch 0 never executed +branch 1 never executed + -: 1125: { + #####: 1126: drawCard(currentPlayer, state); +call 0 never executed + -: 1127: } + -: 1128: + -: 1129: //discard card from hand + #####: 1130: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1131: return 0; + -: 1132: + -: 1133: case village: + -: 1134: //+1 Card + #####: 1135: drawCard(currentPlayer, state); +call 0 never executed + -: 1136: + -: 1137: //+2 Actions + #####: 1138: state->numActions = state->numActions + 2; + -: 1139: + -: 1140: //discard played card from hand + #####: 1141: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1142: return 0; + -: 1143: + -: 1144: case baron: + #####: 1145: doBaron(choice1, state, currentPlayer); +call 0 never executed + #####: 1146: return 0; + -: 1147: + -: 1148: case great_hall: + -: 1149: //+1 Card + #####: 1150: drawCard(currentPlayer, state); +call 0 never executed + -: 1151: + -: 1152: //+1 Actions + #####: 1153: state->numActions++; + -: 1154: + -: 1155: //discard card from hand + #####: 1156: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1157: return 0; + -: 1158: + -: 1159: case minion: + #####: 1160: doMinion(choice1, choice2, state, handPos, currentPlayer); +call 0 never executed + #####: 1161: return 0; + -: 1162: + -: 1163: case steward: + #####: 1164: if (choice1 == 1) +branch 0 never executed +branch 1 never executed + -: 1165: { + -: 1166: //+2 cards + #####: 1167: drawCard(currentPlayer, state); +call 0 never executed + #####: 1168: drawCard(currentPlayer, state); +call 0 never executed + -: 1169: } + #####: 1170: else if (choice1 == 2) +branch 0 never executed +branch 1 never executed + -: 1171: { + -: 1172: //+2 coins + #####: 1173: state->coins = state->coins + 2; + -: 1174: } + -: 1175: else + -: 1176: { + -: 1177: //trash 2 cards in hand + #####: 1178: discardCard(choice2, currentPlayer, state, 1); +call 0 never executed + #####: 1179: discardCard(choice3, currentPlayer, state, 1); +call 0 never executed + -: 1180: } + -: 1181: + -: 1182: //discard card from hand + #####: 1183: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1184: return 0; + -: 1185: + -: 1186: case tribute: + #####: 1187: doTribute(state, currentPlayer, nextPlayer, tributeRevealedCards); +call 0 never executed + #####: 1188: return 0; + -: 1189: + -: 1190: case ambassador: + #####: 1191: return doAmbassador(choice1, choice2, state, handPos, currentPlayer); +call 0 never executed + -: 1192: + -: 1193: case cutpurse: + -: 1194: + #####: 1195: updateCoins(currentPlayer, state, 2); +call 0 never executed + #####: 1196: for (i = 0; i < state->numPlayers; i++) +branch 0 never executed +branch 1 never executed + -: 1197: { + #####: 1198: if (i != currentPlayer) +branch 0 never executed +branch 1 never executed + -: 1199: { + #####: 1200: for (j = 0; j < state->handCount[i]; j++) +branch 0 never executed +branch 1 never executed + -: 1201: { + #####: 1202: if (state->hand[i][j] == copper) +branch 0 never executed +branch 1 never executed + -: 1203: { + #####: 1204: discardCard(j, i, state, 0); +call 0 never executed + #####: 1205: break; + -: 1206: } + #####: 1207: if (j == state->handCount[i]) +branch 0 never executed +branch 1 never executed + -: 1208: { + #####: 1209: for (k = 0; k < state->handCount[i]; k++) +branch 0 never executed +branch 1 never executed + -: 1210: { + -: 1211: if (DEBUG) + -: 1212: printf("Player %d reveals card number %d\n", i, state->hand[i][k]); + -: 1213: } + #####: 1214: break; + -: 1215: } + -: 1216: } + -: 1217: + -: 1218: } + -: 1219: + -: 1220: } + -: 1221: + -: 1222: //discard played card from hand + #####: 1223: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 1224: + #####: 1225: return 0; + -: 1226: + -: 1227: + -: 1228: case embargo: + -: 1229: //+2 Coins + #####: 1230: state->coins = state->coins + 2; + -: 1231: + -: 1232: //see if selected pile is in play + #####: 1233: if ( state->supplyCount[choice1] == -1 ) +branch 0 never executed +branch 1 never executed + -: 1234: { + #####: 1235: return -1; + -: 1236: } + -: 1237: + -: 1238: //add embargo token to selected supply pile + #####: 1239: state->embargoTokens[choice1]++; + -: 1240: + -: 1241: //trash card + #####: 1242: discardCard(handPos, currentPlayer, state, 1); +call 0 never executed + #####: 1243: return 0; + -: 1244: + -: 1245: case outpost: + -: 1246: //set outpost flag + #####: 1247: state->outpostPlayed++; + -: 1248: + -: 1249: //discard card + #####: 1250: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1251: return 0; + -: 1252: + -: 1253: case salvager: + -: 1254: //+1 buy + #####: 1255: state->numBuys++; + -: 1256: + #####: 1257: if (choice1) +branch 0 never executed +branch 1 never executed + -: 1258: { + -: 1259: //gain coins equal to trashed card + #####: 1260: state->coins = state->coins + getCost( handCard(choice1, state) ); +call 0 never executed +call 1 never executed + -: 1261: //trash card + #####: 1262: discardCard(choice1, currentPlayer, state, 1); +call 0 never executed + -: 1263: } + -: 1264: + -: 1265: //discard card + #####: 1266: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1267: return 0; + -: 1268: + -: 1269: case sea_hag: + #####: 1270: for (i = 0; i < state->numPlayers; i++) { +branch 0 never executed +branch 1 never executed + #####: 1271: if (i != currentPlayer) { +branch 0 never executed +branch 1 never executed + #####: 1272: state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; + #####: 1273: state->deckCount[i]--; + #####: 1274: state->discardCount[i]++; + #####: 1275: state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse + -: 1276: } + -: 1277: } + #####: 1278: return 0; + -: 1279: + -: 1280: case treasure_map: + -: 1281: //search hand for another treasure_map + #####: 1282: index = -1; + #####: 1283: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 1284: { + #####: 1285: if (state->hand[currentPlayer][i] == treasure_map && i != handPos) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 1286: { + #####: 1287: index = i; + #####: 1288: break; + -: 1289: } + -: 1290: } + #####: 1291: if (index > -1) +branch 0 never executed +branch 1 never executed + -: 1292: { + -: 1293: //trash both treasure cards + #####: 1294: discardCard(handPos, currentPlayer, state, 1); +call 0 never executed + #####: 1295: discardCard(index, currentPlayer, state, 1); +call 0 never executed + -: 1296: + -: 1297: //gain 4 Gold cards + #####: 1298: for (i = 0; i < 4; i++) +branch 0 never executed +branch 1 never executed + -: 1299: { + #####: 1300: gainCard(gold, state, 1, currentPlayer); +call 0 never executed + -: 1301: } + -: 1302: + -: 1303: //return success + #####: 1304: return 1; + -: 1305: } + -: 1306: + -: 1307: //no second treasure_map found in hand + #####: 1308: return -1; + -: 1309: } + -: 1310: + #####: 1311: return -1; + -: 1312:} + -: 1313: +function discardCard called 18 returned 100% blocks executed 89% + 18: 1314:int discardCard(int handPos, int currentPlayer, struct gameState *state, int trashFlag) + -: 1315:{ + -: 1316: + -: 1317: //if card is not trashed, added to Played pile + 18: 1318: if (trashFlag < 1) +branch 0 taken 78% (fallthrough) +branch 1 taken 22% + -: 1319: { + -: 1320: //add card to played pile + 14: 1321: state->playedCards[state->playedCardCount] = state->hand[currentPlayer][handPos]; + 14: 1322: state->playedCardCount++; + -: 1323: } + -: 1324: + -: 1325: //set played card to -1 + 18: 1326: state->hand[currentPlayer][handPos] = -1; + -: 1327: + -: 1328: //remove card from player's hand + 18: 1329: if ( handPos == (state->handCount[currentPlayer] - 1) ) //last card in hand array is played +branch 0 taken 11% (fallthrough) +branch 1 taken 89% + -: 1330: { + -: 1331: //reduce number of cards in hand + 2: 1332: state->handCount[currentPlayer]--; + -: 1333: } + 16: 1334: else if ( state->handCount[currentPlayer] == 1 ) //only one card in hand +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1335: { + -: 1336: //reduce number of cards in hand + #####: 1337: state->handCount[currentPlayer]--; + -: 1338: } + -: 1339: else + -: 1340: { + -: 1341: //replace discarded card with last card in hand + 16: 1342: state->hand[currentPlayer][handPos] = state->hand[currentPlayer][ (state->handCount[currentPlayer] - 1)]; + -: 1343: //set last card to -1 + 16: 1344: state->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1; + -: 1345: //reduce number of cards in hand + 16: 1346: state->handCount[currentPlayer]--; + -: 1347: } + -: 1348: + 18: 1349: return 0; + -: 1350:} + -: 1351: +function gainCard called 4 returned 100% blocks executed 70% + 4: 1352:int gainCard(int supplyPos, struct gameState *state, int toFlag, int player) + -: 1353:{ + -: 1354: //Note: supplyPos is enum of choosen card + -: 1355: + -: 1356: //check if supply pile is empty (0) or card is not used in game (-1) + 4: 1357: if ( supplyCount(supplyPos, state) < 1 ) +call 0 returned 100% +branch 1 taken 0% (fallthrough) +branch 2 taken 100% + -: 1358: { + #####: 1359: return -1; + -: 1360: } + -: 1361: + -: 1362: //added card for [whoseTurn] current player: + -: 1363: // toFlag = 0 : add to discard + -: 1364: // toFlag = 1 : add to deck + -: 1365: // toFlag = 2 : add to hand + -: 1366: + 4: 1367: if (toFlag == 1) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1368: { + #####: 1369: state->deck[ player ][ state->deckCount[player] ] = supplyPos; + #####: 1370: state->deckCount[player]++; + -: 1371: } + 4: 1372: else if (toFlag == 2) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1373: { + #####: 1374: state->hand[ player ][ state->handCount[player] ] = supplyPos; + #####: 1375: state->handCount[player]++; + -: 1376: } + -: 1377: else + -: 1378: { + 4: 1379: state->discard[player][ state->discardCount[player] ] = supplyPos; + 4: 1380: state->discardCount[player]++; + -: 1381: } + -: 1382: + -: 1383: //decrease number in supply pile + 4: 1384: state->supplyCount[supplyPos]--; + -: 1385: + 4: 1386: return 0; + -: 1387:} + -: 1388: +function updateCoins called 5 returned 100% blocks executed 82% + 5: 1389:int updateCoins(int player, struct gameState *state, int bonus) + -: 1390:{ + -: 1391: int i; + -: 1392: + -: 1393: //reset coin count + 5: 1394: state->coins = 0; + -: 1395: + -: 1396: //add coins for each Treasure card in player's hand + 30: 1397: for (i = 0; i < state->handCount[player]; i++) +branch 0 taken 83% +branch 1 taken 17% (fallthrough) + -: 1398: { + 25: 1399: if (state->hand[player][i] == copper) +branch 0 taken 60% (fallthrough) +branch 1 taken 40% + -: 1400: { + 15: 1401: state->coins += 1; + -: 1402: } + 10: 1403: else if (state->hand[player][i] == silver) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1404: { + #####: 1405: state->coins += 2; + -: 1406: } + 10: 1407: else if (state->hand[player][i] == gold) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1408: { + #####: 1409: state->coins += 3; + -: 1410: } + -: 1411: } + -: 1412: + -: 1413: //add bonus + 5: 1414: state->coins += bonus; + -: 1415: + 5: 1416: return 0; + -: 1417:} + -: 1418: + -: 1419: + -: 1420://end of dominion.c diff --git a/dominion/as3/dominion.gcda b/dominion/as3/dominion.gcda new file mode 100644 index 000000000..231f0fbf2 Binary files /dev/null and b/dominion/as3/dominion.gcda differ diff --git a/dominion/as3/dominion.gcno b/dominion/as3/dominion.gcno new file mode 100644 index 000000000..53cd4ee4f Binary files /dev/null and b/dominion/as3/dominion.gcno differ diff --git a/dominion/as3/dominion.h b/dominion/as3/dominion.h new file mode 100644 index 000000000..f9d9039b8 --- /dev/null +++ b/dominion/as3/dominion.h @@ -0,0 +1,131 @@ +#ifndef _DOMINION_H +#define _DOMINION_H + +// Code from various sources, baseline from Kristen Bartosz + +#define MAX_HAND 500 +#define MAX_DECK 500 + +#define MAX_PLAYERS 4 + +#define DEBUG 0 + +/* http://dominion.diehrstraits.com has card texts */ +/* http://dominion.isotropic.org has other stuff */ + +/* hand# means index of a card in current active player's hand */ + +enum CARD +{ curse = 0, + estate, + duchy, + province, + + copper, + silver, + gold, + + adventurer, + /* If no/only 1 treasure found, stop when full deck seen */ + council_room, + feast, /* choice1 is supply # of card gained) */ + gardens, + mine, /* choice1 is hand# of money to trash, choice2 is supply# of + money to put in hand */ + remodel, /* choice1 is hand# of card to remodel, choice2 is supply# */ + smithy, + village, + + baron, /* choice1: boolean for discard of estate */ + /* Discard is always of first (lowest index) estate */ + great_hall, + minion, /* choice1: 1 = +2 coin, 2 = redraw */ + steward, /* choice1: 1 = +2 card, 2 = +2 coin, 3 = trash 2 (choice2,3) */ + tribute, + + ambassador, /* choice1 = hand#, choice2 = number to return to supply */ + cutpurse, + embargo, /* choice1 = supply# */ + outpost, + salvager, /* choice1 = hand# to trash */ + sea_hag, + treasure_map +}; + +struct gameState { + int numPlayers; //number of players + int supplyCount[treasure_map+1]; //this is the amount of a specific type of card given a specific number. + int embargoTokens[treasure_map+1]; + int outpostPlayed; + int outpostTurn; + int whoseTurn; + int phase; + int numActions; /* Starts at 1 each turn */ + int coins; /* Use as you see fit! */ + int numBuys; /* Starts at 1 each turn */ + int hand[MAX_PLAYERS][MAX_HAND]; + int handCount[MAX_PLAYERS]; + int deck[MAX_PLAYERS][MAX_DECK]; + int deckCount[MAX_PLAYERS]; + int discard[MAX_PLAYERS][MAX_DECK]; + int discardCount[MAX_PLAYERS]; + int playedCards[MAX_DECK]; + int playedCardCount; +}; + +/* All functions return -1 on failure, and DO NOT CHANGE GAME STATE; + unless specified for other return, return 0 on success */ + +struct gameState* newGame(); + +int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + int k8, int k9, int k10); + +int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, + struct gameState *state); +/* Responsible for initializing all supplies, and shuffling deck and + drawing starting hands for all players. Check that 10 cards selected + are in fact (different) kingdom cards, and that numPlayers is valid. + +Cards not in game should initialize supply position to -1 */ + +int shuffle(int player, struct gameState *state); +/* Assumes all cards are now in deck array (or hand/played): discard is + empty */ + +int playCard(int handPos, int choice1, int choice2, int choice3, + struct gameState *state); +/* Play card with index handPos from current player's hand */ + +int buyCard(int supplyPos, struct gameState *state); +/* Buy card with supply index supplyPos */ + +int numHandCards(struct gameState *state); +/* How many cards current player has in hand */ + +int handCard(int handNum, struct gameState *state); +/* enum value of indexed card in player's hand */ + +int supplyCount(int card, struct gameState *state); +/* How many of given card are left in supply */ + +int fullDeckCount(int player, int card, struct gameState *state); +/* Here deck = hand + discard + deck */ + +int whoseTurn(struct gameState *state); + +int endTurn(struct gameState *state); +/* Must do phase C and advance to next player; do not advance whose turn + if game is over */ + +int isGameOver(struct gameState *state); + +int scoreFor(int player, struct gameState *state); +/* Negative here does not mean invalid; scores may be negative, + -9999 means invalid input */ + +int getWinners(int players[MAX_PLAYERS], struct gameState *state); +/* Set array position of each player who won (remember ties!) to + 1, others to 0 */ + +#endif diff --git a/dominion/as3/dominion.o b/dominion/as3/dominion.o new file mode 100644 index 000000000..81ae49587 Binary files /dev/null and b/dominion/as3/dominion.o differ diff --git a/dominion/as3/dominion_helpers.h b/dominion/as3/dominion_helpers.h new file mode 100644 index 000000000..0887fda15 --- /dev/null +++ b/dominion/as3/dominion_helpers.h @@ -0,0 +1,15 @@ +#ifndef _DOMINION_HELPERS_H +#define _DOMINION_HELPERS_H + +#include "dominion.h" + +int drawCard(int player, struct gameState *state); +int updateCoins(int player, struct gameState *state, int bonus); +int discardCard(int handPos, int currentPlayer, struct gameState *state, + int trashFlag); +int gainCard(int supplyPos, struct gameState *state, int toFlag, int player); +int getCost(int cardNumber); +int cardEffect(int card, int choice1, int choice2, int choice3, + struct gameState *state, int handPos, int *bonus); + +#endif diff --git a/dominion/as3/hw.c b/dominion/as3/hw.c new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/dominion/as3/hw.c @@ -0,0 +1 @@ + diff --git a/dominion/as3/rngs.c b/dominion/as3/rngs.c new file mode 100644 index 000000000..a85bbc961 --- /dev/null +++ b/dominion/as3/rngs.c @@ -0,0 +1,183 @@ +/* ------------------------------------------------------------------------- + * This is an ANSI C library for multi-stream random number generation. + * The use of this library is recommended as a replacement for the ANSI C + * rand() and srand() functions, particularly in simulation applications + * where the statistical 'goodness' of the random number generator is + * important. The library supplies 256 streams of random numbers; use + * SelectStream(s) to switch between streams indexed s = 0,1,...,255. + * + * The streams must be initialized. The recommended way to do this is by + * using the function PlantSeeds(x) with the value of x used to initialize + * the default stream and all other streams initialized automatically with + * values dependent on the value of x. The following convention is used + * to initialize the default stream: + * if x > 0 then x is the state + * if x < 0 then the state is obtained from the system clock + * if x = 0 then the state is to be supplied interactively. + * + * The generator used in this library is a so-called 'Lehmer random number + * generator' which returns a pseudo-random number uniformly distributed + * 0.0 and 1.0. The period is (m - 1) where m = 2,147,483,647 and the + * smallest and largest possible values are (1 / m) and 1 - (1 / m) + * respectively. For more details see: + * + * "Random Number Generators: Good Ones Are Hard To Find" + * Steve Park and Keith Miller + * Communications of the ACM, October 1988 + * + * Name : rngs.c (Random Number Generation - Multiple Streams) + * Authors : Steve Park & Dave Geyer + * Language : ANSI C + * Latest Revision : 09-22-98 + * ------------------------------------------------------------------------- + */ + +#include +#include +#include "rngs.h" + +#define MODULUS 2147483647 /* DON'T CHANGE THIS VALUE */ +#define MULTIPLIER 48271 /* DON'T CHANGE THIS VALUE */ +#define CHECK 399268537 /* DON'T CHANGE THIS VALUE */ +#define STREAMS 256 /* # of streams, DON'T CHANGE THIS VALUE */ +#define A256 22925 /* jump multiplier, DON'T CHANGE THIS VALUE */ +#define DEFAULT 123456789 /* initial seed, use 0 < DEFAULT < MODULUS */ + +static long seed[STREAMS] = {DEFAULT}; /* current state of each stream */ +static int stream = 0; /* stream index, 0 is the default */ +static int initialized = 0; /* test for stream initialization */ + + +double Random(void) +/* ---------------------------------------------------------------- + * Random returns a pseudo-random real number uniformly distributed + * between 0.0 and 1.0. + * ---------------------------------------------------------------- + */ +{ + const long Q = MODULUS / MULTIPLIER; + const long R = MODULUS % MULTIPLIER; + long t; + + t = MULTIPLIER * (seed[stream] % Q) - R * (seed[stream] / Q); + if (t > 0) + seed[stream] = t; + else + seed[stream] = t + MODULUS; + return ((double) seed[stream] / MODULUS); +} + + +void PlantSeeds(long x) +/* --------------------------------------------------------------------- + * Use this function to set the state of all the random number generator + * streams by "planting" a sequence of states (seeds), one per stream, + * with all states dictated by the state of the default stream. + * The sequence of planted states is separated one from the next by + * 8,367,782 calls to Random(). + * --------------------------------------------------------------------- + */ +{ + const long Q = MODULUS / A256; + const long R = MODULUS % A256; + int j; + int s; + + initialized = 1; + s = stream; /* remember the current stream */ + SelectStream(0); /* change to stream 0 */ + PutSeed(x); /* set seed[0] */ + stream = s; /* reset the current stream */ + for (j = 1; j < STREAMS; j++) { + x = A256 * (seed[j - 1] % Q) - R * (seed[j - 1] / Q); + if (x > 0) + seed[j] = x; + else + seed[j] = x + MODULUS; + } +} + + +void PutSeed(long x) +/* --------------------------------------------------------------- + * Use this function to set the state of the current random number + * generator stream according to the following conventions: + * if x > 0 then x is the state (unless too large) + * if x < 0 then the state is obtained from the system clock + * if x = 0 then the state is to be supplied interactively + * --------------------------------------------------------------- + */ +{ + char ok = 0; + + if (x > 0) + x = x % MODULUS; /* correct if x is too large */ + if (x < 0) + x = ((unsigned long) time((time_t *) NULL)) % MODULUS; + if (x == 0) + while (!ok) { + printf("\nEnter a positive integer seed (9 digits or less) >> "); + scanf("%ld", &x); + ok = (0 < x) && (x < MODULUS); + if (!ok) + printf("\nInput out of range ... try again\n"); + } + seed[stream] = x; +} + + +void GetSeed(long *x) +/* --------------------------------------------------------------- + * Use this function to get the state of the current random number + * generator stream. + * --------------------------------------------------------------- + */ +{ + *x = seed[stream]; +} + + +void SelectStream(int index) +/* ------------------------------------------------------------------ + * Use this function to set the current random number generator + * stream -- that stream from which the next random number will come. + * ------------------------------------------------------------------ + */ +{ + stream = ((unsigned int) index) % STREAMS; + if ((initialized == 0) && (stream != 0)) /* protect against */ + PlantSeeds(DEFAULT); /* un-initialized streams */ +} + + +void TestRandom(void) +/* ------------------------------------------------------------------ + * Use this (optional) function to test for a correct implementation. + * ------------------------------------------------------------------ + */ +{ + long i; + long x; + double u; + char ok = 0; + + SelectStream(0); /* select the default stream */ + PutSeed(1); /* and set the state to 1 */ + for(i = 0; i < 10000; i++) { + u = Random(); + if (ok) + printf(" %f \n\n", u); + + } + GetSeed(&x); /* get the new state value */ + ok = (x == CHECK); /* and check for correctness */ + + SelectStream(1); /* select stream 1 */ + PlantSeeds(1); /* set the state of all streams */ + GetSeed(&x); /* get the state of stream 1 */ + ok = ok && (x == A256); /* x should be the jump multiplier */ + if (ok) + printf("\n The implementation of rngs.c is correct.\n\n"); + else + printf("\n\a ERROR -- the implementation of rngs.c is not correct.\n\n"); +} diff --git a/dominion/as3/rngs.gcda b/dominion/as3/rngs.gcda new file mode 100644 index 000000000..e0619095e Binary files /dev/null and b/dominion/as3/rngs.gcda differ diff --git a/dominion/as3/rngs.gcno b/dominion/as3/rngs.gcno new file mode 100644 index 000000000..f05d60f39 Binary files /dev/null and b/dominion/as3/rngs.gcno differ diff --git a/dominion/as3/rngs.h b/dominion/as3/rngs.h new file mode 100644 index 000000000..c9f3f451a --- /dev/null +++ b/dominion/as3/rngs.h @@ -0,0 +1,19 @@ +/* ----------------------------------------------------------------------- + * Name : rngs.h (header file for the library file rngs.c) + * Author : Steve Park & Dave Geyer + * Language : ANSI C + * Latest Revision : 09-22-98 + * ----------------------------------------------------------------------- + */ + +#if !defined( _RNGS_ ) +#define _RNGS_ + +double Random(void); +void PlantSeeds(long x); +void GetSeed(long *x); +void PutSeed(long x); +void SelectStream(int index); +void TestRandom(void); + +#endif diff --git a/dominion/as3/rngs.o b/dominion/as3/rngs.o new file mode 100644 index 000000000..4f59e8b88 Binary files /dev/null and b/dominion/as3/rngs.o differ diff --git a/dominion/as3/unittest1 b/dominion/as3/unittest1 new file mode 100644 index 000000000..3aa1f9ff8 Binary files /dev/null and b/dominion/as3/unittest1 differ diff --git a/dominion/as3/unittest1.gcda b/dominion/as3/unittest1.gcda new file mode 100644 index 000000000..b77277840 Binary files /dev/null and b/dominion/as3/unittest1.gcda differ diff --git a/dominion/as3/unittest1.gcno b/dominion/as3/unittest1.gcno new file mode 100644 index 000000000..f88979db7 Binary files /dev/null and b/dominion/as3/unittest1.gcno differ diff --git a/dominion/as3/unittest2 b/dominion/as3/unittest2 new file mode 100644 index 000000000..f7d822035 Binary files /dev/null and b/dominion/as3/unittest2 differ diff --git a/dominion/as3/unittest2.gcda b/dominion/as3/unittest2.gcda new file mode 100644 index 000000000..afbec2732 Binary files /dev/null and b/dominion/as3/unittest2.gcda differ diff --git a/dominion/as3/unittest2.gcno b/dominion/as3/unittest2.gcno new file mode 100644 index 000000000..4fc66e70d Binary files /dev/null and b/dominion/as3/unittest2.gcno differ diff --git a/dominion/as3/unittest3 b/dominion/as3/unittest3 new file mode 100644 index 000000000..ca08a5ffa Binary files /dev/null and b/dominion/as3/unittest3 differ diff --git a/dominion/as3/unittest3.gcda b/dominion/as3/unittest3.gcda new file mode 100644 index 000000000..db7f1f315 Binary files /dev/null and b/dominion/as3/unittest3.gcda differ diff --git a/dominion/as3/unittest3.gcno b/dominion/as3/unittest3.gcno new file mode 100644 index 000000000..a11220c9c Binary files /dev/null and b/dominion/as3/unittest3.gcno differ diff --git a/dominion/as3/unittest4 b/dominion/as3/unittest4 new file mode 100644 index 000000000..19ad1d52e Binary files /dev/null and b/dominion/as3/unittest4 differ diff --git a/dominion/as3/unittest4.gcda b/dominion/as3/unittest4.gcda new file mode 100644 index 000000000..9448441fa Binary files /dev/null and b/dominion/as3/unittest4.gcda differ diff --git a/dominion/as3/unittest4.gcno b/dominion/as3/unittest4.gcno new file mode 100644 index 000000000..c33bc567f Binary files /dev/null and b/dominion/as3/unittest4.gcno differ diff --git a/dominion/as3/unittest5 b/dominion/as3/unittest5 new file mode 100644 index 000000000..5855f8fc4 Binary files /dev/null and b/dominion/as3/unittest5 differ diff --git a/dominion/as3/unittest5.gcda b/dominion/as3/unittest5.gcda new file mode 100644 index 000000000..01dae6880 Binary files /dev/null and b/dominion/as3/unittest5.gcda differ diff --git a/dominion/as3/unittest5.gcno b/dominion/as3/unittest5.gcno new file mode 100644 index 000000000..7982f5a17 Binary files /dev/null and b/dominion/as3/unittest5.gcno differ diff --git a/dominion/as3/unittestresults.out b/dominion/as3/unittestresults.out new file mode 100644 index 000000000..e7b35ea86 --- /dev/null +++ b/dominion/as3/unittestresults.out @@ -0,0 +1,963 @@ + +Begin Testing doBaron(): + +Test 1 +Assert failed: Number of buys not increased by 1 +Assert failed: Baron card not discarded +Test 2 +Assert failed: Number of buys not increased by 1 +Assert failed: Baron card not discarded +Test 3 +Assert failed: Number of buys not increased by 1 +Assert failed: Coins not increased by 4 +Assert failed: Baron card not discarded +End of doBaron() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:0.00% of 20 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 28 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:0.00% of 17 +Branches executed:0.00% of 16 +Taken at least once:0.00% of 16 +Calls executed:0.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:0.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:0.00% of 2 +No branches +Calls executed:0.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:83.87% of 62 +Branches executed:95.65% of 46 +Taken at least once:80.43% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:21.78% of 583 +Branches executed:21.03% of 409 +Taken at least once:16.87% of 409 +Calls executed:13.40% of 97 +Creating 'dominion.c.gcov' + + +Begin Testing doMinion(): + +Test 1 +Test 2 +Assert failed: Current player should have exactly 4 cards +Assert failed: A player with less than 5 cards discarded hand +End of doMinion() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:92.31% of 13 +Branches executed:100.00% of 6 +Taken at least once:66.67% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:0.00% of 20 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 28 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:93.55% of 62 +Branches executed:100.00% of 46 +Taken at least once:89.13% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:28.47% of 583 +Branches executed:26.89% of 409 +Taken at least once:22.49% of 409 +Calls executed:20.62% of 97 +Creating 'dominion.c.gcov' + + +Begin Testing doAmbassador(): + +Test 1 +Assert failed: Didn't return -1 when trying to discard too many cards +Test 2 +Assert failed: Didn't return -1 when trying to discard ambassador card +End of doAmbassador() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:92.31% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:90.00% of 20 +Branches executed:100.00% of 22 +Taken at least once:77.27% of 22 +Calls executed:100.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 28 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:93.55% of 62 +Branches executed:100.00% of 46 +Taken at least once:89.13% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:31.56% of 583 +Branches executed:32.27% of 409 +Taken at least once:26.89% of 409 +Calls executed:23.71% of 97 +Creating 'dominion.c.gcov' + + +Begin Testing doTribute(): + +Test 1 +Assert failed: Tribute card not discarded +Assert failed: Didn't draw 2 cards +Test 2 +Assert failed: Tribute card not discarded +Assert failed: Didn't draw 2 cards +Assert failed: Actions didn't increase by 2 +Test 3 +Assert failed: Tribute card not discarded +Assert failed: Didn't draw 2 cards +End of doTribute() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:92.31% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:90.00% of 20 +Branches executed:100.00% of 22 +Taken at least once:77.27% of 22 +Calls executed:100.00% of 3 + +Function 'doTribute' +Lines executed:82.14% of 28 +Branches executed:100.00% of 30 +Taken at least once:70.00% of 30 +Calls executed:100.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:93.55% of 62 +Branches executed:100.00% of 46 +Taken at least once:89.13% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:35.51% of 583 +Branches executed:39.61% of 409 +Taken at least once:32.03% of 409 +Calls executed:25.77% of 97 +Creating 'dominion.c.gcov' + + +Begin Testing doMine(): + +Test 1 +Assert failed: Didn't return -1 when trying to trash a curse +Test 2 +Assert failed: Silver not gained to hand +Test 3 +End of doMine() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:92.31% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:90.00% of 20 +Branches executed:100.00% of 22 +Taken at least once:77.27% of 22 +Calls executed:100.00% of 3 + +Function 'doTribute' +Lines executed:82.14% of 28 +Branches executed:100.00% of 30 +Taken at least once:70.00% of 30 +Calls executed:100.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:85.71% of 14 +Branches executed:100.00% of 12 +Taken at least once:58.33% of 12 +Calls executed:100.00% of 4 + +Function 'getCost' +Lines executed:16.67% of 30 +Branches executed:100.00% of 28 +Taken at least once:10.71% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:93.55% of 62 +Branches executed:100.00% of 46 +Taken at least once:89.13% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:38.42% of 583 +Branches executed:49.39% of 409 +Taken at least once:34.47% of 409 +Calls executed:29.90% of 97 +Creating 'dominion.c.gcov' + diff --git a/dominion/dominion.c b/dominion/dominion.c index c94e2edb9..8f4591d76 100644 --- a/dominion/dominion.c +++ b/dominion/dominion.c @@ -5,22 +5,25 @@ #include #include -int compare(const void* a, const void* b) { - if (*(int*)a > *(int*)b) +int compare(const void *a, const void *b) +{ + if (*(int *)a > *(int *)b) return 1; - if (*(int*)a < *(int*)b) + if (*(int *)a < *(int *)b) return -1; return 0; } -struct gameState* newGame() { - struct gameState* g = malloc(sizeof(struct gameState)); +struct gameState *newGame() +{ + struct gameState *g = malloc(sizeof(struct gameState)); return g; } -int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, - int k8, int k9, int k10) { - int* k = malloc(10 * sizeof(int)); +int *kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + int k8, int k9, int k10) +{ + int *k = malloc(10 * sizeof(int)); k[0] = k1; k[1] = k2; k[2] = k3; @@ -35,7 +38,8 @@ int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, } int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, - struct gameState *state) { + struct gameState *state) +{ int i; int j; int it; @@ -65,7 +69,6 @@ int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, } } - //initialize supply /////////////////////////////// @@ -103,19 +106,21 @@ int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, state->supplyCount[gold] = 30; //set number of Kingdom cards - for (i = adventurer; i <= treasure_map; i++) //loop all cards + for (i = adventurer; i <= treasure_map; i++) //loop all cards { - for (j = 0; j < 10; j++) //loop chosen 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) { + if (numPlayers == 2) + { state->supplyCount[i] = 8; } - else { + else + { state->supplyCount[i] = 12; } } @@ -125,12 +130,11 @@ int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, } break; } - else //card is not in the set choosen for the game + else //card is not in the set choosen for the game { state->supplyCount[i] = -1; } } - } //////////////////////// @@ -155,7 +159,7 @@ int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, //shuffle player decks for (i = 0; i < numPlayers; i++) { - if ( shuffle(i, state) < 0 ) + if (shuffle(i, state) < 0) { return -1; } @@ -191,7 +195,8 @@ int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, //int it; move to top //Moved draw cards to here, only drawing at the start of a turn - for (it = 0; it < 5; it++) { + for (it = 0; it < 5; it++) + { drawCard(state->whoseTurn, state); } @@ -200,8 +205,8 @@ int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, return 0; } -int shuffle(int player, struct gameState *state) { - +int shuffle(int player, struct gameState *state) +{ int newDeck[MAX_DECK]; int newDeckPos = 0; @@ -210,19 +215,22 @@ int shuffle(int player, struct gameState *state) { if (state->deckCount[player] < 1) return -1; - qsort ((void*)(state->deck[player]), state->deckCount[player], sizeof(int), compare); + qsort((void *)(state->deck[player]), state->deckCount[player], sizeof(int), compare); /* SORT CARDS IN DECK TO ENSURE DETERMINISM! */ - while (state->deckCount[player] > 0) { + while (state->deckCount[player] > 0) + { card = floor(Random() * state->deckCount[player]); newDeck[newDeckPos] = state->deck[player][card]; newDeckPos++; - for (i = card; i < state->deckCount[player]-1; i++) { - state->deck[player][i] = state->deck[player][i+1]; + for (i = card; i < state->deckCount[player] - 1; i++) + { + state->deck[player][i] = state->deck[player][i + 1]; } state->deckCount[player]--; } - for (i = 0; i < newDeckPos; i++) { + for (i = 0; i < newDeckPos; i++) + { state->deck[player][i] = newDeck[i]; state->deckCount[player]++; } @@ -233,7 +241,7 @@ int shuffle(int player, struct gameState *state) { int playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state) { int card; - int coin_bonus = 0; //tracks coins gain from actions + int coin_bonus = 0; //tracks coins gain from actions //check if it is the right phase if (state->phase != 0) @@ -242,7 +250,7 @@ int playCard(int handPos, int choice1, int choice2, int choice3, struct gameStat } //check if player has enough actions - if ( state->numActions < 1 ) + if (state->numActions < 1) { return -1; } @@ -251,13 +259,13 @@ int playCard(int handPos, int choice1, int choice2, int choice3, struct gameStat card = handCard(handPos, state); //check if selected card is an action - if ( card < adventurer || card > treasure_map ) + if (card < adventurer || card > treasure_map) { return -1; } //play card - if ( cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0 ) + if (cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0) { return -1; } @@ -271,9 +279,11 @@ int playCard(int handPos, int choice1, int choice2, int choice3, struct gameStat return 0; } -int buyCard(int supplyPos, struct gameState *state) { +int buyCard(int supplyPos, struct gameState *state) +{ int who; - if (DEBUG) { + if (DEBUG) + { printf("Entering buyCard...\n"); } @@ -281,20 +291,27 @@ int buyCard(int supplyPos, struct gameState *state) { who = state->whoseTurn; - if (state->numBuys < 1) { + if (state->numBuys < 1) + { if (DEBUG) printf("You do not have any buys left\n"); return -1; - } else if (supplyCount(supplyPos, state) <1) { + } + else if (supplyCount(supplyPos, state) < 1) + { if (DEBUG) printf("There are not any of that type of card left\n"); return -1; - } else if (state->coins < getCost(supplyPos)) { + } + else if (state->coins < getCost(supplyPos)) + { if (DEBUG) printf("You do not have enough money to buy that. You have %d coins.\n", state->coins); return -1; - } else { - state->phase=1; + } + else + { + state->phase = 1; //state->supplyCount[supplyPos]--; gainCard(supplyPos, state, 0, who); //card goes in discard, this might be wrong.. (2 means goes into hand, 0 goes into discard) @@ -310,63 +327,75 @@ int buyCard(int supplyPos, struct gameState *state) { return 0; } -int numHandCards(struct gameState *state) { - return state->handCount[ whoseTurn(state) ]; +int numHandCards(struct gameState *state) +{ + return state->handCount[whoseTurn(state)]; } -int handCard(int handPos, struct gameState *state) { +int handCard(int handPos, struct gameState *state) +{ int currentPlayer = whoseTurn(state); return state->hand[currentPlayer][handPos]; } -int supplyCount(int card, struct gameState *state) { +int supplyCount(int card, struct gameState *state) +{ return state->supplyCount[card]; } -int fullDeckCount(int player, int card, struct gameState *state) { +int fullDeckCount(int player, int card, struct gameState *state) +{ int i; int count = 0; for (i = 0; i < state->deckCount[player]; i++) { - if (state->deck[player][i] == card) count++; + if (state->deck[player][i] == card) + count++; } for (i = 0; i < state->handCount[player]; i++) { - if (state->hand[player][i] == card) count++; + if (state->hand[player][i] == card) + count++; } for (i = 0; i < state->discardCount[player]; i++) { - if (state->discard[player][i] == card) count++; + if (state->discard[player][i] == card) + count++; } return count; } -int whoseTurn(struct gameState *state) { +int whoseTurn(struct gameState *state) +{ return state->whoseTurn; } -int endTurn(struct gameState *state) { +int endTurn(struct gameState *state) +{ int k; int i; int currentPlayer = whoseTurn(state); //Discard hand - for (i = 0; i < state->handCount[currentPlayer]; i++) { - state->discard[currentPlayer][state->discardCount[currentPlayer]++] = state->hand[currentPlayer][i];//Discard - state->hand[currentPlayer][i] = -1;//Set card to -1 + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + state->discard[currentPlayer][state->discardCount[currentPlayer]++] = state->hand[currentPlayer][i]; //Discard + state->hand[currentPlayer][i] = -1; //Set card to -1 } - state->handCount[currentPlayer] = 0;//Reset hand count + state->handCount[currentPlayer] = 0; //Reset hand count //Code for determining the player - if (currentPlayer < (state->numPlayers - 1)) { - state->whoseTurn = currentPlayer + 1;//Still safe to increment + if (currentPlayer < (state->numPlayers - 1)) + { + state->whoseTurn = currentPlayer + 1; //Still safe to increment } - else { - state->whoseTurn = 0;//Max player has been reached, loop back around to player 1 + else + { + state->whoseTurn = 0; //Max player has been reached, loop back around to player 1 } state->outpostPlayed = 0; @@ -379,8 +408,9 @@ int endTurn(struct gameState *state) { //int k; move to top //Next player draws hand - for (k = 0; k < 5; k++) { - drawCard(state->whoseTurn, state);//Draw a card + for (k = 0; k < 5; k++) + { + drawCard(state->whoseTurn, state); //Draw a card } //Update money @@ -389,7 +419,8 @@ int endTurn(struct gameState *state) { return 0; } -int isGameOver(struct gameState *state) { +int isGameOver(struct gameState *state) +{ int i; int j; @@ -408,7 +439,7 @@ int isGameOver(struct gameState *state) { j++; } } - if ( j >= 3) + if (j >= 3) { return 1; } @@ -416,83 +447,103 @@ int isGameOver(struct gameState *state) { return 0; } -int scoreFor (int player, struct gameState *state) { +int scoreFor(int player, struct gameState *state) +{ int i; int score = 0; //score from hand for (i = 0; i < state->handCount[player]; i++) { - if (state->hand[player][i] == curse) { + if (state->hand[player][i] == curse) + { score = score - 1; }; - if (state->hand[player][i] == estate) { + if (state->hand[player][i] == estate) + { score = score + 1; }; - if (state->hand[player][i] == duchy) { + if (state->hand[player][i] == duchy) + { score = score + 3; }; - if (state->hand[player][i] == province) { + if (state->hand[player][i] == province) + { score = score + 6; }; - if (state->hand[player][i] == great_hall) { + if (state->hand[player][i] == great_hall) + { score = score + 1; }; - if (state->hand[player][i] == gardens) { - score = score + ( fullDeckCount(player, 0, state) / 10 ); + if (state->hand[player][i] == gardens) + { + score = score + (fullDeckCount(player, 0, state) / 10); }; } //score from discard for (i = 0; i < state->discardCount[player]; i++) { - if (state->discard[player][i] == curse) { + if (state->discard[player][i] == curse) + { score = score - 1; }; - if (state->discard[player][i] == estate) { + if (state->discard[player][i] == estate) + { score = score + 1; }; - if (state->discard[player][i] == duchy) { + if (state->discard[player][i] == duchy) + { score = score + 3; }; - if (state->discard[player][i] == province) { + if (state->discard[player][i] == province) + { score = score + 6; }; - if (state->discard[player][i] == great_hall) { + if (state->discard[player][i] == great_hall) + { score = score + 1; }; - if (state->discard[player][i] == gardens) { - score = score + ( fullDeckCount(player, 0, state) / 10 ); + if (state->discard[player][i] == gardens) + { + score = score + (fullDeckCount(player, 0, state) / 10); }; } //score from deck for (i = 0; i < state->discardCount[player]; i++) { - if (state->deck[player][i] == curse) { + if (state->deck[player][i] == curse) + { score = score - 1; }; - if (state->deck[player][i] == estate) { + if (state->deck[player][i] == estate) + { score = score + 1; }; - if (state->deck[player][i] == duchy) { + if (state->deck[player][i] == duchy) + { score = score + 3; }; - if (state->deck[player][i] == province) { + if (state->deck[player][i] == province) + { score = score + 6; }; - if (state->deck[player][i] == great_hall) { + if (state->deck[player][i] == great_hall) + { score = score + 1; }; - if (state->deck[player][i] == gardens) { - score = score + ( fullDeckCount(player, 0, state) / 10 ); + if (state->deck[player][i] == gardens) + { + score = score + (fullDeckCount(player, 0, state) / 10); }; } return score; } -int getWinners(int players[MAX_PLAYERS], struct gameState *state) { +int getWinners(int players[MAX_PLAYERS], struct gameState *state) +{ int i; int j; int highScore; @@ -508,7 +559,7 @@ int getWinners(int players[MAX_PLAYERS], struct gameState *state) { } else { - players[i] = scoreFor (i, state); + players[i] = scoreFor(i, state); } } @@ -527,7 +578,7 @@ int getWinners(int players[MAX_PLAYERS], struct gameState *state) { currentPlayer = whoseTurn(state); for (i = 0; i < MAX_PLAYERS; i++) { - if ( players[i] == highScore && i > currentPlayer ) + if (players[i] == highScore && i > currentPlayer) { players[i]++; } @@ -537,7 +588,7 @@ int getWinners(int players[MAX_PLAYERS], struct gameState *state) { j = 0; for (i = 0; i < MAX_PLAYERS; i++) { - if ( players[i] > players[j] ) + if (players[i] > players[j]) { j = i; } @@ -547,7 +598,7 @@ int getWinners(int players[MAX_PLAYERS], struct gameState *state) { //set winners in array to 1 and rest to 0 for (i = 0; i < MAX_PLAYERS; i++) { - if ( players[i] == highScore ) + if (players[i] == highScore) { players[i] = 1; } @@ -561,58 +612,65 @@ int getWinners(int players[MAX_PLAYERS], struct gameState *state) { } int drawCard(int player, struct gameState *state) -{ int count; +{ + int count; int deckCounter; - if (state->deckCount[player] <= 0) { //Deck is empty + if (state->deckCount[player] <= 0) + { //Deck is empty //Step 1 Shuffle the discard pile back into a deck int i; //Move discard to deck - for (i = 0; i < state->discardCount[player]; i++) { + for (i = 0; i < state->discardCount[player]; i++) + { state->deck[player][i] = state->discard[player][i]; state->discard[player][i] = -1; } state->deckCount[player] = state->discardCount[player]; - state->discardCount[player] = 0;//Reset discard + state->discardCount[player] = 0; //Reset discard //Shufffle the deck - shuffle(player, state);//Shuffle the deck up and make it so that we can draw + shuffle(player, state); //Shuffle the deck up and make it so that we can draw - if (DEBUG) { //Debug statements + if (DEBUG) + { //Debug statements printf("Deck count now: %d\n", state->deckCount[player]); } state->discardCount[player] = 0; //Step 2 Draw Card - count = state->handCount[player];//Get current player's hand count + count = state->handCount[player]; //Get current player's hand count - if (DEBUG) { //Debug statements + if (DEBUG) + { //Debug statements printf("Current hand count: %d\n", count); } - deckCounter = state->deckCount[player];//Create a holder for the deck count + deckCounter = state->deckCount[player]; //Create a holder for the deck count if (deckCounter == 0) return -1; - state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to hand + state->hand[player][count] = state->deck[player][deckCounter - 1]; //Add card to hand state->deckCount[player]--; - state->handCount[player]++;//Increment hand count + state->handCount[player]++; //Increment hand count } - else { - int count = state->handCount[player];//Get current hand count for player + else + { + int count = state->handCount[player]; //Get current hand count for player int deckCounter; - if (DEBUG) { //Debug statements + if (DEBUG) + { //Debug statements printf("Current hand count: %d\n", count); } - deckCounter = state->deckCount[player];//Create holder for the deck count - state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to the hand + deckCounter = state->deckCount[player]; //Create holder for the deck count + state->hand[player][count] = state->deck[player][deckCounter - 1]; //Add card to the hand state->deckCount[player]--; - state->handCount[player]++;//Increment hand count + state->handCount[player]++; //Increment hand count } return 0; @@ -620,7 +678,7 @@ int drawCard(int player, struct gameState *state) int getCost(int cardNumber) { - switch( cardNumber ) + switch (cardNumber) { case curse: return 0; @@ -681,6 +739,315 @@ int getCost(int cardNumber) return -1; } +void supplyEstate(struct gameState *state, int player) +{ + if (supplyCount(estate, state) > 0) + { + gainCard(estate, state, 0, player); //Gain an estate + + state->supplyCount[estate]--; //Decrement Estates + if (supplyCount(estate, state) == 0) + { + isGameOver(state); + } + } +} +void increaseTreasure(struct gameState *state, int amount) +{ + state->coins += amount; +} + +void putDiscardedInDeck(struct gameState *state, int player) +{ + int i; + if (state->deckCount[player] == 0) + { + for (i = 0; i < state->discardCount[player]; i++) + { + state->deck[player][i] = state->discard[player][i]; //Move to deck + state->deckCount[player]++; + state->discard[player][i] = -1; + state->discardCount[player]--; + } + + shuffle(player, state); //Shuffle the deck + } +} + +int discardTopCardFromDeck(struct gameState *state, int player) +{ + int cardToDiscard = state->deck[player][state->deckCount[player] - 1]; + state->deck[player][state->deckCount[player]--] = -1; + state->deckCount[player]--; + + state->discard[player][state->discardCount[player]] = cardToDiscard; + state->discardCount[player]++; + return cardToDiscard; +} + +int baronEffect(struct gameState *state, int choiceDiscardCard) +{ + int currentPlayer = whoseTurn(state); + state->numBuys++; //Increase buys by 1! + if (choiceDiscardCard > 0) + { //Boolean true or going to discard an estate + int p = 0; //Iterator for hand! + int card_not_discarded = 1; //Flag for discard set! + + while (card_not_discarded) + { + if (state->hand[currentPlayer][p] == estate) + { //Found an estate card! + increaseTreasure(state, 5); //Add 4 coins to the amount of coins + state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; + state->discardCount[currentPlayer]++; + for (; p < state->handCount[currentPlayer]; p++) + { + state->hand[currentPlayer][p] = state->hand[currentPlayer][p + 1]; + } + state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; + state->handCount[currentPlayer]--; + card_not_discarded = 0; //Exit the loop + } + else if (p > state->handCount[currentPlayer]) + { + if (DEBUG) + { + printf("No estate cards in your hand, invalid choice\n"); + printf("Must gain an estate if there are any\n"); + } + supplyEstate(state, currentPlayer); + } + + else + { + p++; //Next card + } + } + } + + else + { + supplyEstate(state, currentPlayer); + } + + return 0; +} + +int minionEffect(struct gameState *state, int choiceGainCoins, int choiceDiscard, int handPos) +{ + int currentPlayer = whoseTurn(state); + //+1 action + state->numActions++; + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + if (choiceGainCoins) + { + increaseTreasure(state, 3); //Add 4 coins to the amount of coins + } + else if (choiceDiscard) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 + { + //discard hand + while (numHandCards(state) > 0) + { + discardCard(handPos, currentPlayer, state, 0); + } + + //draw 4 + int i, j; + for (i = 0; i < 4; i++) + { + drawCard(currentPlayer, state); + } + + //other players discard hand and redraw if hand size > 4 + for (i = 0; i < state->numPlayers; i++) + { + if (state->handCount[i] > 4) + { + //discard hand + while (state->handCount[i] > 0) + { + discardCard(handPos, i, state, 0); + } + + //draw 4 + for (j = 0; j < 4; j++) + { + drawCard(i, state); + } + } + + } + } + return 0; +} + +int ambassadorEffect(struct gameState *state, int cardToDiscard, int numberOfCardsToDiscard, int handPos) +{ + + int currentPlayer = whoseTurn(state); + int i, j; + j = 0; //used to check if player has enough cards to discard + + if (numberOfCardsToDiscard > 2 || numberOfCardsToDiscard < 0) + { + return -1; + } + + else if (cardToDiscard == handPos) + { + return -1; + } + + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (i != handPos && i == state->hand[currentPlayer][cardToDiscard] && i != cardToDiscard) + { + j++; + } + } + if (j < numberOfCardsToDiscard) + { + return -1; + } + + if (DEBUG) + printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][cardToDiscard]); + + + //each other player gains a copy of revealed card + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + gainCard(state->hand[currentPlayer][cardToDiscard], state, 0, i); + } + } + + + //trash copies of cards returned to supply + for (j = 0; j < numberOfCardsToDiscard; j++) + { + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == state->hand[currentPlayer][cardToDiscard]) + { + discardCard(i, currentPlayer, state, 1); + break; + } + } + } + + return 0; +} + +int tributeEffect(struct gameState *state, int handPos) +{ + + int currentPlayer = whoseTurn(state); + int nextPlayer = currentPlayer + 1; + int tributeRevealedCards[2] = {-1, -1}; + int i; + + + if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) + { + if (state->deckCount[nextPlayer] > 0) + { + tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer] - 1]; + state->deckCount[nextPlayer]--; + } + else if (state->discardCount[nextPlayer] > 0) + { + tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer] - 1]; + state->discardCount[nextPlayer]--; + } + else + { + //No Card to Reveal + if (DEBUG) + { + printf("No cards to reveal\n"); + } + } + } + + else + { + + putDiscardedInDeck(state, nextPlayer); + + tributeRevealedCards[0] = discardTopCardFromDeck(state, nextPlayer); + tributeRevealedCards[1] = discardTopCardFromDeck(state, nextPlayer); + } + + if (tributeRevealedCards[0] == tributeRevealedCards[1]) + { //If we have a duplicate card, just drop one + + } + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + + for (i = 0; i <= 2; i++) + { + if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) + { //Treasure cards + state->coins += 2; + } + + else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall) + { //Victory Card Found + drawCard(currentPlayer, state); + drawCard(currentPlayer, state); + } + else + { //Action Card + state->numActions = state->numActions + 2; + } + } + + return 0; +} + +int mineEffect(struct gameState *state, int treasureToTrash, int treasureToGain, int handPos) +{ + int j, i; + int currentPlayer = whoseTurn(state); + + j = state->hand[currentPlayer][treasureToTrash]; //store card we will trash + + + + if (treasureToGain > treasure_map || treasureToGain < curse) + { + return -1; + } + + else if ((getCost(state->hand[currentPlayer][treasureToTrash]) + 3) > getCost(treasureToGain)) + { + return -1; + } + + gainCard(treasureToGain, state, 2, currentPlayer); + //discard card from hand + + //discard trashed card + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == j) + { + discardCard(i, currentPlayer, state, 1); + break; + } + } + + return 0; +} + int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) { int i; @@ -691,37 +1058,40 @@ int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState int currentPlayer = whoseTurn(state); int nextPlayer = currentPlayer + 1; - int tributeRevealedCards[2] = {-1, -1}; - int temphand[MAX_HAND];// moved above the if statement - int drawntreasure=0; + int temphand[MAX_HAND]; // moved above the if statement + int drawntreasure = 0; int cardDrawn; - int z = 0;// this is the counter for the temp hand - if (nextPlayer > (state->numPlayers - 1)) { + int z = 0; // this is the counter for the temp hand + if (nextPlayer > (state->numPlayers - 1)) + { nextPlayer = 0; } - //uses switch to select card and perform actions - switch( card ) + switch (card) { case adventurer: - while(drawntreasure<2) { - if (state->deckCount[currentPlayer] <1) { //if the deck is empty we need to shuffle discard and add to deck + while (drawntreasure < 2) + { + if (state->deckCount[currentPlayer] < 1) + { //if the deck is empty we need to shuffle discard and add to deck shuffle(currentPlayer, state); } drawCard(currentPlayer, state); - cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card. + cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer] - 1]; //top card of hand is most recently drawn card. if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold) drawntreasure++; - else { - temphand[z]=cardDrawn; + else + { + temphand[z] = cardDrawn; state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one). z++; } } - while(z-1>=0) { - state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn - z=z-1; + while (z - 1 >= 0) + { + state->discard[currentPlayer][state->discardCount[currentPlayer]++] = temphand[z - 1]; // discard all cards in play that have been drawn + z = z - 1; } return 0; @@ -738,7 +1108,7 @@ int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState //Each other player draws a card for (i = 0; i < state->numPlayers; i++) { - if ( i != currentPlayer ) + if (i != currentPlayer) { drawCard(i, state); } @@ -752,49 +1122,58 @@ int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState case feast: //gain card with cost up to 5 //Backup hand - for (i = 0; i <= state->handCount[currentPlayer]; i++) { - temphand[i] = state->hand[currentPlayer][i];//Backup card - state->hand[currentPlayer][i] = -1;//Set to nothing + for (i = 0; i <= state->handCount[currentPlayer]; i++) + { + temphand[i] = state->hand[currentPlayer][i]; //Backup card + state->hand[currentPlayer][i] = -1; //Set to nothing } //Backup hand //Update Coins for Buy updateCoins(currentPlayer, state, 5); - x = 1;//Condition to loop on - while( x == 1) {//Buy one card - if (supplyCount(choice1, state) <= 0) { + x = 1; //Condition to loop on + while (x == 1) + { //Buy one card + if (supplyCount(choice1, state) <= 0) + { if (DEBUG) printf("None of that card left, sorry!\n"); - if (DEBUG) { + if (DEBUG) + { printf("Cards Left: %d\n", supplyCount(choice1, state)); } } - else if (state->coins < getCost(choice1)) { + else if (state->coins < getCost(choice1)) + { printf("That card is too expensive!\n"); - if (DEBUG) { + if (DEBUG) + { printf("Coins: %d < %d\n", state->coins, getCost(choice1)); } } - else { + else + { - if (DEBUG) { + if (DEBUG) + { printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); } - gainCard(choice1, state, 0, currentPlayer);//Gain the card - x = 0;//No more buying cards + gainCard(choice1, state, 0, currentPlayer); //Gain the card + x = 0; //No more buying cards - if (DEBUG) { + if (DEBUG) + { printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); } - } } //Reset Hand - for (i = 0; i <= state->handCount[currentPlayer]; i++) { + for (i = 0; i <= state->handCount[currentPlayer]; i++) + { state->hand[currentPlayer][i] = temphand[i]; temphand[i] = -1; } @@ -806,44 +1185,12 @@ int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState return -1; case mine: - j = state->hand[currentPlayer][choice1]; //store card we will trash - - if (state->hand[currentPlayer][choice1] < copper || state->hand[currentPlayer][choice1] > gold) - { - return -1; - } - - if (choice2 > treasure_map || choice2 < curse) - { - return -1; - } - - if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) ) - { - return -1; - } - - gainCard(choice2, state, 2, currentPlayer); - - //discard card from hand - discardCard(handPos, currentPlayer, state, 0); - - //discard trashed card - for (i = 0; i < state->handCount[currentPlayer]; i++) - { - if (state->hand[currentPlayer][i] == j) - { - discardCard(i, currentPlayer, state, 0); - break; - } - } - - return 0; + return mineEffect(state, choice1, choice2, handPos); case remodel: - j = state->hand[currentPlayer][choice1]; //store card we will trash + j = state->hand[currentPlayer][choice1]; //store card we will trash - if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) ) + if ((getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2)) { return -1; } @@ -863,7 +1210,6 @@ int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState } } - return 0; case smithy: @@ -889,58 +1235,7 @@ int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState return 0; case baron: - state->numBuys++;//Increase buys by 1! - if (choice1 > 0) { //Boolean true or going to discard an estate - int p = 0;//Iterator for hand! - int card_not_discarded = 1;//Flag for discard set! - while(card_not_discarded) { - if (state->hand[currentPlayer][p] == estate) { //Found an estate card! - state->coins += 4;//Add 4 coins to the amount of coins - state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; - state->discardCount[currentPlayer]++; - for (; p < state->handCount[currentPlayer]; p++) { - state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1]; - } - state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; - state->handCount[currentPlayer]--; - card_not_discarded = 0;//Exit the loop - } - else if (p > state->handCount[currentPlayer]) { - if(DEBUG) { - printf("No estate cards in your hand, invalid choice\n"); - printf("Must gain an estate if there are any\n"); - } - if (supplyCount(estate, state) > 0) { - gainCard(estate, state, 0, currentPlayer); - - state->supplyCount[estate]--;//Decrement estates - if (supplyCount(estate, state) == 0) { - isGameOver(state); - } - } - card_not_discarded = 0;//Exit the loop - } - - else { - p++;//Next card - } - } - } - - else { - if (supplyCount(estate, state) > 0) { - gainCard(estate, state, 0, currentPlayer);//Gain an estate - - state->supplyCount[estate]--;//Decrement Estates - if (supplyCount(estate, state) == 0) { - isGameOver(state); - } - } - } - - - return 0; - + return baronEffect(state, choice1); case great_hall: //+1 Card drawCard(currentPlayer, state); @@ -953,54 +1248,7 @@ int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState return 0; case minion: - //+1 action - state->numActions++; - - //discard card from hand - discardCard(handPos, currentPlayer, state, 0); - - if (choice1) - { - state->coins = state->coins + 2; - } - else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 - { - //discard hand - while(numHandCards(state) > 0) - { - discardCard(handPos, currentPlayer, state, 0); - } - - //draw 4 - for (i = 0; i < 4; i++) - { - drawCard(currentPlayer, state); - } - - //other players discard hand and redraw if hand size > 4 - for (i = 0; i < state->numPlayers; i++) - { - if (i != currentPlayer) - { - if ( state->handCount[i] > 4 ) - { - //discard hand - while( state->handCount[i] > 0 ) - { - discardCard(handPos, i, state, 0); - } - - //draw 4 - for (j = 0; j < 4; j++) - { - drawCard(i, state); - } - } - } - } - - } - return 0; + return minionEffect(state, choice1, choice2, handPos); case steward: if (choice1 == 1) @@ -1026,121 +1274,10 @@ int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState return 0; case tribute: - if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) { - if (state->deckCount[nextPlayer] > 0) { - tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; - state->deckCount[nextPlayer]--; - } - else if (state->discardCount[nextPlayer] > 0) { - tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1]; - state->discardCount[nextPlayer]--; - } - else { - //No Card to Reveal - if (DEBUG) { - printf("No cards to reveal\n"); - } - } - } - - else { - if (state->deckCount[nextPlayer] == 0) { - for (i = 0; i < state->discardCount[nextPlayer]; i++) { - state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck - state->deckCount[nextPlayer]++; - state->discard[nextPlayer][i] = -1; - state->discardCount[nextPlayer]--; - } - - shuffle(nextPlayer,state);//Shuffle the deck - } - tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; - state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; - state->deckCount[nextPlayer]--; - tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; - state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; - state->deckCount[nextPlayer]--; - } - - if (tributeRevealedCards[0] == tributeRevealedCards[1]) { //If we have a duplicate card, just drop one - state->playedCards[state->playedCardCount] = tributeRevealedCards[1]; - state->playedCardCount++; - tributeRevealedCards[1] = -1; - } - - for (i = 0; i <= 2; i ++) { - if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) { //Treasure cards - state->coins += 2; - } - - else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall) { //Victory Card Found - drawCard(currentPlayer, state); - drawCard(currentPlayer, state); - } - else { //Action Card - state->numActions = state->numActions + 2; - } - } - - return 0; + return tributeEffect(state, handPos); case ambassador: - j = 0; //used to check if player has enough cards to discard - - if (choice2 > 2 || choice2 < 0) - { - return -1; - } - - if (choice1 == handPos) - { - return -1; - } - - for (i = 0; i < state->handCount[currentPlayer]; i++) - { - if (i != handPos && i == state->hand[currentPlayer][choice1] && i != choice1) - { - j++; - } - } - if (j < choice2) - { - return -1; - } - - if (DEBUG) - printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]); - - //increase supply count for choosen card by amount being discarded - state->supplyCount[state->hand[currentPlayer][choice1]] += choice2; - - //each other player gains a copy of revealed card - for (i = 0; i < state->numPlayers; i++) - { - if (i != currentPlayer) - { - gainCard(state->hand[currentPlayer][choice1], state, 0, i); - } - } - - //discard played card from hand - discardCard(handPos, currentPlayer, state, 0); - - //trash copies of cards returned to supply - for (j = 0; j < choice2; j++) - { - for (i = 0; i < state->handCount[currentPlayer]; i++) - { - if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1]) - { - discardCard(i, currentPlayer, state, 1); - break; - } - } - } - - return 0; + return ambassadorEffect(state, choice1, choice2, handPos); case cutpurse: @@ -1166,9 +1303,7 @@ int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState break; } } - } - } //discard played card from hand @@ -1176,13 +1311,12 @@ int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState return 0; - case embargo: //+2 Coins state->coins = state->coins + 2; //see if selected pile is in play - if ( state->supplyCount[choice1] == -1 ) + if (state->supplyCount[choice1] == -1) { return -1; } @@ -1209,7 +1343,7 @@ int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState if (choice1) { //gain coins equal to trashed card - state->coins = state->coins + getCost( handCard(choice1, state) ); + state->coins = state->coins + getCost(handCard(choice1, state)); //trash card discardCard(choice1, currentPlayer, state, 1); } @@ -1219,12 +1353,14 @@ int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState return 0; case sea_hag: - for (i = 0; i < state->numPlayers; i++) { - if (i != currentPlayer) { + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; state->deckCount[i]--; state->discardCount[i]++; - state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse + state->deck[i][state->deckCount[i]--] = curse; //Top card now a curse } } return 0; @@ -1278,12 +1414,12 @@ int discardCard(int handPos, int currentPlayer, struct gameState *state, int tra state->hand[currentPlayer][handPos] = -1; //remove card from player's hand - if ( handPos == (state->handCount[currentPlayer] - 1) ) //last card in hand array is played + if (handPos == (state->handCount[currentPlayer] - 1)) //last card in hand array is played { //reduce number of cards in hand state->handCount[currentPlayer]--; } - else if ( state->handCount[currentPlayer] == 1 ) //only one card in hand + else if (state->handCount[currentPlayer] == 1) //only one card in hand { //reduce number of cards in hand state->handCount[currentPlayer]--; @@ -1291,7 +1427,7 @@ int discardCard(int handPos, int currentPlayer, struct gameState *state, int tra else { //replace discarded card with last card in hand - state->hand[currentPlayer][handPos] = state->hand[currentPlayer][ (state->handCount[currentPlayer] - 1)]; + state->hand[currentPlayer][handPos] = state->hand[currentPlayer][(state->handCount[currentPlayer] - 1)]; //set last card to -1 state->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1; //reduce number of cards in hand @@ -1306,7 +1442,7 @@ int gainCard(int supplyPos, struct gameState *state, int toFlag, int player) //Note: supplyPos is enum of choosen card //check if supply pile is empty (0) or card is not used in game (-1) - if ( supplyCount(supplyPos, state) < 1 ) + if (supplyCount(supplyPos, state) < 1) { return -1; } @@ -1318,17 +1454,17 @@ int gainCard(int supplyPos, struct gameState *state, int toFlag, int player) if (toFlag == 1) { - state->deck[ player ][ state->deckCount[player] ] = supplyPos; + state->deck[player][state->deckCount[player]] = supplyPos; state->deckCount[player]++; } else if (toFlag == 2) { - state->hand[ player ][ state->handCount[player] ] = supplyPos; + state->hand[player][state->handCount[player]] = supplyPos; state->handCount[player]++; } else { - state->discard[player][ state->discardCount[player] ] = supplyPos; + state->discard[player][state->discardCount[player]] = supplyPos; state->discardCount[player]++; } @@ -1368,6 +1504,4 @@ int updateCoins(int player, struct gameState *state, int bonus) return 0; } - //end of dominion.c - diff --git a/dominion/dominion.c.gcov b/dominion/dominion.c.gcov new file mode 100644 index 000000000..2e0a8d298 --- /dev/null +++ b/dominion/dominion.c.gcov @@ -0,0 +1,1936 @@ + -: 0:Source:dominion.c + -: 0:Graph:dominion.gcno + -: 0:Data:dominion.gcda + -: 0:Runs:3 + -: 0:Programs:3 + -: 1:#include "dominion.h" + -: 2:#include "dominion_helpers.h" + -: 3:#include "rngs.h" + -: 4:#include + -: 5:#include + -: 6:#include + -: 7: +function compare called 93382020 returned 100% blocks executed 100% + 93382020: 8:int compare(const void* a, const void* b) { + 93382020: 9: if (*(int*)a > *(int*)b) +branch 0 taken 1% (fallthrough) +branch 1 taken 99% + 45588: 10: return 1; + 93336432: 11: if (*(int*)a < *(int*)b) +branch 0 taken 27% (fallthrough) +branch 1 taken 73% + 24916392: 12: return -1; + 68420040: 13: return 0; + -: 14:} + -: 15: +function newGame called 0 returned 0% blocks executed 0% + #####: 16:struct gameState* newGame() { + #####: 17: struct gameState* g = malloc(sizeof(struct gameState)); + #####: 18: return g; + -: 19:} + -: 20: +function kingdomCards called 0 returned 0% blocks executed 0% + #####: 21:int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + -: 22: int k8, int k9, int k10) { + #####: 23: int* k = malloc(10 * sizeof(int)); + #####: 24: k[0] = k1; + #####: 25: k[1] = k2; + #####: 26: k[2] = k3; + #####: 27: k[3] = k4; + #####: 28: k[4] = k5; + #####: 29: k[5] = k6; + #####: 30: k[6] = k7; + #####: 31: k[7] = k8; + #####: 32: k[8] = k9; + #####: 33: k[9] = k10; + #####: 34: return k; + -: 35:} + -: 36: +function initializeGame called 2073550 returned 100% blocks executed 95% + 2073550: 37:int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, + -: 38: struct gameState *state) { + -: 39: int i; + -: 40: int j; + -: 41: int it; + -: 42: + -: 43: //set up random number generator + 2073550: 44: SelectStream(1); +call 0 returned 100% + 2073550: 45: PutSeed((long)randomSeed); +call 0 returned 100% + -: 46: + -: 47: //check number of players + 2073550: 48: if (numPlayers > MAX_PLAYERS || numPlayers < 2) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 49: { + #####: 50: return -1; + -: 51: } + -: 52: + -: 53: //set number of players + 2073550: 54: state->numPlayers = numPlayers; + -: 55: + -: 56: //check selected kingdom cards are different + 22809050: 57: for (i = 0; i < 10; i++) +branch 0 taken 91% +branch 1 taken 9% (fallthrough) + -: 58: { +228090500: 59: for (j = 0; j < 10; j++) +branch 0 taken 91% +branch 1 taken 9% (fallthrough) + -: 60: { +207355000: 61: if (j != i && kingdomCards[j] == kingdomCards[i]) +branch 0 taken 90% (fallthrough) +branch 1 taken 10% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 62: { + #####: 63: return -1; + -: 64: } + -: 65: } + -: 66: } + -: 67: + -: 68: + -: 69: //initialize supply + -: 70: /////////////////////////////// + -: 71: + -: 72: //set number of Curse cards + 2073550: 73: if (numPlayers == 2) +branch 0 taken 33% (fallthrough) +branch 1 taken 67% + -: 74: { + 691948: 75: state->supplyCount[curse] = 10; + -: 76: } + 1381602: 77: else if (numPlayers == 3) +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + -: 78: { + 690892: 79: state->supplyCount[curse] = 20; + -: 80: } + -: 81: else + -: 82: { + 690710: 83: state->supplyCount[curse] = 30; + -: 84: } + -: 85: + -: 86: //set number of Victory cards + 2073550: 87: if (numPlayers == 2) +branch 0 taken 33% (fallthrough) +branch 1 taken 67% + -: 88: { + 691948: 89: state->supplyCount[estate] = 8; + 691948: 90: state->supplyCount[duchy] = 8; + 691948: 91: state->supplyCount[province] = 8; + -: 92: } + -: 93: else + -: 94: { + 1381602: 95: state->supplyCount[estate] = 12; + 1381602: 96: state->supplyCount[duchy] = 12; + 1381602: 97: state->supplyCount[province] = 12; + -: 98: } + -: 99: + -: 100: //set number of Treasure cards + 2073550: 101: state->supplyCount[copper] = 60 - (7 * numPlayers); + 2073550: 102: state->supplyCount[silver] = 40; + 2073550: 103: state->supplyCount[gold] = 30; + -: 104: + -: 105: //set number of Kingdom cards + 43544550: 106: for (i = adventurer; i <= treasure_map; i++) //loop all cards +branch 0 taken 95% +branch 1 taken 5% (fallthrough) + -: 107: { +342135750: 108: for (j = 0; j < 10; j++) //loop chosen cards +branch 0 taken 94% +branch 1 taken 6% (fallthrough) + -: 109: { +321400250: 110: if (kingdomCards[j] == i) +branch 0 taken 6% (fallthrough) +branch 1 taken 94% + -: 111: { + -: 112: //check if card is a 'Victory' Kingdom card + 20735500: 113: if (kingdomCards[j] == great_hall || kingdomCards[j] == gardens) +branch 0 taken 90% (fallthrough) +branch 1 taken 10% +branch 2 taken 11% (fallthrough) +branch 3 taken 89% + -: 114: { + 8294200: 115: if (numPlayers == 2) { +branch 0 taken 33% (fallthrough) +branch 1 taken 67% + 1383896: 116: state->supplyCount[i] = 8; + -: 117: } + -: 118: else { + 2763204: 119: state->supplyCount[i] = 12; + -: 120: } + -: 121: } + -: 122: else + -: 123: { + 16588400: 124: state->supplyCount[i] = 10; + -: 125: } + 20735500: 126: break; + -: 127: } + -: 128: else //card is not in the set choosen for the game + -: 129: { +300664750: 130: state->supplyCount[i] = -1; + -: 131: } + -: 132: } + -: 133: + -: 134: } + -: 135: + -: 136: //////////////////////// + -: 137: //supply intilization complete + -: 138: + -: 139: //set player decks + 8292962: 140: for (i = 0; i < numPlayers; i++) +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + -: 141: { + 6219412: 142: state->deckCount[i] = 0; + 24877648: 143: for (j = 0; j < 3; j++) +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + -: 144: { + 18658236: 145: state->deck[i][j] = estate; + 18658236: 146: state->deckCount[i]++; + -: 147: } + 49755296: 148: for (j = 3; j < 10; j++) +branch 0 taken 88% +branch 1 taken 13% (fallthrough) + -: 149: { + 43535884: 150: state->deck[i][j] = copper; + 43535884: 151: state->deckCount[i]++; + -: 152: } + -: 153: } + -: 154: + -: 155: //shuffle player decks + 8292962: 156: for (i = 0; i < numPlayers; i++) +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + -: 157: { + 6219412: 158: if ( shuffle(i, state) < 0 ) +call 0 returned 100% +branch 1 taken 0% (fallthrough) +branch 2 taken 100% + -: 159: { + #####: 160: return -1; + -: 161: } + -: 162: } + -: 163: + -: 164: //draw player hands + 8292962: 165: for (i = 0; i < numPlayers; i++) +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + -: 166: { + -: 167: //initialize hand size to zero + 6219412: 168: state->handCount[i] = 0; + 6219412: 169: state->discardCount[i] = 0; + -: 170: //draw 5 cards + -: 171: // for (j = 0; j < 5; j++) + -: 172: // { + -: 173: // drawCard(i, state); + -: 174: // } + -: 175: } + -: 176: + -: 177: //set embargo tokens to 0 for all supply piles + 58059400: 178: for (i = 0; i <= treasure_map; i++) +branch 0 taken 96% +branch 1 taken 4% (fallthrough) + -: 179: { + 55985850: 180: state->embargoTokens[i] = 0; + -: 181: } + -: 182: + -: 183: //initialize first player's turn + 2073550: 184: state->outpostPlayed = 0; + 2073550: 185: state->phase = 0; + 2073550: 186: state->numActions = 1; + 2073550: 187: state->numBuys = 1; + 2073550: 188: state->playedCardCount = 0; + 2073550: 189: state->whoseTurn = 0; + 2073550: 190: state->handCount[state->whoseTurn] = 0; + -: 191: //int it; move to top + -: 192: + -: 193: //Moved draw cards to here, only drawing at the start of a turn + 12441300: 194: for (it = 0; it < 5; it++) { +branch 0 taken 83% +branch 1 taken 17% (fallthrough) + 10367750: 195: drawCard(state->whoseTurn, state); +call 0 returned 100% + -: 196: } + -: 197: + 2073550: 198: updateCoins(state->whoseTurn, state, 0); +call 0 returned 100% + -: 199: + 2073550: 200: return 0; + -: 201:} + -: 202: +function shuffle called 6297823 returned 100% blocks executed 94% + 6297823: 203:int shuffle(int player, struct gameState *state) { + -: 204: + -: 205: + -: 206: int newDeck[MAX_DECK]; + 6297823: 207: int newDeckPos = 0; + -: 208: int card; + -: 209: int i; + -: 210: + 6297823: 211: if (state->deckCount[player] < 1) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + #####: 212: return -1; + 6297823: 213: qsort ((void*)(state->deck[player]), state->deckCount[player], sizeof(int), compare); +call 0 returned 100% + -: 214: /* SORT CARDS IN DECK TO ENSURE DETERMINISM! */ + -: 215: + 74946595: 216: while (state->deckCount[player] > 0) { +branch 0 taken 91% +branch 1 taken 9% (fallthrough) + 62350949: 217: card = floor(Random() * state->deckCount[player]); +call 0 returned 100% + 62350949: 218: newDeck[newDeckPos] = state->deck[player][card]; + 62350949: 219: newDeckPos++; +228253492: 220: for (i = card; i < state->deckCount[player]-1; i++) { +branch 0 taken 73% +branch 1 taken 27% (fallthrough) +165902543: 221: state->deck[player][i] = state->deck[player][i+1]; + -: 222: } + 62350949: 223: state->deckCount[player]--; + -: 224: } + 68648772: 225: for (i = 0; i < newDeckPos; i++) { +branch 0 taken 91% +branch 1 taken 9% (fallthrough) + 62350949: 226: state->deck[player][i] = newDeck[i]; + 62350949: 227: state->deckCount[player]++; + -: 228: } + -: 229: + 6297823: 230: return 0; + -: 231:} + -: 232: +function playCard called 0 returned 0% blocks executed 0% + #####: 233:int playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state) + -: 234:{ + -: 235: int card; + #####: 236: int coin_bonus = 0; //tracks coins gain from actions + -: 237: + -: 238: //check if it is the right phase + #####: 239: if (state->phase != 0) +branch 0 never executed +branch 1 never executed + -: 240: { + #####: 241: return -1; + -: 242: } + -: 243: + -: 244: //check if player has enough actions + #####: 245: if ( state->numActions < 1 ) +branch 0 never executed +branch 1 never executed + -: 246: { + #####: 247: return -1; + -: 248: } + -: 249: + -: 250: //get card played + #####: 251: card = handCard(handPos, state); +call 0 never executed + -: 252: + -: 253: //check if selected card is an action + #####: 254: if ( card < adventurer || card > treasure_map ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 255: { + #####: 256: return -1; + -: 257: } + -: 258: + -: 259: //play card + #####: 260: if ( cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0 ) +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 261: { + #####: 262: return -1; + -: 263: } + -: 264: + -: 265: //reduce number of actions + #####: 266: state->numActions--; + -: 267: + -: 268: //update coins (Treasure cards may be added with card draws) + #####: 269: updateCoins(state->whoseTurn, state, coin_bonus); +call 0 never executed + -: 270: + #####: 271: return 0; + -: 272:} + -: 273: +function buyCard called 0 returned 0% blocks executed 0% + #####: 274:int buyCard(int supplyPos, struct gameState *state) { + -: 275: int who; + -: 276: if (DEBUG) { + -: 277: printf("Entering buyCard...\n"); + -: 278: } + -: 279: + -: 280: // I don't know what to do about the phase thing. + -: 281: + #####: 282: who = state->whoseTurn; + -: 283: + #####: 284: if (state->numBuys < 1) { +branch 0 never executed +branch 1 never executed + -: 285: if (DEBUG) + -: 286: printf("You do not have any buys left\n"); + #####: 287: return -1; + #####: 288: } else if (supplyCount(supplyPos, state) <1) { +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 289: if (DEBUG) + -: 290: printf("There are not any of that type of card left\n"); + #####: 291: return -1; + #####: 292: } else if (state->coins < getCost(supplyPos)) { +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 293: if (DEBUG) + -: 294: printf("You do not have enough money to buy that. You have %d coins.\n", state->coins); + #####: 295: return -1; + -: 296: } else { + #####: 297: state->phase=1; + -: 298: //state->supplyCount[supplyPos]--; + #####: 299: gainCard(supplyPos, state, 0, who); //card goes in discard, this might be wrong.. (2 means goes into hand, 0 goes into discard) +call 0 never executed + -: 300: + #####: 301: state->coins = (state->coins) - (getCost(supplyPos)); +call 0 never executed + #####: 302: state->numBuys--; + -: 303: if (DEBUG) + -: 304: printf("You bought card number %d for %d coins. You now have %d buys and %d coins.\n", supplyPos, getCost(supplyPos), state->numBuys, state->coins); + -: 305: } + -: 306: + -: 307: //state->discard[who][state->discardCount[who]] = supplyPos; + -: 308: //state->discardCount[who]++; + -: 309: + #####: 310: return 0; + -: 311:} + -: 312: +function numHandCards called 747834 returned 100% blocks executed 100% + 747834: 313:int numHandCards(struct gameState *state) { + 747834: 314: return state->handCount[ whoseTurn(state) ]; +call 0 returned 100% + -: 315:} + -: 316: +function handCard called 0 returned 0% blocks executed 0% + #####: 317:int handCard(int handPos, struct gameState *state) { + #####: 318: int currentPlayer = whoseTurn(state); +call 0 never executed + #####: 319: return state->hand[currentPlayer][handPos]; + -: 320:} + -: 321: +function supplyCount called 1669227 returned 100% blocks executed 100% + 1669227: 322:int supplyCount(int card, struct gameState *state) { + 1669227: 323: return state->supplyCount[card]; + -: 324:} + -: 325: +function fullDeckCount called 0 returned 0% blocks executed 0% + #####: 326:int fullDeckCount(int player, int card, struct gameState *state) { + -: 327: int i; + #####: 328: int count = 0; + -: 329: + #####: 330: for (i = 0; i < state->deckCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 331: { + #####: 332: if (state->deck[player][i] == card) count++; +branch 0 never executed +branch 1 never executed + -: 333: } + -: 334: + #####: 335: for (i = 0; i < state->handCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 336: { + #####: 337: if (state->hand[player][i] == card) count++; +branch 0 never executed +branch 1 never executed + -: 338: } + -: 339: + #####: 340: for (i = 0; i < state->discardCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 341: { + #####: 342: if (state->discard[player][i] == card) count++; +branch 0 never executed +branch 1 never executed + -: 343: } + -: 344: + #####: 345: return count; + -: 346:} + -: 347: +function whoseTurn called 747834 returned 100% blocks executed 100% + 747834: 348:int whoseTurn(struct gameState *state) { + 747834: 349: return state->whoseTurn; + -: 350:} + -: 351: +function endTurn called 0 returned 0% blocks executed 0% + #####: 352:int endTurn(struct gameState *state) { + -: 353: int k; + -: 354: int i; + #####: 355: int currentPlayer = whoseTurn(state); +call 0 never executed + -: 356: + -: 357: //Discard hand + #####: 358: for (i = 0; i < state->handCount[currentPlayer]; i++) { +branch 0 never executed +branch 1 never executed + #####: 359: state->discard[currentPlayer][state->discardCount[currentPlayer]++] = state->hand[currentPlayer][i];//Discard + #####: 360: state->hand[currentPlayer][i] = -1;//Set card to -1 + -: 361: } + #####: 362: state->handCount[currentPlayer] = 0;//Reset hand count + -: 363: + -: 364: //Code for determining the player + #####: 365: if (currentPlayer < (state->numPlayers - 1)) { +branch 0 never executed +branch 1 never executed + #####: 366: state->whoseTurn = currentPlayer + 1;//Still safe to increment + -: 367: } + -: 368: else { + #####: 369: state->whoseTurn = 0;//Max player has been reached, loop back around to player 1 + -: 370: } + -: 371: + #####: 372: state->outpostPlayed = 0; + #####: 373: state->phase = 0; + #####: 374: state->numActions = 1; + #####: 375: state->coins = 0; + #####: 376: state->numBuys = 1; + #####: 377: state->playedCardCount = 0; + #####: 378: state->handCount[state->whoseTurn] = 0; + -: 379: + -: 380: //int k; move to top + -: 381: //Next player draws hand + #####: 382: for (k = 0; k < 5; k++) { +branch 0 never executed +branch 1 never executed + #####: 383: drawCard(state->whoseTurn, state);//Draw a card +call 0 never executed + -: 384: } + -: 385: + -: 386: //Update money + #####: 387: updateCoins(state->whoseTurn, state, 0); +call 0 never executed + -: 388: + #####: 389: return 0; + -: 390:} + -: 391: +function isGameOver called 0 returned 0% blocks executed 0% + #####: 392:int isGameOver(struct gameState *state) { + -: 393: int i; + -: 394: int j; + -: 395: + -: 396: //if stack of Province cards is empty, the game ends + #####: 397: if (state->supplyCount[province] == 0) +branch 0 never executed +branch 1 never executed + -: 398: { + #####: 399: return 1; + -: 400: } + -: 401: + -: 402: //if three supply pile are at 0, the game ends + #####: 403: j = 0; + #####: 404: for (i = 0; i < 25; i++) +branch 0 never executed +branch 1 never executed + -: 405: { + #####: 406: if (state->supplyCount[i] == 0) +branch 0 never executed +branch 1 never executed + -: 407: { + #####: 408: j++; + -: 409: } + -: 410: } + #####: 411: if ( j >= 3) +branch 0 never executed +branch 1 never executed + -: 412: { + #####: 413: return 1; + -: 414: } + -: 415: + #####: 416: return 0; + -: 417:} + -: 418: +function scoreFor called 0 returned 0% blocks executed 0% + #####: 419:int scoreFor (int player, struct gameState *state) { + -: 420: + -: 421: int i; + #####: 422: int score = 0; + -: 423: //score from hand + #####: 424: for (i = 0; i < state->handCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 425: { + #####: 426: if (state->hand[player][i] == curse) { +branch 0 never executed +branch 1 never executed + #####: 427: score = score - 1; + -: 428: }; + #####: 429: if (state->hand[player][i] == estate) { +branch 0 never executed +branch 1 never executed + #####: 430: score = score + 1; + -: 431: }; + #####: 432: if (state->hand[player][i] == duchy) { +branch 0 never executed +branch 1 never executed + #####: 433: score = score + 3; + -: 434: }; + #####: 435: if (state->hand[player][i] == province) { +branch 0 never executed +branch 1 never executed + #####: 436: score = score + 6; + -: 437: }; + #####: 438: if (state->hand[player][i] == great_hall) { +branch 0 never executed +branch 1 never executed + #####: 439: score = score + 1; + -: 440: }; + #####: 441: if (state->hand[player][i] == gardens) { +branch 0 never executed +branch 1 never executed + #####: 442: score = score + ( fullDeckCount(player, 0, state) / 10 ); +call 0 never executed + -: 443: }; + -: 444: } + -: 445: + -: 446: //score from discard + #####: 447: for (i = 0; i < state->discardCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 448: { + #####: 449: if (state->discard[player][i] == curse) { +branch 0 never executed +branch 1 never executed + #####: 450: score = score - 1; + -: 451: }; + #####: 452: if (state->discard[player][i] == estate) { +branch 0 never executed +branch 1 never executed + #####: 453: score = score + 1; + -: 454: }; + #####: 455: if (state->discard[player][i] == duchy) { +branch 0 never executed +branch 1 never executed + #####: 456: score = score + 3; + -: 457: }; + #####: 458: if (state->discard[player][i] == province) { +branch 0 never executed +branch 1 never executed + #####: 459: score = score + 6; + -: 460: }; + #####: 461: if (state->discard[player][i] == great_hall) { +branch 0 never executed +branch 1 never executed + #####: 462: score = score + 1; + -: 463: }; + #####: 464: if (state->discard[player][i] == gardens) { +branch 0 never executed +branch 1 never executed + #####: 465: score = score + ( fullDeckCount(player, 0, state) / 10 ); +call 0 never executed + -: 466: }; + -: 467: } + -: 468: + -: 469: //score from deck + #####: 470: for (i = 0; i < state->discardCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 471: { + #####: 472: if (state->deck[player][i] == curse) { +branch 0 never executed +branch 1 never executed + #####: 473: score = score - 1; + -: 474: }; + #####: 475: if (state->deck[player][i] == estate) { +branch 0 never executed +branch 1 never executed + #####: 476: score = score + 1; + -: 477: }; + #####: 478: if (state->deck[player][i] == duchy) { +branch 0 never executed +branch 1 never executed + #####: 479: score = score + 3; + -: 480: }; + #####: 481: if (state->deck[player][i] == province) { +branch 0 never executed +branch 1 never executed + #####: 482: score = score + 6; + -: 483: }; + #####: 484: if (state->deck[player][i] == great_hall) { +branch 0 never executed +branch 1 never executed + #####: 485: score = score + 1; + -: 486: }; + #####: 487: if (state->deck[player][i] == gardens) { +branch 0 never executed +branch 1 never executed + #####: 488: score = score + ( fullDeckCount(player, 0, state) / 10 ); +call 0 never executed + -: 489: }; + -: 490: } + -: 491: + #####: 492: return score; + -: 493:} + -: 494: +function getWinners called 0 returned 0% blocks executed 0% + #####: 495:int getWinners(int players[MAX_PLAYERS], struct gameState *state) { + -: 496: int i; + -: 497: int j; + -: 498: int highScore; + -: 499: int currentPlayer; + -: 500: + -: 501: //get score for each player + #####: 502: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 503: { + -: 504: //set unused player scores to -9999 + #####: 505: if (i >= state->numPlayers) +branch 0 never executed +branch 1 never executed + -: 506: { + #####: 507: players[i] = -9999; + -: 508: } + -: 509: else + -: 510: { + #####: 511: players[i] = scoreFor (i, state); +call 0 never executed + -: 512: } + -: 513: } + -: 514: + -: 515: //find highest score + #####: 516: j = 0; + #####: 517: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 518: { + #####: 519: if (players[i] > players[j]) +branch 0 never executed +branch 1 never executed + -: 520: { + #####: 521: j = i; + -: 522: } + -: 523: } + #####: 524: highScore = players[j]; + -: 525: + -: 526: //add 1 to players who had less turns + #####: 527: currentPlayer = whoseTurn(state); +call 0 never executed + #####: 528: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 529: { + #####: 530: if ( players[i] == highScore && i > currentPlayer ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 531: { + #####: 532: players[i]++; + -: 533: } + -: 534: } + -: 535: + -: 536: //find new highest score + #####: 537: j = 0; + #####: 538: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 539: { + #####: 540: if ( players[i] > players[j] ) +branch 0 never executed +branch 1 never executed + -: 541: { + #####: 542: j = i; + -: 543: } + -: 544: } + #####: 545: highScore = players[j]; + -: 546: + -: 547: //set winners in array to 1 and rest to 0 + #####: 548: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 549: { + #####: 550: if ( players[i] == highScore ) +branch 0 never executed +branch 1 never executed + -: 551: { + #####: 552: players[i] = 1; + -: 553: } + -: 554: else + -: 555: { + #####: 556: players[i] = 0; + -: 557: } + -: 558: } + -: 559: + #####: 560: return 0; + -: 561:} + -: 562: +function drawCard called 15673140 returned 100% blocks executed 38% + 15673140: 563:int drawCard(int player, struct gameState *state) + -: 564:{ int count; + -: 565: int deckCounter; + 15673140: 566: if (state->deckCount[player] <= 0) { //Deck is empty +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 567: + -: 568: //Step 1 Shuffle the discard pile back into a deck + -: 569: int i; + -: 570: //Move discard to deck + #####: 571: for (i = 0; i < state->discardCount[player]; i++) { +branch 0 never executed +branch 1 never executed + #####: 572: state->deck[player][i] = state->discard[player][i]; + #####: 573: state->discard[player][i] = -1; + -: 574: } + -: 575: + #####: 576: state->deckCount[player] = state->discardCount[player]; + #####: 577: state->discardCount[player] = 0;//Reset discard + -: 578: + -: 579: //Shufffle the deck + #####: 580: shuffle(player, state);//Shuffle the deck up and make it so that we can draw +call 0 never executed + -: 581: + -: 582: if (DEBUG) { //Debug statements + -: 583: printf("Deck count now: %d\n", state->deckCount[player]); + -: 584: } + -: 585: + #####: 586: state->discardCount[player] = 0; + -: 587: + -: 588: //Step 2 Draw Card + #####: 589: count = state->handCount[player];//Get current player's hand count + -: 590: + -: 591: if (DEBUG) { //Debug statements + -: 592: printf("Current hand count: %d\n", count); + -: 593: } + -: 594: + #####: 595: deckCounter = state->deckCount[player];//Create a holder for the deck count + -: 596: + #####: 597: if (deckCounter == 0) +branch 0 never executed +branch 1 never executed + #####: 598: return -1; + -: 599: + #####: 600: state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to hand + #####: 601: state->deckCount[player]--; + #####: 602: state->handCount[player]++;//Increment hand count + -: 603: } + -: 604: + -: 605: else { + 15673140: 606: int count = state->handCount[player];//Get current hand count for player + -: 607: int deckCounter; + -: 608: if (DEBUG) { //Debug statements + -: 609: printf("Current hand count: %d\n", count); + -: 610: } + -: 611: + 15673140: 612: deckCounter = state->deckCount[player];//Create holder for the deck count + 15673140: 613: state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to the hand + 15673140: 614: state->deckCount[player]--; + 15673140: 615: state->handCount[player]++;//Increment hand count + -: 616: } + -: 617: + 15673140: 618: return 0; + -: 619:} + -: 620: +function getCost called 0 returned 0% blocks executed 0% + #####: 621:int getCost(int cardNumber) + -: 622:{ + #####: 623: switch( cardNumber ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed +branch 6 never executed +branch 7 never executed +branch 8 never executed +branch 9 never executed +branch 10 never executed +branch 11 never executed +branch 12 never executed +branch 13 never executed +branch 14 never executed +branch 15 never executed +branch 16 never executed +branch 17 never executed +branch 18 never executed +branch 19 never executed +branch 20 never executed +branch 21 never executed +branch 22 never executed +branch 23 never executed +branch 24 never executed +branch 25 never executed +branch 26 never executed +branch 27 never executed + -: 624: { + -: 625: case curse: + #####: 626: return 0; + -: 627: case estate: + #####: 628: return 2; + -: 629: case duchy: + #####: 630: return 5; + -: 631: case province: + #####: 632: return 8; + -: 633: case copper: + #####: 634: return 0; + -: 635: case silver: + #####: 636: return 3; + -: 637: case gold: + #####: 638: return 6; + -: 639: case adventurer: + #####: 640: return 6; + -: 641: case council_room: + #####: 642: return 5; + -: 643: case feast: + #####: 644: return 4; + -: 645: case gardens: + #####: 646: return 4; + -: 647: case mine: + #####: 648: return 5; + -: 649: case remodel: + #####: 650: return 4; + -: 651: case smithy: + #####: 652: return 4; + -: 653: case village: + #####: 654: return 3; + -: 655: case baron: + #####: 656: return 4; + -: 657: case great_hall: + #####: 658: return 3; + -: 659: case minion: + #####: 660: return 5; + -: 661: case steward: + #####: 662: return 3; + -: 663: case tribute: + #####: 664: return 5; + -: 665: case ambassador: + #####: 666: return 3; + -: 667: case cutpurse: + #####: 668: return 4; + -: 669: case embargo: + #####: 670: return 2; + -: 671: case outpost: + #####: 672: return 5; + -: 673: case salvager: + #####: 674: return 4; + -: 675: case sea_hag: + #####: 676: return 4; + -: 677: case treasure_map: + #####: 678: return 4; + -: 679: } + -: 680: + #####: 681: return -1; + -: 682:} + -: 683: +function doMine called 0 returned 0% blocks executed 0% + #####: 684:int doMine(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) + -: 685:{ + -: 686: int i; + -: 687: int j; + -: 688: + #####: 689: j = state->hand[currentPlayer][choice1]; //store card we will trash + -: 690: + #####: 691: if (/*state->hand[currentPlayer][choice1] < copper ||*/ state->hand[currentPlayer][choice1] > gold) +branch 0 never executed +branch 1 never executed + -: 692: { + #####: 693: return -1; + -: 694: } + -: 695: + #####: 696: if (choice2 > treasure_map || choice2 < curse) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 697: { + #####: 698: return -1; + -: 699: } + -: 700: + #####: 701: if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) ) +call 0 never executed +call 1 never executed +branch 2 never executed +branch 3 never executed + -: 702: { + #####: 703: return -1; + -: 704: } + -: 705: + -: 706: //gainCard(choice2, state, 2, currentPlayer); + -: 707: + -: 708: //discard card from hand + #####: 709: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 710: + -: 711: //discard trashed card + #####: 712: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 713: { + #####: 714: if (state->hand[currentPlayer][i] == j) +branch 0 never executed +branch 1 never executed + -: 715: { + #####: 716: discardCard(i, currentPlayer, state, 0); +call 0 never executed + #####: 717: break; + -: 718: } + -: 719: } + -: 720: + #####: 721: return 0; + -: 722:} + -: 723: +function getEstateCard called 556409 returned 100% blocks executed 86% + 556409: 724:void getEstateCard(struct gameState *state, int currentPlayer) + -: 725:{ + 556409: 726: if (supplyCount(estate, state) > 0) { +call 0 returned 100% +branch 1 taken 100% (fallthrough) +branch 2 taken 0% + 556409: 727: gainCard(estate, state, 0, currentPlayer);//Gain an estate +call 0 returned 100% + -: 728: + 556409: 729: state->supplyCount[estate]--;//Decrement Estates + 556409: 730: if (supplyCount(estate, state) == 0) { +call 0 returned 100% +branch 1 taken 0% (fallthrough) +branch 2 taken 100% + #####: 731: isGameOver(state); +call 0 never executed + -: 732: } + -: 733: } + 556409: 734:} + -: 735: +function doBaron called 647059 returned 100% blocks executed 100% + 647059: 736:void doBaron(int choice1, struct gameState *state, int currentPlayer) + -: 737:{ + 647059: 738: state->numBuys++;//Increase buys by 1! + 647059: 739: state->numBuys++;//Increase buys by 1! + 647059: 740: if (choice1 > 0) { //Boolean true or going to discard an estate +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + 322771: 741: int p = 1; //0;//Iterator for hand! + 322771: 742: int card_not_discarded = 1;//Flag for discard set! + 1333592: 743: while(card_not_discarded) { +branch 0 taken 68% +branch 1 taken 32% (fallthrough) + 688050: 744: if (state->hand[currentPlayer][p] == estate) { //Found an estate card! +branch 0 taken 13% (fallthrough) +branch 1 taken 87% + 90650: 745: state->coins += 4;//Add 4 coins to the amount of coins + 90650: 746: state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; + 90650: 747: state->discardCount[currentPlayer]++; + 247791: 748: for (; p < state->handCount[currentPlayer]; p++) { +branch 0 taken 63% +branch 1 taken 37% (fallthrough) + 157141: 749: state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1]; + -: 750: } + 90650: 751: state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; + 90650: 752: state->handCount[currentPlayer]--; + 90650: 753: card_not_discarded = 0;//Exit the loop + -: 754: } + 597400: 755: else if (p > state->handCount[currentPlayer]) { +branch 0 taken 39% (fallthrough) +branch 1 taken 61% + -: 756: if(DEBUG) { + -: 757: printf("No estate cards in your hand, invalid choice\n"); + -: 758: printf("Must gain an estate if there are any\n"); + -: 759: } + 232121: 760: getEstateCard(state, currentPlayer); +call 0 returned 100% + 232121: 761: card_not_discarded = 0;//Exit the loop + -: 762: } + -: 763: + -: 764: else { + 365279: 765: p++;//Next card + -: 766: } + -: 767: } + -: 768: } + -: 769: + -: 770: else { + 324288: 771: getEstateCard(state, currentPlayer); +call 0 returned 100% + -: 772: } + 647059: 773:} + -: 774: +function doMinion called 720681 returned 100% blocks executed 100% + 720681: 775:void doMinion(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) + -: 776:{ + -: 777: int i; + -: 778: int j; + -: 779: + -: 780: //+1 action + 720681: 781: state->numActions++; + -: 782: + -: 783: //discard card from hand + 720681: 784: discardCard(handPos, currentPlayer, state, 0); +call 0 returned 100% + -: 785: + 720681: 786: if (choice1) +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + -: 787: { + 361452: 788: state->coins = state->coins + 2; + -: 789: } + 359229: 790: else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 +branch 0 taken 100% (fallthrough) +branch 1 taken 0% + -: 791: { + -: 792: //discard hand + 1107063: 793: while(numHandCards(state) > 1 /*0*/) +call 0 returned 100% +branch 1 taken 52% +branch 2 taken 48% (fallthrough) + -: 794: { + 388605: 795: discardCard(handPos, currentPlayer, state, 0); +call 0 returned 100% + -: 796: } + -: 797: + -: 798: //draw 4 + 1796145: 799: for (i = 0; i < 4; i++) +branch 0 taken 80% +branch 1 taken 20% (fallthrough) + -: 800: { + 1436916: 801: drawCard(currentPlayer, state); +call 0 returned 100% + -: 802: } + -: 803: + -: 804: //other players discard hand and redraw if hand size > 4 + 1436917: 805: for (i = 0; i < state->numPlayers; i++) +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + -: 806: { + 1077688: 807: if (i != currentPlayer) +branch 0 taken 67% (fallthrough) +branch 1 taken 33% + -: 808: { + -: 809: //if ( state->handCount[i] > 4 ) + -: 810: { + -: 811: //discard hand + 4671315: 812: while( state->handCount[i] > 0 ) +branch 0 taken 82% +branch 1 taken 18% (fallthrough) + -: 813: { + 3234397: 814: discardCard(handPos, i, state, 0); +call 0 returned 100% + -: 815: } + -: 816: + -: 817: //draw 4 + 3592295: 818: for (j = 0; j < 4; j++) +branch 0 taken 80% +branch 1 taken 20% (fallthrough) + -: 819: { + 2873836: 820: drawCard(i, state); +call 0 returned 100% + -: 821: } + -: 822: } + -: 823: } + -: 824: } + -: 825: } + 720681: 826:} + -: 827: +function doTribute called 705810 returned 100% blocks executed 100% + 705810: 828:void doTribute(struct gameState *state, int currentPlayer, int nextPlayer, int tributeRevealedCards[2]) + -: 829:{ + -: 830: int i; + -: 831: + 705810: 832: if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) { +branch 0 taken 8% (fallthrough) +branch 1 taken 92% + 58992: 833: if (state->deckCount[nextPlayer] > 0) { +branch 0 taken 33% (fallthrough) +branch 1 taken 67% + 19584: 834: tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + 19584: 835: state->deckCount[nextPlayer]--; + -: 836: } + 39408: 837: else if (state->discardCount[nextPlayer] > 0) { +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + 19581: 838: tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1]; + 19581: 839: state->discardCount[nextPlayer]--; + -: 840: } + -: 841: else { + -: 842: //No Card to Reveal + -: 843: if (DEBUG) { + -: 844: printf("No cards to reveal\n"); + -: 845: } + -: 846: } + -: 847: } + -: 848: + -: 849: else { + 646818: 850: if (state->deckCount[nextPlayer] == 0) { +branch 0 taken 12% (fallthrough) +branch 1 taken 88% + 235240: 851: for (i = 0; i < state->discardCount[nextPlayer]; i++) { +branch 0 taken 67% +branch 1 taken 33% (fallthrough) + 156829: 852: state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck + 156829: 853: state->deckCount[nextPlayer]++; + 156829: 854: state->discard[nextPlayer][i] = -1; + 156829: 855: state->discardCount[nextPlayer]--; + -: 856: } + -: 857: + 78411: 858: shuffle(nextPlayer,state);//Shuffle the deck +call 0 returned 100% + -: 859: } + 646818: 860: tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + 646818: 861: state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + 646818: 862: state->deckCount[nextPlayer]--; + 646818: 863: tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + 646818: 864: state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + 646818: 865: state->deckCount[nextPlayer]--; + -: 866: } + -: 867: + 705810: 868: if (tributeRevealedCards[0] == tributeRevealedCards[1]) { //If we have a duplicate card, just drop one +branch 0 taken 7% (fallthrough) +branch 1 taken 93% + 46711: 869: state->playedCards[state->playedCardCount] = tributeRevealedCards[1]; + 46711: 870: state->playedCardCount++; + 46711: 871: tributeRevealedCards[1] = -1; + -: 872: } + -: 873: + 2823240: 874: for (i = 0; i <= 2; i ++) { +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + 2117430: 875: if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) { //Treasure cards +branch 0 taken 97% (fallthrough) +branch 1 taken 3% +branch 2 taken 96% (fallthrough) +branch 3 taken 4% +branch 4 taken 4% (fallthrough) +branch 5 taken 96% + 216627: 876: state->numActions = state->numActions + 2; + -: 877: } + -: 878: + 1900803: 879: else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall) { //Victory Card Found +branch 0 taken 96% (fallthrough) +branch 1 taken 4% +branch 2 taken 96% (fallthrough) +branch 3 taken 4% +branch 4 taken 56% (fallthrough) +branch 5 taken 44% +branch 6 taken 93% (fallthrough) +branch 7 taken 7% +branch 8 taken 0% (fallthrough) +branch 9 taken 100% + 994638: 880: drawCard(currentPlayer, state); +call 0 returned 100% + -: 881: //drawCard(currentPlayer, state); + -: 882: } + -: 883: else { //Action Card + 906165: 884: state->coins += 2; + -: 885: } + -: 886: } + 705810: 887:} + -: 888: +function doAmbassador called 0 returned 0% blocks executed 0% + #####: 889:int doAmbassador(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) + -: 890:{ + -: 891: int i; + -: 892: int j; + -: 893: + #####: 894: j = 0; //used to check if player has enough cards to discard + -: 895: + #####: 896: if (choice2 > 3 || choice2 < 0) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 897: { + #####: 898: return -1; + -: 899: } + -: 900: + -: 901:/* + -: 902: if (choice1 == handPos) + -: 903: { + -: 904: return -1; + -: 905: } + -: 906: */ + -: 907: + #####: 908: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 909: { + #####: 910: if (i != handPos && i == state->hand[currentPlayer][choice1] && i != choice1) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed + -: 911: { + #####: 912: j++; + -: 913: } + -: 914: } + #####: 915: if (j < choice2) +branch 0 never executed +branch 1 never executed + -: 916: { + #####: 917: return -1; + -: 918: } + -: 919: + -: 920: if (DEBUG) + -: 921: printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]); + -: 922: + -: 923: //increase supply count for choosen card by amount being discarded + #####: 924: state->supplyCount[state->hand[currentPlayer][choice1]] += choice2; + -: 925: + -: 926: //each other player gains a copy of revealed card + #####: 927: for (i = 0; i < state->numPlayers; i++) +branch 0 never executed +branch 1 never executed + -: 928: { + #####: 929: if (i != currentPlayer) +branch 0 never executed +branch 1 never executed + -: 930: { + #####: 931: gainCard(state->hand[currentPlayer][choice1], state, 0, i); +call 0 never executed + -: 932: } + -: 933: } + -: 934: + -: 935: //discard played card from hand + #####: 936: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 937: + -: 938: //trash copies of cards returned to supply + #####: 939: for (j = 0; j < choice2; j++) +branch 0 never executed +branch 1 never executed + -: 940: { + #####: 941: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 942: { + #####: 943: if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1]) +branch 0 never executed +branch 1 never executed + -: 944: { + #####: 945: discardCard(i, currentPlayer, state, 1); +call 0 never executed + #####: 946: break; + -: 947: } + -: 948: } + -: 949: } + -: 950: + #####: 951: return 0; + -: 952:} + -: 953: +function cardEffect called 0 returned 0% blocks executed 0% + #####: 954:int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) + -: 955:{ + -: 956: int i; + -: 957: int j; + -: 958: int k; + -: 959: int x; + -: 960: int index; + #####: 961: int currentPlayer = whoseTurn(state); +call 0 never executed + #####: 962: int nextPlayer = currentPlayer + 1; + -: 963: + #####: 964: int tributeRevealedCards[2] = {-1, -1}; + -: 965: int temphand[MAX_HAND];// moved above the if statement + #####: 966: int drawntreasure=0; + -: 967: int cardDrawn; + #####: 968: int z = 0;// this is the counter for the temp hand + #####: 969: if (nextPlayer > (state->numPlayers - 1)) { +branch 0 never executed +branch 1 never executed + #####: 970: nextPlayer = 0; + -: 971: } + -: 972: + -: 973: + -: 974: //uses switch to select card and perform actions + #####: 975: switch( card ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed +branch 6 never executed +branch 7 never executed +branch 8 never executed +branch 9 never executed +branch 10 never executed +branch 11 never executed +branch 12 never executed +branch 13 never executed +branch 14 never executed +branch 15 never executed +branch 16 never executed +branch 17 never executed +branch 18 never executed +branch 19 never executed +branch 20 never executed + -: 976: { + -: 977: case adventurer: + #####: 978: while(drawntreasure<2) { +branch 0 never executed +branch 1 never executed + #####: 979: if (state->deckCount[currentPlayer] <1) { //if the deck is empty we need to shuffle discard and add to deck +branch 0 never executed +branch 1 never executed + #####: 980: shuffle(currentPlayer, state); +call 0 never executed + -: 981: } + #####: 982: drawCard(currentPlayer, state); +call 0 never executed + #####: 983: cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card. + #####: 984: if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed + #####: 985: drawntreasure++; + -: 986: else { + #####: 987: temphand[z]=cardDrawn; + #####: 988: state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one). + #####: 989: z++; + -: 990: } + -: 991: } + #####: 992: while(z-1>=0) { +branch 0 never executed +branch 1 never executed + #####: 993: state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn + #####: 994: z=z-1; + -: 995: } + #####: 996: return 0; + -: 997: + -: 998: case council_room: + -: 999: //+4 Cards + #####: 1000: for (i = 0; i < 4; i++) +branch 0 never executed +branch 1 never executed + -: 1001: { + #####: 1002: drawCard(currentPlayer, state); +call 0 never executed + -: 1003: } + -: 1004: + -: 1005: //+1 Buy + #####: 1006: state->numBuys++; + -: 1007: + -: 1008: //Each other player draws a card + #####: 1009: for (i = 0; i < state->numPlayers; i++) +branch 0 never executed +branch 1 never executed + -: 1010: { + #####: 1011: if ( i != currentPlayer ) +branch 0 never executed +branch 1 never executed + -: 1012: { + #####: 1013: drawCard(i, state); +call 0 never executed + -: 1014: } + -: 1015: } + -: 1016: + -: 1017: //put played card in played card pile + #####: 1018: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 1019: + #####: 1020: return 0; + -: 1021: + -: 1022: case feast: + -: 1023: //gain card with cost up to 5 + -: 1024: //Backup hand + #####: 1025: for (i = 0; i <= state->handCount[currentPlayer]; i++) { +branch 0 never executed +branch 1 never executed + #####: 1026: temphand[i] = state->hand[currentPlayer][i];//Backup card + #####: 1027: state->hand[currentPlayer][i] = -1;//Set to nothing + -: 1028: } + -: 1029: //Backup hand + -: 1030: + -: 1031: //Update Coins for Buy + #####: 1032: updateCoins(currentPlayer, state, 5); +call 0 never executed + #####: 1033: x = 1;//Condition to loop on + #####: 1034: while( x == 1) {//Buy one card +branch 0 never executed +branch 1 never executed + #####: 1035: if (supplyCount(choice1, state) <= 0) { +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 1036: if (DEBUG) + -: 1037: printf("None of that card left, sorry!\n"); + -: 1038: + -: 1039: if (DEBUG) { + -: 1040: printf("Cards Left: %d\n", supplyCount(choice1, state)); + -: 1041: } + -: 1042: } + #####: 1043: else if (state->coins < getCost(choice1)) { +call 0 never executed +branch 1 never executed +branch 2 never executed + #####: 1044: printf("That card is too expensive!\n"); +call 0 never executed + -: 1045: + -: 1046: if (DEBUG) { + -: 1047: printf("Coins: %d < %d\n", state->coins, getCost(choice1)); + -: 1048: } + -: 1049: } + -: 1050: else { + -: 1051: + -: 1052: if (DEBUG) { + -: 1053: printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + -: 1054: } + -: 1055: + #####: 1056: gainCard(choice1, state, 0, currentPlayer);//Gain the card +call 0 never executed + #####: 1057: x = 0;//No more buying cards + -: 1058: + -: 1059: if (DEBUG) { + -: 1060: printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + -: 1061: } + -: 1062: + -: 1063: } + -: 1064: } + -: 1065: + -: 1066: //Reset Hand + #####: 1067: for (i = 0; i <= state->handCount[currentPlayer]; i++) { +branch 0 never executed +branch 1 never executed + #####: 1068: state->hand[currentPlayer][i] = temphand[i]; + #####: 1069: temphand[i] = -1; + -: 1070: } + -: 1071: //Reset Hand + -: 1072: + #####: 1073: return 0; + -: 1074: + -: 1075: case gardens: + #####: 1076: return -1; + -: 1077: + -: 1078: case mine: + #####: 1079: return doMine(choice1, choice2, state, handPos, currentPlayer); +call 0 never executed + -: 1080: + -: 1081: case remodel: + #####: 1082: j = state->hand[currentPlayer][choice1]; //store card we will trash + -: 1083: + #####: 1084: if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) ) +call 0 never executed +call 1 never executed +branch 2 never executed +branch 3 never executed + -: 1085: { + #####: 1086: return -1; + -: 1087: } + -: 1088: + #####: 1089: gainCard(choice2, state, 0, currentPlayer); +call 0 never executed + -: 1090: + -: 1091: //discard card from hand + #####: 1092: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 1093: + -: 1094: //discard trashed card + #####: 1095: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 1096: { + #####: 1097: if (state->hand[currentPlayer][i] == j) +branch 0 never executed +branch 1 never executed + -: 1098: { + #####: 1099: discardCard(i, currentPlayer, state, 0); +call 0 never executed + #####: 1100: break; + -: 1101: } + -: 1102: } + -: 1103: + -: 1104: + #####: 1105: return 0; + -: 1106: + -: 1107: case smithy: + -: 1108: //+3 Cards + #####: 1109: for (i = 0; i < 3; i++) +branch 0 never executed +branch 1 never executed + -: 1110: { + #####: 1111: drawCard(currentPlayer, state); +call 0 never executed + -: 1112: } + -: 1113: + -: 1114: //discard card from hand + #####: 1115: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1116: return 0; + -: 1117: + -: 1118: case village: + -: 1119: //+1 Card + #####: 1120: drawCard(currentPlayer, state); +call 0 never executed + -: 1121: + -: 1122: //+2 Actions + #####: 1123: state->numActions = state->numActions + 2; + -: 1124: + -: 1125: //discard played card from hand + #####: 1126: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1127: return 0; + -: 1128: + -: 1129: case baron: + #####: 1130: doBaron(choice1, state, currentPlayer); +call 0 never executed + #####: 1131: return 0; + -: 1132: + -: 1133: case great_hall: + -: 1134: //+1 Card + #####: 1135: drawCard(currentPlayer, state); +call 0 never executed + -: 1136: + -: 1137: //+1 Actions + #####: 1138: state->numActions++; + -: 1139: + -: 1140: //discard card from hand + #####: 1141: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1142: return 0; + -: 1143: + -: 1144: case minion: + #####: 1145: doMinion(choice1, choice2, state, handPos, currentPlayer); +call 0 never executed + #####: 1146: return 0; + -: 1147: + -: 1148: case steward: + #####: 1149: if (choice1 == 1) +branch 0 never executed +branch 1 never executed + -: 1150: { + -: 1151: //+2 cards + #####: 1152: drawCard(currentPlayer, state); +call 0 never executed + #####: 1153: drawCard(currentPlayer, state); +call 0 never executed + -: 1154: } + #####: 1155: else if (choice1 == 2) +branch 0 never executed +branch 1 never executed + -: 1156: { + -: 1157: //+2 coins + #####: 1158: state->coins = state->coins + 2; + -: 1159: } + -: 1160: else + -: 1161: { + -: 1162: //trash 2 cards in hand + #####: 1163: discardCard(choice2, currentPlayer, state, 1); +call 0 never executed + #####: 1164: discardCard(choice3, currentPlayer, state, 1); +call 0 never executed + -: 1165: } + -: 1166: + -: 1167: //discard card from hand + #####: 1168: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1169: return 0; + -: 1170: + -: 1171: case tribute: + #####: 1172: doTribute(state, currentPlayer, nextPlayer, tributeRevealedCards); +call 0 never executed + #####: 1173: return 0; + -: 1174: + -: 1175: case ambassador: + #####: 1176: return doAmbassador(choice1, choice2, state, handPos, currentPlayer); +call 0 never executed + -: 1177: + -: 1178: case cutpurse: + -: 1179: + #####: 1180: updateCoins(currentPlayer, state, 2); +call 0 never executed + #####: 1181: for (i = 0; i < state->numPlayers; i++) +branch 0 never executed +branch 1 never executed + -: 1182: { + #####: 1183: if (i != currentPlayer) +branch 0 never executed +branch 1 never executed + -: 1184: { + #####: 1185: for (j = 0; j < state->handCount[i]; j++) +branch 0 never executed +branch 1 never executed + -: 1186: { + #####: 1187: if (state->hand[i][j] == copper) +branch 0 never executed +branch 1 never executed + -: 1188: { + #####: 1189: discardCard(j, i, state, 0); +call 0 never executed + #####: 1190: break; + -: 1191: } + #####: 1192: if (j == state->handCount[i]) +branch 0 never executed +branch 1 never executed + -: 1193: { + #####: 1194: for (k = 0; k < state->handCount[i]; k++) +branch 0 never executed +branch 1 never executed + -: 1195: { + -: 1196: if (DEBUG) + -: 1197: printf("Player %d reveals card number %d\n", i, state->hand[i][k]); + -: 1198: } + #####: 1199: break; + -: 1200: } + -: 1201: } + -: 1202: + -: 1203: } + -: 1204: + -: 1205: } + -: 1206: + -: 1207: //discard played card from hand + #####: 1208: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 1209: + #####: 1210: return 0; + -: 1211: + -: 1212: + -: 1213: case embargo: + -: 1214: //+2 Coins + #####: 1215: state->coins = state->coins + 2; + -: 1216: + -: 1217: //see if selected pile is in play + #####: 1218: if ( state->supplyCount[choice1] == -1 ) +branch 0 never executed +branch 1 never executed + -: 1219: { + #####: 1220: return -1; + -: 1221: } + -: 1222: + -: 1223: //add embargo token to selected supply pile + #####: 1224: state->embargoTokens[choice1]++; + -: 1225: + -: 1226: //trash card + #####: 1227: discardCard(handPos, currentPlayer, state, 1); +call 0 never executed + #####: 1228: return 0; + -: 1229: + -: 1230: case outpost: + -: 1231: //set outpost flag + #####: 1232: state->outpostPlayed++; + -: 1233: + -: 1234: //discard card + #####: 1235: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1236: return 0; + -: 1237: + -: 1238: case salvager: + -: 1239: //+1 buy + #####: 1240: state->numBuys++; + -: 1241: + #####: 1242: if (choice1) +branch 0 never executed +branch 1 never executed + -: 1243: { + -: 1244: //gain coins equal to trashed card + #####: 1245: state->coins = state->coins + getCost( handCard(choice1, state) ); +call 0 never executed +call 1 never executed + -: 1246: //trash card + #####: 1247: discardCard(choice1, currentPlayer, state, 1); +call 0 never executed + -: 1248: } + -: 1249: + -: 1250: //discard card + #####: 1251: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1252: return 0; + -: 1253: + -: 1254: case sea_hag: + #####: 1255: for (i = 0; i < state->numPlayers; i++) { +branch 0 never executed +branch 1 never executed + #####: 1256: if (i != currentPlayer) { +branch 0 never executed +branch 1 never executed + #####: 1257: state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; + #####: 1258: state->deckCount[i]--; + #####: 1259: state->discardCount[i]++; + #####: 1260: state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse + -: 1261: } + -: 1262: } + #####: 1263: return 0; + -: 1264: + -: 1265: case treasure_map: + -: 1266: //search hand for another treasure_map + #####: 1267: index = -1; + #####: 1268: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 1269: { + #####: 1270: if (state->hand[currentPlayer][i] == treasure_map && i != handPos) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 1271: { + #####: 1272: index = i; + #####: 1273: break; + -: 1274: } + -: 1275: } + #####: 1276: if (index > -1) +branch 0 never executed +branch 1 never executed + -: 1277: { + -: 1278: //trash both treasure cards + #####: 1279: discardCard(handPos, currentPlayer, state, 1); +call 0 never executed + #####: 1280: discardCard(index, currentPlayer, state, 1); +call 0 never executed + -: 1281: + -: 1282: //gain 4 Gold cards + #####: 1283: for (i = 0; i < 4; i++) +branch 0 never executed +branch 1 never executed + -: 1284: { + #####: 1285: gainCard(gold, state, 1, currentPlayer); +call 0 never executed + -: 1286: } + -: 1287: + -: 1288: //return success + #####: 1289: return 1; + -: 1290: } + -: 1291: + -: 1292: //no second treasure_map found in hand + #####: 1293: return -1; + -: 1294: } + -: 1295: + #####: 1296: return -1; + -: 1297:} + -: 1298: +function discardCard called 4343683 returned 100% blocks executed 100% + 4343683: 1299:int discardCard(int handPos, int currentPlayer, struct gameState *state, int trashFlag) + -: 1300:{ + -: 1301: + -: 1302: //if card is not trashed, added to Played pile + 4343683: 1303: if (trashFlag < 1) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% + -: 1304: { + -: 1305: //add card to played pile + 4343683: 1306: state->playedCards[state->playedCardCount] = state->hand[currentPlayer][handPos]; + 4343683: 1307: state->playedCardCount++; + -: 1308: } + -: 1309: + -: 1310: //set played card to -1 + 4343683: 1311: state->hand[currentPlayer][handPos] = -1; + -: 1312: + -: 1313: //remove card from player's hand + 4343683: 1314: if ( handPos == (state->handCount[currentPlayer] - 1) ) //last card in hand array is played +branch 0 taken 17% (fallthrough) +branch 1 taken 83% + -: 1315: { + -: 1316: //reduce number of cards in hand + 739365: 1317: state->handCount[currentPlayer]--; + -: 1318: } + 3604318: 1319: else if ( state->handCount[currentPlayer] == 1 ) //only one card in hand +branch 0 taken 16% (fallthrough) +branch 1 taken 84% + -: 1320: { + -: 1321: //reduce number of cards in hand + 575003: 1322: state->handCount[currentPlayer]--; + -: 1323: } + -: 1324: else + -: 1325: { + -: 1326: //replace discarded card with last card in hand + 3029315: 1327: state->hand[currentPlayer][handPos] = state->hand[currentPlayer][ (state->handCount[currentPlayer] - 1)]; + -: 1328: //set last card to -1 + 3029315: 1329: state->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1; + -: 1330: //reduce number of cards in hand + 3029315: 1331: state->handCount[currentPlayer]--; + -: 1332: } + -: 1333: + 4343683: 1334: return 0; + -: 1335:} + -: 1336: +function gainCard called 556409 returned 100% blocks executed 70% + 556409: 1337:int gainCard(int supplyPos, struct gameState *state, int toFlag, int player) + -: 1338:{ + -: 1339: //Note: supplyPos is enum of choosen card + -: 1340: + -: 1341: //check if supply pile is empty (0) or card is not used in game (-1) + 556409: 1342: if ( supplyCount(supplyPos, state) < 1 ) +call 0 returned 100% +branch 1 taken 0% (fallthrough) +branch 2 taken 100% + -: 1343: { + #####: 1344: return -1; + -: 1345: } + -: 1346: + -: 1347: //added card for [whoseTurn] current player: + -: 1348: // toFlag = 0 : add to discard + -: 1349: // toFlag = 1 : add to deck + -: 1350: // toFlag = 2 : add to hand + -: 1351: + 556409: 1352: if (toFlag == 1) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1353: { + #####: 1354: state->deck[ player ][ state->deckCount[player] ] = supplyPos; + #####: 1355: state->deckCount[player]++; + -: 1356: } + 556409: 1357: else if (toFlag == 2) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1358: { + #####: 1359: state->hand[ player ][ state->handCount[player] ] = supplyPos; + #####: 1360: state->handCount[player]++; + -: 1361: } + -: 1362: else + -: 1363: { + 556409: 1364: state->discard[player][ state->discardCount[player] ] = supplyPos; + 556409: 1365: state->discardCount[player]++; + -: 1366: } + -: 1367: + -: 1368: //decrease number in supply pile + 556409: 1369: state->supplyCount[supplyPos]--; + -: 1370: + 556409: 1371: return 0; + -: 1372:} + -: 1373: +function updateCoins called 4147100 returned 100% blocks executed 100% + 4147100: 1374:int updateCoins(int player, struct gameState *state, int bonus) + -: 1375:{ + -: 1376: int i; + -: 1377: + -: 1378: //reset coin count + 4147100: 1379: state->coins = 0; + -: 1380: + -: 1381: //add coins for each Treasure card in player's hand + 18253150: 1382: for (i = 0; i < state->handCount[player]; i++) +branch 0 taken 77% +branch 1 taken 23% (fallthrough) + -: 1383: { + 14106050: 1384: if (state->hand[player][i] == copper) +branch 0 taken 45% (fallthrough) +branch 1 taken 55% + -: 1385: { + 6412512: 1386: state->coins += 1; + -: 1387: } + 7693538: 1388: else if (state->hand[player][i] == silver) +branch 0 taken 2% (fallthrough) +branch 1 taken 98% + -: 1389: { + 191917: 1390: state->coins += 2; + -: 1391: } + 7501621: 1392: else if (state->hand[player][i] == gold) +branch 0 taken 3% (fallthrough) +branch 1 taken 97% + -: 1393: { + 192262: 1394: state->coins += 3; + -: 1395: } + -: 1396: } + -: 1397: + -: 1398: //add bonus + 4147100: 1399: state->coins += bonus; + -: 1400: + 4147100: 1401: return 0; + -: 1402:} + -: 1403: + -: 1404: + -: 1405://end of dominion.c diff --git a/dominion/dominion.gcda b/dominion/dominion.gcda new file mode 100644 index 000000000..863dde89a Binary files /dev/null and b/dominion/dominion.gcda differ diff --git a/dominion/dominion.gcno b/dominion/dominion.gcno new file mode 100644 index 000000000..ffbf6b315 Binary files /dev/null and b/dominion/dominion.gcno differ diff --git a/dominion/dominion.o b/dominion/dominion.o new file mode 100644 index 000000000..cac69eeac Binary files /dev/null and b/dominion/dominion.o differ diff --git a/dominion/randomtestcard1 b/dominion/randomtestcard1 new file mode 100644 index 000000000..658665dc1 Binary files /dev/null and b/dominion/randomtestcard1 differ diff --git a/dominion/randomtestcard1.c b/dominion/randomtestcard1.c new file mode 100644 index 000000000..8ced8f990 --- /dev/null +++ b/dominion/randomtestcard1.c @@ -0,0 +1,123 @@ +#include +#include +#include +#include +#include "dominion.h" + +int baronEffect(struct gameState *state, int choiceDiscardCard); +int updateCoins(int player, struct gameState *state, int bonus); + +void assert(int a, unsigned int* counter) { + if (!a) { + (*counter)++; + } +} + +void assertEqual(int a, int b, unsigned int* counter) { + if (a != b) { + (*counter)++; + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int cardCount(int *container, int size, int card) { + int count = 0; + + for (int i=0; i < size; i++) { + if (container[i] == card) { + count++; + } + } + return count; +} + +int main() { + int seed = 47; + int numPlayers; + int currentPlayer; + int choice1; + int baronPosition; + int estatePosition; + int estateInHand; + time_t start; + time_t duration = 5; + unsigned int numTests = 0; + unsigned int buyFails = 0; + unsigned int estateDiscardFails = 0; + unsigned int baronDiscardFails = 0; + unsigned int estateGainFails = 0; + unsigned int coinIncreaseFails = 0; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, baron, great_hall }; + + // declare the game state + struct gameState G, G2; + + // Initialize random number generator + srand(time(0)); + + printf("\nBegin Testing baronEffect():\n\n"); + start = time(NULL); + while (time(NULL) - start < duration) { + numTests++; + printf("baronEffect test #%d\n", numTests); + numPlayers = rand() % 3 + 2; // random number of players: 2-4 + initializeGame(numPlayers, k, seed, &G); + + currentPlayer = rand() % numPlayers; // random current player: 0-numPlayers + G.whoseTurn = currentPlayer; + + // Generate 5 random cards for the player's hand + for (int i=0; i < 5; i++) { + G.hand[currentPlayer][i] = rand() % baron; // choose cards between curse and village + } + + baronPosition = rand() % 5; // random position for Baron card + G.hand[currentPlayer][baronPosition] = baron; + + //estateInHand = rand() % 2; // choose whether an estate card is in hand + estateInHand = 1; // always put estate in hand to work around infinite loop bug in teammate's code + if (estateInHand) { + while (1) { + estatePosition = rand() % 5; // random position for Estate card + if (estatePosition != baronPosition) + break; + } + G.hand[currentPlayer][estatePosition] = estate; + } + updateCoins(currentPlayer, &G, 0); + + memcpy(&G2, &G, sizeof(G)); + choice1 = rand() % 2; // choose whether to discard or gain estate card + baronEffect(&G2, choice1); + + assertEqual(G2.numBuys, G.numBuys + 1, &buyFails); + if (choice1 && estateInHand) { + assertEqual(cardCount(G2.hand[currentPlayer], G2.handCount[currentPlayer], estate), + cardCount(G.hand[currentPlayer], G.handCount[currentPlayer], estate) - 1, &estateDiscardFails); + assertEqual(G2.coins, G.coins + 4, &coinIncreaseFails); + } + assert(containsCard(G2.playedCards, G2.playedCardCount, baron), &baronDiscardFails); + if (!choice1) + assert(containsCard(G2.discard[currentPlayer], G2.discardCount[currentPlayer], estate), &estateGainFails); + } + printf("Number of tests run: %d\n", numTests); + printf("Number of times numBuys was not increased by 1: %d\n", buyFails); + printf("Number of times Estate card was not discarded: %d\n", estateDiscardFails); + printf("Number of times Baron card was not discarded: %d\n", baronDiscardFails); + printf("Number of times Estate card was not gained: %d\n", estateGainFails); + printf("Number of times coins was not increased by 4: %d\n", coinIncreaseFails); + + printf("End of baronEffect() Tests\n\n"); + return 0; +} diff --git a/dominion/randomtestcard1.gcda b/dominion/randomtestcard1.gcda new file mode 100644 index 000000000..189119319 Binary files /dev/null and b/dominion/randomtestcard1.gcda differ diff --git a/dominion/randomtestcard1.gcno b/dominion/randomtestcard1.gcno new file mode 100644 index 000000000..975deb27e Binary files /dev/null and b/dominion/randomtestcard1.gcno differ diff --git a/dominion/randomtestcard2 b/dominion/randomtestcard2 new file mode 100644 index 000000000..dd5c3c780 Binary files /dev/null and b/dominion/randomtestcard2 differ diff --git a/dominion/randomtestcard2.c b/dominion/randomtestcard2.c new file mode 100644 index 000000000..d2825ca28 --- /dev/null +++ b/dominion/randomtestcard2.c @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include "dominion.h" + +int minionEffect(struct gameState *state, int choiceGainCoins, int choiceDiscard, int handPos); +int updateCoins(int player, struct gameState *state, int bonus); + +void assert(int a, unsigned int* counter) { + if (!a) { + (*counter)++; + } +} + +void assertEqual(int a, int b, unsigned int* counter) { + if (a != b) { + (*counter)++; + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int main() { + int seed = 47; + int numPlayers; + int currentPlayer; + int choice1; + int choice2; + int minionPosition; + time_t start; + time_t duration = 5; + unsigned int numTests = 0; + unsigned int actionFails = 0; + unsigned int minionDiscardFails = 0; + unsigned int curPlayerDiscardFails = 0; + unsigned int shouldDiscardFails = 0; + unsigned int shouldNotDiscardFails = 0; + unsigned int coinIncreaseFails = 0; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, minion, great_hall }; + + // declare the game state + struct gameState G, G2; + + // Initialize random number generator + srand(time(0)); + + printf("\nBegin Testing minionEffect():\n\n"); + start = time(NULL); + while (time(NULL) - start < duration) { + numTests++; + numPlayers = rand() % 3 + 2; // random number of players: 2-4 + initializeGame(numPlayers, k, seed, &G); + + currentPlayer = rand() % numPlayers; // random current player: 0-numPlayers + G.whoseTurn = currentPlayer; + + // Generate 5 random cards for the player's hand + for (int i=0; i < 5; i++) { + G.hand[currentPlayer][i] = rand() % baron; // choose cards between curse and village + } + + minionPosition = rand() % 5; // random position for Minion card + G.hand[currentPlayer][minionPosition] = minion; + updateCoins(currentPlayer, &G, 0); + + if (rand() % 2 == 1) { + choice1 = 1; + choice2 = 0; + } + else { + choice1 = 0; + choice2 = 1; + for (int i=0; i < numPlayers; i++) { + if (i != currentPlayer) { + G.handCount[i] = rand() % 4 + 3; + } + } + } + + memcpy(&G2, &G, sizeof(G)); + minionEffect(&G2, choice1, choice2, minionPosition); + assertEqual(G2.numActions, G.numActions + 1, &actionFails); + assert(containsCard(G2.playedCards, G2.playedCardCount, minion), &minionDiscardFails); + if (choice1) { + assertEqual(G2.coins, G.coins + 2, &coinIncreaseFails); + } + else { + assertEqual(G2.handCount[currentPlayer], 4, &curPlayerDiscardFails); + for (int i=0; i < numPlayers; i++) { + if (i != currentPlayer) { + if (G.handCount[i] > 4) + assertEqual(G2.handCount[i], 4, &shouldDiscardFails); + else + assertEqual(G2.handCount[i], G.handCount[i], &shouldNotDiscardFails); + } + } + } + } + printf("Number of tests run: %d\n", numTests); + printf("Number of times numActions was not increased by 1: %d\n", actionFails); + printf("Number of times Minion card was not discarded: %d\n", minionDiscardFails); + printf("Number of times current player didn't discard hand correctly: %d\n", curPlayerDiscardFails); + printf("Number of times a player with 5 or more cards didn't discard: %d\n", shouldDiscardFails); + printf("Number of times a player with less than 5 cards did discard: %d\n", shouldNotDiscardFails); + printf("Number of times coins was not increased by 2: %d\n", coinIncreaseFails); + + printf("End of minionEffect() Tests\n\n"); + return 0; +} diff --git a/dominion/randomtestcard2.gcda b/dominion/randomtestcard2.gcda new file mode 100644 index 000000000..3d16734d4 Binary files /dev/null and b/dominion/randomtestcard2.gcda differ diff --git a/dominion/randomtestcard2.gcno b/dominion/randomtestcard2.gcno new file mode 100644 index 000000000..c6b256665 Binary files /dev/null and b/dominion/randomtestcard2.gcno differ diff --git a/dominion/randomtestcard3 b/dominion/randomtestcard3 new file mode 100644 index 000000000..005eedec2 Binary files /dev/null and b/dominion/randomtestcard3 differ diff --git a/dominion/randomtestcard3.c b/dominion/randomtestcard3.c new file mode 100644 index 000000000..b8b3c4720 --- /dev/null +++ b/dominion/randomtestcard3.c @@ -0,0 +1,157 @@ +#include +#include +#include +#include +#include "dominion.h" + +int tributeEffect(struct gameState *state, int handPos); +int updateCoins(int player, struct gameState *state, int bonus); + +void assert(int a, unsigned int* counter) { + if (!a) { + (*counter)++; + } +} + +void assertEqual(int a, int b, unsigned int* counter) { + if (a != b) { + (*counter)++; + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int cardCount(int *container, int size, int card) { + int count = 0; + + for (int i=0; i < size; i++) { + if (container[i] == card) { + count++; + } + } + return count; +} + +int main() { + int seed = 47; + int numPlayers; + int currentPlayer; + int nextPlayer; + int tributePosition; + int tributeRevealedCards[2]; + int numDeckCards; + int numDiscardCards; + int maxTributeCards; + int numExpectedCardEffects; + int numCardEffects; + int result; + time_t start; + time_t duration = 5; + unsigned int numTests = 0; + unsigned int numEffectsFails = 0; + unsigned int numActionFails = 0; + unsigned int numTreasureFails = 0; + unsigned int numVictoryFails = 0; + unsigned int tributeDiscardFails = 0; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, tribute, great_hall }; + + // declare the game state + struct gameState G, G2; + + // Initialize random number generator + srand(time(0)); + + printf("\nBegin Testing tributeEffect():\n\n"); + start = time(NULL); + while (time(NULL) - start < duration) { + numTests++; + numPlayers = rand() % 3 + 2; // random number of players: 2-4 + initializeGame(numPlayers, k, seed, &G); + + currentPlayer = rand() % numPlayers; // random current player: 0-numPlayers + G.whoseTurn = currentPlayer; + nextPlayer = (currentPlayer + 1) % numPlayers; + + // Generate 5 random cards for the player's hand + for (int i=0; i < 5; i++) { + G.hand[currentPlayer][i] = rand() % baron; // choose cards between curse and village + } + + tributePosition = rand() % 5; // random position for Tribute card + G.hand[currentPlayer][tributePosition] = tribute; + updateCoins(currentPlayer, &G, 0); + + numDeckCards = rand() % 6; + numDiscardCards = rand() % 6; + maxTributeCards = numDeckCards + numDiscardCards; + // Generate random cards for the next player's deck + for (int i=0; i < numDeckCards; i++) { + G.deck[nextPlayer][i] = rand() % baron; // choose cards between curse and village + } + G.deckCount[nextPlayer] = numDeckCards; + // Generate random cards for the next player's discard + for (int i=0; i < numDiscardCards; i++) { + G.discard[nextPlayer][i] = rand() % baron; // choose cards between curse and village + } + G.discardCount[nextPlayer] = numDiscardCards; + + memcpy(&G2, &G, sizeof(G)); + tributeEffect(&G2, tributePosition); + tributeRevealedCards[0] = G2.discard[nextPlayer][G2.discardCount[nextPlayer]-1]; + tributeRevealedCards[1] = G2.discard[nextPlayer][G2.discardCount[nextPlayer]-2]; + + // Calculate the number of expected card effects + if (maxTributeCards < 2) { + numExpectedCardEffects = maxTributeCards; + } + else if (tributeRevealedCards[0] == tributeRevealedCards[1]) { + numExpectedCardEffects = 1; + } + else { + numExpectedCardEffects = 2; + } + numCardEffects = 0; + if (G2.deckCount[currentPlayer] != G.deckCount[currentPlayer]) + numCardEffects++; + if (G2.coins != G.coins) + numCardEffects++; + if (G2.numActions != G.numActions) + numCardEffects++; + assertEqual(numCardEffects, numExpectedCardEffects, &numEffectsFails); + for (int i=0; i < numExpectedCardEffects; i++) { + // Check for Victory card + if (tributeRevealedCards[i] < copper) { + assertEqual(G2.deckCount[currentPlayer], G.deckCount[currentPlayer]-2, &numVictoryFails); + } + // Check for Treasure card + else if (tributeRevealedCards[i] <= gold) { + assertEqual(G2.coins, G.coins+2, &numTreasureFails); + } + // Else it must be an Action card + else { + assertEqual(G2.numActions, G.numActions+2, &numActionFails); + } + } + result = containsCard(G2.playedCards, G2.playedCardCount, tribute); + assert(result, &tributeDiscardFails); + } + printf("Number of tests run: %d\n", numTests); + printf("Number of times the number of effects was incorrect: %d\n", numEffectsFails); + printf("Number of times two cards weren't drawn correctly: %d\n", numVictoryFails); + printf("Number of times coins didn't increase by 2, when it should: %d\n", numTreasureFails); + printf("Number of times numActions didn't increase by 2, when it should: %d\n", numActionFails); + printf("Number of times Tribute card was not discarded: %d\n", tributeDiscardFails); + + printf("End of tributeEffect() Tests\n\n"); + return 0; +} diff --git a/dominion/randomtestcard3.gcda b/dominion/randomtestcard3.gcda new file mode 100644 index 000000000..b8dbfa83b Binary files /dev/null and b/dominion/randomtestcard3.gcda differ diff --git a/dominion/randomtestcard3.gcno b/dominion/randomtestcard3.gcno new file mode 100644 index 000000000..ec10ff044 Binary files /dev/null and b/dominion/randomtestcard3.gcno differ diff --git a/dominion/randomtestresults.out b/dominion/randomtestresults.out new file mode 100644 index 000000000..a8e6d490f --- /dev/null +++ b/dominion/randomtestresults.out @@ -0,0 +1,541 @@ + +Begin Testing doBaron(): + +Number of tests run: 647059 +Number of times numBuys was not increased by 1: 647059 +Number of times Estate card was not discarded: 112780 +Number of times Baron card was not discarded: 647059 +Number of times Estate card was not gained: 0 +Number of times coins was not increased by 4: 88112 +End of doBaron() Tests + +Function 'updateCoins' +Lines executed:100.00% of 11 +Branches executed:100.00% of 8 +Taken at least once:100.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:0.00% of 20 +Branches executed:0.00% of 24 +Taken at least once:0.00% of 24 +Calls executed:0.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 32 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'doMinion' +Lines executed:0.00% of 17 +Branches executed:0.00% of 16 +Taken at least once:0.00% of 16 +Calls executed:0.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:0.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:0.00% of 2 +No branches +Calls executed:0.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:95.16% of 62 +Branches executed:100.00% of 46 +Taken at least once:91.30% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:23.65% of 575 +Branches executed:21.62% of 407 +Taken at least once:18.67% of 407 +Calls executed:14.29% of 91 +Creating 'dominion.c.gcov' + + +Begin Testing doMinion(): + +Number of tests run: 720681 +Number of times numActions was not increased by 1: 0 +Number of times Minion card was not discarded: 0 +Number of times current player didn't discard hand correctly: 359229 +Number of times a player with 5 or more cards didn't discard: 0 +Number of times a player with less than 5 cards did discard: 178973 +Number of times coins was not increased by 2: 0 +End of doMinion() Tests + +Function 'updateCoins' +Lines executed:100.00% of 11 +Branches executed:100.00% of 8 +Taken at least once:100.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:100.00% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:0.00% of 20 +Branches executed:0.00% of 24 +Taken at least once:0.00% of 24 +Calls executed:0.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 32 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:95.16% of 62 +Branches executed:100.00% of 46 +Taken at least once:91.30% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:29.57% of 575 +Branches executed:27.03% of 407 +Taken at least once:23.59% of 407 +Calls executed:21.98% of 91 +Creating 'dominion.c.gcov' + + +Begin Testing doTribute(): + +Number of tests run: 705810 +Number of times the number of effects was incorrect: 217677 +Number of times two cards weren't drawn correctly: 304213 +Number of times coins didn't increase by 2, when it should: 60289 +Number of times numActions didn't increase by 2, when it should: 469058 +Number of times Tribute card was not discarded: 705810 +End of doTribute() Tests + +Function 'updateCoins' +Lines executed:100.00% of 11 +Branches executed:100.00% of 8 +Taken at least once:100.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:100.00% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:0.00% of 20 +Branches executed:0.00% of 24 +Taken at least once:0.00% of 24 +Calls executed:0.00% of 3 + +Function 'doTribute' +Lines executed:100.00% of 32 +Branches executed:100.00% of 30 +Taken at least once:96.67% of 30 +Calls executed:100.00% of 2 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:95.16% of 62 +Branches executed:100.00% of 46 +Taken at least once:91.30% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:100.00% of 6 +Branches executed:100.00% of 4 +Taken at least once:100.00% of 4 +No calls + +File 'dominion.c' +Lines executed:35.30% of 575 +Branches executed:34.40% of 407 +Taken at least once:30.96% of 407 +Calls executed:24.18% of 91 +Creating 'dominion.c.gcov' + diff --git a/dominion/rngs.gcda b/dominion/rngs.gcda new file mode 100644 index 000000000..a192edd9c Binary files /dev/null and b/dominion/rngs.gcda differ diff --git a/dominion/rngs.gcno b/dominion/rngs.gcno new file mode 100644 index 000000000..6d4435a49 Binary files /dev/null and b/dominion/rngs.gcno differ diff --git a/dominion/rngs.o b/dominion/rngs.o new file mode 100644 index 000000000..824e908fc Binary files /dev/null and b/dominion/rngs.o differ diff --git a/dominion/unittest1 b/dominion/unittest1 new file mode 100644 index 000000000..9c15748a2 Binary files /dev/null and b/dominion/unittest1 differ diff --git a/dominion/unittest1.c b/dominion/unittest1.c new file mode 100644 index 000000000..2fe020854 --- /dev/null +++ b/dominion/unittest1.c @@ -0,0 +1,99 @@ +#include +#include +#include +#include "dominion.h" + +int baronEffect(struct gameState *state, int choiceDiscardCard); + +void assert(int a, char *s) { + if (!a) { + printf("Assert failed: %s\n", s); + } +} + +void assertEqual(int a, int b, char *s) { + if (a != b) { + printf("Assert failed: %s\n", s); + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int cardCount(int *container, int size, int card) { + int count = 0; + + for (int i=0; i < size; i++) { + if (container[i] == card) { + count++; + } + } + return count; +} + +int main() { + int seed = 47; + int p; + int choice1; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, baron, great_hall }; + + // declare the game state + struct gameState G, G2; + + printf("\nBegin Testing baronEffect():\n\n"); + initializeGame(2, k, seed, &G); + G.whoseTurn = 0; + + printf("Test 1\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = baron; + choice1 = 0; // choose to gain an estate card + baronEffect(&G2, choice1); + assertEqual(G2.numBuys, G.numBuys + 1, "Number of buys not increased by 1"); + assert(containsCard(G2.discard[p], G2.discardCount[p], estate), "Estate card not gained"); + assert(containsCard(G2.playedCards, G2.playedCardCount, baron), "Baron card not discarded"); + + printf("Test 2\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = baron; + G2.hand[p][1] = estate; + choice1 = 1; // choose to discard an estate card + baronEffect(&G2, choice1); + assertEqual(G2.numBuys, G.numBuys + 1, "Number of buys not increased by 1"); + assertEqual(G2.coins, G.coins + 4, "Coins not increased by 4"); + assertEqual(cardCount(G2.hand[p], G2.handCount[p], estate), + cardCount(G.hand[p], G.handCount[p], estate) - 1, "Estate card not discarded"); + assertEqual(cardCount(G2.hand[p], G2.handCount[p], baron), + cardCount(G.hand[p], G.handCount[p], baron) - 1, "Baron card not discarded"); + + printf("Test 3\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = estate; + G2.hand[p][1] = baron; + G2.hand[p][2] = copper; + G2.hand[p][3] = copper; + G2.hand[p][4] = copper; + choice1 = 1; // choose to discard an estate card + baronEffect(&G2, choice1); + assertEqual(G2.numBuys, G.numBuys + 1, "Number of buys not increased by 1"); + assertEqual(G2.coins, G.coins + 4, "Coins not increased by 4"); + assertEqual(cardCount(G2.hand[p], G2.handCount[p], estate), + cardCount(G.hand[p], G.handCount[p], estate) - 1, "Estate card not discarded"); + assertEqual(cardCount(G2.hand[p], G2.handCount[p], baron), + cardCount(G.hand[p], G.handCount[p], baron) - 1, "Baron card not discarded"); + + printf("End of baronEffect() Tests\n\n"); + return 0; +} diff --git a/dominion/unittest2.c b/dominion/unittest2.c new file mode 100644 index 000000000..f83a8c163 --- /dev/null +++ b/dominion/unittest2.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include "dominion.h" + +int minionEffect(struct gameState *state, int choiceGainCoins, int choiceDiscard, int handPos); + +void assert(int a, char *s) { + if (!a) { + printf("Assert failed: %s\n", s); + } +} + +void assertEqual(int a, int b, char *s) { + if (a != b) { + printf("Assert failed: %s\n", s); + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int main() { + int seed = 47; + int p; + int p2; + int choice1; + int choice2; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, minion, great_hall }; + + // declare the game state + struct gameState G, G2; + + printf("\nBegin Testing minionEffect():\n\n"); + initializeGame(4, k, seed, &G); // 4 players + G.whoseTurn = 0; + + printf("Test 1\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = minion; + choice1 = 1; // choose +2 coins + choice2 = 0; + minionEffect(&G2, choice1, choice2, 0); + assertEqual(G2.numActions, G.numActions + 1, "Number of actions not increased by 1"); + assertEqual(G2.coins, G.coins + 2, "Number of coins not increased by 2"); + assert(containsCard(G2.playedCards, G2.playedCardCount, minion), "Minion card not discarded"); + + printf("Test 2\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + p2 = 2; // another player + G2.hand[p][0] = minion; + G2.handCount[p2] = 3; // change handcount from 5 to 3 + choice1 = 0; + choice2 = 1; // choose to redraw hand + minionEffect(&G2, choice1, choice2, 0); + assertEqual(G2.numActions, G.numActions + 1, "Number of actions not increased by 1"); + assertEqual(G2.handCount[p], 4, "Current player should have exactly 4 cards"); + assertEqual(G2.handCount[p2], 3, "A player with less than 5 cards discarded hand"); + assert(containsCard(G2.playedCards, G2.playedCardCount, minion), "Minion card not discarded"); + + printf("End of minionEffect() Tests\n\n"); + return 0; +} diff --git a/dominion/unittest3.c b/dominion/unittest3.c new file mode 100644 index 000000000..3d8068e58 --- /dev/null +++ b/dominion/unittest3.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include "dominion.h" + +int ambassadorEffect(struct gameState *state, int cardToDiscard, int numberOfCardsToDiscard, int handPos); + +void assert(int a, char *s) { + if (!a) { + printf("Assert failed: %s\n", s); + } +} + +void assertEqual(int a, int b, char *s) { + if (a != b) { + printf("Assert failed: %s\n", s); + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int cardCount(int *container, int size, int card) { + int count = 0; + + for (int i=0; i < size; i++) { + if (container[i] == card) { + count++; + } + } + return count; +} + +int main() { + int seed = 47; + int p; + int p2; + int handPos; + int choice1; + int choice2; + int ret_val; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, ambassador, great_hall }; + + // declare the game state + struct gameState G, G2; + + printf("\nBegin Testing ambassadorEffect():\n\n"); + initializeGame(2, k, seed, &G); + G.whoseTurn = 0; + + printf("Test 1\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + p2 = 1; + G2.hand[p][0] = copper; + G2.hand[p][1] = smithy; + G2.hand[p][2] = copper; + G2.hand[p][3] = copper; + G2.hand[p][4] = ambassador; + choice1 = 0; // choose to discard copper + choice2 = 3; // choose to discard 3 of them + handPos = 4; // ambassador + ret_val = ambassadorEffect(&G2, choice1, choice2, handPos); + assertEqual(ret_val, -1, "Didn't return -1 when trying to discard too many cards"); + assertEqual(cardCount(G2.hand[p], G2.handCount[p], copper), + cardCount(G.hand[p], G.handCount[p], copper) - choice2, "Trashed the wrong number of cards"); + assert(containsCard(G2.playedCards, G2.playedCardCount, ambassador), "Ambassador card not discarded"); + assert(containsCard(G2.discard[p2], G2.discardCount[p2], copper), "Player 2 did not gain a copper"); + + printf("Test 2\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + p2 = 1; + G2.hand[p][0] = ambassador; + G2.hand[p][1] = ambassador; + choice1 = 0; // choose to discard ambassador + choice2 = 1; // choose to discard 1 of them + handPos = 0; // ambassador + ret_val = ambassadorEffect(&G2, choice1, choice2, handPos); + assertEqual(ret_val, -1, "Didn't return -1 when trying to discard ambassador card"); + assert(containsCard(G2.playedCards, G2.playedCardCount, ambassador), "Ambassador card not discarded"); + assert(containsCard(G2.discard[p2], G2.discardCount[p2], ambassador), "Player 2 did not gain an ambassador card"); + + printf("End of ambassadorEffect() Tests\n\n"); + return 0; +} diff --git a/dominion/unittest4 b/dominion/unittest4 new file mode 100644 index 000000000..afe4efd37 Binary files /dev/null and b/dominion/unittest4 differ diff --git a/dominion/unittest4.c b/dominion/unittest4.c new file mode 100644 index 000000000..054b2907e --- /dev/null +++ b/dominion/unittest4.c @@ -0,0 +1,128 @@ +#include +#include +#include +#include "dominion.h" + +int tributeEffect(struct gameState *state, int handPos); + +void assert(int a, char *s) { + if (!a) { + printf("Assert failed: %s\n", s); + } +} + +void assertEqual(int a, int b, char *s) { + if (a != b) { + printf("Assert failed: %s\n", s); + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int cardCount(int *container, int size, int card) { + int count = 0; + + for (int i=0; i < size; i++) { + if (container[i] == card) { + count++; + } + } + return count; +} + +int main() { + int seed = 47; + int p; + int p2; + //int tributeRevealedCards[2]; + int result; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, tribute, great_hall }; + + // declare the game state + struct gameState G, G2; + + printf("\nBegin Testing tributeEffect():\n\n"); + initializeGame(2, k, seed, &G); + G.whoseTurn = 1; + + // Debug test + memcpy(&G2, &G, sizeof(G)); + p = 1; + p2 = 0; + G2.hand[p][0] = tribute; + G2.deck[p2][G2.deckCount[p2]-2] = smithy; + G2.deck[p2][G2.deckCount[p2]-1] = estate; + tributeEffect(&G2, 0); + result = containsCard(G2.playedCards, G2.playedCardCount, tribute); + assert(result, "Tribute card not discarded"); + if (result) + assertEqual(G2.handCount[p], G.handCount[p]+1, "Didn't draw 2 cards"); + else + assertEqual(G2.handCount[p], G.handCount[p]+2, "Didn't draw 2 cards"); + assertEqual(G2.numActions, G.numActions+2, "Actions didn't increase by 2"); + +/* + printf("Test 1\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + p2 = 1; + G2.hand[p][0] = tribute; + G2.deckCount[p2] = 0; + G2.discardCount[p2] = 2; + G2.discard[p2][G2.discardCount[p2]-2] = copper; + G2.discard[p2][G2.discardCount[p2]-1] = estate; + tributeEffect(&G2, 0); + result = containsCard(G2.playedCards, G2.playedCardCount, tribute); + assert(result, "Tribute card not discarded"); + if (result) + assertEqual(G2.handCount[p], G.handCount[p]+1, "Didn't draw 2 cards"); + else + assertEqual(G2.handCount[p], G.handCount[p]+2, "Didn't draw 2 cards"); + assertEqual(G2.coins, G.coins+2, "Coins didn't increase by 2"); + + printf("Test 2\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + p2 = 1; + G2.hand[p][0] = tribute; + G2.deck[p2][G2.deckCount[p2]-2] = smithy; + G2.deck[p2][G2.deckCount[p2]-1] = estate; + tributeEffect(&G2, 0); + result = containsCard(G2.playedCards, G2.playedCardCount, tribute); + assert(result, "Tribute card not discarded"); + if (result) + assertEqual(G2.handCount[p], G.handCount[p]+1, "Didn't draw 2 cards"); + else + assertEqual(G2.handCount[p], G.handCount[p]+2, "Didn't draw 2 cards"); + assertEqual(G2.numActions, G.numActions+2, "Actions didn't increase by 2"); + + printf("Test 3\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + p2 = 1; + G2.hand[p][0] = tribute; + G2.deckCount[p2] = 0; + G2.discardCount[p2] = 1; + G2.discard[p2][0] = estate; + tributeEffect(&G2, 0); + result = containsCard(G2.playedCards, G2.playedCardCount, tribute); + assert(result, "Tribute card not discarded"); + if (result) + assertEqual(G2.handCount[p], G.handCount[p]+1, "Didn't draw 2 cards"); + else + assertEqual(G2.handCount[p], G.handCount[p]+2, "Didn't draw 2 cards"); +*/ + + printf("End of tributeEffect() Tests\n\n"); + return 0; +} diff --git a/dominion/unittest4.gcda b/dominion/unittest4.gcda new file mode 100644 index 000000000..62ce12b1d Binary files /dev/null and b/dominion/unittest4.gcda differ diff --git a/dominion/unittest4.gcno b/dominion/unittest4.gcno new file mode 100644 index 000000000..2331b99ef Binary files /dev/null and b/dominion/unittest4.gcno differ diff --git a/dominion/unittest5.c b/dominion/unittest5.c new file mode 100644 index 000000000..9008593bd --- /dev/null +++ b/dominion/unittest5.c @@ -0,0 +1,99 @@ +#include +#include +#include +#include "dominion.h" + +int mineEffect(struct gameState *state, int treasureToTrash, int treasureToGain, int handPos); + +void assert(int a, char *s) { + if (!a) { + printf("Assert failed: %s\n", s); + } +} + +void assertEqual(int a, int b, char *s) { + if (a != b) { + printf("Assert failed: %s\n", s); + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int cardCount(int *container, int size, int card) { + int count = 0; + + for (int i=0; i < size; i++) { + if (container[i] == card) { + count++; + } + } + return count; +} + +int main() { + int seed = 47; + int p; + int handPos; + int choice1; + int choice2; + int ret_val; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, ambassador, great_hall }; + + // declare the game state + struct gameState G, G2; + + printf("\nBegin Testing mineEffect():\n\n"); + initializeGame(2, k, seed, &G); + G.whoseTurn = 0; + + printf("Test 1\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = curse; + G2.hand[p][1] = mine; + choice1 = 0; // choose to trash curse + choice2 = silver; // choose to gain a silver + handPos = 1; // mine + ret_val = mineEffect(&G2, choice1, choice2, handPos); + assertEqual(ret_val, -1, "Didn't return -1 when trying to trash a curse"); + + printf("Test 2\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = copper; + G2.hand[p][1] = mine; + G2.hand[p][2] = copper; + G2.hand[p][3] = estate; + G2.hand[p][4] = estate; + choice1 = 0; // choose to trash copper + choice2 = silver; // choose to gain a silver + handPos = 1; // mine + ret_val = mineEffect(&G2, choice1, choice2, handPos); + assert(containsCard(G2.playedCards, G2.playedCardCount, mine), "Mine card not discarded"); + assert(containsCard(G2.hand[p], G2.handCount[p], silver), "Silver not gained to hand"); + assert(containsCard(G2.playedCards, G2.playedCardCount, copper), "Copper card not discarded"); + + printf("Test 3\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = smithy; + G2.hand[p][1] = mine; + choice1 = 0; // choose to trash smithy + choice2 = silver; // choose to gain a silver + handPos = 1; // mine + ret_val = mineEffect(&G2, choice1, choice2, handPos); + assertEqual(ret_val, -1, "Didn't return -1 when trying to trash a smithy"); + + printf("End of mineEffect() Tests\n\n"); + return 0; +} diff --git a/projects/alghanmz/a3/dominion.c b/projects/alghanmz/a3/dominion.c new file mode 100644 index 000000000..0c865f97e --- /dev/null +++ b/projects/alghanmz/a3/dominion.c @@ -0,0 +1,1420 @@ +#include "dominion.h" +#include "dominion_helpers.h" +#include "rngs.h" +#include +#include +#include + +int compare(const void* a, const void* b) { + if (*(int*)a > *(int*)b) + return 1; + if (*(int*)a < *(int*)b) + return -1; + return 0; +} + +struct gameState* newGame() { + struct gameState* g = malloc(sizeof(struct gameState)); + return g; +} + +int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + int k8, int k9, int k10) { + int* k = malloc(10 * sizeof(int)); + k[0] = k1; + k[1] = k2; + k[2] = k3; + k[3] = k4; + k[4] = k5; + k[5] = k6; + k[6] = k7; + k[7] = k8; + k[8] = k9; + k[9] = k10; + return k; +} + +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 shuffle(int player, struct gameState *state) { + + + int newDeck[MAX_DECK]; + int newDeckPos = 0; + int card; + int i; + + if (state->deckCount[player] < 1) + return -1; + qsort ((void*)(state->deck[player]), state->deckCount[player], sizeof(int), compare); + /* SORT CARDS IN DECK TO ENSURE DETERMINISM! */ + + while (state->deckCount[player] > 0) { + card = floor(Random() * state->deckCount[player]); + newDeck[newDeckPos] = state->deck[player][card]; + newDeckPos++; + for (i = card; i < state->deckCount[player]-1; i++) { + state->deck[player][i] = state->deck[player][i+1]; + } + state->deckCount[player]--; + } + for (i = 0; i < newDeckPos; i++) { + state->deck[player][i] = newDeck[i]; + state->deckCount[player]++; + } + + return 0; +} + +int playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state) +{ + int card; + int coin_bonus = 0; //tracks coins gain from actions + + //check if it is the right phase + if (state->phase != 0) + { + return -1; + } + + //check if player has enough actions + if ( state->numActions < 1 ) + { + return -1; + } + + //get card played + card = handCard(handPos, state); + + //check if selected card is an action + if ( card < adventurer || card > treasure_map ) + { + return -1; + } + + //play card + if ( cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0 ) + { + return -1; + } + + //reduce number of actions + state->numActions--; + + //update coins (Treasure cards may be added with card draws) + updateCoins(state->whoseTurn, state, coin_bonus); + + return 0; +} + +int buyCard(int supplyPos, struct gameState *state) { + int who; + if (DEBUG) { + printf("Entering buyCard...\n"); + } + + // I don't know what to do about the phase thing. + + who = state->whoseTurn; + + if (state->numBuys < 1) { + if (DEBUG) + printf("You do not have any buys left\n"); + return -1; + } else if (supplyCount(supplyPos, state) <1) { + if (DEBUG) + printf("There are not any of that type of card left\n"); + return -1; + } else if (state->coins < getCost(supplyPos)) { + if (DEBUG) + printf("You do not have enough money to buy that. You have %d coins.\n", state->coins); + return -1; + } else { + state->phase=1; + //state->supplyCount[supplyPos]--; + gainCard(supplyPos, state, 0, who); //card goes in discard, this might be wrong.. (2 means goes into hand, 0 goes into discard) + + state->coins = (state->coins) - (getCost(supplyPos)); + state->numBuys--; + if (DEBUG) + printf("You bought card number %d for %d coins. You now have %d buys and %d coins.\n", supplyPos, getCost(supplyPos), state->numBuys, state->coins); + } + + //state->discard[who][state->discardCount[who]] = supplyPos; + //state->discardCount[who]++; + + return 0; +} + +int numHandCards(struct gameState *state) { + return state->handCount[ whoseTurn(state) ]; +} + +int handCard(int handPos, struct gameState *state) { + int currentPlayer = whoseTurn(state); + return state->hand[currentPlayer][handPos]; +} + +int supplyCount(int card, struct gameState *state) { + return state->supplyCount[card]; +} + +int fullDeckCount(int player, int card, struct gameState *state) { + int i; + int count = 0; + + for (i = 0; i < state->deckCount[player]; i++) + { + if (state->deck[player][i] == card) count++; + } + + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == card) count++; + } + + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->discard[player][i] == card) count++; + } + + return count; +} + +int whoseTurn(struct gameState *state) { + return state->whoseTurn; +} + +int endTurn(struct gameState *state) { + int k; + int i; + int currentPlayer = whoseTurn(state); + + //Discard hand + for (i = 0; i < state->handCount[currentPlayer]; i++) { + state->discard[currentPlayer][state->discardCount[currentPlayer]++] = state->hand[currentPlayer][i];//Discard + state->hand[currentPlayer][i] = -1;//Set card to -1 + } + state->handCount[currentPlayer] = 0;//Reset hand count + + //Code for determining the player + if (currentPlayer < (state->numPlayers - 1)) { + state->whoseTurn = currentPlayer + 1;//Still safe to increment + } + else { + state->whoseTurn = 0;//Max player has been reached, loop back around to player 1 + } + + state->outpostPlayed = 0; + state->phase = 0; + state->numActions = 1; + state->coins = 0; + state->numBuys = 1; + state->playedCardCount = 0; + state->handCount[state->whoseTurn] = 0; + + //int k; move to top + //Next player draws hand + for (k = 0; k < 5; k++) { + drawCard(state->whoseTurn, state);//Draw a card + } + + //Update money + updateCoins(state->whoseTurn, state, 0); + + return 0; +} + +int isGameOver(struct gameState *state) { + int i; + int j; + + //if stack of Province cards is empty, the game ends + if (state->supplyCount[province] == 0) + { + return 1; + } + + //if three supply pile are at 0, the game ends + j = 0; + for (i = 0; i < 25; i++) + { + if (state->supplyCount[i] == 0) + { + j++; + } + } + if ( j >= 3) + { + return 1; + } + + return 0; +} + +int scoreFor (int player, struct gameState *state) { + + int i; + int score = 0; + //score from hand + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == curse) { + score = score - 1; + }; + if (state->hand[player][i] == estate) { + score = score + 1; + }; + if (state->hand[player][i] == duchy) { + score = score + 3; + }; + if (state->hand[player][i] == province) { + score = score + 6; + }; + if (state->hand[player][i] == great_hall) { + score = score + 1; + }; + if (state->hand[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + //score from discard + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->discard[player][i] == curse) { + score = score - 1; + }; + if (state->discard[player][i] == estate) { + score = score + 1; + }; + if (state->discard[player][i] == duchy) { + score = score + 3; + }; + if (state->discard[player][i] == province) { + score = score + 6; + }; + if (state->discard[player][i] == great_hall) { + score = score + 1; + }; + if (state->discard[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + //score from deck + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->deck[player][i] == curse) { + score = score - 1; + }; + if (state->deck[player][i] == estate) { + score = score + 1; + }; + if (state->deck[player][i] == duchy) { + score = score + 3; + }; + if (state->deck[player][i] == province) { + score = score + 6; + }; + if (state->deck[player][i] == great_hall) { + score = score + 1; + }; + if (state->deck[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + return score; +} + +int getWinners(int players[MAX_PLAYERS], struct gameState *state) { + int i; + int j; + int highScore; + int currentPlayer; + + //get score for each player + for (i = 0; i < MAX_PLAYERS; i++) + { + //set unused player scores to -9999 + if (i >= state->numPlayers) + { + players[i] = -9999; + } + else + { + players[i] = scoreFor (i, state); + } + } + + //find highest score + j = 0; + for (i = 0; i < MAX_PLAYERS; i++) + { + if (players[i] > players[j]) + { + j = i; + } + } + highScore = players[j]; + + //add 1 to players who had less turns + currentPlayer = whoseTurn(state); + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] == highScore && i > currentPlayer ) + { + players[i]++; + } + } + + //find new highest score + j = 0; + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] > players[j] ) + { + j = i; + } + } + highScore = players[j]; + + //set winners in array to 1 and rest to 0 + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] == highScore ) + { + players[i] = 1; + } + else + { + players[i] = 0; + } + } + + return 0; +} + +int drawCard(int player, struct gameState *state) +{ int count; + int deckCounter; + if (state->deckCount[player] <= 0) { //Deck is empty + + //Step 1 Shuffle the discard pile back into a deck + int i; + //Move discard to deck + for (i = 0; i < state->discardCount[player]; i++) { + state->deck[player][i] = state->discard[player][i]; + state->discard[player][i] = -1; + } + + state->deckCount[player] = state->discardCount[player]; + state->discardCount[player] = 0;//Reset discard + + //Shufffle the deck + shuffle(player, state);//Shuffle the deck up and make it so that we can draw + + if (DEBUG) { //Debug statements + printf("Deck count now: %d\n", state->deckCount[player]); + } + + state->discardCount[player] = 0; + + //Step 2 Draw Card + count = state->handCount[player];//Get current player's hand count + + if (DEBUG) { //Debug statements + printf("Current hand count: %d\n", count); + } + + deckCounter = state->deckCount[player];//Create a holder for the deck count + + if (deckCounter == 0) + return -1; + + state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to hand + state->deckCount[player]--; + state->handCount[player]++;//Increment hand count + } + + else { + int count = state->handCount[player];//Get current hand count for player + int deckCounter; + if (DEBUG) { //Debug statements + printf("Current hand count: %d\n", count); + } + + deckCounter = state->deckCount[player];//Create holder for the deck count + state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to the hand + state->deckCount[player]--; + state->handCount[player]++;//Increment hand count + } + + return 0; +} + +int getCost(int cardNumber) +{ + switch( cardNumber ) + { + case curse: + return 0; + case estate: + return 2; + case duchy: + return 5; + case province: + return 8; + case copper: + return 0; + case silver: + return 3; + case gold: + return 6; + case adventurer: + return 6; + case council_room: + return 5; + case feast: + return 4; + case gardens: + return 4; + case mine: + return 5; + case remodel: + return 4; + case smithy: + return 4; + case village: + return 3; + case baron: + return 4; + case great_hall: + return 3; + case minion: + return 5; + case steward: + return 3; + case tribute: + return 5; + case ambassador: + return 3; + case cutpurse: + return 4; + case embargo: + return 2; + case outpost: + return 5; + case salvager: + return 4; + case sea_hag: + return 4; + case treasure_map: + return 4; + } + + return -1; +} + +int doMine(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) +{ + int i; + int j; + + j = state->hand[currentPlayer][choice1]; //store card we will trash + + if (/*state->hand[currentPlayer][choice1] < copper ||*/ state->hand[currentPlayer][choice1] > gold) + { + return -1; + } + + if (choice2 > treasure_map || choice2 < curse) + { + return -1; + } + + if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) ) + { + return -1; + } + + //gainCard(choice2, state, 2, currentPlayer); + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + //discard trashed card + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == j) + { + discardCard(i, currentPlayer, state, 0); + break; + } + } + + return 0; +} + +void getEstateCard(struct gameState *state, int currentPlayer) +{ + if (supplyCount(estate, state) > 0) { + gainCard(estate, state, 0, currentPlayer);//Gain an estate + + state->supplyCount[estate]--;//Decrement Estates + if (supplyCount(estate, state) == 0) { + isGameOver(state); + } + } +} + +void doBaron(int choice1, struct gameState *state, int currentPlayer) +{ + state->numBuys++;//Increase buys by 1! + state->numBuys++;//Increase buys by 1! + if (choice1 > 0) { //Boolean true or going to discard an estate + int p = 1; //0;//Iterator for hand! + int card_not_discarded = 1;//Flag for discard set! + while(card_not_discarded) { + if (state->hand[currentPlayer][p] == estate) { //Found an estate card! + state->coins += 4;//Add 4 coins to the amount of coins + state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; + state->discardCount[currentPlayer]++; + for (; p < state->handCount[currentPlayer]; p++) { + state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1]; + } + state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; + state->handCount[currentPlayer]--; + card_not_discarded = 0;//Exit the loop + } + else if (p > state->handCount[currentPlayer]) { + if(DEBUG) { + printf("No estate cards in your hand, invalid choice\n"); + printf("Must gain an estate if there are any\n"); + } + getEstateCard(state, currentPlayer); + card_not_discarded = 0;//Exit the loop + } + + else { + p++;//Next card + } + } + } + + else { + getEstateCard(state, currentPlayer); + } +} + +void doMinion(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) +{ + int i; + int j; + + //+1 action + state->numActions++; + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + if (choice1) + { + state->coins = state->coins + 2; + } + else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 + { + //discard hand + while(numHandCards(state) > 1 /*0*/) + { + discardCard(handPos, currentPlayer, state, 0); + } + + //draw 4 + for (i = 0; i < 4; i++) + { + drawCard(currentPlayer, state); + } + + //other players discard hand and redraw if hand size > 4 + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + //if ( state->handCount[i] > 4 ) + { + //discard hand + while( state->handCount[i] > 0 ) + { + discardCard(handPos, i, state, 0); + } + + //draw 4 + for (j = 0; j < 4; j++) + { + drawCard(i, state); + } + } + } + } + } +} + +void printDeck(struct gameState *state, int p) { + printf("Deck:"); + for (int i=0; i < state->deckCount[p]; i++) + printf(" %d", state->deck[p][i]); + printf("\n"); +} + +void printHand(struct gameState *state, int p) { + printf("Hand:"); + for (int i=0; i < state->handCount[p]; i++) + printf(" %d", state->hand[p][i]); + printf("\n"); +} + +void doTribute(struct gameState *state, int currentPlayer, int nextPlayer, int tributeRevealedCards[2]) +{ + int i; + + if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) { + if (state->deckCount[nextPlayer] > 0) { + tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + state->deckCount[nextPlayer]--; + } + else if (state->discardCount[nextPlayer] > 0) { + tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1]; + state->discardCount[nextPlayer]--; + } + else { + //No Card to Reveal + if (DEBUG) { + printf("No cards to reveal\n"); + } + } + } + + else { + if (state->deckCount[nextPlayer] == 0) { + for (i = 0; i < state->discardCount[nextPlayer]; i++) { + state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck + state->deckCount[nextPlayer]++; + state->discard[nextPlayer][i] = -1; + state->discardCount[nextPlayer]--; + } + + shuffle(nextPlayer,state);//Shuffle the deck + } + tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + //state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + //state->deckCount[nextPlayer]--; + //tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-2]; + //state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + //state->deckCount[nextPlayer]--; + } + + if (tributeRevealedCards[0] == tributeRevealedCards[1]) { //If we have a duplicate card, just drop one + state->playedCards[state->playedCardCount] = tributeRevealedCards[1]; + state->playedCardCount++; + tributeRevealedCards[1] = -1; + } + + for (i = 0; i < 2; i ++) { + if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) { //Treasure cards + state->numActions = state->numActions + 2; + } + + else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall) { //Victory Card Found + drawCard(currentPlayer, state); + //drawCard(currentPlayer, state); + } + else { //Action Card + state->coins += 2; + } + } +} + +int doAmbassador(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) +{ + int i; + int j; + + j = 0; //used to check if player has enough cards to discard + + if (choice2 > 3 || choice2 < 0) + { + return -1; + } + +/* + if (choice1 == handPos) + { + return -1; + } + */ + + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (i != handPos && state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1] /*&& i != choice1*/) + { + j++; + } + } + if (j < choice2) + { + return -1; + } + + if (DEBUG) + printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]); + + //increase supply count for choosen card by amount being discarded + state->supplyCount[state->hand[currentPlayer][choice1]] += choice2; + + //each other player gains a copy of revealed card + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + gainCard(state->hand[currentPlayer][choice1], state, 0, i); + } + } + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + + //trash copies of cards returned to supply + for (j = 0; j < choice2; j++) + { + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1]) + { + discardCard(i, currentPlayer, state, 1); + break; + } + } + } + + return 0; +} + +int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) +{ + int i; + int j; + int k; + int x; + int index; + int currentPlayer = whoseTurn(state); + int nextPlayer = currentPlayer + 1; + + int tributeRevealedCards[2] = {-1, -1}; + int temphand[MAX_HAND];// moved above the if statement + int drawntreasure=0; + int cardDrawn; + int z = 0;// this is the counter for the temp hand + if (nextPlayer > (state->numPlayers - 1)) { + nextPlayer = 0; + } + + + //uses switch to select card and perform actions + switch( card ) + { + case adventurer: + while(drawntreasure<2) { + if (state->deckCount[currentPlayer] <1) { //if the deck is empty we need to shuffle discard and add to deck + shuffle(currentPlayer, state); + } + drawCard(currentPlayer, state); + cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card. + if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold) + drawntreasure++; + else { + temphand[z]=cardDrawn; + state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one). + z++; + } + } + while(z-1>=0) { + state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn + z=z-1; + } + return 0; + + case council_room: + //+4 Cards + for (i = 0; i < 4; i++) + { + drawCard(currentPlayer, state); + } + + //+1 Buy + state->numBuys++; + + //Each other player draws a card + for (i = 0; i < state->numPlayers; i++) + { + if ( i != currentPlayer ) + { + drawCard(i, state); + } + } + + //put played card in played card pile + discardCard(handPos, currentPlayer, state, 0); + + return 0; + + case feast: + //gain card with cost up to 5 + //Backup hand + for (i = 0; i <= state->handCount[currentPlayer]; i++) { + temphand[i] = state->hand[currentPlayer][i];//Backup card + state->hand[currentPlayer][i] = -1;//Set to nothing + } + //Backup hand + + //Update Coins for Buy + updateCoins(currentPlayer, state, 5); + x = 1;//Condition to loop on + while( x == 1) {//Buy one card + if (supplyCount(choice1, state) <= 0) { + if (DEBUG) + printf("None of that card left, sorry!\n"); + + if (DEBUG) { + printf("Cards Left: %d\n", supplyCount(choice1, state)); + } + } + else if (state->coins < getCost(choice1)) { + printf("That card is too expensive!\n"); + + if (DEBUG) { + printf("Coins: %d < %d\n", state->coins, getCost(choice1)); + } + } + else { + + if (DEBUG) { + printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + } + + gainCard(choice1, state, 0, currentPlayer);//Gain the card + x = 0;//No more buying cards + + if (DEBUG) { + printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + } + + } + } + + //Reset Hand + for (i = 0; i <= state->handCount[currentPlayer]; i++) { + state->hand[currentPlayer][i] = temphand[i]; + temphand[i] = -1; + } + //Reset Hand + + return 0; + + case gardens: + return -1; + + case mine: + return doMine(choice1, choice2, state, handPos, currentPlayer); + + case remodel: + j = state->hand[currentPlayer][choice1]; //store card we will trash + + if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) ) + { + return -1; + } + + gainCard(choice2, state, 0, currentPlayer); + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + //discard trashed card + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == j) + { + discardCard(i, currentPlayer, state, 0); + break; + } + } + + + return 0; + + case smithy: + //+3 Cards + for (i = 0; i < 3; i++) + { + drawCard(currentPlayer, state); + } + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case village: + //+1 Card + drawCard(currentPlayer, state); + + //+2 Actions + state->numActions = state->numActions + 2; + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case baron: + doBaron(choice1, state, currentPlayer); + return 0; + + case great_hall: + //+1 Card + drawCard(currentPlayer, state); + + //+1 Actions + state->numActions++; + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case minion: + doMinion(choice1, choice2, state, handPos, currentPlayer); + return 0; + + case steward: + if (choice1 == 1) + { + //+2 cards + drawCard(currentPlayer, state); + drawCard(currentPlayer, state); + } + else if (choice1 == 2) + { + //+2 coins + state->coins = state->coins + 2; + } + else + { + //trash 2 cards in hand + discardCard(choice2, currentPlayer, state, 1); + discardCard(choice3, currentPlayer, state, 1); + } + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case tribute: + doTribute(state, currentPlayer, nextPlayer, tributeRevealedCards); + return 0; + + case ambassador: + return doAmbassador(choice1, choice2, state, handPos, currentPlayer); + + case cutpurse: + + updateCoins(currentPlayer, state, 2); + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + for (j = 0; j < state->handCount[i]; j++) + { + if (state->hand[i][j] == copper) + { + discardCard(j, i, state, 0); + break; + } + if (j == state->handCount[i]) + { + for (k = 0; k < state->handCount[i]; k++) + { + if (DEBUG) + printf("Player %d reveals card number %d\n", i, state->hand[i][k]); + } + break; + } + } + + } + + } + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + + return 0; + + + case embargo: + //+2 Coins + state->coins = state->coins + 2; + + //see if selected pile is in play + if ( state->supplyCount[choice1] == -1 ) + { + return -1; + } + + //add embargo token to selected supply pile + state->embargoTokens[choice1]++; + + //trash card + discardCard(handPos, currentPlayer, state, 1); + return 0; + + case outpost: + //set outpost flag + state->outpostPlayed++; + + //discard card + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case salvager: + //+1 buy + state->numBuys++; + + if (choice1) + { + //gain coins equal to trashed card + state->coins = state->coins + getCost( handCard(choice1, state) ); + //trash card + discardCard(choice1, currentPlayer, state, 1); + } + + //discard card + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case sea_hag: + for (i = 0; i < state->numPlayers; i++) { + if (i != currentPlayer) { + state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; + state->deckCount[i]--; + state->discardCount[i]++; + state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse + } + } + return 0; + + case treasure_map: + //search hand for another treasure_map + index = -1; + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == treasure_map && i != handPos) + { + index = i; + break; + } + } + if (index > -1) + { + //trash both treasure cards + discardCard(handPos, currentPlayer, state, 1); + discardCard(index, currentPlayer, state, 1); + + //gain 4 Gold cards + for (i = 0; i < 4; i++) + { + gainCard(gold, state, 1, currentPlayer); + } + + //return success + return 1; + } + + //no second treasure_map found in hand + return -1; + } + + return -1; +} + +int discardCard(int handPos, int currentPlayer, struct gameState *state, int trashFlag) +{ + + //if card is not trashed, added to Played pile + if (trashFlag < 1) + { + //add card to played pile + state->playedCards[state->playedCardCount] = state->hand[currentPlayer][handPos]; + state->playedCardCount++; + } + + //set played card to -1 + state->hand[currentPlayer][handPos] = -1; + + //remove card from player's hand + if ( handPos == (state->handCount[currentPlayer] - 1) ) //last card in hand array is played + { + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + else if ( state->handCount[currentPlayer] == 1 ) //only one card in hand + { + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + else + { + //replace discarded card with last card in hand + state->hand[currentPlayer][handPos] = state->hand[currentPlayer][ (state->handCount[currentPlayer] - 1)]; + //set last card to -1 + state->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1; + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + + return 0; +} + +int gainCard(int supplyPos, struct gameState *state, int toFlag, int player) +{ + //Note: supplyPos is enum of choosen card + + //check if supply pile is empty (0) or card is not used in game (-1) + if ( supplyCount(supplyPos, state) < 1 ) + { + return -1; + } + + //added card for [whoseTurn] current player: + // toFlag = 0 : add to discard + // toFlag = 1 : add to deck + // toFlag = 2 : add to hand + + if (toFlag == 1) + { + state->deck[ player ][ state->deckCount[player] ] = supplyPos; + state->deckCount[player]++; + } + else if (toFlag == 2) + { + state->hand[ player ][ state->handCount[player] ] = supplyPos; + state->handCount[player]++; + } + else + { + state->discard[player][ state->discardCount[player] ] = supplyPos; + state->discardCount[player]++; + } + + //decrease number in supply pile + state->supplyCount[supplyPos]--; + + return 0; +} + +int updateCoins(int player, struct gameState *state, int bonus) +{ + int i; + + //reset coin count + state->coins = 0; + + //add coins for each Treasure card in player's hand + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == copper) + { + state->coins += 1; + } + else if (state->hand[player][i] == silver) + { + state->coins += 2; + } + else if (state->hand[player][i] == gold) + { + state->coins += 3; + } + } + + //add bonus + state->coins += bonus; + + return 0; +} + + +//end of dominion.c diff --git a/projects/alghanmz/a3/dominion.c.gcov b/projects/alghanmz/a3/dominion.c.gcov new file mode 100644 index 000000000..3292286c4 --- /dev/null +++ b/projects/alghanmz/a3/dominion.c.gcov @@ -0,0 +1,1961 @@ + -: 0:Source:dominion.c + -: 0:Graph:dominion.gcno + -: 0:Data:dominion.gcda + -: 0:Runs:5 + -: 0:Programs:5 + -: 1:#include "dominion.h" + -: 2:#include "dominion_helpers.h" + -: 3:#include "rngs.h" + -: 4:#include + -: 5:#include + -: 6:#include + -: 7: +function compare called 180 returned 100% blocks executed 83% + 180: 8:int compare(const void* a, const void* b) { + 180: 9: if (*(int*)a > *(int*)b) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + #####: 10: return 1; + 180: 11: if (*(int*)a < *(int*)b) +branch 0 taken 27% (fallthrough) +branch 1 taken 73% + 48: 12: return -1; + 132: 13: return 0; + -: 14:} + -: 15: +function newGame called 0 returned 0% blocks executed 0% + #####: 16:struct gameState* newGame() { + #####: 17: struct gameState* g = malloc(sizeof(struct gameState)); + #####: 18: return g; + -: 19:} + -: 20: +function kingdomCards called 0 returned 0% blocks executed 0% + #####: 21:int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + -: 22: int k8, int k9, int k10) { + #####: 23: int* k = malloc(10 * sizeof(int)); + #####: 24: k[0] = k1; + #####: 25: k[1] = k2; + #####: 26: k[2] = k3; + #####: 27: k[3] = k4; + #####: 28: k[4] = k5; + #####: 29: k[5] = k6; + #####: 30: k[6] = k7; + #####: 31: k[7] = k8; + #####: 32: k[8] = k9; + #####: 33: k[9] = k10; + #####: 34: return k; + -: 35:} + -: 36: +function initializeGame called 5 returned 100% blocks executed 94% + 5: 37:int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, + -: 38: struct gameState *state) { + -: 39: int i; + -: 40: int j; + -: 41: int it; + -: 42: + -: 43: //set up random number generator + 5: 44: SelectStream(1); +call 0 returned 100% + 5: 45: PutSeed((long)randomSeed); +call 0 returned 100% + -: 46: + -: 47: //check number of players + 5: 48: if (numPlayers > MAX_PLAYERS || numPlayers < 2) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 49: { + #####: 50: return -1; + -: 51: } + -: 52: + -: 53: //set number of players + 5: 54: state->numPlayers = numPlayers; + -: 55: + -: 56: //check selected kingdom cards are different + 55: 57: for (i = 0; i < 10; i++) +branch 0 taken 91% +branch 1 taken 9% (fallthrough) + -: 58: { + 550: 59: for (j = 0; j < 10; j++) +branch 0 taken 91% +branch 1 taken 9% (fallthrough) + -: 60: { + 500: 61: if (j != i && kingdomCards[j] == kingdomCards[i]) +branch 0 taken 90% (fallthrough) +branch 1 taken 10% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 62: { + #####: 63: return -1; + -: 64: } + -: 65: } + -: 66: } + -: 67: + -: 68: + -: 69: //initialize supply + -: 70: /////////////////////////////// + -: 71: + -: 72: //set number of Curse cards + 5: 73: if (numPlayers == 2) +branch 0 taken 80% (fallthrough) +branch 1 taken 20% + -: 74: { + 4: 75: state->supplyCount[curse] = 10; + -: 76: } + 1: 77: else if (numPlayers == 3) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 78: { + #####: 79: state->supplyCount[curse] = 20; + -: 80: } + -: 81: else + -: 82: { + 1: 83: state->supplyCount[curse] = 30; + -: 84: } + -: 85: + -: 86: //set number of Victory cards + 5: 87: if (numPlayers == 2) +branch 0 taken 80% (fallthrough) +branch 1 taken 20% + -: 88: { + 4: 89: state->supplyCount[estate] = 8; + 4: 90: state->supplyCount[duchy] = 8; + 4: 91: state->supplyCount[province] = 8; + -: 92: } + -: 93: else + -: 94: { + 1: 95: state->supplyCount[estate] = 12; + 1: 96: state->supplyCount[duchy] = 12; + 1: 97: state->supplyCount[province] = 12; + -: 98: } + -: 99: + -: 100: //set number of Treasure cards + 5: 101: state->supplyCount[copper] = 60 - (7 * numPlayers); + 5: 102: state->supplyCount[silver] = 40; + 5: 103: state->supplyCount[gold] = 30; + -: 104: + -: 105: //set number of Kingdom cards + 105: 106: for (i = adventurer; i <= treasure_map; i++) //loop all cards +branch 0 taken 95% +branch 1 taken 5% (fallthrough) + -: 107: { + 825: 108: for (j = 0; j < 10; j++) //loop chosen cards +branch 0 taken 94% +branch 1 taken 6% (fallthrough) + -: 109: { + 775: 110: if (kingdomCards[j] == i) +branch 0 taken 6% (fallthrough) +branch 1 taken 94% + -: 111: { + -: 112: //check if card is a 'Victory' Kingdom card + 50: 113: if (kingdomCards[j] == great_hall || kingdomCards[j] == gardens) +branch 0 taken 90% (fallthrough) +branch 1 taken 10% +branch 2 taken 11% (fallthrough) +branch 3 taken 89% + -: 114: { + 20: 115: if (numPlayers == 2) { +branch 0 taken 80% (fallthrough) +branch 1 taken 20% + 8: 116: state->supplyCount[i] = 8; + -: 117: } + -: 118: else { + 2: 119: state->supplyCount[i] = 12; + -: 120: } + -: 121: } + -: 122: else + -: 123: { + 40: 124: state->supplyCount[i] = 10; + -: 125: } + 50: 126: break; + -: 127: } + -: 128: else //card is not in the set choosen for the game + -: 129: { + 725: 130: state->supplyCount[i] = -1; + -: 131: } + -: 132: } + -: 133: + -: 134: } + -: 135: + -: 136: //////////////////////// + -: 137: //supply intilization complete + -: 138: + -: 139: //set player decks + 17: 140: for (i = 0; i < numPlayers; i++) +branch 0 taken 71% +branch 1 taken 29% (fallthrough) + -: 141: { + 12: 142: state->deckCount[i] = 0; + 48: 143: for (j = 0; j < 3; j++) +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + -: 144: { + 36: 145: state->deck[i][j] = estate; + 36: 146: state->deckCount[i]++; + -: 147: } + 96: 148: for (j = 3; j < 10; j++) +branch 0 taken 88% +branch 1 taken 13% (fallthrough) + -: 149: { + 84: 150: state->deck[i][j] = copper; + 84: 151: state->deckCount[i]++; + -: 152: } + -: 153: } + -: 154: + -: 155: //shuffle player decks + 17: 156: for (i = 0; i < numPlayers; i++) +branch 0 taken 71% +branch 1 taken 29% (fallthrough) + -: 157: { + 12: 158: if ( shuffle(i, state) < 0 ) +call 0 returned 100% +branch 1 taken 0% (fallthrough) +branch 2 taken 100% + -: 159: { + #####: 160: return -1; + -: 161: } + -: 162: } + -: 163: + -: 164: //draw player hands + 17: 165: for (i = 0; i < numPlayers; i++) +branch 0 taken 71% +branch 1 taken 29% (fallthrough) + -: 166: { + -: 167: //initialize hand size to zero + 12: 168: state->handCount[i] = 0; + 12: 169: state->discardCount[i] = 0; + -: 170: //draw 5 cards + -: 171: // for (j = 0; j < 5; j++) + -: 172: // { + -: 173: // drawCard(i, state); + -: 174: // } + -: 175: } + -: 176: + -: 177: //set embargo tokens to 0 for all supply piles + 140: 178: for (i = 0; i <= treasure_map; i++) +branch 0 taken 96% +branch 1 taken 4% (fallthrough) + -: 179: { + 135: 180: state->embargoTokens[i] = 0; + -: 181: } + -: 182: + -: 183: //initialize first player's turn + 5: 184: state->outpostPlayed = 0; + 5: 185: state->phase = 0; + 5: 186: state->numActions = 1; + 5: 187: state->numBuys = 1; + 5: 188: state->playedCardCount = 0; + 5: 189: state->whoseTurn = 0; + 5: 190: state->handCount[state->whoseTurn] = 0; + -: 191: //int it; move to top + -: 192: + -: 193: //Moved draw cards to here, only drawing at the start of a turn + 30: 194: for (it = 0; it < 5; it++) { +branch 0 taken 83% +branch 1 taken 17% (fallthrough) + 25: 195: drawCard(state->whoseTurn, state); +call 0 returned 100% + -: 196: } + -: 197: + 5: 198: updateCoins(state->whoseTurn, state, 0); +call 0 returned 100% + -: 199: + 5: 200: return 0; + -: 201:} + -: 202: +function shuffle called 13 returned 100% blocks executed 94% + 13: 203:int shuffle(int player, struct gameState *state) { + -: 204: + -: 205: + -: 206: int newDeck[MAX_DECK]; + 13: 207: int newDeckPos = 0; + -: 208: int card; + -: 209: int i; + -: 210: + 13: 211: if (state->deckCount[player] < 1) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + #####: 212: return -1; + 13: 213: qsort ((void*)(state->deck[player]), state->deckCount[player], sizeof(int), compare); +call 0 returned 100% + -: 214: /* SORT CARDS IN DECK TO ENSURE DETERMINISM! */ + -: 215: + 147: 216: while (state->deckCount[player] > 0) { +branch 0 taken 90% +branch 1 taken 10% (fallthrough) + 121: 217: card = floor(Random() * state->deckCount[player]); +call 0 returned 100% + 121: 218: newDeck[newDeckPos] = state->deck[player][card]; + 121: 219: newDeckPos++; + 442: 220: for (i = card; i < state->deckCount[player]-1; i++) { +branch 0 taken 73% +branch 1 taken 27% (fallthrough) + 321: 221: state->deck[player][i] = state->deck[player][i+1]; + -: 222: } + 121: 223: state->deckCount[player]--; + -: 224: } + 134: 225: for (i = 0; i < newDeckPos; i++) { +branch 0 taken 90% +branch 1 taken 10% (fallthrough) + 121: 226: state->deck[player][i] = newDeck[i]; + 121: 227: state->deckCount[player]++; + -: 228: } + -: 229: + 13: 230: return 0; + -: 231:} + -: 232: +function playCard called 0 returned 0% blocks executed 0% + #####: 233:int playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state) + -: 234:{ + -: 235: int card; + #####: 236: int coin_bonus = 0; //tracks coins gain from actions + -: 237: + -: 238: //check if it is the right phase + #####: 239: if (state->phase != 0) +branch 0 never executed +branch 1 never executed + -: 240: { + #####: 241: return -1; + -: 242: } + -: 243: + -: 244: //check if player has enough actions + #####: 245: if ( state->numActions < 1 ) +branch 0 never executed +branch 1 never executed + -: 246: { + #####: 247: return -1; + -: 248: } + -: 249: + -: 250: //get card played + #####: 251: card = handCard(handPos, state); +call 0 never executed + -: 252: + -: 253: //check if selected card is an action + #####: 254: if ( card < adventurer || card > treasure_map ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 255: { + #####: 256: return -1; + -: 257: } + -: 258: + -: 259: //play card + #####: 260: if ( cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0 ) +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 261: { + #####: 262: return -1; + -: 263: } + -: 264: + -: 265: //reduce number of actions + #####: 266: state->numActions--; + -: 267: + -: 268: //update coins (Treasure cards may be added with card draws) + #####: 269: updateCoins(state->whoseTurn, state, coin_bonus); +call 0 never executed + -: 270: + #####: 271: return 0; + -: 272:} + -: 273: +function buyCard called 0 returned 0% blocks executed 0% + #####: 274:int buyCard(int supplyPos, struct gameState *state) { + -: 275: int who; + -: 276: if (DEBUG) { + -: 277: printf("Entering buyCard...\n"); + -: 278: } + -: 279: + -: 280: // I don't know what to do about the phase thing. + -: 281: + #####: 282: who = state->whoseTurn; + -: 283: + #####: 284: if (state->numBuys < 1) { +branch 0 never executed +branch 1 never executed + -: 285: if (DEBUG) + -: 286: printf("You do not have any buys left\n"); + #####: 287: return -1; + #####: 288: } else if (supplyCount(supplyPos, state) <1) { +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 289: if (DEBUG) + -: 290: printf("There are not any of that type of card left\n"); + #####: 291: return -1; + #####: 292: } else if (state->coins < getCost(supplyPos)) { +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 293: if (DEBUG) + -: 294: printf("You do not have enough money to buy that. You have %d coins.\n", state->coins); + #####: 295: return -1; + -: 296: } else { + #####: 297: state->phase=1; + -: 298: //state->supplyCount[supplyPos]--; + #####: 299: gainCard(supplyPos, state, 0, who); //card goes in discard, this might be wrong.. (2 means goes into hand, 0 goes into discard) +call 0 never executed + -: 300: + #####: 301: state->coins = (state->coins) - (getCost(supplyPos)); +call 0 never executed + #####: 302: state->numBuys--; + -: 303: if (DEBUG) + -: 304: printf("You bought card number %d for %d coins. You now have %d buys and %d coins.\n", supplyPos, getCost(supplyPos), state->numBuys, state->coins); + -: 305: } + -: 306: + -: 307: //state->discard[who][state->discardCount[who]] = supplyPos; + -: 308: //state->discardCount[who]++; + -: 309: + #####: 310: return 0; + -: 311:} + -: 312: +function numHandCards called 4 returned 100% blocks executed 100% + 4: 313:int numHandCards(struct gameState *state) { + 4: 314: return state->handCount[ whoseTurn(state) ]; +call 0 returned 100% + -: 315:} + -: 316: +function handCard called 0 returned 0% blocks executed 0% + #####: 317:int handCard(int handPos, struct gameState *state) { + #####: 318: int currentPlayer = whoseTurn(state); +call 0 never executed + #####: 319: return state->hand[currentPlayer][handPos]; + -: 320:} + -: 321: +function supplyCount called 8 returned 100% blocks executed 100% + 8: 322:int supplyCount(int card, struct gameState *state) { + 8: 323: return state->supplyCount[card]; + -: 324:} + -: 325: +function fullDeckCount called 0 returned 0% blocks executed 0% + #####: 326:int fullDeckCount(int player, int card, struct gameState *state) { + -: 327: int i; + #####: 328: int count = 0; + -: 329: + #####: 330: for (i = 0; i < state->deckCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 331: { + #####: 332: if (state->deck[player][i] == card) count++; +branch 0 never executed +branch 1 never executed + -: 333: } + -: 334: + #####: 335: for (i = 0; i < state->handCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 336: { + #####: 337: if (state->hand[player][i] == card) count++; +branch 0 never executed +branch 1 never executed + -: 338: } + -: 339: + #####: 340: for (i = 0; i < state->discardCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 341: { + #####: 342: if (state->discard[player][i] == card) count++; +branch 0 never executed +branch 1 never executed + -: 343: } + -: 344: + #####: 345: return count; + -: 346:} + -: 347: +function whoseTurn called 4 returned 100% blocks executed 100% + 4: 348:int whoseTurn(struct gameState *state) { + 4: 349: return state->whoseTurn; + -: 350:} + -: 351: +function endTurn called 0 returned 0% blocks executed 0% + #####: 352:int endTurn(struct gameState *state) { + -: 353: int k; + -: 354: int i; + #####: 355: int currentPlayer = whoseTurn(state); +call 0 never executed + -: 356: + -: 357: //Discard hand + #####: 358: for (i = 0; i < state->handCount[currentPlayer]; i++) { +branch 0 never executed +branch 1 never executed + #####: 359: state->discard[currentPlayer][state->discardCount[currentPlayer]++] = state->hand[currentPlayer][i];//Discard + #####: 360: state->hand[currentPlayer][i] = -1;//Set card to -1 + -: 361: } + #####: 362: state->handCount[currentPlayer] = 0;//Reset hand count + -: 363: + -: 364: //Code for determining the player + #####: 365: if (currentPlayer < (state->numPlayers - 1)) { +branch 0 never executed +branch 1 never executed + #####: 366: state->whoseTurn = currentPlayer + 1;//Still safe to increment + -: 367: } + -: 368: else { + #####: 369: state->whoseTurn = 0;//Max player has been reached, loop back around to player 1 + -: 370: } + -: 371: + #####: 372: state->outpostPlayed = 0; + #####: 373: state->phase = 0; + #####: 374: state->numActions = 1; + #####: 375: state->coins = 0; + #####: 376: state->numBuys = 1; + #####: 377: state->playedCardCount = 0; + #####: 378: state->handCount[state->whoseTurn] = 0; + -: 379: + -: 380: //int k; move to top + -: 381: //Next player draws hand + #####: 382: for (k = 0; k < 5; k++) { +branch 0 never executed +branch 1 never executed + #####: 383: drawCard(state->whoseTurn, state);//Draw a card +call 0 never executed + -: 384: } + -: 385: + -: 386: //Update money + #####: 387: updateCoins(state->whoseTurn, state, 0); +call 0 never executed + -: 388: + #####: 389: return 0; + -: 390:} + -: 391: +function isGameOver called 0 returned 0% blocks executed 0% + #####: 392:int isGameOver(struct gameState *state) { + -: 393: int i; + -: 394: int j; + -: 395: + -: 396: //if stack of Province cards is empty, the game ends + #####: 397: if (state->supplyCount[province] == 0) +branch 0 never executed +branch 1 never executed + -: 398: { + #####: 399: return 1; + -: 400: } + -: 401: + -: 402: //if three supply pile are at 0, the game ends + #####: 403: j = 0; + #####: 404: for (i = 0; i < 25; i++) +branch 0 never executed +branch 1 never executed + -: 405: { + #####: 406: if (state->supplyCount[i] == 0) +branch 0 never executed +branch 1 never executed + -: 407: { + #####: 408: j++; + -: 409: } + -: 410: } + #####: 411: if ( j >= 3) +branch 0 never executed +branch 1 never executed + -: 412: { + #####: 413: return 1; + -: 414: } + -: 415: + #####: 416: return 0; + -: 417:} + -: 418: +function scoreFor called 0 returned 0% blocks executed 0% + #####: 419:int scoreFor (int player, struct gameState *state) { + -: 420: + -: 421: int i; + #####: 422: int score = 0; + -: 423: //score from hand + #####: 424: for (i = 0; i < state->handCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 425: { + #####: 426: if (state->hand[player][i] == curse) { +branch 0 never executed +branch 1 never executed + #####: 427: score = score - 1; + -: 428: }; + #####: 429: if (state->hand[player][i] == estate) { +branch 0 never executed +branch 1 never executed + #####: 430: score = score + 1; + -: 431: }; + #####: 432: if (state->hand[player][i] == duchy) { +branch 0 never executed +branch 1 never executed + #####: 433: score = score + 3; + -: 434: }; + #####: 435: if (state->hand[player][i] == province) { +branch 0 never executed +branch 1 never executed + #####: 436: score = score + 6; + -: 437: }; + #####: 438: if (state->hand[player][i] == great_hall) { +branch 0 never executed +branch 1 never executed + #####: 439: score = score + 1; + -: 440: }; + #####: 441: if (state->hand[player][i] == gardens) { +branch 0 never executed +branch 1 never executed + #####: 442: score = score + ( fullDeckCount(player, 0, state) / 10 ); +call 0 never executed + -: 443: }; + -: 444: } + -: 445: + -: 446: //score from discard + #####: 447: for (i = 0; i < state->discardCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 448: { + #####: 449: if (state->discard[player][i] == curse) { +branch 0 never executed +branch 1 never executed + #####: 450: score = score - 1; + -: 451: }; + #####: 452: if (state->discard[player][i] == estate) { +branch 0 never executed +branch 1 never executed + #####: 453: score = score + 1; + -: 454: }; + #####: 455: if (state->discard[player][i] == duchy) { +branch 0 never executed +branch 1 never executed + #####: 456: score = score + 3; + -: 457: }; + #####: 458: if (state->discard[player][i] == province) { +branch 0 never executed +branch 1 never executed + #####: 459: score = score + 6; + -: 460: }; + #####: 461: if (state->discard[player][i] == great_hall) { +branch 0 never executed +branch 1 never executed + #####: 462: score = score + 1; + -: 463: }; + #####: 464: if (state->discard[player][i] == gardens) { +branch 0 never executed +branch 1 never executed + #####: 465: score = score + ( fullDeckCount(player, 0, state) / 10 ); +call 0 never executed + -: 466: }; + -: 467: } + -: 468: + -: 469: //score from deck + #####: 470: for (i = 0; i < state->discardCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 471: { + #####: 472: if (state->deck[player][i] == curse) { +branch 0 never executed +branch 1 never executed + #####: 473: score = score - 1; + -: 474: }; + #####: 475: if (state->deck[player][i] == estate) { +branch 0 never executed +branch 1 never executed + #####: 476: score = score + 1; + -: 477: }; + #####: 478: if (state->deck[player][i] == duchy) { +branch 0 never executed +branch 1 never executed + #####: 479: score = score + 3; + -: 480: }; + #####: 481: if (state->deck[player][i] == province) { +branch 0 never executed +branch 1 never executed + #####: 482: score = score + 6; + -: 483: }; + #####: 484: if (state->deck[player][i] == great_hall) { +branch 0 never executed +branch 1 never executed + #####: 485: score = score + 1; + -: 486: }; + #####: 487: if (state->deck[player][i] == gardens) { +branch 0 never executed +branch 1 never executed + #####: 488: score = score + ( fullDeckCount(player, 0, state) / 10 ); +call 0 never executed + -: 489: }; + -: 490: } + -: 491: + #####: 492: return score; + -: 493:} + -: 494: +function getWinners called 0 returned 0% blocks executed 0% + #####: 495:int getWinners(int players[MAX_PLAYERS], struct gameState *state) { + -: 496: int i; + -: 497: int j; + -: 498: int highScore; + -: 499: int currentPlayer; + -: 500: + -: 501: //get score for each player + #####: 502: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 503: { + -: 504: //set unused player scores to -9999 + #####: 505: if (i >= state->numPlayers) +branch 0 never executed +branch 1 never executed + -: 506: { + #####: 507: players[i] = -9999; + -: 508: } + -: 509: else + -: 510: { + #####: 511: players[i] = scoreFor (i, state); +call 0 never executed + -: 512: } + -: 513: } + -: 514: + -: 515: //find highest score + #####: 516: j = 0; + #####: 517: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 518: { + #####: 519: if (players[i] > players[j]) +branch 0 never executed +branch 1 never executed + -: 520: { + #####: 521: j = i; + -: 522: } + -: 523: } + #####: 524: highScore = players[j]; + -: 525: + -: 526: //add 1 to players who had less turns + #####: 527: currentPlayer = whoseTurn(state); +call 0 never executed + #####: 528: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 529: { + #####: 530: if ( players[i] == highScore && i > currentPlayer ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 531: { + #####: 532: players[i]++; + -: 533: } + -: 534: } + -: 535: + -: 536: //find new highest score + #####: 537: j = 0; + #####: 538: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 539: { + #####: 540: if ( players[i] > players[j] ) +branch 0 never executed +branch 1 never executed + -: 541: { + #####: 542: j = i; + -: 543: } + -: 544: } + #####: 545: highScore = players[j]; + -: 546: + -: 547: //set winners in array to 1 and rest to 0 + #####: 548: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 549: { + #####: 550: if ( players[i] == highScore ) +branch 0 never executed +branch 1 never executed + -: 551: { + #####: 552: players[i] = 1; + -: 553: } + -: 554: else + -: 555: { + #####: 556: players[i] = 0; + -: 557: } + -: 558: } + -: 559: + #####: 560: return 0; + -: 561:} + -: 562: +function drawCard called 43 returned 100% blocks executed 38% + 43: 563:int drawCard(int player, struct gameState *state) + -: 564:{ int count; + -: 565: int deckCounter; + 43: 566: if (state->deckCount[player] <= 0) { //Deck is empty +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 567: + -: 568: //Step 1 Shuffle the discard pile back into a deck + -: 569: int i; + -: 570: //Move discard to deck + #####: 571: for (i = 0; i < state->discardCount[player]; i++) { +branch 0 never executed +branch 1 never executed + #####: 572: state->deck[player][i] = state->discard[player][i]; + #####: 573: state->discard[player][i] = -1; + -: 574: } + -: 575: + #####: 576: state->deckCount[player] = state->discardCount[player]; + #####: 577: state->discardCount[player] = 0;//Reset discard + -: 578: + -: 579: //Shufffle the deck + #####: 580: shuffle(player, state);//Shuffle the deck up and make it so that we can draw +call 0 never executed + -: 581: + -: 582: if (DEBUG) { //Debug statements + -: 583: printf("Deck count now: %d\n", state->deckCount[player]); + -: 584: } + -: 585: + #####: 586: state->discardCount[player] = 0; + -: 587: + -: 588: //Step 2 Draw Card + #####: 589: count = state->handCount[player];//Get current player's hand count + -: 590: + -: 591: if (DEBUG) { //Debug statements + -: 592: printf("Current hand count: %d\n", count); + -: 593: } + -: 594: + #####: 595: deckCounter = state->deckCount[player];//Create a holder for the deck count + -: 596: + #####: 597: if (deckCounter == 0) +branch 0 never executed +branch 1 never executed + #####: 598: return -1; + -: 599: + #####: 600: state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to hand + #####: 601: state->deckCount[player]--; + #####: 602: state->handCount[player]++;//Increment hand count + -: 603: } + -: 604: + -: 605: else { + 43: 606: int count = state->handCount[player];//Get current hand count for player + -: 607: int deckCounter; + -: 608: if (DEBUG) { //Debug statements + -: 609: printf("Current hand count: %d\n", count); + -: 610: } + -: 611: + 43: 612: deckCounter = state->deckCount[player];//Create holder for the deck count + 43: 613: state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to the hand + 43: 614: state->deckCount[player]--; + 43: 615: state->handCount[player]++;//Increment hand count + -: 616: } + -: 617: + 43: 618: return 0; + -: 619:} + -: 620: +function getCost called 4 returned 100% blocks executed 17% + 4: 621:int getCost(int cardNumber) + -: 622:{ + 4: 623: switch( cardNumber ) +branch 0 taken 25% +branch 1 taken 0% +branch 2 taken 0% +branch 3 taken 0% +branch 4 taken 25% +branch 5 taken 50% +branch 6 taken 0% +branch 7 taken 0% +branch 8 taken 0% +branch 9 taken 0% +branch 10 taken 0% +branch 11 taken 0% +branch 12 taken 0% +branch 13 taken 0% +branch 14 taken 0% +branch 15 taken 0% +branch 16 taken 0% +branch 17 taken 0% +branch 18 taken 0% +branch 19 taken 0% +branch 20 taken 0% +branch 21 taken 0% +branch 22 taken 0% +branch 23 taken 0% +branch 24 taken 0% +branch 25 taken 0% +branch 26 taken 0% +branch 27 taken 0% + -: 624: { + -: 625: case curse: + 1: 626: return 0; + -: 627: case estate: + #####: 628: return 2; + -: 629: case duchy: + #####: 630: return 5; + -: 631: case province: + #####: 632: return 8; + -: 633: case copper: + 1: 634: return 0; + -: 635: case silver: + 2: 636: return 3; + -: 637: case gold: + #####: 638: return 6; + -: 639: case adventurer: + #####: 640: return 6; + -: 641: case council_room: + #####: 642: return 5; + -: 643: case feast: + #####: 644: return 4; + -: 645: case gardens: + #####: 646: return 4; + -: 647: case mine: + #####: 648: return 5; + -: 649: case remodel: + #####: 650: return 4; + -: 651: case smithy: + #####: 652: return 4; + -: 653: case village: + #####: 654: return 3; + -: 655: case baron: + #####: 656: return 4; + -: 657: case great_hall: + #####: 658: return 3; + -: 659: case minion: + #####: 660: return 5; + -: 661: case steward: + #####: 662: return 3; + -: 663: case tribute: + #####: 664: return 5; + -: 665: case ambassador: + #####: 666: return 3; + -: 667: case cutpurse: + #####: 668: return 4; + -: 669: case embargo: + #####: 670: return 2; + -: 671: case outpost: + #####: 672: return 5; + -: 673: case salvager: + #####: 674: return 4; + -: 675: case sea_hag: + #####: 676: return 4; + -: 677: case treasure_map: + #####: 678: return 4; + -: 679: } + -: 680: + #####: 681: return -1; + -: 682:} + -: 683: +function doMine called 3 returned 100% blocks executed 83% + 3: 684:int doMine(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) + -: 685:{ + -: 686: int i; + -: 687: int j; + -: 688: + 3: 689: j = state->hand[currentPlayer][choice1]; //store card we will trash + -: 690: + 3: 691: if (/*state->hand[currentPlayer][choice1] < copper ||*/ state->hand[currentPlayer][choice1] > gold) +branch 0 taken 33% (fallthrough) +branch 1 taken 67% + -: 692: { + 1: 693: return -1; + -: 694: } + -: 695: + 2: 696: if (choice2 > treasure_map || choice2 < curse) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 697: { + #####: 698: return -1; + -: 699: } + -: 700: + 2: 701: if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) ) +call 0 returned 100% +call 1 returned 100% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 702: { + #####: 703: return -1; + -: 704: } + -: 705: + -: 706: //gainCard(choice2, state, 2, currentPlayer); + -: 707: + -: 708: //discard card from hand + 2: 709: discardCard(handPos, currentPlayer, state, 0); +call 0 returned 100% + -: 710: + -: 711: //discard trashed card + 2: 712: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 taken 100% +branch 1 taken 0% (fallthrough) + -: 713: { + 2: 714: if (state->hand[currentPlayer][i] == j) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% + -: 715: { + 2: 716: discardCard(i, currentPlayer, state, 0); +call 0 returned 100% + 2: 717: break; + -: 718: } + -: 719: } + -: 720: + 2: 721: return 0; + -: 722:} + -: 723: +function getEstateCard called 2 returned 100% blocks executed 86% + 2: 724:void getEstateCard(struct gameState *state, int currentPlayer) + -: 725:{ + 2: 726: if (supplyCount(estate, state) > 0) { +call 0 returned 100% +branch 1 taken 100% (fallthrough) +branch 2 taken 0% + 2: 727: gainCard(estate, state, 0, currentPlayer);//Gain an estate +call 0 returned 100% + -: 728: + 2: 729: state->supplyCount[estate]--;//Decrement Estates + 2: 730: if (supplyCount(estate, state) == 0) { +call 0 returned 100% +branch 1 taken 0% (fallthrough) +branch 2 taken 100% + #####: 731: isGameOver(state); +call 0 never executed + -: 732: } + -: 733: } + 2: 734:} + -: 735: +function doBaron called 3 returned 100% blocks executed 100% + 3: 736:void doBaron(int choice1, struct gameState *state, int currentPlayer) + -: 737:{ + 3: 738: state->numBuys++;//Increase buys by 1! + 3: 739: state->numBuys++;//Increase buys by 1! + 3: 740: if (choice1 > 0) { //Boolean true or going to discard an estate +branch 0 taken 67% (fallthrough) +branch 1 taken 33% + 2: 741: int p = 1; //0;//Iterator for hand! + 2: 742: int card_not_discarded = 1;//Flag for discard set! + 11: 743: while(card_not_discarded) { +branch 0 taken 78% +branch 1 taken 22% (fallthrough) + 7: 744: if (state->hand[currentPlayer][p] == estate) { //Found an estate card! +branch 0 taken 14% (fallthrough) +branch 1 taken 86% + 1: 745: state->coins += 4;//Add 4 coins to the amount of coins + 1: 746: state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; + 1: 747: state->discardCount[currentPlayer]++; + 5: 748: for (; p < state->handCount[currentPlayer]; p++) { +branch 0 taken 80% +branch 1 taken 20% (fallthrough) + 4: 749: state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1]; + -: 750: } + 1: 751: state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; + 1: 752: state->handCount[currentPlayer]--; + 1: 753: card_not_discarded = 0;//Exit the loop + -: 754: } + 6: 755: else if (p > state->handCount[currentPlayer]) { +branch 0 taken 17% (fallthrough) +branch 1 taken 83% + -: 756: if(DEBUG) { + -: 757: printf("No estate cards in your hand, invalid choice\n"); + -: 758: printf("Must gain an estate if there are any\n"); + -: 759: } + 1: 760: getEstateCard(state, currentPlayer); +call 0 returned 100% + 1: 761: card_not_discarded = 0;//Exit the loop + -: 762: } + -: 763: + -: 764: else { + 5: 765: p++;//Next card + -: 766: } + -: 767: } + -: 768: } + -: 769: + -: 770: else { + 1: 771: getEstateCard(state, currentPlayer); +call 0 returned 100% + -: 772: } + 3: 773:} + -: 774: +function doMinion called 2 returned 100% blocks executed 100% + 2: 775:void doMinion(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) + -: 776:{ + -: 777: int i; + -: 778: int j; + -: 779: + -: 780: //+1 action + 2: 781: state->numActions++; + -: 782: + -: 783: //discard card from hand + 2: 784: discardCard(handPos, currentPlayer, state, 0); +call 0 returned 100% + -: 785: + 2: 786: if (choice1) +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + -: 787: { + 1: 788: state->coins = state->coins + 2; + -: 789: } + 1: 790: else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 +branch 0 taken 100% (fallthrough) +branch 1 taken 0% + -: 791: { + -: 792: //discard hand + 5: 793: while(numHandCards(state) > 1 /*0*/) +call 0 returned 100% +branch 1 taken 75% +branch 2 taken 25% (fallthrough) + -: 794: { + 3: 795: discardCard(handPos, currentPlayer, state, 0); +call 0 returned 100% + -: 796: } + -: 797: + -: 798: //draw 4 + 5: 799: for (i = 0; i < 4; i++) +branch 0 taken 80% +branch 1 taken 20% (fallthrough) + -: 800: { + 4: 801: drawCard(currentPlayer, state); +call 0 returned 100% + -: 802: } + -: 803: + -: 804: //other players discard hand and redraw if hand size > 4 + 5: 805: for (i = 0; i < state->numPlayers; i++) +branch 0 taken 80% +branch 1 taken 20% (fallthrough) + -: 806: { + 4: 807: if (i != currentPlayer) +branch 0 taken 75% (fallthrough) +branch 1 taken 25% + -: 808: { + -: 809: //if ( state->handCount[i] > 4 ) + -: 810: { + -: 811: //discard hand + 9: 812: while( state->handCount[i] > 0 ) +branch 0 taken 50% +branch 1 taken 50% (fallthrough) + -: 813: { + 3: 814: discardCard(handPos, i, state, 0); +call 0 returned 100% + -: 815: } + -: 816: + -: 817: //draw 4 + 15: 818: for (j = 0; j < 4; j++) +branch 0 taken 80% +branch 1 taken 20% (fallthrough) + -: 819: { + 12: 820: drawCard(i, state); +call 0 returned 100% + -: 821: } + -: 822: } + -: 823: } + -: 824: } + -: 825: } + 2: 826:} + -: 827: +function printDeck called 0 returned 0% blocks executed 0% + #####: 828:void printDeck(struct gameState *state, int p) { + #####: 829: printf("Deck:"); +call 0 never executed + #####: 830: for (int i=0; i < state->deckCount[p]; i++) +branch 0 never executed +branch 1 never executed + #####: 831: printf(" %d", state->deck[p][i]); +call 0 never executed + #####: 832: printf("\n"); +call 0 never executed + #####: 833:} + -: 834: +function printHand called 0 returned 0% blocks executed 0% + #####: 835:void printHand(struct gameState *state, int p) { + #####: 836: printf("Hand:"); +call 0 never executed + #####: 837: for (int i=0; i < state->handCount[p]; i++) +branch 0 never executed +branch 1 never executed + #####: 838: printf(" %d", state->hand[p][i]); +call 0 never executed + #####: 839: printf("\n"); +call 0 never executed + #####: 840:} + -: 841: +function doTribute called 3 returned 100% blocks executed 93% + 3: 842:void doTribute(struct gameState *state, int currentPlayer, int nextPlayer, int tributeRevealedCards[2]) + -: 843:{ + -: 844: int i; + -: 845: + 3: 846: if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) { +branch 0 taken 33% (fallthrough) +branch 1 taken 67% + 1: 847: if (state->deckCount[nextPlayer] > 0) { +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + #####: 848: tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + #####: 849: state->deckCount[nextPlayer]--; + -: 850: } + 1: 851: else if (state->discardCount[nextPlayer] > 0) { +branch 0 taken 100% (fallthrough) +branch 1 taken 0% + 1: 852: tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1]; + 1: 853: state->discardCount[nextPlayer]--; + -: 854: } + -: 855: else { + -: 856: //No Card to Reveal + -: 857: if (DEBUG) { + -: 858: printf("No cards to reveal\n"); + -: 859: } + -: 860: } + -: 861: } + -: 862: + -: 863: else { + 2: 864: if (state->deckCount[nextPlayer] == 0) { +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + 2: 865: for (i = 0; i < state->discardCount[nextPlayer]; i++) { +branch 0 taken 50% +branch 1 taken 50% (fallthrough) + 1: 866: state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck + 1: 867: state->deckCount[nextPlayer]++; + 1: 868: state->discard[nextPlayer][i] = -1; + 1: 869: state->discardCount[nextPlayer]--; + -: 870: } + -: 871: + 1: 872: shuffle(nextPlayer,state);//Shuffle the deck +call 0 returned 100% + -: 873: } + 2: 874: tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + -: 875: //state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + -: 876: //state->deckCount[nextPlayer]--; + -: 877: //tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + 2: 878: tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-2]; + -: 879: //state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + -: 880: //state->deckCount[nextPlayer]--; + -: 881: } + -: 882: + 3: 883: if (tributeRevealedCards[0] == tributeRevealedCards[1]) { //If we have a duplicate card, just drop one +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + #####: 884: state->playedCards[state->playedCardCount] = tributeRevealedCards[1]; + #####: 885: state->playedCardCount++; + #####: 886: tributeRevealedCards[1] = -1; + -: 887: } + -: 888: + 9: 889: for (i = 0; i < 2; i ++) { +branch 0 taken 67% +branch 1 taken 33% (fallthrough) + 6: 890: if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) { //Treasure cards +branch 0 taken 83% (fallthrough) +branch 1 taken 17% +branch 2 taken 100% (fallthrough) +branch 3 taken 0% +branch 4 taken 0% (fallthrough) +branch 5 taken 100% + 1: 891: state->numActions = state->numActions + 2; + -: 892: } + -: 893: + 5: 894: else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall) { //Victory Card Found +branch 0 taken 60% (fallthrough) +branch 1 taken 40% +branch 2 taken 100% (fallthrough) +branch 3 taken 0% +branch 4 taken 100% (fallthrough) +branch 5 taken 0% +branch 6 taken 100% (fallthrough) +branch 7 taken 0% +branch 8 taken 0% (fallthrough) +branch 9 taken 100% + 2: 895: drawCard(currentPlayer, state); +call 0 returned 100% + -: 896: //drawCard(currentPlayer, state); + -: 897: } + -: 898: else { //Action Card + 3: 899: state->coins += 2; + -: 900: } + -: 901: } + 3: 902:} + -: 903: +function doAmbassador called 2 returned 100% blocks executed 89% + 2: 904:int doAmbassador(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) + -: 905:{ + -: 906: int i; + -: 907: int j; + -: 908: + 2: 909: j = 0; //used to check if player has enough cards to discard + -: 910: + 2: 911: if (choice2 > 3 || choice2 < 0) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 912: { + #####: 913: return -1; + -: 914: } + -: 915: + -: 916:/* + -: 917: if (choice1 == handPos) + -: 918: { + -: 919: return -1; + -: 920: } + -: 921: */ + -: 922: + 12: 923: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 taken 83% +branch 1 taken 17% (fallthrough) + -: 924: { + 10: 925: if (i != handPos && state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1] /*&& i != choice1*/) +branch 0 taken 80% (fallthrough) +branch 1 taken 20% +branch 2 taken 50% (fallthrough) +branch 3 taken 50% + -: 926: { + 4: 927: j++; + -: 928: } + -: 929: } + 2: 930: if (j < choice2) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 931: { + #####: 932: return -1; + -: 933: } + -: 934: + -: 935: if (DEBUG) + -: 936: printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]); + -: 937: + -: 938: //increase supply count for choosen card by amount being discarded + 2: 939: state->supplyCount[state->hand[currentPlayer][choice1]] += choice2; + -: 940: + -: 941: //each other player gains a copy of revealed card + 6: 942: for (i = 0; i < state->numPlayers; i++) +branch 0 taken 67% +branch 1 taken 33% (fallthrough) + -: 943: { + 4: 944: if (i != currentPlayer) +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + -: 945: { + 2: 946: gainCard(state->hand[currentPlayer][choice1], state, 0, i); +call 0 returned 100% + -: 947: } + -: 948: } + -: 949: + -: 950: //discard played card from hand + 2: 951: discardCard(handPos, currentPlayer, state, 0); +call 0 returned 100% + -: 952: + -: 953: //trash copies of cards returned to supply + 6: 954: for (j = 0; j < choice2; j++) +branch 0 taken 67% +branch 1 taken 33% (fallthrough) + -: 955: { + 4: 956: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 taken 100% +branch 1 taken 0% (fallthrough) + -: 957: { + 4: 958: if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1]) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% + -: 959: { + 4: 960: discardCard(i, currentPlayer, state, 1); +call 0 returned 100% + 4: 961: break; + -: 962: } + -: 963: } + -: 964: } + -: 965: + 2: 966: return 0; + -: 967:} + -: 968: +function cardEffect called 0 returned 0% blocks executed 0% + #####: 969:int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) + -: 970:{ + -: 971: int i; + -: 972: int j; + -: 973: int k; + -: 974: int x; + -: 975: int index; + #####: 976: int currentPlayer = whoseTurn(state); +call 0 never executed + #####: 977: int nextPlayer = currentPlayer + 1; + -: 978: + #####: 979: int tributeRevealedCards[2] = {-1, -1}; + -: 980: int temphand[MAX_HAND];// moved above the if statement + #####: 981: int drawntreasure=0; + -: 982: int cardDrawn; + #####: 983: int z = 0;// this is the counter for the temp hand + #####: 984: if (nextPlayer > (state->numPlayers - 1)) { +branch 0 never executed +branch 1 never executed + #####: 985: nextPlayer = 0; + -: 986: } + -: 987: + -: 988: + -: 989: //uses switch to select card and perform actions + #####: 990: switch( card ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed +branch 6 never executed +branch 7 never executed +branch 8 never executed +branch 9 never executed +branch 10 never executed +branch 11 never executed +branch 12 never executed +branch 13 never executed +branch 14 never executed +branch 15 never executed +branch 16 never executed +branch 17 never executed +branch 18 never executed +branch 19 never executed +branch 20 never executed + -: 991: { + -: 992: case adventurer: + #####: 993: while(drawntreasure<2) { +branch 0 never executed +branch 1 never executed + #####: 994: if (state->deckCount[currentPlayer] <1) { //if the deck is empty we need to shuffle discard and add to deck +branch 0 never executed +branch 1 never executed + #####: 995: shuffle(currentPlayer, state); +call 0 never executed + -: 996: } + #####: 997: drawCard(currentPlayer, state); +call 0 never executed + #####: 998: cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card. + #####: 999: if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed + #####: 1000: drawntreasure++; + -: 1001: else { + #####: 1002: temphand[z]=cardDrawn; + #####: 1003: state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one). + #####: 1004: z++; + -: 1005: } + -: 1006: } + #####: 1007: while(z-1>=0) { +branch 0 never executed +branch 1 never executed + #####: 1008: state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn + #####: 1009: z=z-1; + -: 1010: } + #####: 1011: return 0; + -: 1012: + -: 1013: case council_room: + -: 1014: //+4 Cards + #####: 1015: for (i = 0; i < 4; i++) +branch 0 never executed +branch 1 never executed + -: 1016: { + #####: 1017: drawCard(currentPlayer, state); +call 0 never executed + -: 1018: } + -: 1019: + -: 1020: //+1 Buy + #####: 1021: state->numBuys++; + -: 1022: + -: 1023: //Each other player draws a card + #####: 1024: for (i = 0; i < state->numPlayers; i++) +branch 0 never executed +branch 1 never executed + -: 1025: { + #####: 1026: if ( i != currentPlayer ) +branch 0 never executed +branch 1 never executed + -: 1027: { + #####: 1028: drawCard(i, state); +call 0 never executed + -: 1029: } + -: 1030: } + -: 1031: + -: 1032: //put played card in played card pile + #####: 1033: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 1034: + #####: 1035: return 0; + -: 1036: + -: 1037: case feast: + -: 1038: //gain card with cost up to 5 + -: 1039: //Backup hand + #####: 1040: for (i = 0; i <= state->handCount[currentPlayer]; i++) { +branch 0 never executed +branch 1 never executed + #####: 1041: temphand[i] = state->hand[currentPlayer][i];//Backup card + #####: 1042: state->hand[currentPlayer][i] = -1;//Set to nothing + -: 1043: } + -: 1044: //Backup hand + -: 1045: + -: 1046: //Update Coins for Buy + #####: 1047: updateCoins(currentPlayer, state, 5); +call 0 never executed + #####: 1048: x = 1;//Condition to loop on + #####: 1049: while( x == 1) {//Buy one card +branch 0 never executed +branch 1 never executed + #####: 1050: if (supplyCount(choice1, state) <= 0) { +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 1051: if (DEBUG) + -: 1052: printf("None of that card left, sorry!\n"); + -: 1053: + -: 1054: if (DEBUG) { + -: 1055: printf("Cards Left: %d\n", supplyCount(choice1, state)); + -: 1056: } + -: 1057: } + #####: 1058: else if (state->coins < getCost(choice1)) { +call 0 never executed +branch 1 never executed +branch 2 never executed + #####: 1059: printf("That card is too expensive!\n"); +call 0 never executed + -: 1060: + -: 1061: if (DEBUG) { + -: 1062: printf("Coins: %d < %d\n", state->coins, getCost(choice1)); + -: 1063: } + -: 1064: } + -: 1065: else { + -: 1066: + -: 1067: if (DEBUG) { + -: 1068: printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + -: 1069: } + -: 1070: + #####: 1071: gainCard(choice1, state, 0, currentPlayer);//Gain the card +call 0 never executed + #####: 1072: x = 0;//No more buying cards + -: 1073: + -: 1074: if (DEBUG) { + -: 1075: printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + -: 1076: } + -: 1077: + -: 1078: } + -: 1079: } + -: 1080: + -: 1081: //Reset Hand + #####: 1082: for (i = 0; i <= state->handCount[currentPlayer]; i++) { +branch 0 never executed +branch 1 never executed + #####: 1083: state->hand[currentPlayer][i] = temphand[i]; + #####: 1084: temphand[i] = -1; + -: 1085: } + -: 1086: //Reset Hand + -: 1087: + #####: 1088: return 0; + -: 1089: + -: 1090: case gardens: + #####: 1091: return -1; + -: 1092: + -: 1093: case mine: + #####: 1094: return doMine(choice1, choice2, state, handPos, currentPlayer); +call 0 never executed + -: 1095: + -: 1096: case remodel: + #####: 1097: j = state->hand[currentPlayer][choice1]; //store card we will trash + -: 1098: + #####: 1099: if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) ) +call 0 never executed +call 1 never executed +branch 2 never executed +branch 3 never executed + -: 1100: { + #####: 1101: return -1; + -: 1102: } + -: 1103: + #####: 1104: gainCard(choice2, state, 0, currentPlayer); +call 0 never executed + -: 1105: + -: 1106: //discard card from hand + #####: 1107: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 1108: + -: 1109: //discard trashed card + #####: 1110: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 1111: { + #####: 1112: if (state->hand[currentPlayer][i] == j) +branch 0 never executed +branch 1 never executed + -: 1113: { + #####: 1114: discardCard(i, currentPlayer, state, 0); +call 0 never executed + #####: 1115: break; + -: 1116: } + -: 1117: } + -: 1118: + -: 1119: + #####: 1120: return 0; + -: 1121: + -: 1122: case smithy: + -: 1123: //+3 Cards + #####: 1124: for (i = 0; i < 3; i++) +branch 0 never executed +branch 1 never executed + -: 1125: { + #####: 1126: drawCard(currentPlayer, state); +call 0 never executed + -: 1127: } + -: 1128: + -: 1129: //discard card from hand + #####: 1130: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1131: return 0; + -: 1132: + -: 1133: case village: + -: 1134: //+1 Card + #####: 1135: drawCard(currentPlayer, state); +call 0 never executed + -: 1136: + -: 1137: //+2 Actions + #####: 1138: state->numActions = state->numActions + 2; + -: 1139: + -: 1140: //discard played card from hand + #####: 1141: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1142: return 0; + -: 1143: + -: 1144: case baron: + #####: 1145: doBaron(choice1, state, currentPlayer); +call 0 never executed + #####: 1146: return 0; + -: 1147: + -: 1148: case great_hall: + -: 1149: //+1 Card + #####: 1150: drawCard(currentPlayer, state); +call 0 never executed + -: 1151: + -: 1152: //+1 Actions + #####: 1153: state->numActions++; + -: 1154: + -: 1155: //discard card from hand + #####: 1156: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1157: return 0; + -: 1158: + -: 1159: case minion: + #####: 1160: doMinion(choice1, choice2, state, handPos, currentPlayer); +call 0 never executed + #####: 1161: return 0; + -: 1162: + -: 1163: case steward: + #####: 1164: if (choice1 == 1) +branch 0 never executed +branch 1 never executed + -: 1165: { + -: 1166: //+2 cards + #####: 1167: drawCard(currentPlayer, state); +call 0 never executed + #####: 1168: drawCard(currentPlayer, state); +call 0 never executed + -: 1169: } + #####: 1170: else if (choice1 == 2) +branch 0 never executed +branch 1 never executed + -: 1171: { + -: 1172: //+2 coins + #####: 1173: state->coins = state->coins + 2; + -: 1174: } + -: 1175: else + -: 1176: { + -: 1177: //trash 2 cards in hand + #####: 1178: discardCard(choice2, currentPlayer, state, 1); +call 0 never executed + #####: 1179: discardCard(choice3, currentPlayer, state, 1); +call 0 never executed + -: 1180: } + -: 1181: + -: 1182: //discard card from hand + #####: 1183: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1184: return 0; + -: 1185: + -: 1186: case tribute: + #####: 1187: doTribute(state, currentPlayer, nextPlayer, tributeRevealedCards); +call 0 never executed + #####: 1188: return 0; + -: 1189: + -: 1190: case ambassador: + #####: 1191: return doAmbassador(choice1, choice2, state, handPos, currentPlayer); +call 0 never executed + -: 1192: + -: 1193: case cutpurse: + -: 1194: + #####: 1195: updateCoins(currentPlayer, state, 2); +call 0 never executed + #####: 1196: for (i = 0; i < state->numPlayers; i++) +branch 0 never executed +branch 1 never executed + -: 1197: { + #####: 1198: if (i != currentPlayer) +branch 0 never executed +branch 1 never executed + -: 1199: { + #####: 1200: for (j = 0; j < state->handCount[i]; j++) +branch 0 never executed +branch 1 never executed + -: 1201: { + #####: 1202: if (state->hand[i][j] == copper) +branch 0 never executed +branch 1 never executed + -: 1203: { + #####: 1204: discardCard(j, i, state, 0); +call 0 never executed + #####: 1205: break; + -: 1206: } + #####: 1207: if (j == state->handCount[i]) +branch 0 never executed +branch 1 never executed + -: 1208: { + #####: 1209: for (k = 0; k < state->handCount[i]; k++) +branch 0 never executed +branch 1 never executed + -: 1210: { + -: 1211: if (DEBUG) + -: 1212: printf("Player %d reveals card number %d\n", i, state->hand[i][k]); + -: 1213: } + #####: 1214: break; + -: 1215: } + -: 1216: } + -: 1217: + -: 1218: } + -: 1219: + -: 1220: } + -: 1221: + -: 1222: //discard played card from hand + #####: 1223: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 1224: + #####: 1225: return 0; + -: 1226: + -: 1227: + -: 1228: case embargo: + -: 1229: //+2 Coins + #####: 1230: state->coins = state->coins + 2; + -: 1231: + -: 1232: //see if selected pile is in play + #####: 1233: if ( state->supplyCount[choice1] == -1 ) +branch 0 never executed +branch 1 never executed + -: 1234: { + #####: 1235: return -1; + -: 1236: } + -: 1237: + -: 1238: //add embargo token to selected supply pile + #####: 1239: state->embargoTokens[choice1]++; + -: 1240: + -: 1241: //trash card + #####: 1242: discardCard(handPos, currentPlayer, state, 1); +call 0 never executed + #####: 1243: return 0; + -: 1244: + -: 1245: case outpost: + -: 1246: //set outpost flag + #####: 1247: state->outpostPlayed++; + -: 1248: + -: 1249: //discard card + #####: 1250: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1251: return 0; + -: 1252: + -: 1253: case salvager: + -: 1254: //+1 buy + #####: 1255: state->numBuys++; + -: 1256: + #####: 1257: if (choice1) +branch 0 never executed +branch 1 never executed + -: 1258: { + -: 1259: //gain coins equal to trashed card + #####: 1260: state->coins = state->coins + getCost( handCard(choice1, state) ); +call 0 never executed +call 1 never executed + -: 1261: //trash card + #####: 1262: discardCard(choice1, currentPlayer, state, 1); +call 0 never executed + -: 1263: } + -: 1264: + -: 1265: //discard card + #####: 1266: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1267: return 0; + -: 1268: + -: 1269: case sea_hag: + #####: 1270: for (i = 0; i < state->numPlayers; i++) { +branch 0 never executed +branch 1 never executed + #####: 1271: if (i != currentPlayer) { +branch 0 never executed +branch 1 never executed + #####: 1272: state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; + #####: 1273: state->deckCount[i]--; + #####: 1274: state->discardCount[i]++; + #####: 1275: state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse + -: 1276: } + -: 1277: } + #####: 1278: return 0; + -: 1279: + -: 1280: case treasure_map: + -: 1281: //search hand for another treasure_map + #####: 1282: index = -1; + #####: 1283: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 1284: { + #####: 1285: if (state->hand[currentPlayer][i] == treasure_map && i != handPos) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 1286: { + #####: 1287: index = i; + #####: 1288: break; + -: 1289: } + -: 1290: } + #####: 1291: if (index > -1) +branch 0 never executed +branch 1 never executed + -: 1292: { + -: 1293: //trash both treasure cards + #####: 1294: discardCard(handPos, currentPlayer, state, 1); +call 0 never executed + #####: 1295: discardCard(index, currentPlayer, state, 1); +call 0 never executed + -: 1296: + -: 1297: //gain 4 Gold cards + #####: 1298: for (i = 0; i < 4; i++) +branch 0 never executed +branch 1 never executed + -: 1299: { + #####: 1300: gainCard(gold, state, 1, currentPlayer); +call 0 never executed + -: 1301: } + -: 1302: + -: 1303: //return success + #####: 1304: return 1; + -: 1305: } + -: 1306: + -: 1307: //no second treasure_map found in hand + #####: 1308: return -1; + -: 1309: } + -: 1310: + #####: 1311: return -1; + -: 1312:} + -: 1313: +function discardCard called 18 returned 100% blocks executed 89% + 18: 1314:int discardCard(int handPos, int currentPlayer, struct gameState *state, int trashFlag) + -: 1315:{ + -: 1316: + -: 1317: //if card is not trashed, added to Played pile + 18: 1318: if (trashFlag < 1) +branch 0 taken 78% (fallthrough) +branch 1 taken 22% + -: 1319: { + -: 1320: //add card to played pile + 14: 1321: state->playedCards[state->playedCardCount] = state->hand[currentPlayer][handPos]; + 14: 1322: state->playedCardCount++; + -: 1323: } + -: 1324: + -: 1325: //set played card to -1 + 18: 1326: state->hand[currentPlayer][handPos] = -1; + -: 1327: + -: 1328: //remove card from player's hand + 18: 1329: if ( handPos == (state->handCount[currentPlayer] - 1) ) //last card in hand array is played +branch 0 taken 11% (fallthrough) +branch 1 taken 89% + -: 1330: { + -: 1331: //reduce number of cards in hand + 2: 1332: state->handCount[currentPlayer]--; + -: 1333: } + 16: 1334: else if ( state->handCount[currentPlayer] == 1 ) //only one card in hand +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1335: { + -: 1336: //reduce number of cards in hand + #####: 1337: state->handCount[currentPlayer]--; + -: 1338: } + -: 1339: else + -: 1340: { + -: 1341: //replace discarded card with last card in hand + 16: 1342: state->hand[currentPlayer][handPos] = state->hand[currentPlayer][ (state->handCount[currentPlayer] - 1)]; + -: 1343: //set last card to -1 + 16: 1344: state->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1; + -: 1345: //reduce number of cards in hand + 16: 1346: state->handCount[currentPlayer]--; + -: 1347: } + -: 1348: + 18: 1349: return 0; + -: 1350:} + -: 1351: +function gainCard called 4 returned 100% blocks executed 70% + 4: 1352:int gainCard(int supplyPos, struct gameState *state, int toFlag, int player) + -: 1353:{ + -: 1354: //Note: supplyPos is enum of choosen card + -: 1355: + -: 1356: //check if supply pile is empty (0) or card is not used in game (-1) + 4: 1357: if ( supplyCount(supplyPos, state) < 1 ) +call 0 returned 100% +branch 1 taken 0% (fallthrough) +branch 2 taken 100% + -: 1358: { + #####: 1359: return -1; + -: 1360: } + -: 1361: + -: 1362: //added card for [whoseTurn] current player: + -: 1363: // toFlag = 0 : add to discard + -: 1364: // toFlag = 1 : add to deck + -: 1365: // toFlag = 2 : add to hand + -: 1366: + 4: 1367: if (toFlag == 1) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1368: { + #####: 1369: state->deck[ player ][ state->deckCount[player] ] = supplyPos; + #####: 1370: state->deckCount[player]++; + -: 1371: } + 4: 1372: else if (toFlag == 2) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1373: { + #####: 1374: state->hand[ player ][ state->handCount[player] ] = supplyPos; + #####: 1375: state->handCount[player]++; + -: 1376: } + -: 1377: else + -: 1378: { + 4: 1379: state->discard[player][ state->discardCount[player] ] = supplyPos; + 4: 1380: state->discardCount[player]++; + -: 1381: } + -: 1382: + -: 1383: //decrease number in supply pile + 4: 1384: state->supplyCount[supplyPos]--; + -: 1385: + 4: 1386: return 0; + -: 1387:} + -: 1388: +function updateCoins called 5 returned 100% blocks executed 82% + 5: 1389:int updateCoins(int player, struct gameState *state, int bonus) + -: 1390:{ + -: 1391: int i; + -: 1392: + -: 1393: //reset coin count + 5: 1394: state->coins = 0; + -: 1395: + -: 1396: //add coins for each Treasure card in player's hand + 30: 1397: for (i = 0; i < state->handCount[player]; i++) +branch 0 taken 83% +branch 1 taken 17% (fallthrough) + -: 1398: { + 25: 1399: if (state->hand[player][i] == copper) +branch 0 taken 60% (fallthrough) +branch 1 taken 40% + -: 1400: { + 15: 1401: state->coins += 1; + -: 1402: } + 10: 1403: else if (state->hand[player][i] == silver) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1404: { + #####: 1405: state->coins += 2; + -: 1406: } + 10: 1407: else if (state->hand[player][i] == gold) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1408: { + #####: 1409: state->coins += 3; + -: 1410: } + -: 1411: } + -: 1412: + -: 1413: //add bonus + 5: 1414: state->coins += bonus; + -: 1415: + 5: 1416: return 0; + -: 1417:} + -: 1418: + -: 1419: + -: 1420://end of dominion.c diff --git a/projects/alghanmz/a3/dominion.gcda b/projects/alghanmz/a3/dominion.gcda new file mode 100644 index 000000000..231f0fbf2 Binary files /dev/null and b/projects/alghanmz/a3/dominion.gcda differ diff --git a/projects/alghanmz/a3/dominion.gcno b/projects/alghanmz/a3/dominion.gcno new file mode 100644 index 000000000..53cd4ee4f Binary files /dev/null and b/projects/alghanmz/a3/dominion.gcno differ diff --git a/projects/alghanmz/a3/dominion.h b/projects/alghanmz/a3/dominion.h new file mode 100644 index 000000000..f9d9039b8 --- /dev/null +++ b/projects/alghanmz/a3/dominion.h @@ -0,0 +1,131 @@ +#ifndef _DOMINION_H +#define _DOMINION_H + +// Code from various sources, baseline from Kristen Bartosz + +#define MAX_HAND 500 +#define MAX_DECK 500 + +#define MAX_PLAYERS 4 + +#define DEBUG 0 + +/* http://dominion.diehrstraits.com has card texts */ +/* http://dominion.isotropic.org has other stuff */ + +/* hand# means index of a card in current active player's hand */ + +enum CARD +{ curse = 0, + estate, + duchy, + province, + + copper, + silver, + gold, + + adventurer, + /* If no/only 1 treasure found, stop when full deck seen */ + council_room, + feast, /* choice1 is supply # of card gained) */ + gardens, + mine, /* choice1 is hand# of money to trash, choice2 is supply# of + money to put in hand */ + remodel, /* choice1 is hand# of card to remodel, choice2 is supply# */ + smithy, + village, + + baron, /* choice1: boolean for discard of estate */ + /* Discard is always of first (lowest index) estate */ + great_hall, + minion, /* choice1: 1 = +2 coin, 2 = redraw */ + steward, /* choice1: 1 = +2 card, 2 = +2 coin, 3 = trash 2 (choice2,3) */ + tribute, + + ambassador, /* choice1 = hand#, choice2 = number to return to supply */ + cutpurse, + embargo, /* choice1 = supply# */ + outpost, + salvager, /* choice1 = hand# to trash */ + sea_hag, + treasure_map +}; + +struct gameState { + int numPlayers; //number of players + int supplyCount[treasure_map+1]; //this is the amount of a specific type of card given a specific number. + int embargoTokens[treasure_map+1]; + int outpostPlayed; + int outpostTurn; + int whoseTurn; + int phase; + int numActions; /* Starts at 1 each turn */ + int coins; /* Use as you see fit! */ + int numBuys; /* Starts at 1 each turn */ + int hand[MAX_PLAYERS][MAX_HAND]; + int handCount[MAX_PLAYERS]; + int deck[MAX_PLAYERS][MAX_DECK]; + int deckCount[MAX_PLAYERS]; + int discard[MAX_PLAYERS][MAX_DECK]; + int discardCount[MAX_PLAYERS]; + int playedCards[MAX_DECK]; + int playedCardCount; +}; + +/* All functions return -1 on failure, and DO NOT CHANGE GAME STATE; + unless specified for other return, return 0 on success */ + +struct gameState* newGame(); + +int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + int k8, int k9, int k10); + +int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, + struct gameState *state); +/* Responsible for initializing all supplies, and shuffling deck and + drawing starting hands for all players. Check that 10 cards selected + are in fact (different) kingdom cards, and that numPlayers is valid. + +Cards not in game should initialize supply position to -1 */ + +int shuffle(int player, struct gameState *state); +/* Assumes all cards are now in deck array (or hand/played): discard is + empty */ + +int playCard(int handPos, int choice1, int choice2, int choice3, + struct gameState *state); +/* Play card with index handPos from current player's hand */ + +int buyCard(int supplyPos, struct gameState *state); +/* Buy card with supply index supplyPos */ + +int numHandCards(struct gameState *state); +/* How many cards current player has in hand */ + +int handCard(int handNum, struct gameState *state); +/* enum value of indexed card in player's hand */ + +int supplyCount(int card, struct gameState *state); +/* How many of given card are left in supply */ + +int fullDeckCount(int player, int card, struct gameState *state); +/* Here deck = hand + discard + deck */ + +int whoseTurn(struct gameState *state); + +int endTurn(struct gameState *state); +/* Must do phase C and advance to next player; do not advance whose turn + if game is over */ + +int isGameOver(struct gameState *state); + +int scoreFor(int player, struct gameState *state); +/* Negative here does not mean invalid; scores may be negative, + -9999 means invalid input */ + +int getWinners(int players[MAX_PLAYERS], struct gameState *state); +/* Set array position of each player who won (remember ties!) to + 1, others to 0 */ + +#endif diff --git a/projects/alghanmz/a3/dominion.o b/projects/alghanmz/a3/dominion.o new file mode 100644 index 000000000..81ae49587 Binary files /dev/null and b/projects/alghanmz/a3/dominion.o differ diff --git a/projects/alghanmz/a3/dominion_helpers.h b/projects/alghanmz/a3/dominion_helpers.h new file mode 100644 index 000000000..0887fda15 --- /dev/null +++ b/projects/alghanmz/a3/dominion_helpers.h @@ -0,0 +1,15 @@ +#ifndef _DOMINION_HELPERS_H +#define _DOMINION_HELPERS_H + +#include "dominion.h" + +int drawCard(int player, struct gameState *state); +int updateCoins(int player, struct gameState *state, int bonus); +int discardCard(int handPos, int currentPlayer, struct gameState *state, + int trashFlag); +int gainCard(int supplyPos, struct gameState *state, int toFlag, int player); +int getCost(int cardNumber); +int cardEffect(int card, int choice1, int choice2, int choice3, + struct gameState *state, int handPos, int *bonus); + +#endif diff --git a/projects/alghanmz/a3/hw.c b/projects/alghanmz/a3/hw.c new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/projects/alghanmz/a3/hw.c @@ -0,0 +1 @@ + diff --git a/projects/alghanmz/a3/rngs.c b/projects/alghanmz/a3/rngs.c new file mode 100644 index 000000000..a85bbc961 --- /dev/null +++ b/projects/alghanmz/a3/rngs.c @@ -0,0 +1,183 @@ +/* ------------------------------------------------------------------------- + * This is an ANSI C library for multi-stream random number generation. + * The use of this library is recommended as a replacement for the ANSI C + * rand() and srand() functions, particularly in simulation applications + * where the statistical 'goodness' of the random number generator is + * important. The library supplies 256 streams of random numbers; use + * SelectStream(s) to switch between streams indexed s = 0,1,...,255. + * + * The streams must be initialized. The recommended way to do this is by + * using the function PlantSeeds(x) with the value of x used to initialize + * the default stream and all other streams initialized automatically with + * values dependent on the value of x. The following convention is used + * to initialize the default stream: + * if x > 0 then x is the state + * if x < 0 then the state is obtained from the system clock + * if x = 0 then the state is to be supplied interactively. + * + * The generator used in this library is a so-called 'Lehmer random number + * generator' which returns a pseudo-random number uniformly distributed + * 0.0 and 1.0. The period is (m - 1) where m = 2,147,483,647 and the + * smallest and largest possible values are (1 / m) and 1 - (1 / m) + * respectively. For more details see: + * + * "Random Number Generators: Good Ones Are Hard To Find" + * Steve Park and Keith Miller + * Communications of the ACM, October 1988 + * + * Name : rngs.c (Random Number Generation - Multiple Streams) + * Authors : Steve Park & Dave Geyer + * Language : ANSI C + * Latest Revision : 09-22-98 + * ------------------------------------------------------------------------- + */ + +#include +#include +#include "rngs.h" + +#define MODULUS 2147483647 /* DON'T CHANGE THIS VALUE */ +#define MULTIPLIER 48271 /* DON'T CHANGE THIS VALUE */ +#define CHECK 399268537 /* DON'T CHANGE THIS VALUE */ +#define STREAMS 256 /* # of streams, DON'T CHANGE THIS VALUE */ +#define A256 22925 /* jump multiplier, DON'T CHANGE THIS VALUE */ +#define DEFAULT 123456789 /* initial seed, use 0 < DEFAULT < MODULUS */ + +static long seed[STREAMS] = {DEFAULT}; /* current state of each stream */ +static int stream = 0; /* stream index, 0 is the default */ +static int initialized = 0; /* test for stream initialization */ + + +double Random(void) +/* ---------------------------------------------------------------- + * Random returns a pseudo-random real number uniformly distributed + * between 0.0 and 1.0. + * ---------------------------------------------------------------- + */ +{ + const long Q = MODULUS / MULTIPLIER; + const long R = MODULUS % MULTIPLIER; + long t; + + t = MULTIPLIER * (seed[stream] % Q) - R * (seed[stream] / Q); + if (t > 0) + seed[stream] = t; + else + seed[stream] = t + MODULUS; + return ((double) seed[stream] / MODULUS); +} + + +void PlantSeeds(long x) +/* --------------------------------------------------------------------- + * Use this function to set the state of all the random number generator + * streams by "planting" a sequence of states (seeds), one per stream, + * with all states dictated by the state of the default stream. + * The sequence of planted states is separated one from the next by + * 8,367,782 calls to Random(). + * --------------------------------------------------------------------- + */ +{ + const long Q = MODULUS / A256; + const long R = MODULUS % A256; + int j; + int s; + + initialized = 1; + s = stream; /* remember the current stream */ + SelectStream(0); /* change to stream 0 */ + PutSeed(x); /* set seed[0] */ + stream = s; /* reset the current stream */ + for (j = 1; j < STREAMS; j++) { + x = A256 * (seed[j - 1] % Q) - R * (seed[j - 1] / Q); + if (x > 0) + seed[j] = x; + else + seed[j] = x + MODULUS; + } +} + + +void PutSeed(long x) +/* --------------------------------------------------------------- + * Use this function to set the state of the current random number + * generator stream according to the following conventions: + * if x > 0 then x is the state (unless too large) + * if x < 0 then the state is obtained from the system clock + * if x = 0 then the state is to be supplied interactively + * --------------------------------------------------------------- + */ +{ + char ok = 0; + + if (x > 0) + x = x % MODULUS; /* correct if x is too large */ + if (x < 0) + x = ((unsigned long) time((time_t *) NULL)) % MODULUS; + if (x == 0) + while (!ok) { + printf("\nEnter a positive integer seed (9 digits or less) >> "); + scanf("%ld", &x); + ok = (0 < x) && (x < MODULUS); + if (!ok) + printf("\nInput out of range ... try again\n"); + } + seed[stream] = x; +} + + +void GetSeed(long *x) +/* --------------------------------------------------------------- + * Use this function to get the state of the current random number + * generator stream. + * --------------------------------------------------------------- + */ +{ + *x = seed[stream]; +} + + +void SelectStream(int index) +/* ------------------------------------------------------------------ + * Use this function to set the current random number generator + * stream -- that stream from which the next random number will come. + * ------------------------------------------------------------------ + */ +{ + stream = ((unsigned int) index) % STREAMS; + if ((initialized == 0) && (stream != 0)) /* protect against */ + PlantSeeds(DEFAULT); /* un-initialized streams */ +} + + +void TestRandom(void) +/* ------------------------------------------------------------------ + * Use this (optional) function to test for a correct implementation. + * ------------------------------------------------------------------ + */ +{ + long i; + long x; + double u; + char ok = 0; + + SelectStream(0); /* select the default stream */ + PutSeed(1); /* and set the state to 1 */ + for(i = 0; i < 10000; i++) { + u = Random(); + if (ok) + printf(" %f \n\n", u); + + } + GetSeed(&x); /* get the new state value */ + ok = (x == CHECK); /* and check for correctness */ + + SelectStream(1); /* select stream 1 */ + PlantSeeds(1); /* set the state of all streams */ + GetSeed(&x); /* get the state of stream 1 */ + ok = ok && (x == A256); /* x should be the jump multiplier */ + if (ok) + printf("\n The implementation of rngs.c is correct.\n\n"); + else + printf("\n\a ERROR -- the implementation of rngs.c is not correct.\n\n"); +} diff --git a/projects/alghanmz/a3/rngs.gcda b/projects/alghanmz/a3/rngs.gcda new file mode 100644 index 000000000..e0619095e Binary files /dev/null and b/projects/alghanmz/a3/rngs.gcda differ diff --git a/projects/alghanmz/a3/rngs.gcno b/projects/alghanmz/a3/rngs.gcno new file mode 100644 index 000000000..f05d60f39 Binary files /dev/null and b/projects/alghanmz/a3/rngs.gcno differ diff --git a/projects/alghanmz/a3/rngs.h b/projects/alghanmz/a3/rngs.h new file mode 100644 index 000000000..c9f3f451a --- /dev/null +++ b/projects/alghanmz/a3/rngs.h @@ -0,0 +1,19 @@ +/* ----------------------------------------------------------------------- + * Name : rngs.h (header file for the library file rngs.c) + * Author : Steve Park & Dave Geyer + * Language : ANSI C + * Latest Revision : 09-22-98 + * ----------------------------------------------------------------------- + */ + +#if !defined( _RNGS_ ) +#define _RNGS_ + +double Random(void); +void PlantSeeds(long x); +void GetSeed(long *x); +void PutSeed(long x); +void SelectStream(int index); +void TestRandom(void); + +#endif diff --git a/projects/alghanmz/a3/rngs.o b/projects/alghanmz/a3/rngs.o new file mode 100644 index 000000000..4f59e8b88 Binary files /dev/null and b/projects/alghanmz/a3/rngs.o differ diff --git a/projects/alghanmz/a3/unittest1 b/projects/alghanmz/a3/unittest1 new file mode 100644 index 000000000..3aa1f9ff8 Binary files /dev/null and b/projects/alghanmz/a3/unittest1 differ diff --git a/projects/alghanmz/a3/unittest1.gcda b/projects/alghanmz/a3/unittest1.gcda new file mode 100644 index 000000000..b77277840 Binary files /dev/null and b/projects/alghanmz/a3/unittest1.gcda differ diff --git a/projects/alghanmz/a3/unittest1.gcno b/projects/alghanmz/a3/unittest1.gcno new file mode 100644 index 000000000..f88979db7 Binary files /dev/null and b/projects/alghanmz/a3/unittest1.gcno differ diff --git a/projects/alghanmz/a3/unittest2 b/projects/alghanmz/a3/unittest2 new file mode 100644 index 000000000..f7d822035 Binary files /dev/null and b/projects/alghanmz/a3/unittest2 differ diff --git a/projects/alghanmz/a3/unittest2.gcda b/projects/alghanmz/a3/unittest2.gcda new file mode 100644 index 000000000..afbec2732 Binary files /dev/null and b/projects/alghanmz/a3/unittest2.gcda differ diff --git a/projects/alghanmz/a3/unittest2.gcno b/projects/alghanmz/a3/unittest2.gcno new file mode 100644 index 000000000..4fc66e70d Binary files /dev/null and b/projects/alghanmz/a3/unittest2.gcno differ diff --git a/projects/alghanmz/a3/unittest3 b/projects/alghanmz/a3/unittest3 new file mode 100644 index 000000000..ca08a5ffa Binary files /dev/null and b/projects/alghanmz/a3/unittest3 differ diff --git a/projects/alghanmz/a3/unittest3.gcda b/projects/alghanmz/a3/unittest3.gcda new file mode 100644 index 000000000..db7f1f315 Binary files /dev/null and b/projects/alghanmz/a3/unittest3.gcda differ diff --git a/projects/alghanmz/a3/unittest3.gcno b/projects/alghanmz/a3/unittest3.gcno new file mode 100644 index 000000000..a11220c9c Binary files /dev/null and b/projects/alghanmz/a3/unittest3.gcno differ diff --git a/projects/alghanmz/a3/unittest4 b/projects/alghanmz/a3/unittest4 new file mode 100644 index 000000000..19ad1d52e Binary files /dev/null and b/projects/alghanmz/a3/unittest4 differ diff --git a/projects/alghanmz/a3/unittest4.gcda b/projects/alghanmz/a3/unittest4.gcda new file mode 100644 index 000000000..9448441fa Binary files /dev/null and b/projects/alghanmz/a3/unittest4.gcda differ diff --git a/projects/alghanmz/a3/unittest4.gcno b/projects/alghanmz/a3/unittest4.gcno new file mode 100644 index 000000000..c33bc567f Binary files /dev/null and b/projects/alghanmz/a3/unittest4.gcno differ diff --git a/projects/alghanmz/a3/unittest5 b/projects/alghanmz/a3/unittest5 new file mode 100644 index 000000000..5855f8fc4 Binary files /dev/null and b/projects/alghanmz/a3/unittest5 differ diff --git a/projects/alghanmz/a3/unittest5.gcda b/projects/alghanmz/a3/unittest5.gcda new file mode 100644 index 000000000..01dae6880 Binary files /dev/null and b/projects/alghanmz/a3/unittest5.gcda differ diff --git a/projects/alghanmz/a3/unittest5.gcno b/projects/alghanmz/a3/unittest5.gcno new file mode 100644 index 000000000..7982f5a17 Binary files /dev/null and b/projects/alghanmz/a3/unittest5.gcno differ diff --git a/projects/alghanmz/a3/unittestresults.out b/projects/alghanmz/a3/unittestresults.out new file mode 100644 index 000000000..e7b35ea86 --- /dev/null +++ b/projects/alghanmz/a3/unittestresults.out @@ -0,0 +1,963 @@ + +Begin Testing doBaron(): + +Test 1 +Assert failed: Number of buys not increased by 1 +Assert failed: Baron card not discarded +Test 2 +Assert failed: Number of buys not increased by 1 +Assert failed: Baron card not discarded +Test 3 +Assert failed: Number of buys not increased by 1 +Assert failed: Coins not increased by 4 +Assert failed: Baron card not discarded +End of doBaron() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:0.00% of 20 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 28 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:0.00% of 17 +Branches executed:0.00% of 16 +Taken at least once:0.00% of 16 +Calls executed:0.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:0.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:0.00% of 2 +No branches +Calls executed:0.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:83.87% of 62 +Branches executed:95.65% of 46 +Taken at least once:80.43% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:21.78% of 583 +Branches executed:21.03% of 409 +Taken at least once:16.87% of 409 +Calls executed:13.40% of 97 +Creating 'dominion.c.gcov' + + +Begin Testing doMinion(): + +Test 1 +Test 2 +Assert failed: Current player should have exactly 4 cards +Assert failed: A player with less than 5 cards discarded hand +End of doMinion() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:92.31% of 13 +Branches executed:100.00% of 6 +Taken at least once:66.67% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:0.00% of 20 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 28 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:93.55% of 62 +Branches executed:100.00% of 46 +Taken at least once:89.13% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:28.47% of 583 +Branches executed:26.89% of 409 +Taken at least once:22.49% of 409 +Calls executed:20.62% of 97 +Creating 'dominion.c.gcov' + + +Begin Testing doAmbassador(): + +Test 1 +Assert failed: Didn't return -1 when trying to discard too many cards +Test 2 +Assert failed: Didn't return -1 when trying to discard ambassador card +End of doAmbassador() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:92.31% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:90.00% of 20 +Branches executed:100.00% of 22 +Taken at least once:77.27% of 22 +Calls executed:100.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 28 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:93.55% of 62 +Branches executed:100.00% of 46 +Taken at least once:89.13% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:31.56% of 583 +Branches executed:32.27% of 409 +Taken at least once:26.89% of 409 +Calls executed:23.71% of 97 +Creating 'dominion.c.gcov' + + +Begin Testing doTribute(): + +Test 1 +Assert failed: Tribute card not discarded +Assert failed: Didn't draw 2 cards +Test 2 +Assert failed: Tribute card not discarded +Assert failed: Didn't draw 2 cards +Assert failed: Actions didn't increase by 2 +Test 3 +Assert failed: Tribute card not discarded +Assert failed: Didn't draw 2 cards +End of doTribute() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:92.31% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:90.00% of 20 +Branches executed:100.00% of 22 +Taken at least once:77.27% of 22 +Calls executed:100.00% of 3 + +Function 'doTribute' +Lines executed:82.14% of 28 +Branches executed:100.00% of 30 +Taken at least once:70.00% of 30 +Calls executed:100.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:93.55% of 62 +Branches executed:100.00% of 46 +Taken at least once:89.13% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:35.51% of 583 +Branches executed:39.61% of 409 +Taken at least once:32.03% of 409 +Calls executed:25.77% of 97 +Creating 'dominion.c.gcov' + + +Begin Testing doMine(): + +Test 1 +Assert failed: Didn't return -1 when trying to trash a curse +Test 2 +Assert failed: Silver not gained to hand +Test 3 +End of doMine() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:92.31% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:90.00% of 20 +Branches executed:100.00% of 22 +Taken at least once:77.27% of 22 +Calls executed:100.00% of 3 + +Function 'doTribute' +Lines executed:82.14% of 28 +Branches executed:100.00% of 30 +Taken at least once:70.00% of 30 +Calls executed:100.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:85.71% of 14 +Branches executed:100.00% of 12 +Taken at least once:58.33% of 12 +Calls executed:100.00% of 4 + +Function 'getCost' +Lines executed:16.67% of 30 +Branches executed:100.00% of 28 +Taken at least once:10.71% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:93.55% of 62 +Branches executed:100.00% of 46 +Taken at least once:89.13% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:38.42% of 583 +Branches executed:49.39% of 409 +Taken at least once:34.47% of 409 +Calls executed:29.90% of 97 +Creating 'dominion.c.gcov' + diff --git a/projects/alghanmz/a4/Makefile old b/projects/alghanmz/a4/Makefile old new file mode 100644 index 000000000..5541801f3 --- /dev/null +++ b/projects/alghanmz/a4/Makefile old @@ -0,0 +1,31 @@ +CFLAGS= -Wall -fpic -coverage -lm -std=c99 + +rngs.o: rngs.h rngs.c + gcc -c rngs.c -g $(CFLAGS) + +dominion.o: dominion.h dominion.c rngs.o + gcc -c dominion.c -g $(CFLAGS) + +playdom: dominion.o playdom.c + gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS) +#To run playdom you need to entere: ./playdom like ./playdom 10*/ + +testDrawCard: testDrawCard.c dominion.o rngs.o + gcc -o testDrawCard -g testDrawCard.c dominion.o rngs.o $(CFLAGS) + +interface.o: interface.h interface.c + gcc -c interface.c -g $(CFLAGS) + +runtests: testDrawCard + ./testDrawCard &> unittestresult.out + gcov dominion.c >> unittestresult.out + cat dominion.c.gcov >> unittestresult.out + + +player: player.c interface.o + gcc -o player player.c -g dominion.o rngs.o interface.o $(CFLAGS) + +all: playdom player + +clean: + rm -f *.o playdom.exe playdom player player.exe *.gcov *.gcda *.gcno *.so *.out testDrawCard testDrawCard.exe diff --git a/projects/alghanmz/a4/READM.md b/projects/alghanmz/a4/READM.md new file mode 100644 index 000000000..c3599f6ad --- /dev/null +++ b/projects/alghanmz/a4/READM.md @@ -0,0 +1,2 @@ +run make all #To compile the dominion code +run ./playdom 30 # to run playdom code diff --git a/projects/alghanmz/a4/dominion.c b/projects/alghanmz/a4/dominion.c new file mode 100644 index 000000000..739e2605e --- /dev/null +++ b/projects/alghanmz/a4/dominion.c @@ -0,0 +1,1405 @@ +#include "dominion.h" +#include "dominion_helpers.h" +#include "rngs.h" +#include +#include +#include + +int compare(const void* a, const void* b) { + if (*(int*)a > *(int*)b) + return 1; + if (*(int*)a < *(int*)b) + return -1; + return 0; +} + +struct gameState* newGame() { + struct gameState* g = malloc(sizeof(struct gameState)); + return g; +} + +int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + int k8, int k9, int k10) { + int* k = malloc(10 * sizeof(int)); + k[0] = k1; + k[1] = k2; + k[2] = k3; + k[3] = k4; + k[4] = k5; + k[5] = k6; + k[6] = k7; + k[7] = k8; + k[8] = k9; + k[9] = k10; + return k; +} + +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 shuffle(int player, struct gameState *state) { + + + int newDeck[MAX_DECK]; + int newDeckPos = 0; + int card; + int i; + + if (state->deckCount[player] < 1) + return -1; + qsort ((void*)(state->deck[player]), state->deckCount[player], sizeof(int), compare); + /* SORT CARDS IN DECK TO ENSURE DETERMINISM! */ + + while (state->deckCount[player] > 0) { + card = floor(Random() * state->deckCount[player]); + newDeck[newDeckPos] = state->deck[player][card]; + newDeckPos++; + for (i = card; i < state->deckCount[player]-1; i++) { + state->deck[player][i] = state->deck[player][i+1]; + } + state->deckCount[player]--; + } + for (i = 0; i < newDeckPos; i++) { + state->deck[player][i] = newDeck[i]; + state->deckCount[player]++; + } + + return 0; +} + +int playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state) +{ + int card; + int coin_bonus = 0; //tracks coins gain from actions + + //check if it is the right phase + if (state->phase != 0) + { + return -1; + } + + //check if player has enough actions + if ( state->numActions < 1 ) + { + return -1; + } + + //get card played + card = handCard(handPos, state); + + //check if selected card is an action + if ( card < adventurer || card > treasure_map ) + { + return -1; + } + + //play card + if ( cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0 ) + { + return -1; + } + + //reduce number of actions + state->numActions--; + + //update coins (Treasure cards may be added with card draws) + updateCoins(state->whoseTurn, state, coin_bonus); + + return 0; +} + +int buyCard(int supplyPos, struct gameState *state) { + int who; + if (DEBUG) { + printf("Entering buyCard...\n"); + } + + // I don't know what to do about the phase thing. + + who = state->whoseTurn; + + if (state->numBuys < 1) { + if (DEBUG) + printf("You do not have any buys left\n"); + return -1; + } else if (supplyCount(supplyPos, state) <1) { + if (DEBUG) + printf("There are not any of that type of card left\n"); + return -1; + } else if (state->coins < getCost(supplyPos)) { + if (DEBUG) + printf("You do not have enough money to buy that. You have %d coins.\n", state->coins); + return -1; + } else { + state->phase=1; + //state->supplyCount[supplyPos]--; + gainCard(supplyPos, state, 0, who); //card goes in discard, this might be wrong.. (2 means goes into hand, 0 goes into discard) + + state->coins = (state->coins) - (getCost(supplyPos)); + state->numBuys--; + if (DEBUG) + printf("You bought card number %d for %d coins. You now have %d buys and %d coins.\n", supplyPos, getCost(supplyPos), state->numBuys, state->coins); + } + + //state->discard[who][state->discardCount[who]] = supplyPos; + //state->discardCount[who]++; + + return 0; +} + +int numHandCards(struct gameState *state) { + return state->handCount[ whoseTurn(state) ]; +} + +int handCard(int handPos, struct gameState *state) { + int currentPlayer = whoseTurn(state); + return state->hand[currentPlayer][handPos]; +} + +int supplyCount(int card, struct gameState *state) { + return state->supplyCount[card]; +} + +int fullDeckCount(int player, int card, struct gameState *state) { + int i; + int count = 0; + + for (i = 0; i < state->deckCount[player]; i++) + { + if (state->deck[player][i] == card) count++; + } + + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == card) count++; + } + + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->discard[player][i] == card) count++; + } + + return count; +} + +int whoseTurn(struct gameState *state) { + return state->whoseTurn; +} + +int endTurn(struct gameState *state) { + int k; + int i; + int currentPlayer = whoseTurn(state); + + //Discard hand + for (i = 0; i < state->handCount[currentPlayer]; i++) { + state->discard[currentPlayer][state->discardCount[currentPlayer]++] = state->hand[currentPlayer][i];//Discard + state->hand[currentPlayer][i] = -1;//Set card to -1 + } + state->handCount[currentPlayer] = 0;//Reset hand count + + //Code for determining the player + if (currentPlayer < (state->numPlayers - 1)) { + state->whoseTurn = currentPlayer + 1;//Still safe to increment + } + else { + state->whoseTurn = 0;//Max player has been reached, loop back around to player 1 + } + + state->outpostPlayed = 0; + state->phase = 0; + state->numActions = 1; + state->coins = 0; + state->numBuys = 1; + state->playedCardCount = 0; + state->handCount[state->whoseTurn] = 0; + + //int k; move to top + //Next player draws hand + for (k = 0; k < 5; k++) { + drawCard(state->whoseTurn, state);//Draw a card + } + + //Update money + updateCoins(state->whoseTurn, state, 0); + + return 0; +} + +int isGameOver(struct gameState *state) { + int i; + int j; + + //if stack of Province cards is empty, the game ends + if (state->supplyCount[province] == 0) + { + return 1; + } + + //if three supply pile are at 0, the game ends + j = 0; + for (i = 0; i < 25; i++) + { + if (state->supplyCount[i] == 0) + { + j++; + } + } + if ( j >= 3) + { + return 1; + } + + return 0; +} + +int scoreFor (int player, struct gameState *state) { + + int i; + int score = 0; + //score from hand + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == curse) { + score = score - 1; + }; + if (state->hand[player][i] == estate) { + score = score + 1; + }; + if (state->hand[player][i] == duchy) { + score = score + 3; + }; + if (state->hand[player][i] == province) { + score = score + 6; + }; + if (state->hand[player][i] == great_hall) { + score = score + 1; + }; + if (state->hand[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + //score from discard + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->discard[player][i] == curse) { + score = score - 1; + }; + if (state->discard[player][i] == estate) { + score = score + 1; + }; + if (state->discard[player][i] == duchy) { + score = score + 3; + }; + if (state->discard[player][i] == province) { + score = score + 6; + }; + if (state->discard[player][i] == great_hall) { + score = score + 1; + }; + if (state->discard[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + //score from deck + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->deck[player][i] == curse) { + score = score - 1; + }; + if (state->deck[player][i] == estate) { + score = score + 1; + }; + if (state->deck[player][i] == duchy) { + score = score + 3; + }; + if (state->deck[player][i] == province) { + score = score + 6; + }; + if (state->deck[player][i] == great_hall) { + score = score + 1; + }; + if (state->deck[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + return score; +} + +int getWinners(int players[MAX_PLAYERS], struct gameState *state) { + int i; + int j; + int highScore; + int currentPlayer; + + //get score for each player + for (i = 0; i < MAX_PLAYERS; i++) + { + //set unused player scores to -9999 + if (i >= state->numPlayers) + { + players[i] = -9999; + } + else + { + players[i] = scoreFor (i, state); + } + } + + //find highest score + j = 0; + for (i = 0; i < MAX_PLAYERS; i++) + { + if (players[i] > players[j]) + { + j = i; + } + } + highScore = players[j]; + + //add 1 to players who had less turns + currentPlayer = whoseTurn(state); + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] == highScore && i > currentPlayer ) + { + players[i]++; + } + } + + //find new highest score + j = 0; + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] > players[j] ) + { + j = i; + } + } + highScore = players[j]; + + //set winners in array to 1 and rest to 0 + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] == highScore ) + { + players[i] = 1; + } + else + { + players[i] = 0; + } + } + + return 0; +} + +int drawCard(int player, struct gameState *state) +{ int count; + int deckCounter; + if (state->deckCount[player] <= 0) { //Deck is empty + + //Step 1 Shuffle the discard pile back into a deck + int i; + //Move discard to deck + for (i = 0; i < state->discardCount[player]; i++) { + state->deck[player][i] = state->discard[player][i]; + state->discard[player][i] = -1; + } + + state->deckCount[player] = state->discardCount[player]; + state->discardCount[player] = 0;//Reset discard + + //Shufffle the deck + shuffle(player, state);//Shuffle the deck up and make it so that we can draw + + if (DEBUG) { //Debug statements + printf("Deck count now: %d\n", state->deckCount[player]); + } + + state->discardCount[player] = 0; + + //Step 2 Draw Card + count = state->handCount[player];//Get current player's hand count + + if (DEBUG) { //Debug statements + printf("Current hand count: %d\n", count); + } + + deckCounter = state->deckCount[player];//Create a holder for the deck count + + if (deckCounter == 0) + return -1; + + state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to hand + state->deckCount[player]--; + state->handCount[player]++;//Increment hand count + } + + else { + int count = state->handCount[player];//Get current hand count for player + int deckCounter; + if (DEBUG) { //Debug statements + printf("Current hand count: %d\n", count); + } + + deckCounter = state->deckCount[player];//Create holder for the deck count + state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to the hand + state->deckCount[player]--; + state->handCount[player]++;//Increment hand count + } + + return 0; +} + +int getCost(int cardNumber) +{ + switch( cardNumber ) + { + case curse: + return 0; + case estate: + return 2; + case duchy: + return 5; + case province: + return 8; + case copper: + return 0; + case silver: + return 3; + case gold: + return 6; + case adventurer: + return 6; + case council_room: + return 5; + case feast: + return 4; + case gardens: + return 4; + case mine: + return 5; + case remodel: + return 4; + case smithy: + return 4; + case village: + return 3; + case baron: + return 4; + case great_hall: + return 3; + case minion: + return 5; + case steward: + return 3; + case tribute: + return 5; + case ambassador: + return 3; + case cutpurse: + return 4; + case embargo: + return 2; + case outpost: + return 5; + case salvager: + return 4; + case sea_hag: + return 4; + case treasure_map: + return 4; + } + + return -1; +} + +int doMine(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) +{ + int i; + int j; + + j = state->hand[currentPlayer][choice1]; //store card we will trash + + if (/*state->hand[currentPlayer][choice1] < copper ||*/ state->hand[currentPlayer][choice1] > gold) + { + return -1; + } + + if (choice2 > treasure_map || choice2 < curse) + { + return -1; + } + + if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) ) + { + return -1; + } + + //gainCard(choice2, state, 2, currentPlayer); + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + //discard trashed card + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == j) + { + discardCard(i, currentPlayer, state, 0); + break; + } + } + + return 0; +} + +void getEstateCard(struct gameState *state, int currentPlayer) +{ + if (supplyCount(estate, state) > 0) { + gainCard(estate, state, 0, currentPlayer);//Gain an estate + + state->supplyCount[estate]--;//Decrement Estates + if (supplyCount(estate, state) == 0) { + isGameOver(state); + } + } +} + +void doBaron(int choice1, struct gameState *state, int currentPlayer) +{ + state->numBuys++;//Increase buys by 1! + state->numBuys++;//Increase buys by 1! + if (choice1 > 0) { //Boolean true or going to discard an estate + int p = 1; //0;//Iterator for hand! + int card_not_discarded = 1;//Flag for discard set! + while(card_not_discarded) { + if (state->hand[currentPlayer][p] == estate) { //Found an estate card! + state->coins += 4;//Add 4 coins to the amount of coins + state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; + state->discardCount[currentPlayer]++; + for (; p < state->handCount[currentPlayer]; p++) { + state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1]; + } + state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; + state->handCount[currentPlayer]--; + card_not_discarded = 0;//Exit the loop + } + else if (p > state->handCount[currentPlayer]) { + if(DEBUG) { + printf("No estate cards in your hand, invalid choice\n"); + printf("Must gain an estate if there are any\n"); + } + getEstateCard(state, currentPlayer); + card_not_discarded = 0;//Exit the loop + } + + else { + p++;//Next card + } + } + } + + else { + getEstateCard(state, currentPlayer); + } +} + +void doMinion(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) +{ + int i; + int j; + + //+1 action + state->numActions++; + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + if (choice1) + { + state->coins = state->coins + 2; + } + else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 + { + //discard hand + while(numHandCards(state) > 1 /*0*/) + { + discardCard(handPos, currentPlayer, state, 0); + } + + //draw 4 + for (i = 0; i < 4; i++) + { + drawCard(currentPlayer, state); + } + + //other players discard hand and redraw if hand size > 4 + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + //if ( state->handCount[i] > 4 ) + { + //discard hand + while( state->handCount[i] > 0 ) + { + discardCard(handPos, i, state, 0); + } + + //draw 4 + for (j = 0; j < 4; j++) + { + drawCard(i, state); + } + } + } + } + } +} + +void doTribute(struct gameState *state, int currentPlayer, int nextPlayer, int tributeRevealedCards[2]) +{ + int i; + + if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) { + if (state->deckCount[nextPlayer] > 0) { + tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + state->deckCount[nextPlayer]--; + } + else if (state->discardCount[nextPlayer] > 0) { + tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1]; + state->discardCount[nextPlayer]--; + } + else { + //No Card to Reveal + if (DEBUG) { + printf("No cards to reveal\n"); + } + } + } + + else { + if (state->deckCount[nextPlayer] == 0) { + for (i = 0; i < state->discardCount[nextPlayer]; i++) { + state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck + state->deckCount[nextPlayer]++; + state->discard[nextPlayer][i] = -1; + state->discardCount[nextPlayer]--; + } + + shuffle(nextPlayer,state);//Shuffle the deck + } + tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + state->deckCount[nextPlayer]--; + tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + state->deckCount[nextPlayer]--; + } + + if (tributeRevealedCards[0] == tributeRevealedCards[1]) { //If we have a duplicate card, just drop one + state->playedCards[state->playedCardCount] = tributeRevealedCards[1]; + state->playedCardCount++; + tributeRevealedCards[1] = -1; + } + + for (i = 0; i <= 2; i ++) { + if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) { //Treasure cards + state->numActions = state->numActions + 2; + } + + else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall) { //Victory Card Found + drawCard(currentPlayer, state); + //drawCard(currentPlayer, state); + } + else { //Action Card + state->coins += 2; + } + } +} + +int doAmbassador(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) +{ + int i; + int j; + + j = 0; //used to check if player has enough cards to discard + + if (choice2 > 3 || choice2 < 0) + { + return -1; + } + +/* + if (choice1 == handPos) + { + return -1; + } + */ + + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (i != handPos && i == state->hand[currentPlayer][choice1] && i != choice1) + { + j++; + } + } + if (j < choice2) + { + return -1; + } + + if (DEBUG) + printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]); + + //increase supply count for choosen card by amount being discarded + state->supplyCount[state->hand[currentPlayer][choice1]] += choice2; + + //each other player gains a copy of revealed card + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + gainCard(state->hand[currentPlayer][choice1], state, 0, i); + } + } + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + + //trash copies of cards returned to supply + for (j = 0; j < choice2; j++) + { + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1]) + { + discardCard(i, currentPlayer, state, 1); + break; + } + } + } + + return 0; +} + +int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) +{ + int i; + int j; + int k; + int x; + int index; + int currentPlayer = whoseTurn(state); + int nextPlayer = currentPlayer + 1; + + int tributeRevealedCards[2] = {-1, -1}; + int temphand[MAX_HAND];// moved above the if statement + int drawntreasure=0; + int cardDrawn; + int z = 0;// this is the counter for the temp hand + if (nextPlayer > (state->numPlayers - 1)) { + nextPlayer = 0; + } + + + //uses switch to select card and perform actions + switch( card ) + { + case adventurer: + while(drawntreasure<2) { + if (state->deckCount[currentPlayer] <1) { //if the deck is empty we need to shuffle discard and add to deck + shuffle(currentPlayer, state); + } + drawCard(currentPlayer, state); + cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card. + if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold) + drawntreasure++; + else { + temphand[z]=cardDrawn; + state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one). + z++; + } + } + while(z-1>=0) { + state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn + z=z-1; + } + return 0; + + case council_room: + //+4 Cards + for (i = 0; i < 4; i++) + { + drawCard(currentPlayer, state); + } + + //+1 Buy + state->numBuys++; + + //Each other player draws a card + for (i = 0; i < state->numPlayers; i++) + { + if ( i != currentPlayer ) + { + drawCard(i, state); + } + } + + //put played card in played card pile + discardCard(handPos, currentPlayer, state, 0); + + return 0; + + case feast: + //gain card with cost up to 5 + //Backup hand + for (i = 0; i <= state->handCount[currentPlayer]; i++) { + temphand[i] = state->hand[currentPlayer][i];//Backup card + state->hand[currentPlayer][i] = -1;//Set to nothing + } + //Backup hand + + //Update Coins for Buy + updateCoins(currentPlayer, state, 5); + x = 1;//Condition to loop on + while( x == 1) {//Buy one card + if (supplyCount(choice1, state) <= 0) { + if (DEBUG) + printf("None of that card left, sorry!\n"); + + if (DEBUG) { + printf("Cards Left: %d\n", supplyCount(choice1, state)); + } + } + else if (state->coins < getCost(choice1)) { + printf("That card is too expensive!\n"); + + if (DEBUG) { + printf("Coins: %d < %d\n", state->coins, getCost(choice1)); + } + } + else { + + if (DEBUG) { + printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + } + + gainCard(choice1, state, 0, currentPlayer);//Gain the card + x = 0;//No more buying cards + + if (DEBUG) { + printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + } + + } + } + + //Reset Hand + for (i = 0; i <= state->handCount[currentPlayer]; i++) { + state->hand[currentPlayer][i] = temphand[i]; + temphand[i] = -1; + } + //Reset Hand + + return 0; + + case gardens: + return -1; + + case mine: + return doMine(choice1, choice2, state, handPos, currentPlayer); + + case remodel: + j = state->hand[currentPlayer][choice1]; //store card we will trash + + if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) ) + { + return -1; + } + + gainCard(choice2, state, 0, currentPlayer); + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + //discard trashed card + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == j) + { + discardCard(i, currentPlayer, state, 0); + break; + } + } + + + return 0; + + case smithy: + //+3 Cards + for (i = 0; i < 3; i++) + { + drawCard(currentPlayer, state); + } + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case village: + //+1 Card + drawCard(currentPlayer, state); + + //+2 Actions + state->numActions = state->numActions + 2; + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case baron: + doBaron(choice1, state, currentPlayer); + return 0; + + case great_hall: + //+1 Card + drawCard(currentPlayer, state); + + //+1 Actions + state->numActions++; + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case minion: + doMinion(choice1, choice2, state, handPos, currentPlayer); + return 0; + + case steward: + if (choice1 == 1) + { + //+2 cards + drawCard(currentPlayer, state); + drawCard(currentPlayer, state); + } + else if (choice1 == 2) + { + //+2 coins + state->coins = state->coins + 2; + } + else + { + //trash 2 cards in hand + discardCard(choice2, currentPlayer, state, 1); + discardCard(choice3, currentPlayer, state, 1); + } + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case tribute: + doTribute(state, currentPlayer, nextPlayer, tributeRevealedCards); + return 0; + + case ambassador: + return doAmbassador(choice1, choice2, state, handPos, currentPlayer); + + case cutpurse: + + updateCoins(currentPlayer, state, 2); + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + for (j = 0; j < state->handCount[i]; j++) + { + if (state->hand[i][j] == copper) + { + discardCard(j, i, state, 0); + break; + } + if (j == state->handCount[i]) + { + for (k = 0; k < state->handCount[i]; k++) + { + if (DEBUG) + printf("Player %d reveals card number %d\n", i, state->hand[i][k]); + } + break; + } + } + + } + + } + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + + return 0; + + + case embargo: + //+2 Coins + state->coins = state->coins + 2; + + //see if selected pile is in play + if ( state->supplyCount[choice1] == -1 ) + { + return -1; + } + + //add embargo token to selected supply pile + state->embargoTokens[choice1]++; + + //trash card + discardCard(handPos, currentPlayer, state, 1); + return 0; + + case outpost: + //set outpost flag + state->outpostPlayed++; + + //discard card + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case salvager: + //+1 buy + state->numBuys++; + + if (choice1) + { + //gain coins equal to trashed card + state->coins = state->coins + getCost( handCard(choice1, state) ); + //trash card + discardCard(choice1, currentPlayer, state, 1); + } + + //discard card + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case sea_hag: + for (i = 0; i < state->numPlayers; i++) { + if (i != currentPlayer) { + state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; + state->deckCount[i]--; + state->discardCount[i]++; + state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse + } + } + return 0; + + case treasure_map: + //search hand for another treasure_map + index = -1; + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == treasure_map && i != handPos) + { + index = i; + break; + } + } + if (index > -1) + { + //trash both treasure cards + discardCard(handPos, currentPlayer, state, 1); + discardCard(index, currentPlayer, state, 1); + + //gain 4 Gold cards + for (i = 0; i < 4; i++) + { + gainCard(gold, state, 1, currentPlayer); + } + + //return success + return 1; + } + + //no second treasure_map found in hand + return -1; + } + + return -1; +} + +int discardCard(int handPos, int currentPlayer, struct gameState *state, int trashFlag) +{ + + //if card is not trashed, added to Played pile + if (trashFlag < 1) + { + //add card to played pile + state->playedCards[state->playedCardCount] = state->hand[currentPlayer][handPos]; + state->playedCardCount++; + } + + //set played card to -1 + state->hand[currentPlayer][handPos] = -1; + + //remove card from player's hand + if ( handPos == (state->handCount[currentPlayer] - 1) ) //last card in hand array is played + { + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + else if ( state->handCount[currentPlayer] == 1 ) //only one card in hand + { + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + else + { + //replace discarded card with last card in hand + state->hand[currentPlayer][handPos] = state->hand[currentPlayer][ (state->handCount[currentPlayer] - 1)]; + //set last card to -1 + state->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1; + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + + return 0; +} + +int gainCard(int supplyPos, struct gameState *state, int toFlag, int player) +{ + //Note: supplyPos is enum of choosen card + + //check if supply pile is empty (0) or card is not used in game (-1) + if ( supplyCount(supplyPos, state) < 1 ) + { + return -1; + } + + //added card for [whoseTurn] current player: + // toFlag = 0 : add to discard + // toFlag = 1 : add to deck + // toFlag = 2 : add to hand + + if (toFlag == 1) + { + state->deck[ player ][ state->deckCount[player] ] = supplyPos; + state->deckCount[player]++; + } + else if (toFlag == 2) + { + state->hand[ player ][ state->handCount[player] ] = supplyPos; + state->handCount[player]++; + } + else + { + state->discard[player][ state->discardCount[player] ] = supplyPos; + state->discardCount[player]++; + } + + //decrease number in supply pile + state->supplyCount[supplyPos]--; + + return 0; +} + +int updateCoins(int player, struct gameState *state, int bonus) +{ + int i; + + //reset coin count + state->coins = 0; + + //add coins for each Treasure card in player's hand + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == copper) + { + state->coins += 1; + } + else if (state->hand[player][i] == silver) + { + state->coins += 2; + } + else if (state->hand[player][i] == gold) + { + state->coins += 3; + } + } + + //add bonus + state->coins += bonus; + + return 0; +} + + +//end of dominion.c diff --git a/projects/alghanmz/a4/dominion.c.gcov b/projects/alghanmz/a4/dominion.c.gcov new file mode 100644 index 000000000..2e0a8d298 --- /dev/null +++ b/projects/alghanmz/a4/dominion.c.gcov @@ -0,0 +1,1936 @@ + -: 0:Source:dominion.c + -: 0:Graph:dominion.gcno + -: 0:Data:dominion.gcda + -: 0:Runs:3 + -: 0:Programs:3 + -: 1:#include "dominion.h" + -: 2:#include "dominion_helpers.h" + -: 3:#include "rngs.h" + -: 4:#include + -: 5:#include + -: 6:#include + -: 7: +function compare called 93382020 returned 100% blocks executed 100% + 93382020: 8:int compare(const void* a, const void* b) { + 93382020: 9: if (*(int*)a > *(int*)b) +branch 0 taken 1% (fallthrough) +branch 1 taken 99% + 45588: 10: return 1; + 93336432: 11: if (*(int*)a < *(int*)b) +branch 0 taken 27% (fallthrough) +branch 1 taken 73% + 24916392: 12: return -1; + 68420040: 13: return 0; + -: 14:} + -: 15: +function newGame called 0 returned 0% blocks executed 0% + #####: 16:struct gameState* newGame() { + #####: 17: struct gameState* g = malloc(sizeof(struct gameState)); + #####: 18: return g; + -: 19:} + -: 20: +function kingdomCards called 0 returned 0% blocks executed 0% + #####: 21:int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + -: 22: int k8, int k9, int k10) { + #####: 23: int* k = malloc(10 * sizeof(int)); + #####: 24: k[0] = k1; + #####: 25: k[1] = k2; + #####: 26: k[2] = k3; + #####: 27: k[3] = k4; + #####: 28: k[4] = k5; + #####: 29: k[5] = k6; + #####: 30: k[6] = k7; + #####: 31: k[7] = k8; + #####: 32: k[8] = k9; + #####: 33: k[9] = k10; + #####: 34: return k; + -: 35:} + -: 36: +function initializeGame called 2073550 returned 100% blocks executed 95% + 2073550: 37:int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, + -: 38: struct gameState *state) { + -: 39: int i; + -: 40: int j; + -: 41: int it; + -: 42: + -: 43: //set up random number generator + 2073550: 44: SelectStream(1); +call 0 returned 100% + 2073550: 45: PutSeed((long)randomSeed); +call 0 returned 100% + -: 46: + -: 47: //check number of players + 2073550: 48: if (numPlayers > MAX_PLAYERS || numPlayers < 2) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 49: { + #####: 50: return -1; + -: 51: } + -: 52: + -: 53: //set number of players + 2073550: 54: state->numPlayers = numPlayers; + -: 55: + -: 56: //check selected kingdom cards are different + 22809050: 57: for (i = 0; i < 10; i++) +branch 0 taken 91% +branch 1 taken 9% (fallthrough) + -: 58: { +228090500: 59: for (j = 0; j < 10; j++) +branch 0 taken 91% +branch 1 taken 9% (fallthrough) + -: 60: { +207355000: 61: if (j != i && kingdomCards[j] == kingdomCards[i]) +branch 0 taken 90% (fallthrough) +branch 1 taken 10% +branch 2 taken 0% (fallthrough) +branch 3 taken 100% + -: 62: { + #####: 63: return -1; + -: 64: } + -: 65: } + -: 66: } + -: 67: + -: 68: + -: 69: //initialize supply + -: 70: /////////////////////////////// + -: 71: + -: 72: //set number of Curse cards + 2073550: 73: if (numPlayers == 2) +branch 0 taken 33% (fallthrough) +branch 1 taken 67% + -: 74: { + 691948: 75: state->supplyCount[curse] = 10; + -: 76: } + 1381602: 77: else if (numPlayers == 3) +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + -: 78: { + 690892: 79: state->supplyCount[curse] = 20; + -: 80: } + -: 81: else + -: 82: { + 690710: 83: state->supplyCount[curse] = 30; + -: 84: } + -: 85: + -: 86: //set number of Victory cards + 2073550: 87: if (numPlayers == 2) +branch 0 taken 33% (fallthrough) +branch 1 taken 67% + -: 88: { + 691948: 89: state->supplyCount[estate] = 8; + 691948: 90: state->supplyCount[duchy] = 8; + 691948: 91: state->supplyCount[province] = 8; + -: 92: } + -: 93: else + -: 94: { + 1381602: 95: state->supplyCount[estate] = 12; + 1381602: 96: state->supplyCount[duchy] = 12; + 1381602: 97: state->supplyCount[province] = 12; + -: 98: } + -: 99: + -: 100: //set number of Treasure cards + 2073550: 101: state->supplyCount[copper] = 60 - (7 * numPlayers); + 2073550: 102: state->supplyCount[silver] = 40; + 2073550: 103: state->supplyCount[gold] = 30; + -: 104: + -: 105: //set number of Kingdom cards + 43544550: 106: for (i = adventurer; i <= treasure_map; i++) //loop all cards +branch 0 taken 95% +branch 1 taken 5% (fallthrough) + -: 107: { +342135750: 108: for (j = 0; j < 10; j++) //loop chosen cards +branch 0 taken 94% +branch 1 taken 6% (fallthrough) + -: 109: { +321400250: 110: if (kingdomCards[j] == i) +branch 0 taken 6% (fallthrough) +branch 1 taken 94% + -: 111: { + -: 112: //check if card is a 'Victory' Kingdom card + 20735500: 113: if (kingdomCards[j] == great_hall || kingdomCards[j] == gardens) +branch 0 taken 90% (fallthrough) +branch 1 taken 10% +branch 2 taken 11% (fallthrough) +branch 3 taken 89% + -: 114: { + 8294200: 115: if (numPlayers == 2) { +branch 0 taken 33% (fallthrough) +branch 1 taken 67% + 1383896: 116: state->supplyCount[i] = 8; + -: 117: } + -: 118: else { + 2763204: 119: state->supplyCount[i] = 12; + -: 120: } + -: 121: } + -: 122: else + -: 123: { + 16588400: 124: state->supplyCount[i] = 10; + -: 125: } + 20735500: 126: break; + -: 127: } + -: 128: else //card is not in the set choosen for the game + -: 129: { +300664750: 130: state->supplyCount[i] = -1; + -: 131: } + -: 132: } + -: 133: + -: 134: } + -: 135: + -: 136: //////////////////////// + -: 137: //supply intilization complete + -: 138: + -: 139: //set player decks + 8292962: 140: for (i = 0; i < numPlayers; i++) +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + -: 141: { + 6219412: 142: state->deckCount[i] = 0; + 24877648: 143: for (j = 0; j < 3; j++) +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + -: 144: { + 18658236: 145: state->deck[i][j] = estate; + 18658236: 146: state->deckCount[i]++; + -: 147: } + 49755296: 148: for (j = 3; j < 10; j++) +branch 0 taken 88% +branch 1 taken 13% (fallthrough) + -: 149: { + 43535884: 150: state->deck[i][j] = copper; + 43535884: 151: state->deckCount[i]++; + -: 152: } + -: 153: } + -: 154: + -: 155: //shuffle player decks + 8292962: 156: for (i = 0; i < numPlayers; i++) +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + -: 157: { + 6219412: 158: if ( shuffle(i, state) < 0 ) +call 0 returned 100% +branch 1 taken 0% (fallthrough) +branch 2 taken 100% + -: 159: { + #####: 160: return -1; + -: 161: } + -: 162: } + -: 163: + -: 164: //draw player hands + 8292962: 165: for (i = 0; i < numPlayers; i++) +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + -: 166: { + -: 167: //initialize hand size to zero + 6219412: 168: state->handCount[i] = 0; + 6219412: 169: state->discardCount[i] = 0; + -: 170: //draw 5 cards + -: 171: // for (j = 0; j < 5; j++) + -: 172: // { + -: 173: // drawCard(i, state); + -: 174: // } + -: 175: } + -: 176: + -: 177: //set embargo tokens to 0 for all supply piles + 58059400: 178: for (i = 0; i <= treasure_map; i++) +branch 0 taken 96% +branch 1 taken 4% (fallthrough) + -: 179: { + 55985850: 180: state->embargoTokens[i] = 0; + -: 181: } + -: 182: + -: 183: //initialize first player's turn + 2073550: 184: state->outpostPlayed = 0; + 2073550: 185: state->phase = 0; + 2073550: 186: state->numActions = 1; + 2073550: 187: state->numBuys = 1; + 2073550: 188: state->playedCardCount = 0; + 2073550: 189: state->whoseTurn = 0; + 2073550: 190: state->handCount[state->whoseTurn] = 0; + -: 191: //int it; move to top + -: 192: + -: 193: //Moved draw cards to here, only drawing at the start of a turn + 12441300: 194: for (it = 0; it < 5; it++) { +branch 0 taken 83% +branch 1 taken 17% (fallthrough) + 10367750: 195: drawCard(state->whoseTurn, state); +call 0 returned 100% + -: 196: } + -: 197: + 2073550: 198: updateCoins(state->whoseTurn, state, 0); +call 0 returned 100% + -: 199: + 2073550: 200: return 0; + -: 201:} + -: 202: +function shuffle called 6297823 returned 100% blocks executed 94% + 6297823: 203:int shuffle(int player, struct gameState *state) { + -: 204: + -: 205: + -: 206: int newDeck[MAX_DECK]; + 6297823: 207: int newDeckPos = 0; + -: 208: int card; + -: 209: int i; + -: 210: + 6297823: 211: if (state->deckCount[player] < 1) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + #####: 212: return -1; + 6297823: 213: qsort ((void*)(state->deck[player]), state->deckCount[player], sizeof(int), compare); +call 0 returned 100% + -: 214: /* SORT CARDS IN DECK TO ENSURE DETERMINISM! */ + -: 215: + 74946595: 216: while (state->deckCount[player] > 0) { +branch 0 taken 91% +branch 1 taken 9% (fallthrough) + 62350949: 217: card = floor(Random() * state->deckCount[player]); +call 0 returned 100% + 62350949: 218: newDeck[newDeckPos] = state->deck[player][card]; + 62350949: 219: newDeckPos++; +228253492: 220: for (i = card; i < state->deckCount[player]-1; i++) { +branch 0 taken 73% +branch 1 taken 27% (fallthrough) +165902543: 221: state->deck[player][i] = state->deck[player][i+1]; + -: 222: } + 62350949: 223: state->deckCount[player]--; + -: 224: } + 68648772: 225: for (i = 0; i < newDeckPos; i++) { +branch 0 taken 91% +branch 1 taken 9% (fallthrough) + 62350949: 226: state->deck[player][i] = newDeck[i]; + 62350949: 227: state->deckCount[player]++; + -: 228: } + -: 229: + 6297823: 230: return 0; + -: 231:} + -: 232: +function playCard called 0 returned 0% blocks executed 0% + #####: 233:int playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state) + -: 234:{ + -: 235: int card; + #####: 236: int coin_bonus = 0; //tracks coins gain from actions + -: 237: + -: 238: //check if it is the right phase + #####: 239: if (state->phase != 0) +branch 0 never executed +branch 1 never executed + -: 240: { + #####: 241: return -1; + -: 242: } + -: 243: + -: 244: //check if player has enough actions + #####: 245: if ( state->numActions < 1 ) +branch 0 never executed +branch 1 never executed + -: 246: { + #####: 247: return -1; + -: 248: } + -: 249: + -: 250: //get card played + #####: 251: card = handCard(handPos, state); +call 0 never executed + -: 252: + -: 253: //check if selected card is an action + #####: 254: if ( card < adventurer || card > treasure_map ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 255: { + #####: 256: return -1; + -: 257: } + -: 258: + -: 259: //play card + #####: 260: if ( cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0 ) +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 261: { + #####: 262: return -1; + -: 263: } + -: 264: + -: 265: //reduce number of actions + #####: 266: state->numActions--; + -: 267: + -: 268: //update coins (Treasure cards may be added with card draws) + #####: 269: updateCoins(state->whoseTurn, state, coin_bonus); +call 0 never executed + -: 270: + #####: 271: return 0; + -: 272:} + -: 273: +function buyCard called 0 returned 0% blocks executed 0% + #####: 274:int buyCard(int supplyPos, struct gameState *state) { + -: 275: int who; + -: 276: if (DEBUG) { + -: 277: printf("Entering buyCard...\n"); + -: 278: } + -: 279: + -: 280: // I don't know what to do about the phase thing. + -: 281: + #####: 282: who = state->whoseTurn; + -: 283: + #####: 284: if (state->numBuys < 1) { +branch 0 never executed +branch 1 never executed + -: 285: if (DEBUG) + -: 286: printf("You do not have any buys left\n"); + #####: 287: return -1; + #####: 288: } else if (supplyCount(supplyPos, state) <1) { +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 289: if (DEBUG) + -: 290: printf("There are not any of that type of card left\n"); + #####: 291: return -1; + #####: 292: } else if (state->coins < getCost(supplyPos)) { +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 293: if (DEBUG) + -: 294: printf("You do not have enough money to buy that. You have %d coins.\n", state->coins); + #####: 295: return -1; + -: 296: } else { + #####: 297: state->phase=1; + -: 298: //state->supplyCount[supplyPos]--; + #####: 299: gainCard(supplyPos, state, 0, who); //card goes in discard, this might be wrong.. (2 means goes into hand, 0 goes into discard) +call 0 never executed + -: 300: + #####: 301: state->coins = (state->coins) - (getCost(supplyPos)); +call 0 never executed + #####: 302: state->numBuys--; + -: 303: if (DEBUG) + -: 304: printf("You bought card number %d for %d coins. You now have %d buys and %d coins.\n", supplyPos, getCost(supplyPos), state->numBuys, state->coins); + -: 305: } + -: 306: + -: 307: //state->discard[who][state->discardCount[who]] = supplyPos; + -: 308: //state->discardCount[who]++; + -: 309: + #####: 310: return 0; + -: 311:} + -: 312: +function numHandCards called 747834 returned 100% blocks executed 100% + 747834: 313:int numHandCards(struct gameState *state) { + 747834: 314: return state->handCount[ whoseTurn(state) ]; +call 0 returned 100% + -: 315:} + -: 316: +function handCard called 0 returned 0% blocks executed 0% + #####: 317:int handCard(int handPos, struct gameState *state) { + #####: 318: int currentPlayer = whoseTurn(state); +call 0 never executed + #####: 319: return state->hand[currentPlayer][handPos]; + -: 320:} + -: 321: +function supplyCount called 1669227 returned 100% blocks executed 100% + 1669227: 322:int supplyCount(int card, struct gameState *state) { + 1669227: 323: return state->supplyCount[card]; + -: 324:} + -: 325: +function fullDeckCount called 0 returned 0% blocks executed 0% + #####: 326:int fullDeckCount(int player, int card, struct gameState *state) { + -: 327: int i; + #####: 328: int count = 0; + -: 329: + #####: 330: for (i = 0; i < state->deckCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 331: { + #####: 332: if (state->deck[player][i] == card) count++; +branch 0 never executed +branch 1 never executed + -: 333: } + -: 334: + #####: 335: for (i = 0; i < state->handCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 336: { + #####: 337: if (state->hand[player][i] == card) count++; +branch 0 never executed +branch 1 never executed + -: 338: } + -: 339: + #####: 340: for (i = 0; i < state->discardCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 341: { + #####: 342: if (state->discard[player][i] == card) count++; +branch 0 never executed +branch 1 never executed + -: 343: } + -: 344: + #####: 345: return count; + -: 346:} + -: 347: +function whoseTurn called 747834 returned 100% blocks executed 100% + 747834: 348:int whoseTurn(struct gameState *state) { + 747834: 349: return state->whoseTurn; + -: 350:} + -: 351: +function endTurn called 0 returned 0% blocks executed 0% + #####: 352:int endTurn(struct gameState *state) { + -: 353: int k; + -: 354: int i; + #####: 355: int currentPlayer = whoseTurn(state); +call 0 never executed + -: 356: + -: 357: //Discard hand + #####: 358: for (i = 0; i < state->handCount[currentPlayer]; i++) { +branch 0 never executed +branch 1 never executed + #####: 359: state->discard[currentPlayer][state->discardCount[currentPlayer]++] = state->hand[currentPlayer][i];//Discard + #####: 360: state->hand[currentPlayer][i] = -1;//Set card to -1 + -: 361: } + #####: 362: state->handCount[currentPlayer] = 0;//Reset hand count + -: 363: + -: 364: //Code for determining the player + #####: 365: if (currentPlayer < (state->numPlayers - 1)) { +branch 0 never executed +branch 1 never executed + #####: 366: state->whoseTurn = currentPlayer + 1;//Still safe to increment + -: 367: } + -: 368: else { + #####: 369: state->whoseTurn = 0;//Max player has been reached, loop back around to player 1 + -: 370: } + -: 371: + #####: 372: state->outpostPlayed = 0; + #####: 373: state->phase = 0; + #####: 374: state->numActions = 1; + #####: 375: state->coins = 0; + #####: 376: state->numBuys = 1; + #####: 377: state->playedCardCount = 0; + #####: 378: state->handCount[state->whoseTurn] = 0; + -: 379: + -: 380: //int k; move to top + -: 381: //Next player draws hand + #####: 382: for (k = 0; k < 5; k++) { +branch 0 never executed +branch 1 never executed + #####: 383: drawCard(state->whoseTurn, state);//Draw a card +call 0 never executed + -: 384: } + -: 385: + -: 386: //Update money + #####: 387: updateCoins(state->whoseTurn, state, 0); +call 0 never executed + -: 388: + #####: 389: return 0; + -: 390:} + -: 391: +function isGameOver called 0 returned 0% blocks executed 0% + #####: 392:int isGameOver(struct gameState *state) { + -: 393: int i; + -: 394: int j; + -: 395: + -: 396: //if stack of Province cards is empty, the game ends + #####: 397: if (state->supplyCount[province] == 0) +branch 0 never executed +branch 1 never executed + -: 398: { + #####: 399: return 1; + -: 400: } + -: 401: + -: 402: //if three supply pile are at 0, the game ends + #####: 403: j = 0; + #####: 404: for (i = 0; i < 25; i++) +branch 0 never executed +branch 1 never executed + -: 405: { + #####: 406: if (state->supplyCount[i] == 0) +branch 0 never executed +branch 1 never executed + -: 407: { + #####: 408: j++; + -: 409: } + -: 410: } + #####: 411: if ( j >= 3) +branch 0 never executed +branch 1 never executed + -: 412: { + #####: 413: return 1; + -: 414: } + -: 415: + #####: 416: return 0; + -: 417:} + -: 418: +function scoreFor called 0 returned 0% blocks executed 0% + #####: 419:int scoreFor (int player, struct gameState *state) { + -: 420: + -: 421: int i; + #####: 422: int score = 0; + -: 423: //score from hand + #####: 424: for (i = 0; i < state->handCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 425: { + #####: 426: if (state->hand[player][i] == curse) { +branch 0 never executed +branch 1 never executed + #####: 427: score = score - 1; + -: 428: }; + #####: 429: if (state->hand[player][i] == estate) { +branch 0 never executed +branch 1 never executed + #####: 430: score = score + 1; + -: 431: }; + #####: 432: if (state->hand[player][i] == duchy) { +branch 0 never executed +branch 1 never executed + #####: 433: score = score + 3; + -: 434: }; + #####: 435: if (state->hand[player][i] == province) { +branch 0 never executed +branch 1 never executed + #####: 436: score = score + 6; + -: 437: }; + #####: 438: if (state->hand[player][i] == great_hall) { +branch 0 never executed +branch 1 never executed + #####: 439: score = score + 1; + -: 440: }; + #####: 441: if (state->hand[player][i] == gardens) { +branch 0 never executed +branch 1 never executed + #####: 442: score = score + ( fullDeckCount(player, 0, state) / 10 ); +call 0 never executed + -: 443: }; + -: 444: } + -: 445: + -: 446: //score from discard + #####: 447: for (i = 0; i < state->discardCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 448: { + #####: 449: if (state->discard[player][i] == curse) { +branch 0 never executed +branch 1 never executed + #####: 450: score = score - 1; + -: 451: }; + #####: 452: if (state->discard[player][i] == estate) { +branch 0 never executed +branch 1 never executed + #####: 453: score = score + 1; + -: 454: }; + #####: 455: if (state->discard[player][i] == duchy) { +branch 0 never executed +branch 1 never executed + #####: 456: score = score + 3; + -: 457: }; + #####: 458: if (state->discard[player][i] == province) { +branch 0 never executed +branch 1 never executed + #####: 459: score = score + 6; + -: 460: }; + #####: 461: if (state->discard[player][i] == great_hall) { +branch 0 never executed +branch 1 never executed + #####: 462: score = score + 1; + -: 463: }; + #####: 464: if (state->discard[player][i] == gardens) { +branch 0 never executed +branch 1 never executed + #####: 465: score = score + ( fullDeckCount(player, 0, state) / 10 ); +call 0 never executed + -: 466: }; + -: 467: } + -: 468: + -: 469: //score from deck + #####: 470: for (i = 0; i < state->discardCount[player]; i++) +branch 0 never executed +branch 1 never executed + -: 471: { + #####: 472: if (state->deck[player][i] == curse) { +branch 0 never executed +branch 1 never executed + #####: 473: score = score - 1; + -: 474: }; + #####: 475: if (state->deck[player][i] == estate) { +branch 0 never executed +branch 1 never executed + #####: 476: score = score + 1; + -: 477: }; + #####: 478: if (state->deck[player][i] == duchy) { +branch 0 never executed +branch 1 never executed + #####: 479: score = score + 3; + -: 480: }; + #####: 481: if (state->deck[player][i] == province) { +branch 0 never executed +branch 1 never executed + #####: 482: score = score + 6; + -: 483: }; + #####: 484: if (state->deck[player][i] == great_hall) { +branch 0 never executed +branch 1 never executed + #####: 485: score = score + 1; + -: 486: }; + #####: 487: if (state->deck[player][i] == gardens) { +branch 0 never executed +branch 1 never executed + #####: 488: score = score + ( fullDeckCount(player, 0, state) / 10 ); +call 0 never executed + -: 489: }; + -: 490: } + -: 491: + #####: 492: return score; + -: 493:} + -: 494: +function getWinners called 0 returned 0% blocks executed 0% + #####: 495:int getWinners(int players[MAX_PLAYERS], struct gameState *state) { + -: 496: int i; + -: 497: int j; + -: 498: int highScore; + -: 499: int currentPlayer; + -: 500: + -: 501: //get score for each player + #####: 502: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 503: { + -: 504: //set unused player scores to -9999 + #####: 505: if (i >= state->numPlayers) +branch 0 never executed +branch 1 never executed + -: 506: { + #####: 507: players[i] = -9999; + -: 508: } + -: 509: else + -: 510: { + #####: 511: players[i] = scoreFor (i, state); +call 0 never executed + -: 512: } + -: 513: } + -: 514: + -: 515: //find highest score + #####: 516: j = 0; + #####: 517: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 518: { + #####: 519: if (players[i] > players[j]) +branch 0 never executed +branch 1 never executed + -: 520: { + #####: 521: j = i; + -: 522: } + -: 523: } + #####: 524: highScore = players[j]; + -: 525: + -: 526: //add 1 to players who had less turns + #####: 527: currentPlayer = whoseTurn(state); +call 0 never executed + #####: 528: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 529: { + #####: 530: if ( players[i] == highScore && i > currentPlayer ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 531: { + #####: 532: players[i]++; + -: 533: } + -: 534: } + -: 535: + -: 536: //find new highest score + #####: 537: j = 0; + #####: 538: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 539: { + #####: 540: if ( players[i] > players[j] ) +branch 0 never executed +branch 1 never executed + -: 541: { + #####: 542: j = i; + -: 543: } + -: 544: } + #####: 545: highScore = players[j]; + -: 546: + -: 547: //set winners in array to 1 and rest to 0 + #####: 548: for (i = 0; i < MAX_PLAYERS; i++) +branch 0 never executed +branch 1 never executed + -: 549: { + #####: 550: if ( players[i] == highScore ) +branch 0 never executed +branch 1 never executed + -: 551: { + #####: 552: players[i] = 1; + -: 553: } + -: 554: else + -: 555: { + #####: 556: players[i] = 0; + -: 557: } + -: 558: } + -: 559: + #####: 560: return 0; + -: 561:} + -: 562: +function drawCard called 15673140 returned 100% blocks executed 38% + 15673140: 563:int drawCard(int player, struct gameState *state) + -: 564:{ int count; + -: 565: int deckCounter; + 15673140: 566: if (state->deckCount[player] <= 0) { //Deck is empty +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 567: + -: 568: //Step 1 Shuffle the discard pile back into a deck + -: 569: int i; + -: 570: //Move discard to deck + #####: 571: for (i = 0; i < state->discardCount[player]; i++) { +branch 0 never executed +branch 1 never executed + #####: 572: state->deck[player][i] = state->discard[player][i]; + #####: 573: state->discard[player][i] = -1; + -: 574: } + -: 575: + #####: 576: state->deckCount[player] = state->discardCount[player]; + #####: 577: state->discardCount[player] = 0;//Reset discard + -: 578: + -: 579: //Shufffle the deck + #####: 580: shuffle(player, state);//Shuffle the deck up and make it so that we can draw +call 0 never executed + -: 581: + -: 582: if (DEBUG) { //Debug statements + -: 583: printf("Deck count now: %d\n", state->deckCount[player]); + -: 584: } + -: 585: + #####: 586: state->discardCount[player] = 0; + -: 587: + -: 588: //Step 2 Draw Card + #####: 589: count = state->handCount[player];//Get current player's hand count + -: 590: + -: 591: if (DEBUG) { //Debug statements + -: 592: printf("Current hand count: %d\n", count); + -: 593: } + -: 594: + #####: 595: deckCounter = state->deckCount[player];//Create a holder for the deck count + -: 596: + #####: 597: if (deckCounter == 0) +branch 0 never executed +branch 1 never executed + #####: 598: return -1; + -: 599: + #####: 600: state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to hand + #####: 601: state->deckCount[player]--; + #####: 602: state->handCount[player]++;//Increment hand count + -: 603: } + -: 604: + -: 605: else { + 15673140: 606: int count = state->handCount[player];//Get current hand count for player + -: 607: int deckCounter; + -: 608: if (DEBUG) { //Debug statements + -: 609: printf("Current hand count: %d\n", count); + -: 610: } + -: 611: + 15673140: 612: deckCounter = state->deckCount[player];//Create holder for the deck count + 15673140: 613: state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to the hand + 15673140: 614: state->deckCount[player]--; + 15673140: 615: state->handCount[player]++;//Increment hand count + -: 616: } + -: 617: + 15673140: 618: return 0; + -: 619:} + -: 620: +function getCost called 0 returned 0% blocks executed 0% + #####: 621:int getCost(int cardNumber) + -: 622:{ + #####: 623: switch( cardNumber ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed +branch 6 never executed +branch 7 never executed +branch 8 never executed +branch 9 never executed +branch 10 never executed +branch 11 never executed +branch 12 never executed +branch 13 never executed +branch 14 never executed +branch 15 never executed +branch 16 never executed +branch 17 never executed +branch 18 never executed +branch 19 never executed +branch 20 never executed +branch 21 never executed +branch 22 never executed +branch 23 never executed +branch 24 never executed +branch 25 never executed +branch 26 never executed +branch 27 never executed + -: 624: { + -: 625: case curse: + #####: 626: return 0; + -: 627: case estate: + #####: 628: return 2; + -: 629: case duchy: + #####: 630: return 5; + -: 631: case province: + #####: 632: return 8; + -: 633: case copper: + #####: 634: return 0; + -: 635: case silver: + #####: 636: return 3; + -: 637: case gold: + #####: 638: return 6; + -: 639: case adventurer: + #####: 640: return 6; + -: 641: case council_room: + #####: 642: return 5; + -: 643: case feast: + #####: 644: return 4; + -: 645: case gardens: + #####: 646: return 4; + -: 647: case mine: + #####: 648: return 5; + -: 649: case remodel: + #####: 650: return 4; + -: 651: case smithy: + #####: 652: return 4; + -: 653: case village: + #####: 654: return 3; + -: 655: case baron: + #####: 656: return 4; + -: 657: case great_hall: + #####: 658: return 3; + -: 659: case minion: + #####: 660: return 5; + -: 661: case steward: + #####: 662: return 3; + -: 663: case tribute: + #####: 664: return 5; + -: 665: case ambassador: + #####: 666: return 3; + -: 667: case cutpurse: + #####: 668: return 4; + -: 669: case embargo: + #####: 670: return 2; + -: 671: case outpost: + #####: 672: return 5; + -: 673: case salvager: + #####: 674: return 4; + -: 675: case sea_hag: + #####: 676: return 4; + -: 677: case treasure_map: + #####: 678: return 4; + -: 679: } + -: 680: + #####: 681: return -1; + -: 682:} + -: 683: +function doMine called 0 returned 0% blocks executed 0% + #####: 684:int doMine(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) + -: 685:{ + -: 686: int i; + -: 687: int j; + -: 688: + #####: 689: j = state->hand[currentPlayer][choice1]; //store card we will trash + -: 690: + #####: 691: if (/*state->hand[currentPlayer][choice1] < copper ||*/ state->hand[currentPlayer][choice1] > gold) +branch 0 never executed +branch 1 never executed + -: 692: { + #####: 693: return -1; + -: 694: } + -: 695: + #####: 696: if (choice2 > treasure_map || choice2 < curse) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 697: { + #####: 698: return -1; + -: 699: } + -: 700: + #####: 701: if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) ) +call 0 never executed +call 1 never executed +branch 2 never executed +branch 3 never executed + -: 702: { + #####: 703: return -1; + -: 704: } + -: 705: + -: 706: //gainCard(choice2, state, 2, currentPlayer); + -: 707: + -: 708: //discard card from hand + #####: 709: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 710: + -: 711: //discard trashed card + #####: 712: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 713: { + #####: 714: if (state->hand[currentPlayer][i] == j) +branch 0 never executed +branch 1 never executed + -: 715: { + #####: 716: discardCard(i, currentPlayer, state, 0); +call 0 never executed + #####: 717: break; + -: 718: } + -: 719: } + -: 720: + #####: 721: return 0; + -: 722:} + -: 723: +function getEstateCard called 556409 returned 100% blocks executed 86% + 556409: 724:void getEstateCard(struct gameState *state, int currentPlayer) + -: 725:{ + 556409: 726: if (supplyCount(estate, state) > 0) { +call 0 returned 100% +branch 1 taken 100% (fallthrough) +branch 2 taken 0% + 556409: 727: gainCard(estate, state, 0, currentPlayer);//Gain an estate +call 0 returned 100% + -: 728: + 556409: 729: state->supplyCount[estate]--;//Decrement Estates + 556409: 730: if (supplyCount(estate, state) == 0) { +call 0 returned 100% +branch 1 taken 0% (fallthrough) +branch 2 taken 100% + #####: 731: isGameOver(state); +call 0 never executed + -: 732: } + -: 733: } + 556409: 734:} + -: 735: +function doBaron called 647059 returned 100% blocks executed 100% + 647059: 736:void doBaron(int choice1, struct gameState *state, int currentPlayer) + -: 737:{ + 647059: 738: state->numBuys++;//Increase buys by 1! + 647059: 739: state->numBuys++;//Increase buys by 1! + 647059: 740: if (choice1 > 0) { //Boolean true or going to discard an estate +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + 322771: 741: int p = 1; //0;//Iterator for hand! + 322771: 742: int card_not_discarded = 1;//Flag for discard set! + 1333592: 743: while(card_not_discarded) { +branch 0 taken 68% +branch 1 taken 32% (fallthrough) + 688050: 744: if (state->hand[currentPlayer][p] == estate) { //Found an estate card! +branch 0 taken 13% (fallthrough) +branch 1 taken 87% + 90650: 745: state->coins += 4;//Add 4 coins to the amount of coins + 90650: 746: state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; + 90650: 747: state->discardCount[currentPlayer]++; + 247791: 748: for (; p < state->handCount[currentPlayer]; p++) { +branch 0 taken 63% +branch 1 taken 37% (fallthrough) + 157141: 749: state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1]; + -: 750: } + 90650: 751: state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; + 90650: 752: state->handCount[currentPlayer]--; + 90650: 753: card_not_discarded = 0;//Exit the loop + -: 754: } + 597400: 755: else if (p > state->handCount[currentPlayer]) { +branch 0 taken 39% (fallthrough) +branch 1 taken 61% + -: 756: if(DEBUG) { + -: 757: printf("No estate cards in your hand, invalid choice\n"); + -: 758: printf("Must gain an estate if there are any\n"); + -: 759: } + 232121: 760: getEstateCard(state, currentPlayer); +call 0 returned 100% + 232121: 761: card_not_discarded = 0;//Exit the loop + -: 762: } + -: 763: + -: 764: else { + 365279: 765: p++;//Next card + -: 766: } + -: 767: } + -: 768: } + -: 769: + -: 770: else { + 324288: 771: getEstateCard(state, currentPlayer); +call 0 returned 100% + -: 772: } + 647059: 773:} + -: 774: +function doMinion called 720681 returned 100% blocks executed 100% + 720681: 775:void doMinion(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) + -: 776:{ + -: 777: int i; + -: 778: int j; + -: 779: + -: 780: //+1 action + 720681: 781: state->numActions++; + -: 782: + -: 783: //discard card from hand + 720681: 784: discardCard(handPos, currentPlayer, state, 0); +call 0 returned 100% + -: 785: + 720681: 786: if (choice1) +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + -: 787: { + 361452: 788: state->coins = state->coins + 2; + -: 789: } + 359229: 790: else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 +branch 0 taken 100% (fallthrough) +branch 1 taken 0% + -: 791: { + -: 792: //discard hand + 1107063: 793: while(numHandCards(state) > 1 /*0*/) +call 0 returned 100% +branch 1 taken 52% +branch 2 taken 48% (fallthrough) + -: 794: { + 388605: 795: discardCard(handPos, currentPlayer, state, 0); +call 0 returned 100% + -: 796: } + -: 797: + -: 798: //draw 4 + 1796145: 799: for (i = 0; i < 4; i++) +branch 0 taken 80% +branch 1 taken 20% (fallthrough) + -: 800: { + 1436916: 801: drawCard(currentPlayer, state); +call 0 returned 100% + -: 802: } + -: 803: + -: 804: //other players discard hand and redraw if hand size > 4 + 1436917: 805: for (i = 0; i < state->numPlayers; i++) +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + -: 806: { + 1077688: 807: if (i != currentPlayer) +branch 0 taken 67% (fallthrough) +branch 1 taken 33% + -: 808: { + -: 809: //if ( state->handCount[i] > 4 ) + -: 810: { + -: 811: //discard hand + 4671315: 812: while( state->handCount[i] > 0 ) +branch 0 taken 82% +branch 1 taken 18% (fallthrough) + -: 813: { + 3234397: 814: discardCard(handPos, i, state, 0); +call 0 returned 100% + -: 815: } + -: 816: + -: 817: //draw 4 + 3592295: 818: for (j = 0; j < 4; j++) +branch 0 taken 80% +branch 1 taken 20% (fallthrough) + -: 819: { + 2873836: 820: drawCard(i, state); +call 0 returned 100% + -: 821: } + -: 822: } + -: 823: } + -: 824: } + -: 825: } + 720681: 826:} + -: 827: +function doTribute called 705810 returned 100% blocks executed 100% + 705810: 828:void doTribute(struct gameState *state, int currentPlayer, int nextPlayer, int tributeRevealedCards[2]) + -: 829:{ + -: 830: int i; + -: 831: + 705810: 832: if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) { +branch 0 taken 8% (fallthrough) +branch 1 taken 92% + 58992: 833: if (state->deckCount[nextPlayer] > 0) { +branch 0 taken 33% (fallthrough) +branch 1 taken 67% + 19584: 834: tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + 19584: 835: state->deckCount[nextPlayer]--; + -: 836: } + 39408: 837: else if (state->discardCount[nextPlayer] > 0) { +branch 0 taken 50% (fallthrough) +branch 1 taken 50% + 19581: 838: tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1]; + 19581: 839: state->discardCount[nextPlayer]--; + -: 840: } + -: 841: else { + -: 842: //No Card to Reveal + -: 843: if (DEBUG) { + -: 844: printf("No cards to reveal\n"); + -: 845: } + -: 846: } + -: 847: } + -: 848: + -: 849: else { + 646818: 850: if (state->deckCount[nextPlayer] == 0) { +branch 0 taken 12% (fallthrough) +branch 1 taken 88% + 235240: 851: for (i = 0; i < state->discardCount[nextPlayer]; i++) { +branch 0 taken 67% +branch 1 taken 33% (fallthrough) + 156829: 852: state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck + 156829: 853: state->deckCount[nextPlayer]++; + 156829: 854: state->discard[nextPlayer][i] = -1; + 156829: 855: state->discardCount[nextPlayer]--; + -: 856: } + -: 857: + 78411: 858: shuffle(nextPlayer,state);//Shuffle the deck +call 0 returned 100% + -: 859: } + 646818: 860: tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + 646818: 861: state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + 646818: 862: state->deckCount[nextPlayer]--; + 646818: 863: tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + 646818: 864: state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + 646818: 865: state->deckCount[nextPlayer]--; + -: 866: } + -: 867: + 705810: 868: if (tributeRevealedCards[0] == tributeRevealedCards[1]) { //If we have a duplicate card, just drop one +branch 0 taken 7% (fallthrough) +branch 1 taken 93% + 46711: 869: state->playedCards[state->playedCardCount] = tributeRevealedCards[1]; + 46711: 870: state->playedCardCount++; + 46711: 871: tributeRevealedCards[1] = -1; + -: 872: } + -: 873: + 2823240: 874: for (i = 0; i <= 2; i ++) { +branch 0 taken 75% +branch 1 taken 25% (fallthrough) + 2117430: 875: if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) { //Treasure cards +branch 0 taken 97% (fallthrough) +branch 1 taken 3% +branch 2 taken 96% (fallthrough) +branch 3 taken 4% +branch 4 taken 4% (fallthrough) +branch 5 taken 96% + 216627: 876: state->numActions = state->numActions + 2; + -: 877: } + -: 878: + 1900803: 879: else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall) { //Victory Card Found +branch 0 taken 96% (fallthrough) +branch 1 taken 4% +branch 2 taken 96% (fallthrough) +branch 3 taken 4% +branch 4 taken 56% (fallthrough) +branch 5 taken 44% +branch 6 taken 93% (fallthrough) +branch 7 taken 7% +branch 8 taken 0% (fallthrough) +branch 9 taken 100% + 994638: 880: drawCard(currentPlayer, state); +call 0 returned 100% + -: 881: //drawCard(currentPlayer, state); + -: 882: } + -: 883: else { //Action Card + 906165: 884: state->coins += 2; + -: 885: } + -: 886: } + 705810: 887:} + -: 888: +function doAmbassador called 0 returned 0% blocks executed 0% + #####: 889:int doAmbassador(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) + -: 890:{ + -: 891: int i; + -: 892: int j; + -: 893: + #####: 894: j = 0; //used to check if player has enough cards to discard + -: 895: + #####: 896: if (choice2 > 3 || choice2 < 0) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 897: { + #####: 898: return -1; + -: 899: } + -: 900: + -: 901:/* + -: 902: if (choice1 == handPos) + -: 903: { + -: 904: return -1; + -: 905: } + -: 906: */ + -: 907: + #####: 908: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 909: { + #####: 910: if (i != handPos && i == state->hand[currentPlayer][choice1] && i != choice1) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed + -: 911: { + #####: 912: j++; + -: 913: } + -: 914: } + #####: 915: if (j < choice2) +branch 0 never executed +branch 1 never executed + -: 916: { + #####: 917: return -1; + -: 918: } + -: 919: + -: 920: if (DEBUG) + -: 921: printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]); + -: 922: + -: 923: //increase supply count for choosen card by amount being discarded + #####: 924: state->supplyCount[state->hand[currentPlayer][choice1]] += choice2; + -: 925: + -: 926: //each other player gains a copy of revealed card + #####: 927: for (i = 0; i < state->numPlayers; i++) +branch 0 never executed +branch 1 never executed + -: 928: { + #####: 929: if (i != currentPlayer) +branch 0 never executed +branch 1 never executed + -: 930: { + #####: 931: gainCard(state->hand[currentPlayer][choice1], state, 0, i); +call 0 never executed + -: 932: } + -: 933: } + -: 934: + -: 935: //discard played card from hand + #####: 936: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 937: + -: 938: //trash copies of cards returned to supply + #####: 939: for (j = 0; j < choice2; j++) +branch 0 never executed +branch 1 never executed + -: 940: { + #####: 941: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 942: { + #####: 943: if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1]) +branch 0 never executed +branch 1 never executed + -: 944: { + #####: 945: discardCard(i, currentPlayer, state, 1); +call 0 never executed + #####: 946: break; + -: 947: } + -: 948: } + -: 949: } + -: 950: + #####: 951: return 0; + -: 952:} + -: 953: +function cardEffect called 0 returned 0% blocks executed 0% + #####: 954:int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) + -: 955:{ + -: 956: int i; + -: 957: int j; + -: 958: int k; + -: 959: int x; + -: 960: int index; + #####: 961: int currentPlayer = whoseTurn(state); +call 0 never executed + #####: 962: int nextPlayer = currentPlayer + 1; + -: 963: + #####: 964: int tributeRevealedCards[2] = {-1, -1}; + -: 965: int temphand[MAX_HAND];// moved above the if statement + #####: 966: int drawntreasure=0; + -: 967: int cardDrawn; + #####: 968: int z = 0;// this is the counter for the temp hand + #####: 969: if (nextPlayer > (state->numPlayers - 1)) { +branch 0 never executed +branch 1 never executed + #####: 970: nextPlayer = 0; + -: 971: } + -: 972: + -: 973: + -: 974: //uses switch to select card and perform actions + #####: 975: switch( card ) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed +branch 6 never executed +branch 7 never executed +branch 8 never executed +branch 9 never executed +branch 10 never executed +branch 11 never executed +branch 12 never executed +branch 13 never executed +branch 14 never executed +branch 15 never executed +branch 16 never executed +branch 17 never executed +branch 18 never executed +branch 19 never executed +branch 20 never executed + -: 976: { + -: 977: case adventurer: + #####: 978: while(drawntreasure<2) { +branch 0 never executed +branch 1 never executed + #####: 979: if (state->deckCount[currentPlayer] <1) { //if the deck is empty we need to shuffle discard and add to deck +branch 0 never executed +branch 1 never executed + #####: 980: shuffle(currentPlayer, state); +call 0 never executed + -: 981: } + #####: 982: drawCard(currentPlayer, state); +call 0 never executed + #####: 983: cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card. + #####: 984: if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed +branch 4 never executed +branch 5 never executed + #####: 985: drawntreasure++; + -: 986: else { + #####: 987: temphand[z]=cardDrawn; + #####: 988: state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one). + #####: 989: z++; + -: 990: } + -: 991: } + #####: 992: while(z-1>=0) { +branch 0 never executed +branch 1 never executed + #####: 993: state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn + #####: 994: z=z-1; + -: 995: } + #####: 996: return 0; + -: 997: + -: 998: case council_room: + -: 999: //+4 Cards + #####: 1000: for (i = 0; i < 4; i++) +branch 0 never executed +branch 1 never executed + -: 1001: { + #####: 1002: drawCard(currentPlayer, state); +call 0 never executed + -: 1003: } + -: 1004: + -: 1005: //+1 Buy + #####: 1006: state->numBuys++; + -: 1007: + -: 1008: //Each other player draws a card + #####: 1009: for (i = 0; i < state->numPlayers; i++) +branch 0 never executed +branch 1 never executed + -: 1010: { + #####: 1011: if ( i != currentPlayer ) +branch 0 never executed +branch 1 never executed + -: 1012: { + #####: 1013: drawCard(i, state); +call 0 never executed + -: 1014: } + -: 1015: } + -: 1016: + -: 1017: //put played card in played card pile + #####: 1018: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 1019: + #####: 1020: return 0; + -: 1021: + -: 1022: case feast: + -: 1023: //gain card with cost up to 5 + -: 1024: //Backup hand + #####: 1025: for (i = 0; i <= state->handCount[currentPlayer]; i++) { +branch 0 never executed +branch 1 never executed + #####: 1026: temphand[i] = state->hand[currentPlayer][i];//Backup card + #####: 1027: state->hand[currentPlayer][i] = -1;//Set to nothing + -: 1028: } + -: 1029: //Backup hand + -: 1030: + -: 1031: //Update Coins for Buy + #####: 1032: updateCoins(currentPlayer, state, 5); +call 0 never executed + #####: 1033: x = 1;//Condition to loop on + #####: 1034: while( x == 1) {//Buy one card +branch 0 never executed +branch 1 never executed + #####: 1035: if (supplyCount(choice1, state) <= 0) { +call 0 never executed +branch 1 never executed +branch 2 never executed + -: 1036: if (DEBUG) + -: 1037: printf("None of that card left, sorry!\n"); + -: 1038: + -: 1039: if (DEBUG) { + -: 1040: printf("Cards Left: %d\n", supplyCount(choice1, state)); + -: 1041: } + -: 1042: } + #####: 1043: else if (state->coins < getCost(choice1)) { +call 0 never executed +branch 1 never executed +branch 2 never executed + #####: 1044: printf("That card is too expensive!\n"); +call 0 never executed + -: 1045: + -: 1046: if (DEBUG) { + -: 1047: printf("Coins: %d < %d\n", state->coins, getCost(choice1)); + -: 1048: } + -: 1049: } + -: 1050: else { + -: 1051: + -: 1052: if (DEBUG) { + -: 1053: printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + -: 1054: } + -: 1055: + #####: 1056: gainCard(choice1, state, 0, currentPlayer);//Gain the card +call 0 never executed + #####: 1057: x = 0;//No more buying cards + -: 1058: + -: 1059: if (DEBUG) { + -: 1060: printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + -: 1061: } + -: 1062: + -: 1063: } + -: 1064: } + -: 1065: + -: 1066: //Reset Hand + #####: 1067: for (i = 0; i <= state->handCount[currentPlayer]; i++) { +branch 0 never executed +branch 1 never executed + #####: 1068: state->hand[currentPlayer][i] = temphand[i]; + #####: 1069: temphand[i] = -1; + -: 1070: } + -: 1071: //Reset Hand + -: 1072: + #####: 1073: return 0; + -: 1074: + -: 1075: case gardens: + #####: 1076: return -1; + -: 1077: + -: 1078: case mine: + #####: 1079: return doMine(choice1, choice2, state, handPos, currentPlayer); +call 0 never executed + -: 1080: + -: 1081: case remodel: + #####: 1082: j = state->hand[currentPlayer][choice1]; //store card we will trash + -: 1083: + #####: 1084: if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) ) +call 0 never executed +call 1 never executed +branch 2 never executed +branch 3 never executed + -: 1085: { + #####: 1086: return -1; + -: 1087: } + -: 1088: + #####: 1089: gainCard(choice2, state, 0, currentPlayer); +call 0 never executed + -: 1090: + -: 1091: //discard card from hand + #####: 1092: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 1093: + -: 1094: //discard trashed card + #####: 1095: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 1096: { + #####: 1097: if (state->hand[currentPlayer][i] == j) +branch 0 never executed +branch 1 never executed + -: 1098: { + #####: 1099: discardCard(i, currentPlayer, state, 0); +call 0 never executed + #####: 1100: break; + -: 1101: } + -: 1102: } + -: 1103: + -: 1104: + #####: 1105: return 0; + -: 1106: + -: 1107: case smithy: + -: 1108: //+3 Cards + #####: 1109: for (i = 0; i < 3; i++) +branch 0 never executed +branch 1 never executed + -: 1110: { + #####: 1111: drawCard(currentPlayer, state); +call 0 never executed + -: 1112: } + -: 1113: + -: 1114: //discard card from hand + #####: 1115: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1116: return 0; + -: 1117: + -: 1118: case village: + -: 1119: //+1 Card + #####: 1120: drawCard(currentPlayer, state); +call 0 never executed + -: 1121: + -: 1122: //+2 Actions + #####: 1123: state->numActions = state->numActions + 2; + -: 1124: + -: 1125: //discard played card from hand + #####: 1126: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1127: return 0; + -: 1128: + -: 1129: case baron: + #####: 1130: doBaron(choice1, state, currentPlayer); +call 0 never executed + #####: 1131: return 0; + -: 1132: + -: 1133: case great_hall: + -: 1134: //+1 Card + #####: 1135: drawCard(currentPlayer, state); +call 0 never executed + -: 1136: + -: 1137: //+1 Actions + #####: 1138: state->numActions++; + -: 1139: + -: 1140: //discard card from hand + #####: 1141: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1142: return 0; + -: 1143: + -: 1144: case minion: + #####: 1145: doMinion(choice1, choice2, state, handPos, currentPlayer); +call 0 never executed + #####: 1146: return 0; + -: 1147: + -: 1148: case steward: + #####: 1149: if (choice1 == 1) +branch 0 never executed +branch 1 never executed + -: 1150: { + -: 1151: //+2 cards + #####: 1152: drawCard(currentPlayer, state); +call 0 never executed + #####: 1153: drawCard(currentPlayer, state); +call 0 never executed + -: 1154: } + #####: 1155: else if (choice1 == 2) +branch 0 never executed +branch 1 never executed + -: 1156: { + -: 1157: //+2 coins + #####: 1158: state->coins = state->coins + 2; + -: 1159: } + -: 1160: else + -: 1161: { + -: 1162: //trash 2 cards in hand + #####: 1163: discardCard(choice2, currentPlayer, state, 1); +call 0 never executed + #####: 1164: discardCard(choice3, currentPlayer, state, 1); +call 0 never executed + -: 1165: } + -: 1166: + -: 1167: //discard card from hand + #####: 1168: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1169: return 0; + -: 1170: + -: 1171: case tribute: + #####: 1172: doTribute(state, currentPlayer, nextPlayer, tributeRevealedCards); +call 0 never executed + #####: 1173: return 0; + -: 1174: + -: 1175: case ambassador: + #####: 1176: return doAmbassador(choice1, choice2, state, handPos, currentPlayer); +call 0 never executed + -: 1177: + -: 1178: case cutpurse: + -: 1179: + #####: 1180: updateCoins(currentPlayer, state, 2); +call 0 never executed + #####: 1181: for (i = 0; i < state->numPlayers; i++) +branch 0 never executed +branch 1 never executed + -: 1182: { + #####: 1183: if (i != currentPlayer) +branch 0 never executed +branch 1 never executed + -: 1184: { + #####: 1185: for (j = 0; j < state->handCount[i]; j++) +branch 0 never executed +branch 1 never executed + -: 1186: { + #####: 1187: if (state->hand[i][j] == copper) +branch 0 never executed +branch 1 never executed + -: 1188: { + #####: 1189: discardCard(j, i, state, 0); +call 0 never executed + #####: 1190: break; + -: 1191: } + #####: 1192: if (j == state->handCount[i]) +branch 0 never executed +branch 1 never executed + -: 1193: { + #####: 1194: for (k = 0; k < state->handCount[i]; k++) +branch 0 never executed +branch 1 never executed + -: 1195: { + -: 1196: if (DEBUG) + -: 1197: printf("Player %d reveals card number %d\n", i, state->hand[i][k]); + -: 1198: } + #####: 1199: break; + -: 1200: } + -: 1201: } + -: 1202: + -: 1203: } + -: 1204: + -: 1205: } + -: 1206: + -: 1207: //discard played card from hand + #####: 1208: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + -: 1209: + #####: 1210: return 0; + -: 1211: + -: 1212: + -: 1213: case embargo: + -: 1214: //+2 Coins + #####: 1215: state->coins = state->coins + 2; + -: 1216: + -: 1217: //see if selected pile is in play + #####: 1218: if ( state->supplyCount[choice1] == -1 ) +branch 0 never executed +branch 1 never executed + -: 1219: { + #####: 1220: return -1; + -: 1221: } + -: 1222: + -: 1223: //add embargo token to selected supply pile + #####: 1224: state->embargoTokens[choice1]++; + -: 1225: + -: 1226: //trash card + #####: 1227: discardCard(handPos, currentPlayer, state, 1); +call 0 never executed + #####: 1228: return 0; + -: 1229: + -: 1230: case outpost: + -: 1231: //set outpost flag + #####: 1232: state->outpostPlayed++; + -: 1233: + -: 1234: //discard card + #####: 1235: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1236: return 0; + -: 1237: + -: 1238: case salvager: + -: 1239: //+1 buy + #####: 1240: state->numBuys++; + -: 1241: + #####: 1242: if (choice1) +branch 0 never executed +branch 1 never executed + -: 1243: { + -: 1244: //gain coins equal to trashed card + #####: 1245: state->coins = state->coins + getCost( handCard(choice1, state) ); +call 0 never executed +call 1 never executed + -: 1246: //trash card + #####: 1247: discardCard(choice1, currentPlayer, state, 1); +call 0 never executed + -: 1248: } + -: 1249: + -: 1250: //discard card + #####: 1251: discardCard(handPos, currentPlayer, state, 0); +call 0 never executed + #####: 1252: return 0; + -: 1253: + -: 1254: case sea_hag: + #####: 1255: for (i = 0; i < state->numPlayers; i++) { +branch 0 never executed +branch 1 never executed + #####: 1256: if (i != currentPlayer) { +branch 0 never executed +branch 1 never executed + #####: 1257: state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; + #####: 1258: state->deckCount[i]--; + #####: 1259: state->discardCount[i]++; + #####: 1260: state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse + -: 1261: } + -: 1262: } + #####: 1263: return 0; + -: 1264: + -: 1265: case treasure_map: + -: 1266: //search hand for another treasure_map + #####: 1267: index = -1; + #####: 1268: for (i = 0; i < state->handCount[currentPlayer]; i++) +branch 0 never executed +branch 1 never executed + -: 1269: { + #####: 1270: if (state->hand[currentPlayer][i] == treasure_map && i != handPos) +branch 0 never executed +branch 1 never executed +branch 2 never executed +branch 3 never executed + -: 1271: { + #####: 1272: index = i; + #####: 1273: break; + -: 1274: } + -: 1275: } + #####: 1276: if (index > -1) +branch 0 never executed +branch 1 never executed + -: 1277: { + -: 1278: //trash both treasure cards + #####: 1279: discardCard(handPos, currentPlayer, state, 1); +call 0 never executed + #####: 1280: discardCard(index, currentPlayer, state, 1); +call 0 never executed + -: 1281: + -: 1282: //gain 4 Gold cards + #####: 1283: for (i = 0; i < 4; i++) +branch 0 never executed +branch 1 never executed + -: 1284: { + #####: 1285: gainCard(gold, state, 1, currentPlayer); +call 0 never executed + -: 1286: } + -: 1287: + -: 1288: //return success + #####: 1289: return 1; + -: 1290: } + -: 1291: + -: 1292: //no second treasure_map found in hand + #####: 1293: return -1; + -: 1294: } + -: 1295: + #####: 1296: return -1; + -: 1297:} + -: 1298: +function discardCard called 4343683 returned 100% blocks executed 100% + 4343683: 1299:int discardCard(int handPos, int currentPlayer, struct gameState *state, int trashFlag) + -: 1300:{ + -: 1301: + -: 1302: //if card is not trashed, added to Played pile + 4343683: 1303: if (trashFlag < 1) +branch 0 taken 100% (fallthrough) +branch 1 taken 0% + -: 1304: { + -: 1305: //add card to played pile + 4343683: 1306: state->playedCards[state->playedCardCount] = state->hand[currentPlayer][handPos]; + 4343683: 1307: state->playedCardCount++; + -: 1308: } + -: 1309: + -: 1310: //set played card to -1 + 4343683: 1311: state->hand[currentPlayer][handPos] = -1; + -: 1312: + -: 1313: //remove card from player's hand + 4343683: 1314: if ( handPos == (state->handCount[currentPlayer] - 1) ) //last card in hand array is played +branch 0 taken 17% (fallthrough) +branch 1 taken 83% + -: 1315: { + -: 1316: //reduce number of cards in hand + 739365: 1317: state->handCount[currentPlayer]--; + -: 1318: } + 3604318: 1319: else if ( state->handCount[currentPlayer] == 1 ) //only one card in hand +branch 0 taken 16% (fallthrough) +branch 1 taken 84% + -: 1320: { + -: 1321: //reduce number of cards in hand + 575003: 1322: state->handCount[currentPlayer]--; + -: 1323: } + -: 1324: else + -: 1325: { + -: 1326: //replace discarded card with last card in hand + 3029315: 1327: state->hand[currentPlayer][handPos] = state->hand[currentPlayer][ (state->handCount[currentPlayer] - 1)]; + -: 1328: //set last card to -1 + 3029315: 1329: state->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1; + -: 1330: //reduce number of cards in hand + 3029315: 1331: state->handCount[currentPlayer]--; + -: 1332: } + -: 1333: + 4343683: 1334: return 0; + -: 1335:} + -: 1336: +function gainCard called 556409 returned 100% blocks executed 70% + 556409: 1337:int gainCard(int supplyPos, struct gameState *state, int toFlag, int player) + -: 1338:{ + -: 1339: //Note: supplyPos is enum of choosen card + -: 1340: + -: 1341: //check if supply pile is empty (0) or card is not used in game (-1) + 556409: 1342: if ( supplyCount(supplyPos, state) < 1 ) +call 0 returned 100% +branch 1 taken 0% (fallthrough) +branch 2 taken 100% + -: 1343: { + #####: 1344: return -1; + -: 1345: } + -: 1346: + -: 1347: //added card for [whoseTurn] current player: + -: 1348: // toFlag = 0 : add to discard + -: 1349: // toFlag = 1 : add to deck + -: 1350: // toFlag = 2 : add to hand + -: 1351: + 556409: 1352: if (toFlag == 1) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1353: { + #####: 1354: state->deck[ player ][ state->deckCount[player] ] = supplyPos; + #####: 1355: state->deckCount[player]++; + -: 1356: } + 556409: 1357: else if (toFlag == 2) +branch 0 taken 0% (fallthrough) +branch 1 taken 100% + -: 1358: { + #####: 1359: state->hand[ player ][ state->handCount[player] ] = supplyPos; + #####: 1360: state->handCount[player]++; + -: 1361: } + -: 1362: else + -: 1363: { + 556409: 1364: state->discard[player][ state->discardCount[player] ] = supplyPos; + 556409: 1365: state->discardCount[player]++; + -: 1366: } + -: 1367: + -: 1368: //decrease number in supply pile + 556409: 1369: state->supplyCount[supplyPos]--; + -: 1370: + 556409: 1371: return 0; + -: 1372:} + -: 1373: +function updateCoins called 4147100 returned 100% blocks executed 100% + 4147100: 1374:int updateCoins(int player, struct gameState *state, int bonus) + -: 1375:{ + -: 1376: int i; + -: 1377: + -: 1378: //reset coin count + 4147100: 1379: state->coins = 0; + -: 1380: + -: 1381: //add coins for each Treasure card in player's hand + 18253150: 1382: for (i = 0; i < state->handCount[player]; i++) +branch 0 taken 77% +branch 1 taken 23% (fallthrough) + -: 1383: { + 14106050: 1384: if (state->hand[player][i] == copper) +branch 0 taken 45% (fallthrough) +branch 1 taken 55% + -: 1385: { + 6412512: 1386: state->coins += 1; + -: 1387: } + 7693538: 1388: else if (state->hand[player][i] == silver) +branch 0 taken 2% (fallthrough) +branch 1 taken 98% + -: 1389: { + 191917: 1390: state->coins += 2; + -: 1391: } + 7501621: 1392: else if (state->hand[player][i] == gold) +branch 0 taken 3% (fallthrough) +branch 1 taken 97% + -: 1393: { + 192262: 1394: state->coins += 3; + -: 1395: } + -: 1396: } + -: 1397: + -: 1398: //add bonus + 4147100: 1399: state->coins += bonus; + -: 1400: + 4147100: 1401: return 0; + -: 1402:} + -: 1403: + -: 1404: + -: 1405://end of dominion.c diff --git a/projects/alghanmz/a4/dominion.gcda b/projects/alghanmz/a4/dominion.gcda new file mode 100644 index 000000000..515b2ab33 Binary files /dev/null and b/projects/alghanmz/a4/dominion.gcda differ diff --git a/projects/alghanmz/a4/dominion.gcno b/projects/alghanmz/a4/dominion.gcno new file mode 100644 index 000000000..d2c549165 Binary files /dev/null and b/projects/alghanmz/a4/dominion.gcno differ diff --git a/projects/alghanmz/a4/dominion.h b/projects/alghanmz/a4/dominion.h new file mode 100644 index 000000000..f9d9039b8 --- /dev/null +++ b/projects/alghanmz/a4/dominion.h @@ -0,0 +1,131 @@ +#ifndef _DOMINION_H +#define _DOMINION_H + +// Code from various sources, baseline from Kristen Bartosz + +#define MAX_HAND 500 +#define MAX_DECK 500 + +#define MAX_PLAYERS 4 + +#define DEBUG 0 + +/* http://dominion.diehrstraits.com has card texts */ +/* http://dominion.isotropic.org has other stuff */ + +/* hand# means index of a card in current active player's hand */ + +enum CARD +{ curse = 0, + estate, + duchy, + province, + + copper, + silver, + gold, + + adventurer, + /* If no/only 1 treasure found, stop when full deck seen */ + council_room, + feast, /* choice1 is supply # of card gained) */ + gardens, + mine, /* choice1 is hand# of money to trash, choice2 is supply# of + money to put in hand */ + remodel, /* choice1 is hand# of card to remodel, choice2 is supply# */ + smithy, + village, + + baron, /* choice1: boolean for discard of estate */ + /* Discard is always of first (lowest index) estate */ + great_hall, + minion, /* choice1: 1 = +2 coin, 2 = redraw */ + steward, /* choice1: 1 = +2 card, 2 = +2 coin, 3 = trash 2 (choice2,3) */ + tribute, + + ambassador, /* choice1 = hand#, choice2 = number to return to supply */ + cutpurse, + embargo, /* choice1 = supply# */ + outpost, + salvager, /* choice1 = hand# to trash */ + sea_hag, + treasure_map +}; + +struct gameState { + int numPlayers; //number of players + int supplyCount[treasure_map+1]; //this is the amount of a specific type of card given a specific number. + int embargoTokens[treasure_map+1]; + int outpostPlayed; + int outpostTurn; + int whoseTurn; + int phase; + int numActions; /* Starts at 1 each turn */ + int coins; /* Use as you see fit! */ + int numBuys; /* Starts at 1 each turn */ + int hand[MAX_PLAYERS][MAX_HAND]; + int handCount[MAX_PLAYERS]; + int deck[MAX_PLAYERS][MAX_DECK]; + int deckCount[MAX_PLAYERS]; + int discard[MAX_PLAYERS][MAX_DECK]; + int discardCount[MAX_PLAYERS]; + int playedCards[MAX_DECK]; + int playedCardCount; +}; + +/* All functions return -1 on failure, and DO NOT CHANGE GAME STATE; + unless specified for other return, return 0 on success */ + +struct gameState* newGame(); + +int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + int k8, int k9, int k10); + +int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, + struct gameState *state); +/* Responsible for initializing all supplies, and shuffling deck and + drawing starting hands for all players. Check that 10 cards selected + are in fact (different) kingdom cards, and that numPlayers is valid. + +Cards not in game should initialize supply position to -1 */ + +int shuffle(int player, struct gameState *state); +/* Assumes all cards are now in deck array (or hand/played): discard is + empty */ + +int playCard(int handPos, int choice1, int choice2, int choice3, + struct gameState *state); +/* Play card with index handPos from current player's hand */ + +int buyCard(int supplyPos, struct gameState *state); +/* Buy card with supply index supplyPos */ + +int numHandCards(struct gameState *state); +/* How many cards current player has in hand */ + +int handCard(int handNum, struct gameState *state); +/* enum value of indexed card in player's hand */ + +int supplyCount(int card, struct gameState *state); +/* How many of given card are left in supply */ + +int fullDeckCount(int player, int card, struct gameState *state); +/* Here deck = hand + discard + deck */ + +int whoseTurn(struct gameState *state); + +int endTurn(struct gameState *state); +/* Must do phase C and advance to next player; do not advance whose turn + if game is over */ + +int isGameOver(struct gameState *state); + +int scoreFor(int player, struct gameState *state); +/* Negative here does not mean invalid; scores may be negative, + -9999 means invalid input */ + +int getWinners(int players[MAX_PLAYERS], struct gameState *state); +/* Set array position of each player who won (remember ties!) to + 1, others to 0 */ + +#endif diff --git a/projects/alghanmz/a4/dominion.o b/projects/alghanmz/a4/dominion.o new file mode 100644 index 000000000..885f3ea63 Binary files /dev/null and b/projects/alghanmz/a4/dominion.o differ diff --git a/projects/alghanmz/a4/dominion_helpers.h b/projects/alghanmz/a4/dominion_helpers.h new file mode 100644 index 000000000..0887fda15 --- /dev/null +++ b/projects/alghanmz/a4/dominion_helpers.h @@ -0,0 +1,15 @@ +#ifndef _DOMINION_HELPERS_H +#define _DOMINION_HELPERS_H + +#include "dominion.h" + +int drawCard(int player, struct gameState *state); +int updateCoins(int player, struct gameState *state, int bonus); +int discardCard(int handPos, int currentPlayer, struct gameState *state, + int trashFlag); +int gainCard(int supplyPos, struct gameState *state, int toFlag, int player); +int getCost(int cardNumber); +int cardEffect(int card, int choice1, int choice2, int choice3, + struct gameState *state, int handPos, int *bonus); + +#endif diff --git a/projects/alghanmz/a4/hw.c b/projects/alghanmz/a4/hw.c new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/projects/alghanmz/a4/hw.c @@ -0,0 +1 @@ + diff --git a/projects/alghanmz/a4/interface.c b/projects/alghanmz/a4/interface.c new file mode 100644 index 000000000..58cc5ba58 --- /dev/null +++ b/projects/alghanmz/a4/interface.c @@ -0,0 +1,425 @@ +/* Interactive Dominion Interface + +Sam Heinith CS362 +1/26/2010 +*/ + +#include +#include +#include +#include +#include "rngs.h" +#include "interface.h" +#include "dominion.h" + + +void cardNumToName(int card, char *name) { + switch(card) { + case curse: + strcpy(name,"Curse"); + break; + case estate: + strcpy(name,"Estate"); + break; + case duchy: + strcpy(name,"Duchy"); + break; + case province: + strcpy(name,"Province"); + break; + case copper: + strcpy(name,"Copper"); + break; + case silver: + strcpy(name,"Silver"); + break; + case gold: + strcpy(name,"Gold"); + break; + case adventurer: + strcpy(name,"Adventurer"); + break; + case council_room: + strcpy(name,"Council Room"); + break; + case feast: + strcpy(name,"Feast"); + break; + case gardens: + strcpy(name,"Gardens"); + break; + case mine: + strcpy(name,"Mine"); + break; + case remodel: + strcpy(name,"Remodel"); + break; + case smithy: + strcpy(name,"Smithy"); + break; + case village: + strcpy(name,"Village"); + break; + case baron: + strcpy(name,"Baron"); + break; + case great_hall: + strcpy(name,"Great Hall"); + break; + case minion: + strcpy(name,"Minion"); + break; + case steward: + strcpy(name,"Steward"); + break; + case tribute: + strcpy(name,"Tribute"); + break; + case ambassador: + strcpy(name,"Ambassador"); + break; + case cutpurse: + strcpy(name,"Cutpurse"); + break; + case embargo: + strcpy(name,"Embargo"); + break; + case outpost: + strcpy(name,"Outpost"); + break; + case salvager: + strcpy(name,"Salvager"); + break; + case sea_hag: + strcpy(name,"Sea Hag"); + break; + case treasure_map: + strcpy(name,"Treasure Map"); + break; + + default: + strcpy(name,"?"); + } + +} + + + +int getCardCost(int card) { + int cost; + switch(card) { + case curse: + cost = CURSE_COST; + break; + case estate: + cost = ESTATE_COST; + break; + case duchy: + cost = DUCHY_COST; + break; + case province: + cost = PROVINCE_COST; + break; + case copper: + cost = COPPER_COST; + break; + case silver: + cost = SILVER_COST; + break; + case gold: + cost = GOLD_COST; + break; + case adventurer: + cost = ADVENTURER_COST; + break; + case council_room: + cost = COUNCIL_ROOM_COST; + break; + case feast: + cost = FEAST_COST; + break; + case gardens: + cost = GARDEN_COST; + break; + case mine: + cost = MINE_COST; + break; + case remodel: + cost = REMODEL_COST; + break; + case smithy: + cost = SMITHY_COST; + break; + case village: + cost = VILLAGE_COST; + break; + case baron: + cost = BARON_COST; + break; + case great_hall: + cost = GREAT_HALL_COST; + break; + case minion: + cost = MINION_COST; + break; + case steward: + cost = STEWARD_COST; + break; + case tribute: + cost = TRIBUTE_COST; + break; + case ambassador: + cost = AMBASSADOR_COST; + break; + case cutpurse: + cost = CUTPURSE_COST; + break; + case embargo: + cost = EMBARGO_COST; + break; + case outpost: + cost = OUTPOST_COST; + break; + case salvager: + cost = SALVAGER_COST; + break; + case sea_hag: + cost = SEA_HAG_COST; + break; + case treasure_map: + cost = TREASURE_MAP_COST; + break; + default: + cost = ONETHOUSAND; + } + return cost; +} + + + + + + +void printHand(int player, struct gameState *game) { + int handCount = game->handCount[player]; + int handIndex; + printf("Player %d's hand:\n", player); + if(handCount > 0) printf("# Card\n"); + for(handIndex = 0; handIndex < handCount; handIndex++) { + int card = game->hand[player][handIndex]; + char name[MAX_STRING_LENGTH]; + cardNumToName(card, name); + printf("%-2d %-13s\n", handIndex, name); + } + printf("\n"); +} + + + +void printDeck(int player, struct gameState *game) { + int deckCount = game->deckCount[player]; + int deckIndex; + printf("Player %d's deck: \n", player); + if(deckCount > 0) printf("# Card\n"); + for(deckIndex = 0; deckIndex < deckCount; deckIndex++) { + int card = game->deck[player][deckIndex]; + char name[MAX_STRING_LENGTH]; + cardNumToName(card, name); + printf("%-2d %-13s\n", deckIndex, name); + } + printf("\n"); +} + +void printPlayed(int player, struct gameState *game) { + int playedCount = game->playedCardCount; + int playedIndex; + printf("Player %d's played cards: \n", player); + if(playedCount > 0) printf("# Card\n"); + for(playedIndex = 0; playedIndex < playedCount; playedIndex++) { + int card = game->playedCards[playedIndex]; + char name[MAX_STRING_LENGTH]; + cardNumToName(card, name); + printf("%-2d %-13s \n", playedIndex, name); + } + printf("\n"); +} + + + +void printDiscard(int player, struct gameState *game) { + int discardCount = game->discardCount[player]; + int discardIndex; + printf("Player %d's discard: \n", player); + if(discardCount > 0) printf("# Card\n"); + for(discardIndex = 0; discardIndex < discardCount; discardIndex++) { + int card = game->discard[player][discardIndex]; + char name[MAX_STRING_LENGTH]; + cardNumToName(card, name); + printf("%-2d %-13s \n", discardIndex, name); + } + printf("\n"); +} + + + + +void printSupply(struct gameState *game) { + int cardNum, cardCost, cardCount; + char name[MAX_STRING_LENGTH]; + printf("# Card Cost Copies\n"); + for(cardNum = 0; cardNum < NUM_TOTAL_K_CARDS; cardNum++) { + cardCount = game->supplyCount[cardNum]; + if(cardCount == -1) continue; + cardNumToName(cardNum, name); + cardCost = getCardCost(cardNum); + printf("%-2d %-13s %-5d %-5d", cardNum, name, cardCost, cardCount); + printf("\n"); + } + printf("\n"); +} + + +void printState(struct gameState *game) { + int numActions = game->numActions; + int numCoins = game->coins; + int numBuys = game->numBuys; + int currentPlayer = game->whoseTurn; + int phase = game->phase; + char phaseName[MAX_STRING_LENGTH]; + phaseNumToName(phase,phaseName); + printf("Player %d:\n%s phase\n%d actions\n%d coins\n%d buys\n\n", currentPlayer, phaseName, numActions, numCoins, numBuys); +} + +void printScores(struct gameState *game) { + int playerNum, score[MAX_PLAYERS]; + int numPlayers = game->numPlayers; + for(playerNum = 0; playerNum < numPlayers; playerNum++) { + score[playerNum] = scoreFor(playerNum,game); + printf("Player %d has a score of %d\n", playerNum, score[playerNum]); + } +} + + +void printHelp(void) { + printf("Commands are: \n\ + add [Supply Card Number] - add any card to your hand (teh hacks)\n\ + buy [Supply Card Number] - buy a card at supply position\n\ + end - end your turn\n\ + init [Number of Players] [Number of Bots] - initialize the game\n\ + num - print number of cards in your hand\n\ + play [Hand Index] [Choice] [Choice] [Choice] - play a card from your hand\n\ + resign - end the game showing the current scores\n\ + show - show your current hand\n\ + stat - show your turn's status\n\ + supp - show the supply\n\ + whos - whos turn\n\ + exit - exit the interface"); + printf("\n\n"); + +} + + +void phaseNumToName(int phase, char *name) { + switch(phase) { + case ACTION_PHASE: + strcpy(name,"Action"); + break; + case BUY_PHASE: + strcpy(name,"Buy"); + break; + case CLEANUP_PHASE: + strcpy(name,"Cleanup"); + break; + } +} + + +int addCardToHand(int player, int card, struct gameState *game) { + if(card >= adventurer && card < NUM_TOTAL_K_CARDS) { + int handTop = game->handCount[player]; + game->hand[player][handTop] = card; + game->handCount[player]++; + return SUCCESS; + } else { + return FAILURE; + } + +} + +void selectKingdomCards(int randomSeed, int kingCards[NUM_K_CARDS]) { + int i, used, card, numSelected = 0; + SelectStream(1); + PutSeed((long)randomSeed); + + + while(numSelected < NUM_K_CARDS) { + used = FALSE; + card = floor(Random() * NUM_TOTAL_K_CARDS); + if(card < adventurer) continue; + for(i = 0; i < numSelected; i++) { + if(kingCards[i] == card) { + used = TRUE; + break; + } + } + if(used == TRUE) continue; + kingCards[numSelected] = card; + numSelected++; + } +} + + +int countHandCoins(int player, struct gameState *game) { + int card, index, coinage = 0; + + for(index = 0; index < game->handCount[player]; index++) { + card = game->hand[player][index]; + switch(card) { + case copper: + coinage += COPPER_VALUE; + break; + case silver: + coinage += SILVER_VALUE; + break; + case gold: + coinage += GOLD_VALUE; + break; + } + } + return coinage; +} + + +void executeBotTurn(int player, int *turnNum, struct gameState *game) { + int coins = countHandCoins(player, game); + + printf("*****************Executing Bot Player %d Turn Number %d*****************\n", player, *turnNum); + printSupply(game); + //sleep(1); //Thinking... + + if(coins >= PROVINCE_COST && supplyCount(province,game) > 0) { + buyCard(province,game); + printf("Player %d buys card Province\n\n", player); + } + else if(supplyCount(province,game) == 0 && coins >= DUCHY_COST ) { + buyCard(duchy,game); + printf("Player %d buys card Duchy\n\n", player); + } + else if(coins >= GOLD_COST && supplyCount(gold,game) > 0) { + buyCard(gold,game); + printf("Player %d buys card Gold\n\n", player); + } + else if(coins >= SILVER_COST && supplyCount(silver,game) > 0) { + buyCard(silver,game); + printf("Player %d buys card Silver\n\n", player); + + } + + + if(player == (game->numPlayers -1)) (*turnNum)++; + endTurn(game); + if(! isGameOver(game)) { + int currentPlayer = whoseTurn(game); + printf("Player %d's turn number %d\n\n", currentPlayer, (*turnNum)); + } +} diff --git a/projects/alghanmz/a4/interface.h b/projects/alghanmz/a4/interface.h new file mode 100644 index 000000000..6f7bacac2 --- /dev/null +++ b/projects/alghanmz/a4/interface.h @@ -0,0 +1,128 @@ +/* Interactive Dominion Interface + + Sam Heinith CS362 + 1/26/2010 +*/ + + + +#ifndef _INTERFACE_H +#define _INTERFACE_H + + + +#include "dominion.h" + +//Last card enum (Treasure map) card number plus one for the 0th card. +#define NUM_TOTAL_K_CARDS (treasure_map + 1) +#define NUM_K_CARDS 10 +#define NUM_V_CARDS_2 8 +#define NUM_V_CARDS_3or4 12 +#define NUM_C_CARDS_2 10 +#define NUM_C_CARDS_3 20 +#define NUM_C_CARDS_4 30 +#define NUM_COPPER 60 +#define NUM_SILVER 40 +#define NUM_GOLD 30 +#define UNUSED -1 +#define START_COPPER 7 +#define START_ESTATE 3 +#define HANDSIZE 5 + +#define COMPARE(string1, string2) strncmp(string1, string2, 4) +#define MAX_STRING_LENGTH 32 +#define TRUE 1 +#define FALSE 0 + +#define SUCCESS 0 +#define FAILURE -1 + +#define MATCH 0 +#define WINNER 1 +#define NOT_WINNER 0 + +//The Game Phases +#define ACTION_PHASE 0 +#define BUY_PHASE 1 +#define CLEANUP_PHASE 2 + +#define COPPER_VALUE 1 +#define SILVER_VALUE 2 +#define GOLD_VALUE 3 + +//From Dominion List Spoiler +#define COPPER_COST 0 +#define SILVER_COST 3 +#define GOLD_COST 6 +#define ESTATE_COST 2 +#define DUCHY_COST 5 +#define PROVINCE_COST 8 +#define CURSE_COST 0 +#define ADVENTURER_COST 6 +#define COUNCIL_ROOM_COST 5 +#define FEAST_COST 4 +#define GARDEN_COST 4 +#define MINE_COST 5 +#define MONEYLENDER_COST 4 +#define REMODEL_COST 4 +#define SMITHY_COST 4 +#define VILLAGE_COST 3 +#define WOODCUTTER_COST 3 +#define BARON_COST 4 +#define GREAT_HALL_COST 3 +#define MINION_COST 5 +#define SHANTY_TOWN_COST 3 +#define STEWARD_COST 3 +#define TRIBUTE_COST 5 +#define WISHING_WELL_COST 3 +#define AMBASSADOR_COST 3 +#define CUTPURSE_COST 4 +#define EMBARGO_COST 2 +#define OUTPOST_COST 5 +#define SALVAGER_COST 4 +#define SEA_HAG_COST 4 +#define TREASURE_MAP_COST 4 +#define ONETHOUSAND 1000 + + +int addCardToHand(int player, int card, struct gameState *game); + +int countHandCoins(int player, struct gameState *game); + + +void executeBotTurn(int player, int *turnNum, struct gameState *game); + +void phaseNumToName(int phase, char *name); +void cardNumToName(int card, char *name); + +int getCardCost(int card); + +void printHelp(void); + +void printHand(int player, struct gameState *game); + +void printDeck(int player, struct gameState *game); + +void printDiscard(int player, struct gameState *game); + +void printPlayed(int player, struct gameState *game); + +void printState(struct gameState *game); + +void printSupply(struct gameState *game); + +void printGameState(struct gameState *game); + +void printScores(struct gameState *game); + +void selectKingdomCards(int randomSeed, int kingdomCards[NUM_K_CARDS]); + + + +#endif + + + + + + diff --git a/projects/alghanmz/a4/playdom.c b/projects/alghanmz/a4/playdom.c new file mode 100644 index 000000000..336d9a661 --- /dev/null +++ b/projects/alghanmz/a4/playdom.c @@ -0,0 +1,135 @@ +#include "dominion.h" +#include +#include "rngs.h" +#include + +int main (int argc, char** argv) { + struct gameState G; + int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, + sea_hag, tribute, smithy + }; + + printf ("Starting game.\n"); + + initializeGame(2, k, atoi(argv[1]), &G); + + int money = 0; + int smithyPos = -1; + int adventurerPos = -1; + int i=0; + + int numSmithies = 0; + int numAdventurers = 0; + + while (!isGameOver(&G)) { + money = 0; + smithyPos = -1; + adventurerPos = -1; + for (i = 0; i < numHandCards(&G); i++) { + if (handCard(i, &G) == copper) + money++; + else if (handCard(i, &G) == silver) + money += 2; + else if (handCard(i, &G) == gold) + money += 3; + else if (handCard(i, &G) == smithy) + smithyPos = i; + else if (handCard(i, &G) == adventurer) + adventurerPos = i; + } + + if (whoseTurn(&G) == 0) { + if (smithyPos != -1) { + printf("0: smithy played from position %d\n", smithyPos); + playCard(smithyPos, -1, -1, -1, &G); + printf("smithy played.\n"); + money = 0; + i=0; + while(i= 8) { + printf("0: bought province\n"); + buyCard(province, &G); + } + else if (money >= 6) { + printf("0: bought gold\n"); + buyCard(gold, &G); + } + else if ((money >= 4) && (numSmithies < 2)) { + printf("0: bought smithy\n"); + buyCard(smithy, &G); + numSmithies++; + } + else if (money >= 3) { + printf("0: bought silver\n"); + buyCard(silver, &G); + } + + printf("0: end turn\n"); + endTurn(&G); + } + else { + if (adventurerPos != -1) { + printf("1: adventurer played from position %d\n", adventurerPos); + playCard(adventurerPos, -1, -1, -1, &G); + money = 0; + i=0; + while(i= 8) { + printf("1: bought province\n"); + buyCard(province, &G); + } + else if ((money >= 6) && (numAdventurers < 2)) { + printf("1: bought adventurer\n"); + buyCard(adventurer, &G); + numAdventurers++; + } else if (money >= 6) { + printf("1: bought gold\n"); + buyCard(gold, &G); + } + else if (money >= 3) { + printf("1: bought silver\n"); + buyCard(silver, &G); + } + printf("1: endTurn\n"); + + endTurn(&G); + } + } // end of While + + printf ("Finished game.\n"); + printf ("Player 0: %d\nPlayer 1: %d\n", scoreFor(0, &G), scoreFor(1, &G)); + + return 0; +} diff --git a/projects/alghanmz/a4/player.c b/projects/alghanmz/a4/player.c new file mode 100644 index 000000000..0a169d126 --- /dev/null +++ b/projects/alghanmz/a4/player.c @@ -0,0 +1,205 @@ +/* Interactive Dominion Interface + Version 7 + + Sam Heinith CS362 + Questions/Comments: + heiniths@onid.orst.edu + 1/26/2010 +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include "dominion.h" +#include "interface.h" +#include "rngs.h" + + +int main2(int argc, char *argv[]) { + //Default cards, as defined in playDom + int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy}; + struct gameState g; + initializeGame(2,k,1,&g); + printf ("SUCCESSFUL INIT\n"); + getchar(); + return 0; +} + +int main(int argc, char* argv[]) { + char *add = "add"; + char *buyC = "buy"; + char *endT = "end"; + char *exit = "exit"; + char *help = "help"; + char *init = "init"; + char *numH = "num"; + char *play = "play"; + char *resign = "resi"; + char *show = "show"; + char *stat = "stat"; + char *supply = "supp"; + char *whos = "whos"; + + char command[MAX_STRING_LENGTH]; + char line[MAX_STRING_LENGTH]; + char cardName[MAX_STRING_LENGTH]; + + //Array to hold bot presence + int isBot[MAX_PLAYERS] = { 0, 0, 0, 0}; + + int players[MAX_PLAYERS]; + int playerNum; + int outcome; + int currentPlayer; + int gameOver = FALSE; + int gameStarted = FALSE; + int turnNum = 0; + + int randomSeed = atoi(argv[1]); + + //Default cards, as defined in playDom + int kCards[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy}; + + struct gameState g; + struct gameState * game = &g; + + memset(game,0,sizeof(struct gameState)); + + if(argc != 2) { + printf("Usage: player [integer random number seed]\n"); + return EXIT_SUCCESS; + } + + if(randomSeed <= 0) { + printf("Usage: player [integer random number seed]\n"); + return EXIT_SUCCESS; + } + + initializeGame(2,kCards,randomSeed,game); + + printf("Please enter a command or \"help\" for commands\n"); + + + while(TRUE) { + int arg0 = UNUSED; + int arg1 = UNUSED; + int arg2 = UNUSED; + int arg3 = UNUSED; + + outcome = FAILURE; + strcpy(line,""); + strcpy(command,""); + strcpy(cardName,""); + + currentPlayer = whoseTurn(game); + + //If you are getting a seg fault comment this if block out + gameOver = isGameOver(game); + if(gameStarted == TRUE && gameOver == TRUE) { + printScores(game); + getWinners(players, game); + printf("After %d turns, the winner(s) are:\n", turnNum); + for(playerNum = 0; playerNum < game->numPlayers; playerNum++) { + if(players[playerNum] == WINNER) printf("Player %d\n", playerNum); + } + for(playerNum = 0; playerNum < game->numPlayers; playerNum++) { + printHand(playerNum, game); + printPlayed(playerNum, game); + printDiscard(playerNum, game); + printDeck(playerNum, game); + } + + break; //Exit out of the game/while loop + } + + + if(isBot[currentPlayer] == TRUE) { + executeBotTurn(currentPlayer, &turnNum, game); + continue; + } + + printf("$ "); + fgets(line, MAX_STRING_LENGTH, stdin); + sscanf(line, "%s %d %d %d %d", command, &arg0, &arg1, &arg2, &arg3); + + + if(COMPARE(command, add) == 0) { + outcome = addCardToHand(currentPlayer, arg0, game); + cardNumToName(arg0, cardName); + printf("Player %d adds %s to their hand\n\n", currentPlayer, cardName); + } else if(COMPARE(command, buyC) == 0) { + outcome = buyCard(arg0, game); + cardNumToName(arg0, cardName); + if(outcome == SUCCESS) { + printf("Player %d buys card %d, %s\n\n", currentPlayer, arg0, cardName); + } else { + printf("Player %d cannot buy card %d, %s\n\n", currentPlayer, arg0, cardName); + } + } else if(COMPARE(command, endT) == 0) { + if(gameStarted == TRUE) { + if(currentPlayer == (game->numPlayers -1)) turnNum++; + endTurn(game); + currentPlayer = whoseTurn(game); + printf("Player %d's turn number %d\n\n", currentPlayer, turnNum); + } + + } else if(COMPARE(command, exit) == 0) { + break; + } else if(COMPARE(command, help) == 0) { + printHelp(); + } else if(COMPARE(command, init) == 0) { + int numHuman = arg0 - arg1; + for(playerNum = numHuman; playerNum < arg0; playerNum++) { + isBot[playerNum] = TRUE; + } + // selectKingdomCards(randomSeed, kCards); //Comment this out to use the default card set defined in playDom. + outcome = initializeGame(arg0, kCards, randomSeed, game); + printf("\n"); + if(outcome == SUCCESS) { + gameStarted = TRUE; + currentPlayer = whoseTurn(game); + printf("Player %d's turn number %d\n\n", currentPlayer, turnNum); + } + + } else if(COMPARE(command, numH) == 0) { + int numCards = numHandCards(game); + printf("There are %d cards in your hand.\n", numCards); + } else if(COMPARE(command, play) == 0) { + int card = handCard(arg0,game); + outcome = playCard(arg0, arg1, arg2, arg3, game); + cardNumToName(card, cardName); + if(outcome == SUCCESS) { + printf("Player %d plays %s\n\n", currentPlayer, cardName); + } else { + printf("Player %d cannot play card %d\n\n", currentPlayer, arg0); + } + + } else if(COMPARE(command, resign) == 0) { + endTurn(game); + printScores(game); + break; + } else if(COMPARE(command, show) == 0) { + if(gameStarted == FALSE) continue; + printHand(currentPlayer, game); + printPlayed(currentPlayer, game); + //printDiscard(currentPlayer, game); + //printDeck(currentPlayer, game); + } else if(COMPARE(command, stat) == 0) { + if(gameStarted == FALSE) continue; + printState(game); + } else if(COMPARE(command, supply) == 0) { + printSupply(game); + } else if(COMPARE(command, whos) == 0) { + int playerNum = whoseTurn(game); + printf("Player %d's turn\n", playerNum); + } + } + + return EXIT_SUCCESS; + +} diff --git a/projects/alghanmz/a4/randomtestcard1 b/projects/alghanmz/a4/randomtestcard1 new file mode 100644 index 000000000..658665dc1 Binary files /dev/null and b/projects/alghanmz/a4/randomtestcard1 differ diff --git a/projects/alghanmz/a4/randomtestcard1.gcda b/projects/alghanmz/a4/randomtestcard1.gcda new file mode 100644 index 000000000..189119319 Binary files /dev/null and b/projects/alghanmz/a4/randomtestcard1.gcda differ diff --git a/projects/alghanmz/a4/randomtestcard1.gcno b/projects/alghanmz/a4/randomtestcard1.gcno new file mode 100644 index 000000000..975deb27e Binary files /dev/null and b/projects/alghanmz/a4/randomtestcard1.gcno differ diff --git a/projects/alghanmz/a4/randomtestcard2 b/projects/alghanmz/a4/randomtestcard2 new file mode 100644 index 000000000..dd5c3c780 Binary files /dev/null and b/projects/alghanmz/a4/randomtestcard2 differ diff --git a/projects/alghanmz/a4/randomtestcard2.gcda b/projects/alghanmz/a4/randomtestcard2.gcda new file mode 100644 index 000000000..3d16734d4 Binary files /dev/null and b/projects/alghanmz/a4/randomtestcard2.gcda differ diff --git a/projects/alghanmz/a4/randomtestcard2.gcno b/projects/alghanmz/a4/randomtestcard2.gcno new file mode 100644 index 000000000..c6b256665 Binary files /dev/null and b/projects/alghanmz/a4/randomtestcard2.gcno differ diff --git a/projects/alghanmz/a4/randomtestcard3 b/projects/alghanmz/a4/randomtestcard3 new file mode 100644 index 000000000..005eedec2 Binary files /dev/null and b/projects/alghanmz/a4/randomtestcard3 differ diff --git a/projects/alghanmz/a4/randomtestcard3.gcda b/projects/alghanmz/a4/randomtestcard3.gcda new file mode 100644 index 000000000..b8dbfa83b Binary files /dev/null and b/projects/alghanmz/a4/randomtestcard3.gcda differ diff --git a/projects/alghanmz/a4/randomtestcard3.gcno b/projects/alghanmz/a4/randomtestcard3.gcno new file mode 100644 index 000000000..ec10ff044 Binary files /dev/null and b/projects/alghanmz/a4/randomtestcard3.gcno differ diff --git a/projects/alghanmz/a4/randomtestresults.out b/projects/alghanmz/a4/randomtestresults.out new file mode 100644 index 000000000..a8e6d490f --- /dev/null +++ b/projects/alghanmz/a4/randomtestresults.out @@ -0,0 +1,541 @@ + +Begin Testing doBaron(): + +Number of tests run: 647059 +Number of times numBuys was not increased by 1: 647059 +Number of times Estate card was not discarded: 112780 +Number of times Baron card was not discarded: 647059 +Number of times Estate card was not gained: 0 +Number of times coins was not increased by 4: 88112 +End of doBaron() Tests + +Function 'updateCoins' +Lines executed:100.00% of 11 +Branches executed:100.00% of 8 +Taken at least once:100.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:0.00% of 20 +Branches executed:0.00% of 24 +Taken at least once:0.00% of 24 +Calls executed:0.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 32 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'doMinion' +Lines executed:0.00% of 17 +Branches executed:0.00% of 16 +Taken at least once:0.00% of 16 +Calls executed:0.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:0.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:0.00% of 2 +No branches +Calls executed:0.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:95.16% of 62 +Branches executed:100.00% of 46 +Taken at least once:91.30% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:23.65% of 575 +Branches executed:21.62% of 407 +Taken at least once:18.67% of 407 +Calls executed:14.29% of 91 +Creating 'dominion.c.gcov' + + +Begin Testing doMinion(): + +Number of tests run: 720681 +Number of times numActions was not increased by 1: 0 +Number of times Minion card was not discarded: 0 +Number of times current player didn't discard hand correctly: 359229 +Number of times a player with 5 or more cards didn't discard: 0 +Number of times a player with less than 5 cards did discard: 178973 +Number of times coins was not increased by 2: 0 +End of doMinion() Tests + +Function 'updateCoins' +Lines executed:100.00% of 11 +Branches executed:100.00% of 8 +Taken at least once:100.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:100.00% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:0.00% of 20 +Branches executed:0.00% of 24 +Taken at least once:0.00% of 24 +Calls executed:0.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 32 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:95.16% of 62 +Branches executed:100.00% of 46 +Taken at least once:91.30% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:29.57% of 575 +Branches executed:27.03% of 407 +Taken at least once:23.59% of 407 +Calls executed:21.98% of 91 +Creating 'dominion.c.gcov' + + +Begin Testing doTribute(): + +Number of tests run: 705810 +Number of times the number of effects was incorrect: 217677 +Number of times two cards weren't drawn correctly: 304213 +Number of times coins didn't increase by 2, when it should: 60289 +Number of times numActions didn't increase by 2, when it should: 469058 +Number of times Tribute card was not discarded: 705810 +End of doTribute() Tests + +Function 'updateCoins' +Lines executed:100.00% of 11 +Branches executed:100.00% of 8 +Taken at least once:100.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:100.00% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:0.00% of 20 +Branches executed:0.00% of 24 +Taken at least once:0.00% of 24 +Calls executed:0.00% of 3 + +Function 'doTribute' +Lines executed:100.00% of 32 +Branches executed:100.00% of 30 +Taken at least once:96.67% of 30 +Calls executed:100.00% of 2 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:95.16% of 62 +Branches executed:100.00% of 46 +Taken at least once:91.30% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:100.00% of 6 +Branches executed:100.00% of 4 +Taken at least once:100.00% of 4 +No calls + +File 'dominion.c' +Lines executed:35.30% of 575 +Branches executed:34.40% of 407 +Taken at least once:30.96% of 407 +Calls executed:24.18% of 91 +Creating 'dominion.c.gcov' + diff --git a/projects/alghanmz/a4/rngs.c b/projects/alghanmz/a4/rngs.c new file mode 100644 index 000000000..a85bbc961 --- /dev/null +++ b/projects/alghanmz/a4/rngs.c @@ -0,0 +1,183 @@ +/* ------------------------------------------------------------------------- + * This is an ANSI C library for multi-stream random number generation. + * The use of this library is recommended as a replacement for the ANSI C + * rand() and srand() functions, particularly in simulation applications + * where the statistical 'goodness' of the random number generator is + * important. The library supplies 256 streams of random numbers; use + * SelectStream(s) to switch between streams indexed s = 0,1,...,255. + * + * The streams must be initialized. The recommended way to do this is by + * using the function PlantSeeds(x) with the value of x used to initialize + * the default stream and all other streams initialized automatically with + * values dependent on the value of x. The following convention is used + * to initialize the default stream: + * if x > 0 then x is the state + * if x < 0 then the state is obtained from the system clock + * if x = 0 then the state is to be supplied interactively. + * + * The generator used in this library is a so-called 'Lehmer random number + * generator' which returns a pseudo-random number uniformly distributed + * 0.0 and 1.0. The period is (m - 1) where m = 2,147,483,647 and the + * smallest and largest possible values are (1 / m) and 1 - (1 / m) + * respectively. For more details see: + * + * "Random Number Generators: Good Ones Are Hard To Find" + * Steve Park and Keith Miller + * Communications of the ACM, October 1988 + * + * Name : rngs.c (Random Number Generation - Multiple Streams) + * Authors : Steve Park & Dave Geyer + * Language : ANSI C + * Latest Revision : 09-22-98 + * ------------------------------------------------------------------------- + */ + +#include +#include +#include "rngs.h" + +#define MODULUS 2147483647 /* DON'T CHANGE THIS VALUE */ +#define MULTIPLIER 48271 /* DON'T CHANGE THIS VALUE */ +#define CHECK 399268537 /* DON'T CHANGE THIS VALUE */ +#define STREAMS 256 /* # of streams, DON'T CHANGE THIS VALUE */ +#define A256 22925 /* jump multiplier, DON'T CHANGE THIS VALUE */ +#define DEFAULT 123456789 /* initial seed, use 0 < DEFAULT < MODULUS */ + +static long seed[STREAMS] = {DEFAULT}; /* current state of each stream */ +static int stream = 0; /* stream index, 0 is the default */ +static int initialized = 0; /* test for stream initialization */ + + +double Random(void) +/* ---------------------------------------------------------------- + * Random returns a pseudo-random real number uniformly distributed + * between 0.0 and 1.0. + * ---------------------------------------------------------------- + */ +{ + const long Q = MODULUS / MULTIPLIER; + const long R = MODULUS % MULTIPLIER; + long t; + + t = MULTIPLIER * (seed[stream] % Q) - R * (seed[stream] / Q); + if (t > 0) + seed[stream] = t; + else + seed[stream] = t + MODULUS; + return ((double) seed[stream] / MODULUS); +} + + +void PlantSeeds(long x) +/* --------------------------------------------------------------------- + * Use this function to set the state of all the random number generator + * streams by "planting" a sequence of states (seeds), one per stream, + * with all states dictated by the state of the default stream. + * The sequence of planted states is separated one from the next by + * 8,367,782 calls to Random(). + * --------------------------------------------------------------------- + */ +{ + const long Q = MODULUS / A256; + const long R = MODULUS % A256; + int j; + int s; + + initialized = 1; + s = stream; /* remember the current stream */ + SelectStream(0); /* change to stream 0 */ + PutSeed(x); /* set seed[0] */ + stream = s; /* reset the current stream */ + for (j = 1; j < STREAMS; j++) { + x = A256 * (seed[j - 1] % Q) - R * (seed[j - 1] / Q); + if (x > 0) + seed[j] = x; + else + seed[j] = x + MODULUS; + } +} + + +void PutSeed(long x) +/* --------------------------------------------------------------- + * Use this function to set the state of the current random number + * generator stream according to the following conventions: + * if x > 0 then x is the state (unless too large) + * if x < 0 then the state is obtained from the system clock + * if x = 0 then the state is to be supplied interactively + * --------------------------------------------------------------- + */ +{ + char ok = 0; + + if (x > 0) + x = x % MODULUS; /* correct if x is too large */ + if (x < 0) + x = ((unsigned long) time((time_t *) NULL)) % MODULUS; + if (x == 0) + while (!ok) { + printf("\nEnter a positive integer seed (9 digits or less) >> "); + scanf("%ld", &x); + ok = (0 < x) && (x < MODULUS); + if (!ok) + printf("\nInput out of range ... try again\n"); + } + seed[stream] = x; +} + + +void GetSeed(long *x) +/* --------------------------------------------------------------- + * Use this function to get the state of the current random number + * generator stream. + * --------------------------------------------------------------- + */ +{ + *x = seed[stream]; +} + + +void SelectStream(int index) +/* ------------------------------------------------------------------ + * Use this function to set the current random number generator + * stream -- that stream from which the next random number will come. + * ------------------------------------------------------------------ + */ +{ + stream = ((unsigned int) index) % STREAMS; + if ((initialized == 0) && (stream != 0)) /* protect against */ + PlantSeeds(DEFAULT); /* un-initialized streams */ +} + + +void TestRandom(void) +/* ------------------------------------------------------------------ + * Use this (optional) function to test for a correct implementation. + * ------------------------------------------------------------------ + */ +{ + long i; + long x; + double u; + char ok = 0; + + SelectStream(0); /* select the default stream */ + PutSeed(1); /* and set the state to 1 */ + for(i = 0; i < 10000; i++) { + u = Random(); + if (ok) + printf(" %f \n\n", u); + + } + GetSeed(&x); /* get the new state value */ + ok = (x == CHECK); /* and check for correctness */ + + SelectStream(1); /* select stream 1 */ + PlantSeeds(1); /* set the state of all streams */ + GetSeed(&x); /* get the state of stream 1 */ + ok = ok && (x == A256); /* x should be the jump multiplier */ + if (ok) + printf("\n The implementation of rngs.c is correct.\n\n"); + else + printf("\n\a ERROR -- the implementation of rngs.c is not correct.\n\n"); +} diff --git a/projects/alghanmz/a4/rngs.gcda b/projects/alghanmz/a4/rngs.gcda new file mode 100644 index 000000000..d4c1edc67 Binary files /dev/null and b/projects/alghanmz/a4/rngs.gcda differ diff --git a/projects/alghanmz/a4/rngs.gcno b/projects/alghanmz/a4/rngs.gcno new file mode 100644 index 000000000..72dec7986 Binary files /dev/null and b/projects/alghanmz/a4/rngs.gcno differ diff --git a/projects/alghanmz/a4/rngs.h b/projects/alghanmz/a4/rngs.h new file mode 100644 index 000000000..c9f3f451a --- /dev/null +++ b/projects/alghanmz/a4/rngs.h @@ -0,0 +1,19 @@ +/* ----------------------------------------------------------------------- + * Name : rngs.h (header file for the library file rngs.c) + * Author : Steve Park & Dave Geyer + * Language : ANSI C + * Latest Revision : 09-22-98 + * ----------------------------------------------------------------------- + */ + +#if !defined( _RNGS_ ) +#define _RNGS_ + +double Random(void); +void PlantSeeds(long x); +void GetSeed(long *x); +void PutSeed(long x); +void SelectStream(int index); +void TestRandom(void); + +#endif diff --git a/projects/alghanmz/a4/rngs.o b/projects/alghanmz/a4/rngs.o new file mode 100644 index 000000000..6a9e8488b Binary files /dev/null and b/projects/alghanmz/a4/rngs.o differ diff --git a/projects/alghanmz/a4/rt.c b/projects/alghanmz/a4/rt.c new file mode 100644 index 000000000..5805bb9b4 --- /dev/null +++ b/projects/alghanmz/a4/rt.c @@ -0,0 +1,27 @@ +#include "rngs.h" +#include +#include + +int main(int argc, char** argv) { + if (argc < 3) { + printf ("Not enough inputs: seed target\n"); + } + + SelectStream(1); + PutSeed((long)atoi(argv[1])); + + int done = 0; + int c = 1000000000; + + while (!done) { + c = floor(Random() * 1000000000); + // if (c % 100000 == 0) { + // printf ("c = %d\n", c); + // } + if (c == atoi(argv[2])) { + printf ("Found the bug!\n"); + done = 1; + } + } +} + diff --git a/projects/alghanmz/a4/testdrawcard.c b/projects/alghanmz/a4/testdrawcard.c new file mode 100644 index 000000000..da5379646 --- /dev/null +++ b/projects/alghanmz/a4/testdrawcard.c @@ -0,0 +1,74 @@ +#include "dominion.h" +#include "dominion_helpers.h" +#include +#include +#include +#include "rngs.h" + +#define DEBUG 0 +#define NOISY_TEST 1 + +int checkDrawCard(int p, struct gameState *post) { + struct gameState pre; + memcpy (&pre, post, sizeof(struct gameState)); + + int r; + // printf ("drawCard PRE: p %d HC %d DeC %d DiC %d\n", + // p, pre.handCount[p], pre.deckCount[p], pre.discardCount[p]); + + r = drawCard (p, post); + + //printf ("drawCard POST: p %d HC %d DeC %d DiC %d\n", + // p, post->handCount[p], post->deckCount[p], post->discardCount[p]); + + if (pre.deckCount[p] > 0) { + pre.handCount[p]++; + pre.hand[p][pre.handCount[p]-1] = pre.deck[p][pre.deckCount[p]-1]; + pre.deckCount[p]--; + } else if (pre.discardCount[p] > 0) { + memcpy(pre.deck[p], post->deck[p], sizeof(int) * pre.discardCount[p]); + memcpy(pre.discard[p], post->discard[p], sizeof(int)*pre.discardCount[p]); + pre.hand[p][post->handCount[p]-1] = post->hand[p][post->handCount[p]-1]; + pre.handCount[p]++; + pre.deckCount[p] = pre.discardCount[p]-1; + pre.discardCount[p] = 0; + } + + assert (r == 0); + + assert(memcmp(&pre, post, sizeof(struct gameState)) == 0); +} + +int main () { + + int i, n, r, p, deckCount, discardCount, handCount; + + int k[10] = {adventurer, council_room, feast, gardens, mine, + remodel, smithy, village, baron, great_hall + }; + + struct gameState G; + + printf ("Testing drawCard.\n"); + + printf ("RANDOM TESTS.\n"); + + SelectStream(2); + PutSeed(3); + + for (n = 0; n < 2000; n++) { + for (i = 0; i < sizeof(struct gameState); i++) { + ((char*)&G)[i] = floor(Random() * 256); + } + p = floor(Random() * 2); + G.deckCount[p] = floor(Random() * MAX_DECK); + G.discardCount[p] = floor(Random() * MAX_DECK); + G.handCount[p] = floor(Random() * MAX_HAND); + checkDrawCard(p, &G); + } + + printf ("ALL TESTS OK\n"); + + exit(0); + +} diff --git a/projects/alghanmz/a4/unittest1 b/projects/alghanmz/a4/unittest1 new file mode 100644 index 000000000..9c15748a2 Binary files /dev/null and b/projects/alghanmz/a4/unittest1 differ diff --git a/projects/alghanmz/alghanmz-assignment-3/Makefile b/projects/alghanmz/alghanmz-assignment-3/Makefile new file mode 100644 index 000000000..377d44b80 --- /dev/null +++ b/projects/alghanmz/alghanmz-assignment-3/Makefile @@ -0,0 +1,46 @@ +CFLAGS= -Wall -fpic -coverage -lm -std=c99 + +unittestresults: unittest1 unittest2 unittest3 unittest4 unittest5 runtests + +rngs.o: rngs.h rngs.c + gcc -c rngs.c $(CFLAGS) + +dominion.o: dominion.h dominion.c rngs.o + gcc -c dominion.c $(CFLAGS) + +unittest1: dominion.o rngs.o unittest1.c + gcc -o unittest1 unittest1.c dominion.o rngs.o $(CFLAGS) + #./unittest1 + +unittest2: dominion.o rngs.o unittest2.c + gcc -o unittest2 unittest2.c dominion.o rngs.o $(CFLAGS) + #./unittest2 + +unittest3: dominion.o rngs.o unittest3.c + gcc -o unittest3 unittest3.c dominion.o rngs.o $(CFLAGS) + #./unittest3 + +unittest4: dominion.o rngs.o unittest4.c + gcc -o unittest4 unittest4.c dominion.o rngs.o $(CFLAGS) + #./unittest4 + +unittest5: dominion.o rngs.o unittest5.c + gcc -o unittest5 unittest5.c dominion.o rngs.o $(CFLAGS) + #./unittest5 + +#ifeq (0,1) +runtests: unittest1 unittest2 unittest3 unittest4 unittest5 + ./unittest1 > unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + ./unittest2 >> unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + ./unittest3 >> unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + ./unittest4 >> unittestresults.out + gcov -b -f dominion.c >> unittestresults.out + ./unittest5 >> unittestresults.out + gcov -b -f dominion.c >> unittestresults.out +#endif + +clean: + rm -f *.o unittest1 unittest2 unittest3 unittest4 unittest5 *.gcov *.gcda *.gcno *.out diff --git a/projects/alghanmz/alghanmz-assignment-3/dominion.c b/projects/alghanmz/alghanmz-assignment-3/dominion.c new file mode 100644 index 000000000..0c865f97e --- /dev/null +++ b/projects/alghanmz/alghanmz-assignment-3/dominion.c @@ -0,0 +1,1420 @@ +#include "dominion.h" +#include "dominion_helpers.h" +#include "rngs.h" +#include +#include +#include + +int compare(const void* a, const void* b) { + if (*(int*)a > *(int*)b) + return 1; + if (*(int*)a < *(int*)b) + return -1; + return 0; +} + +struct gameState* newGame() { + struct gameState* g = malloc(sizeof(struct gameState)); + return g; +} + +int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + int k8, int k9, int k10) { + int* k = malloc(10 * sizeof(int)); + k[0] = k1; + k[1] = k2; + k[2] = k3; + k[3] = k4; + k[4] = k5; + k[5] = k6; + k[6] = k7; + k[7] = k8; + k[8] = k9; + k[9] = k10; + return k; +} + +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 shuffle(int player, struct gameState *state) { + + + int newDeck[MAX_DECK]; + int newDeckPos = 0; + int card; + int i; + + if (state->deckCount[player] < 1) + return -1; + qsort ((void*)(state->deck[player]), state->deckCount[player], sizeof(int), compare); + /* SORT CARDS IN DECK TO ENSURE DETERMINISM! */ + + while (state->deckCount[player] > 0) { + card = floor(Random() * state->deckCount[player]); + newDeck[newDeckPos] = state->deck[player][card]; + newDeckPos++; + for (i = card; i < state->deckCount[player]-1; i++) { + state->deck[player][i] = state->deck[player][i+1]; + } + state->deckCount[player]--; + } + for (i = 0; i < newDeckPos; i++) { + state->deck[player][i] = newDeck[i]; + state->deckCount[player]++; + } + + return 0; +} + +int playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state) +{ + int card; + int coin_bonus = 0; //tracks coins gain from actions + + //check if it is the right phase + if (state->phase != 0) + { + return -1; + } + + //check if player has enough actions + if ( state->numActions < 1 ) + { + return -1; + } + + //get card played + card = handCard(handPos, state); + + //check if selected card is an action + if ( card < adventurer || card > treasure_map ) + { + return -1; + } + + //play card + if ( cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0 ) + { + return -1; + } + + //reduce number of actions + state->numActions--; + + //update coins (Treasure cards may be added with card draws) + updateCoins(state->whoseTurn, state, coin_bonus); + + return 0; +} + +int buyCard(int supplyPos, struct gameState *state) { + int who; + if (DEBUG) { + printf("Entering buyCard...\n"); + } + + // I don't know what to do about the phase thing. + + who = state->whoseTurn; + + if (state->numBuys < 1) { + if (DEBUG) + printf("You do not have any buys left\n"); + return -1; + } else if (supplyCount(supplyPos, state) <1) { + if (DEBUG) + printf("There are not any of that type of card left\n"); + return -1; + } else if (state->coins < getCost(supplyPos)) { + if (DEBUG) + printf("You do not have enough money to buy that. You have %d coins.\n", state->coins); + return -1; + } else { + state->phase=1; + //state->supplyCount[supplyPos]--; + gainCard(supplyPos, state, 0, who); //card goes in discard, this might be wrong.. (2 means goes into hand, 0 goes into discard) + + state->coins = (state->coins) - (getCost(supplyPos)); + state->numBuys--; + if (DEBUG) + printf("You bought card number %d for %d coins. You now have %d buys and %d coins.\n", supplyPos, getCost(supplyPos), state->numBuys, state->coins); + } + + //state->discard[who][state->discardCount[who]] = supplyPos; + //state->discardCount[who]++; + + return 0; +} + +int numHandCards(struct gameState *state) { + return state->handCount[ whoseTurn(state) ]; +} + +int handCard(int handPos, struct gameState *state) { + int currentPlayer = whoseTurn(state); + return state->hand[currentPlayer][handPos]; +} + +int supplyCount(int card, struct gameState *state) { + return state->supplyCount[card]; +} + +int fullDeckCount(int player, int card, struct gameState *state) { + int i; + int count = 0; + + for (i = 0; i < state->deckCount[player]; i++) + { + if (state->deck[player][i] == card) count++; + } + + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == card) count++; + } + + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->discard[player][i] == card) count++; + } + + return count; +} + +int whoseTurn(struct gameState *state) { + return state->whoseTurn; +} + +int endTurn(struct gameState *state) { + int k; + int i; + int currentPlayer = whoseTurn(state); + + //Discard hand + for (i = 0; i < state->handCount[currentPlayer]; i++) { + state->discard[currentPlayer][state->discardCount[currentPlayer]++] = state->hand[currentPlayer][i];//Discard + state->hand[currentPlayer][i] = -1;//Set card to -1 + } + state->handCount[currentPlayer] = 0;//Reset hand count + + //Code for determining the player + if (currentPlayer < (state->numPlayers - 1)) { + state->whoseTurn = currentPlayer + 1;//Still safe to increment + } + else { + state->whoseTurn = 0;//Max player has been reached, loop back around to player 1 + } + + state->outpostPlayed = 0; + state->phase = 0; + state->numActions = 1; + state->coins = 0; + state->numBuys = 1; + state->playedCardCount = 0; + state->handCount[state->whoseTurn] = 0; + + //int k; move to top + //Next player draws hand + for (k = 0; k < 5; k++) { + drawCard(state->whoseTurn, state);//Draw a card + } + + //Update money + updateCoins(state->whoseTurn, state, 0); + + return 0; +} + +int isGameOver(struct gameState *state) { + int i; + int j; + + //if stack of Province cards is empty, the game ends + if (state->supplyCount[province] == 0) + { + return 1; + } + + //if three supply pile are at 0, the game ends + j = 0; + for (i = 0; i < 25; i++) + { + if (state->supplyCount[i] == 0) + { + j++; + } + } + if ( j >= 3) + { + return 1; + } + + return 0; +} + +int scoreFor (int player, struct gameState *state) { + + int i; + int score = 0; + //score from hand + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == curse) { + score = score - 1; + }; + if (state->hand[player][i] == estate) { + score = score + 1; + }; + if (state->hand[player][i] == duchy) { + score = score + 3; + }; + if (state->hand[player][i] == province) { + score = score + 6; + }; + if (state->hand[player][i] == great_hall) { + score = score + 1; + }; + if (state->hand[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + //score from discard + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->discard[player][i] == curse) { + score = score - 1; + }; + if (state->discard[player][i] == estate) { + score = score + 1; + }; + if (state->discard[player][i] == duchy) { + score = score + 3; + }; + if (state->discard[player][i] == province) { + score = score + 6; + }; + if (state->discard[player][i] == great_hall) { + score = score + 1; + }; + if (state->discard[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + //score from deck + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->deck[player][i] == curse) { + score = score - 1; + }; + if (state->deck[player][i] == estate) { + score = score + 1; + }; + if (state->deck[player][i] == duchy) { + score = score + 3; + }; + if (state->deck[player][i] == province) { + score = score + 6; + }; + if (state->deck[player][i] == great_hall) { + score = score + 1; + }; + if (state->deck[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + return score; +} + +int getWinners(int players[MAX_PLAYERS], struct gameState *state) { + int i; + int j; + int highScore; + int currentPlayer; + + //get score for each player + for (i = 0; i < MAX_PLAYERS; i++) + { + //set unused player scores to -9999 + if (i >= state->numPlayers) + { + players[i] = -9999; + } + else + { + players[i] = scoreFor (i, state); + } + } + + //find highest score + j = 0; + for (i = 0; i < MAX_PLAYERS; i++) + { + if (players[i] > players[j]) + { + j = i; + } + } + highScore = players[j]; + + //add 1 to players who had less turns + currentPlayer = whoseTurn(state); + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] == highScore && i > currentPlayer ) + { + players[i]++; + } + } + + //find new highest score + j = 0; + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] > players[j] ) + { + j = i; + } + } + highScore = players[j]; + + //set winners in array to 1 and rest to 0 + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] == highScore ) + { + players[i] = 1; + } + else + { + players[i] = 0; + } + } + + return 0; +} + +int drawCard(int player, struct gameState *state) +{ int count; + int deckCounter; + if (state->deckCount[player] <= 0) { //Deck is empty + + //Step 1 Shuffle the discard pile back into a deck + int i; + //Move discard to deck + for (i = 0; i < state->discardCount[player]; i++) { + state->deck[player][i] = state->discard[player][i]; + state->discard[player][i] = -1; + } + + state->deckCount[player] = state->discardCount[player]; + state->discardCount[player] = 0;//Reset discard + + //Shufffle the deck + shuffle(player, state);//Shuffle the deck up and make it so that we can draw + + if (DEBUG) { //Debug statements + printf("Deck count now: %d\n", state->deckCount[player]); + } + + state->discardCount[player] = 0; + + //Step 2 Draw Card + count = state->handCount[player];//Get current player's hand count + + if (DEBUG) { //Debug statements + printf("Current hand count: %d\n", count); + } + + deckCounter = state->deckCount[player];//Create a holder for the deck count + + if (deckCounter == 0) + return -1; + + state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to hand + state->deckCount[player]--; + state->handCount[player]++;//Increment hand count + } + + else { + int count = state->handCount[player];//Get current hand count for player + int deckCounter; + if (DEBUG) { //Debug statements + printf("Current hand count: %d\n", count); + } + + deckCounter = state->deckCount[player];//Create holder for the deck count + state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to the hand + state->deckCount[player]--; + state->handCount[player]++;//Increment hand count + } + + return 0; +} + +int getCost(int cardNumber) +{ + switch( cardNumber ) + { + case curse: + return 0; + case estate: + return 2; + case duchy: + return 5; + case province: + return 8; + case copper: + return 0; + case silver: + return 3; + case gold: + return 6; + case adventurer: + return 6; + case council_room: + return 5; + case feast: + return 4; + case gardens: + return 4; + case mine: + return 5; + case remodel: + return 4; + case smithy: + return 4; + case village: + return 3; + case baron: + return 4; + case great_hall: + return 3; + case minion: + return 5; + case steward: + return 3; + case tribute: + return 5; + case ambassador: + return 3; + case cutpurse: + return 4; + case embargo: + return 2; + case outpost: + return 5; + case salvager: + return 4; + case sea_hag: + return 4; + case treasure_map: + return 4; + } + + return -1; +} + +int doMine(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) +{ + int i; + int j; + + j = state->hand[currentPlayer][choice1]; //store card we will trash + + if (/*state->hand[currentPlayer][choice1] < copper ||*/ state->hand[currentPlayer][choice1] > gold) + { + return -1; + } + + if (choice2 > treasure_map || choice2 < curse) + { + return -1; + } + + if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) ) + { + return -1; + } + + //gainCard(choice2, state, 2, currentPlayer); + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + //discard trashed card + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == j) + { + discardCard(i, currentPlayer, state, 0); + break; + } + } + + return 0; +} + +void getEstateCard(struct gameState *state, int currentPlayer) +{ + if (supplyCount(estate, state) > 0) { + gainCard(estate, state, 0, currentPlayer);//Gain an estate + + state->supplyCount[estate]--;//Decrement Estates + if (supplyCount(estate, state) == 0) { + isGameOver(state); + } + } +} + +void doBaron(int choice1, struct gameState *state, int currentPlayer) +{ + state->numBuys++;//Increase buys by 1! + state->numBuys++;//Increase buys by 1! + if (choice1 > 0) { //Boolean true or going to discard an estate + int p = 1; //0;//Iterator for hand! + int card_not_discarded = 1;//Flag for discard set! + while(card_not_discarded) { + if (state->hand[currentPlayer][p] == estate) { //Found an estate card! + state->coins += 4;//Add 4 coins to the amount of coins + state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; + state->discardCount[currentPlayer]++; + for (; p < state->handCount[currentPlayer]; p++) { + state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1]; + } + state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; + state->handCount[currentPlayer]--; + card_not_discarded = 0;//Exit the loop + } + else if (p > state->handCount[currentPlayer]) { + if(DEBUG) { + printf("No estate cards in your hand, invalid choice\n"); + printf("Must gain an estate if there are any\n"); + } + getEstateCard(state, currentPlayer); + card_not_discarded = 0;//Exit the loop + } + + else { + p++;//Next card + } + } + } + + else { + getEstateCard(state, currentPlayer); + } +} + +void doMinion(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) +{ + int i; + int j; + + //+1 action + state->numActions++; + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + if (choice1) + { + state->coins = state->coins + 2; + } + else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 + { + //discard hand + while(numHandCards(state) > 1 /*0*/) + { + discardCard(handPos, currentPlayer, state, 0); + } + + //draw 4 + for (i = 0; i < 4; i++) + { + drawCard(currentPlayer, state); + } + + //other players discard hand and redraw if hand size > 4 + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + //if ( state->handCount[i] > 4 ) + { + //discard hand + while( state->handCount[i] > 0 ) + { + discardCard(handPos, i, state, 0); + } + + //draw 4 + for (j = 0; j < 4; j++) + { + drawCard(i, state); + } + } + } + } + } +} + +void printDeck(struct gameState *state, int p) { + printf("Deck:"); + for (int i=0; i < state->deckCount[p]; i++) + printf(" %d", state->deck[p][i]); + printf("\n"); +} + +void printHand(struct gameState *state, int p) { + printf("Hand:"); + for (int i=0; i < state->handCount[p]; i++) + printf(" %d", state->hand[p][i]); + printf("\n"); +} + +void doTribute(struct gameState *state, int currentPlayer, int nextPlayer, int tributeRevealedCards[2]) +{ + int i; + + if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) { + if (state->deckCount[nextPlayer] > 0) { + tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + state->deckCount[nextPlayer]--; + } + else if (state->discardCount[nextPlayer] > 0) { + tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1]; + state->discardCount[nextPlayer]--; + } + else { + //No Card to Reveal + if (DEBUG) { + printf("No cards to reveal\n"); + } + } + } + + else { + if (state->deckCount[nextPlayer] == 0) { + for (i = 0; i < state->discardCount[nextPlayer]; i++) { + state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck + state->deckCount[nextPlayer]++; + state->discard[nextPlayer][i] = -1; + state->discardCount[nextPlayer]--; + } + + shuffle(nextPlayer,state);//Shuffle the deck + } + tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + //state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + //state->deckCount[nextPlayer]--; + //tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-2]; + //state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + //state->deckCount[nextPlayer]--; + } + + if (tributeRevealedCards[0] == tributeRevealedCards[1]) { //If we have a duplicate card, just drop one + state->playedCards[state->playedCardCount] = tributeRevealedCards[1]; + state->playedCardCount++; + tributeRevealedCards[1] = -1; + } + + for (i = 0; i < 2; i ++) { + if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) { //Treasure cards + state->numActions = state->numActions + 2; + } + + else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall) { //Victory Card Found + drawCard(currentPlayer, state); + //drawCard(currentPlayer, state); + } + else { //Action Card + state->coins += 2; + } + } +} + +int doAmbassador(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer) +{ + int i; + int j; + + j = 0; //used to check if player has enough cards to discard + + if (choice2 > 3 || choice2 < 0) + { + return -1; + } + +/* + if (choice1 == handPos) + { + return -1; + } + */ + + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (i != handPos && state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1] /*&& i != choice1*/) + { + j++; + } + } + if (j < choice2) + { + return -1; + } + + if (DEBUG) + printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]); + + //increase supply count for choosen card by amount being discarded + state->supplyCount[state->hand[currentPlayer][choice1]] += choice2; + + //each other player gains a copy of revealed card + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + gainCard(state->hand[currentPlayer][choice1], state, 0, i); + } + } + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + + //trash copies of cards returned to supply + for (j = 0; j < choice2; j++) + { + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1]) + { + discardCard(i, currentPlayer, state, 1); + break; + } + } + } + + return 0; +} + +int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) +{ + int i; + int j; + int k; + int x; + int index; + int currentPlayer = whoseTurn(state); + int nextPlayer = currentPlayer + 1; + + int tributeRevealedCards[2] = {-1, -1}; + int temphand[MAX_HAND];// moved above the if statement + int drawntreasure=0; + int cardDrawn; + int z = 0;// this is the counter for the temp hand + if (nextPlayer > (state->numPlayers - 1)) { + nextPlayer = 0; + } + + + //uses switch to select card and perform actions + switch( card ) + { + case adventurer: + while(drawntreasure<2) { + if (state->deckCount[currentPlayer] <1) { //if the deck is empty we need to shuffle discard and add to deck + shuffle(currentPlayer, state); + } + drawCard(currentPlayer, state); + cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card. + if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold) + drawntreasure++; + else { + temphand[z]=cardDrawn; + state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one). + z++; + } + } + while(z-1>=0) { + state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn + z=z-1; + } + return 0; + + case council_room: + //+4 Cards + for (i = 0; i < 4; i++) + { + drawCard(currentPlayer, state); + } + + //+1 Buy + state->numBuys++; + + //Each other player draws a card + for (i = 0; i < state->numPlayers; i++) + { + if ( i != currentPlayer ) + { + drawCard(i, state); + } + } + + //put played card in played card pile + discardCard(handPos, currentPlayer, state, 0); + + return 0; + + case feast: + //gain card with cost up to 5 + //Backup hand + for (i = 0; i <= state->handCount[currentPlayer]; i++) { + temphand[i] = state->hand[currentPlayer][i];//Backup card + state->hand[currentPlayer][i] = -1;//Set to nothing + } + //Backup hand + + //Update Coins for Buy + updateCoins(currentPlayer, state, 5); + x = 1;//Condition to loop on + while( x == 1) {//Buy one card + if (supplyCount(choice1, state) <= 0) { + if (DEBUG) + printf("None of that card left, sorry!\n"); + + if (DEBUG) { + printf("Cards Left: %d\n", supplyCount(choice1, state)); + } + } + else if (state->coins < getCost(choice1)) { + printf("That card is too expensive!\n"); + + if (DEBUG) { + printf("Coins: %d < %d\n", state->coins, getCost(choice1)); + } + } + else { + + if (DEBUG) { + printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + } + + gainCard(choice1, state, 0, currentPlayer);//Gain the card + x = 0;//No more buying cards + + if (DEBUG) { + printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + } + + } + } + + //Reset Hand + for (i = 0; i <= state->handCount[currentPlayer]; i++) { + state->hand[currentPlayer][i] = temphand[i]; + temphand[i] = -1; + } + //Reset Hand + + return 0; + + case gardens: + return -1; + + case mine: + return doMine(choice1, choice2, state, handPos, currentPlayer); + + case remodel: + j = state->hand[currentPlayer][choice1]; //store card we will trash + + if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) ) + { + return -1; + } + + gainCard(choice2, state, 0, currentPlayer); + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + //discard trashed card + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == j) + { + discardCard(i, currentPlayer, state, 0); + break; + } + } + + + return 0; + + case smithy: + //+3 Cards + for (i = 0; i < 3; i++) + { + drawCard(currentPlayer, state); + } + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case village: + //+1 Card + drawCard(currentPlayer, state); + + //+2 Actions + state->numActions = state->numActions + 2; + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case baron: + doBaron(choice1, state, currentPlayer); + return 0; + + case great_hall: + //+1 Card + drawCard(currentPlayer, state); + + //+1 Actions + state->numActions++; + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case minion: + doMinion(choice1, choice2, state, handPos, currentPlayer); + return 0; + + case steward: + if (choice1 == 1) + { + //+2 cards + drawCard(currentPlayer, state); + drawCard(currentPlayer, state); + } + else if (choice1 == 2) + { + //+2 coins + state->coins = state->coins + 2; + } + else + { + //trash 2 cards in hand + discardCard(choice2, currentPlayer, state, 1); + discardCard(choice3, currentPlayer, state, 1); + } + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case tribute: + doTribute(state, currentPlayer, nextPlayer, tributeRevealedCards); + return 0; + + case ambassador: + return doAmbassador(choice1, choice2, state, handPos, currentPlayer); + + case cutpurse: + + updateCoins(currentPlayer, state, 2); + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + for (j = 0; j < state->handCount[i]; j++) + { + if (state->hand[i][j] == copper) + { + discardCard(j, i, state, 0); + break; + } + if (j == state->handCount[i]) + { + for (k = 0; k < state->handCount[i]; k++) + { + if (DEBUG) + printf("Player %d reveals card number %d\n", i, state->hand[i][k]); + } + break; + } + } + + } + + } + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + + return 0; + + + case embargo: + //+2 Coins + state->coins = state->coins + 2; + + //see if selected pile is in play + if ( state->supplyCount[choice1] == -1 ) + { + return -1; + } + + //add embargo token to selected supply pile + state->embargoTokens[choice1]++; + + //trash card + discardCard(handPos, currentPlayer, state, 1); + return 0; + + case outpost: + //set outpost flag + state->outpostPlayed++; + + //discard card + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case salvager: + //+1 buy + state->numBuys++; + + if (choice1) + { + //gain coins equal to trashed card + state->coins = state->coins + getCost( handCard(choice1, state) ); + //trash card + discardCard(choice1, currentPlayer, state, 1); + } + + //discard card + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case sea_hag: + for (i = 0; i < state->numPlayers; i++) { + if (i != currentPlayer) { + state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; + state->deckCount[i]--; + state->discardCount[i]++; + state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse + } + } + return 0; + + case treasure_map: + //search hand for another treasure_map + index = -1; + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == treasure_map && i != handPos) + { + index = i; + break; + } + } + if (index > -1) + { + //trash both treasure cards + discardCard(handPos, currentPlayer, state, 1); + discardCard(index, currentPlayer, state, 1); + + //gain 4 Gold cards + for (i = 0; i < 4; i++) + { + gainCard(gold, state, 1, currentPlayer); + } + + //return success + return 1; + } + + //no second treasure_map found in hand + return -1; + } + + return -1; +} + +int discardCard(int handPos, int currentPlayer, struct gameState *state, int trashFlag) +{ + + //if card is not trashed, added to Played pile + if (trashFlag < 1) + { + //add card to played pile + state->playedCards[state->playedCardCount] = state->hand[currentPlayer][handPos]; + state->playedCardCount++; + } + + //set played card to -1 + state->hand[currentPlayer][handPos] = -1; + + //remove card from player's hand + if ( handPos == (state->handCount[currentPlayer] - 1) ) //last card in hand array is played + { + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + else if ( state->handCount[currentPlayer] == 1 ) //only one card in hand + { + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + else + { + //replace discarded card with last card in hand + state->hand[currentPlayer][handPos] = state->hand[currentPlayer][ (state->handCount[currentPlayer] - 1)]; + //set last card to -1 + state->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1; + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + + return 0; +} + +int gainCard(int supplyPos, struct gameState *state, int toFlag, int player) +{ + //Note: supplyPos is enum of choosen card + + //check if supply pile is empty (0) or card is not used in game (-1) + if ( supplyCount(supplyPos, state) < 1 ) + { + return -1; + } + + //added card for [whoseTurn] current player: + // toFlag = 0 : add to discard + // toFlag = 1 : add to deck + // toFlag = 2 : add to hand + + if (toFlag == 1) + { + state->deck[ player ][ state->deckCount[player] ] = supplyPos; + state->deckCount[player]++; + } + else if (toFlag == 2) + { + state->hand[ player ][ state->handCount[player] ] = supplyPos; + state->handCount[player]++; + } + else + { + state->discard[player][ state->discardCount[player] ] = supplyPos; + state->discardCount[player]++; + } + + //decrease number in supply pile + state->supplyCount[supplyPos]--; + + return 0; +} + +int updateCoins(int player, struct gameState *state, int bonus) +{ + int i; + + //reset coin count + state->coins = 0; + + //add coins for each Treasure card in player's hand + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == copper) + { + state->coins += 1; + } + else if (state->hand[player][i] == silver) + { + state->coins += 2; + } + else if (state->hand[player][i] == gold) + { + state->coins += 3; + } + } + + //add bonus + state->coins += bonus; + + return 0; +} + + +//end of dominion.c diff --git a/projects/alghanmz/alghanmz-assignment-3/dominion.h b/projects/alghanmz/alghanmz-assignment-3/dominion.h new file mode 100644 index 000000000..f9d9039b8 --- /dev/null +++ b/projects/alghanmz/alghanmz-assignment-3/dominion.h @@ -0,0 +1,131 @@ +#ifndef _DOMINION_H +#define _DOMINION_H + +// Code from various sources, baseline from Kristen Bartosz + +#define MAX_HAND 500 +#define MAX_DECK 500 + +#define MAX_PLAYERS 4 + +#define DEBUG 0 + +/* http://dominion.diehrstraits.com has card texts */ +/* http://dominion.isotropic.org has other stuff */ + +/* hand# means index of a card in current active player's hand */ + +enum CARD +{ curse = 0, + estate, + duchy, + province, + + copper, + silver, + gold, + + adventurer, + /* If no/only 1 treasure found, stop when full deck seen */ + council_room, + feast, /* choice1 is supply # of card gained) */ + gardens, + mine, /* choice1 is hand# of money to trash, choice2 is supply# of + money to put in hand */ + remodel, /* choice1 is hand# of card to remodel, choice2 is supply# */ + smithy, + village, + + baron, /* choice1: boolean for discard of estate */ + /* Discard is always of first (lowest index) estate */ + great_hall, + minion, /* choice1: 1 = +2 coin, 2 = redraw */ + steward, /* choice1: 1 = +2 card, 2 = +2 coin, 3 = trash 2 (choice2,3) */ + tribute, + + ambassador, /* choice1 = hand#, choice2 = number to return to supply */ + cutpurse, + embargo, /* choice1 = supply# */ + outpost, + salvager, /* choice1 = hand# to trash */ + sea_hag, + treasure_map +}; + +struct gameState { + int numPlayers; //number of players + int supplyCount[treasure_map+1]; //this is the amount of a specific type of card given a specific number. + int embargoTokens[treasure_map+1]; + int outpostPlayed; + int outpostTurn; + int whoseTurn; + int phase; + int numActions; /* Starts at 1 each turn */ + int coins; /* Use as you see fit! */ + int numBuys; /* Starts at 1 each turn */ + int hand[MAX_PLAYERS][MAX_HAND]; + int handCount[MAX_PLAYERS]; + int deck[MAX_PLAYERS][MAX_DECK]; + int deckCount[MAX_PLAYERS]; + int discard[MAX_PLAYERS][MAX_DECK]; + int discardCount[MAX_PLAYERS]; + int playedCards[MAX_DECK]; + int playedCardCount; +}; + +/* All functions return -1 on failure, and DO NOT CHANGE GAME STATE; + unless specified for other return, return 0 on success */ + +struct gameState* newGame(); + +int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + int k8, int k9, int k10); + +int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, + struct gameState *state); +/* Responsible for initializing all supplies, and shuffling deck and + drawing starting hands for all players. Check that 10 cards selected + are in fact (different) kingdom cards, and that numPlayers is valid. + +Cards not in game should initialize supply position to -1 */ + +int shuffle(int player, struct gameState *state); +/* Assumes all cards are now in deck array (or hand/played): discard is + empty */ + +int playCard(int handPos, int choice1, int choice2, int choice3, + struct gameState *state); +/* Play card with index handPos from current player's hand */ + +int buyCard(int supplyPos, struct gameState *state); +/* Buy card with supply index supplyPos */ + +int numHandCards(struct gameState *state); +/* How many cards current player has in hand */ + +int handCard(int handNum, struct gameState *state); +/* enum value of indexed card in player's hand */ + +int supplyCount(int card, struct gameState *state); +/* How many of given card are left in supply */ + +int fullDeckCount(int player, int card, struct gameState *state); +/* Here deck = hand + discard + deck */ + +int whoseTurn(struct gameState *state); + +int endTurn(struct gameState *state); +/* Must do phase C and advance to next player; do not advance whose turn + if game is over */ + +int isGameOver(struct gameState *state); + +int scoreFor(int player, struct gameState *state); +/* Negative here does not mean invalid; scores may be negative, + -9999 means invalid input */ + +int getWinners(int players[MAX_PLAYERS], struct gameState *state); +/* Set array position of each player who won (remember ties!) to + 1, others to 0 */ + +#endif diff --git a/projects/alghanmz/alghanmz-assignment-3/hw33.c b/projects/alghanmz/alghanmz-assignment-3/hw33.c new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/projects/alghanmz/alghanmz-assignment-3/hw33.c @@ -0,0 +1 @@ + diff --git a/projects/alghanmz/alghanmz-assignment-3/unittest1.c b/projects/alghanmz/alghanmz-assignment-3/unittest1.c new file mode 100644 index 000000000..de2476384 --- /dev/null +++ b/projects/alghanmz/alghanmz-assignment-3/unittest1.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include "dominion.h" + +void doBaron(int choice1, struct gameState *state, int currentPlayer); + +void assert(int a, char *s) { + if (!a) { + printf("Assert failed: %s\n", s); + } +} + +void assertEqual(int a, int b, char *s) { + if (a != b) { + printf("Assert failed: %s\n", s); + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int cardCount(int *container, int size, int card) { + int count = 0; + + for (int i=0; i < size; i++) { + if (container[i] == card) { + count++; + } + } + return count; +} + +int main() { + int seed = 47; + int p; + int choice1; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, baron, great_hall }; + + // declare the game state + struct gameState G, G2; + + printf("\nBegin Testing doBaron():\n\n"); + initializeGame(2, k, seed, &G); + + printf("Test 1\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = baron; + choice1 = 0; // choose to gain an estate card + doBaron(choice1, &G2, 0); + assertEqual(G2.numBuys, G.numBuys + 1, "Number of buys not increased by 1"); + assert(containsCard(G2.discard[p], G2.discardCount[p], estate), "Estate card not gained"); + assert(containsCard(G2.playedCards, G2.playedCardCount, baron), "Baron card not discarded"); + + printf("Test 2\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = baron; + G2.hand[p][1] = estate; + choice1 = 1; // choose to discard an estate card + doBaron(choice1, &G2, 0); + assertEqual(G2.numBuys, G.numBuys + 1, "Number of buys not increased by 1"); + assertEqual(G2.coins, G.coins + 4, "Coins not increased by 4"); + assertEqual(cardCount(G2.hand[p], G2.handCount[p], estate), + cardCount(G.hand[p], G.handCount[p], estate) - 1, "Estate card not discarded"); + assertEqual(cardCount(G2.hand[p], G2.handCount[p], baron), + cardCount(G.hand[p], G.handCount[p], baron) - 1, "Baron card not discarded"); + + printf("Test 3\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = estate; + G2.hand[p][1] = baron; + G2.hand[p][2] = copper; + G2.hand[p][3] = copper; + G2.hand[p][4] = copper; + choice1 = 1; // choose to discard an estate card + doBaron(choice1, &G2, 0); + assertEqual(G2.numBuys, G.numBuys + 1, "Number of buys not increased by 1"); + assertEqual(G2.coins, G.coins + 4, "Coins not increased by 4"); + assertEqual(cardCount(G2.hand[p], G2.handCount[p], estate), + cardCount(G.hand[p], G.handCount[p], estate) - 1, "Estate card not discarded"); + assertEqual(cardCount(G2.hand[p], G2.handCount[p], baron), + cardCount(G.hand[p], G.handCount[p], baron) - 1, "Baron card not discarded"); + + printf("End of doBaron() Tests\n\n"); + return 0; +} diff --git a/projects/alghanmz/alghanmz-assignment-3/unittest2.c b/projects/alghanmz/alghanmz-assignment-3/unittest2.c new file mode 100644 index 000000000..c22d721b2 --- /dev/null +++ b/projects/alghanmz/alghanmz-assignment-3/unittest2.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include "dominion.h" + +void doMinion(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer); + +void assert(int a, char *s) { + if (!a) { + printf("Assert failed: %s\n", s); + } +} + +void assertEqual(int a, int b, char *s) { + if (a != b) { + printf("Assert failed: %s\n", s); + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int main() { + int seed = 47; + int p; + int p2; + int choice1; + int choice2; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, minion, great_hall }; + + // declare the game state + struct gameState G, G2; + + printf("\nBegin Testing doMinion():\n\n"); + initializeGame(4, k, seed, &G); // 4 players + + printf("Test 1\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = minion; + choice1 = 1; // choose +2 coins + choice2 = 0; + doMinion(choice1, choice2, &G2, 0, p); + assertEqual(G2.numActions, G.numActions + 1, "Number of actions not increased by 1"); + assertEqual(G2.coins, G.coins + 2, "Number of coins not increased by 2"); + assert(containsCard(G2.playedCards, G2.playedCardCount, minion), "Minion card not discarded"); + + printf("Test 2\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + p2 = 2; // another player + G2.hand[p][0] = minion; + G2.handCount[p2] = 3; // change handcount from 5 to 3 + choice1 = 0; + choice2 = 1; // choose to redraw hand + doMinion(choice1, choice2, &G2, 0, p); + assertEqual(G2.numActions, G.numActions + 1, "Number of actions not increased by 1"); + assertEqual(G2.handCount[p], 4, "Current player should have exactly 4 cards"); + assertEqual(G2.handCount[p2], 3, "A player with less than 5 cards discarded hand"); + assert(containsCard(G2.playedCards, G2.playedCardCount, minion), "Minion card not discarded"); + + printf("End of doMinion() Tests\n\n"); + return 0; +} diff --git a/projects/alghanmz/alghanmz-assignment-3/unittest3.c b/projects/alghanmz/alghanmz-assignment-3/unittest3.c new file mode 100644 index 000000000..5de2181f2 --- /dev/null +++ b/projects/alghanmz/alghanmz-assignment-3/unittest3.c @@ -0,0 +1,94 @@ +#include +#include +#include +#include "dominion.h" + +int doAmbassador(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer); + +void assert(int a, char *s) { + if (!a) { + printf("Assert failed: %s\n", s); + } +} + +void assertEqual(int a, int b, char *s) { + if (a != b) { + printf("Assert failed: %s\n", s); + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int cardCount(int *container, int size, int card) { + int count = 0; + + for (int i=0; i < size; i++) { + if (container[i] == card) { + count++; + } + } + return count; +} + +int main() { + int seed = 47; + int p; + int p2; + int handPos; + int choice1; + int choice2; + int ret_val; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, ambassador, great_hall }; + + // declare the game state + struct gameState G, G2; + + printf("\nBegin Testing doAmbassador():\n\n"); + initializeGame(2, k, seed, &G); + + printf("Test 1\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + p2 = 1; + G2.hand[p][0] = copper; + G2.hand[p][1] = smithy; + G2.hand[p][2] = copper; + G2.hand[p][3] = copper; + G2.hand[p][4] = ambassador; + choice1 = 0; // choose to discard copper + choice2 = 3; // choose to discard 3 of them + handPos = 4; // ambassador + ret_val = doAmbassador(choice1, choice2, &G2, handPos, p); + assertEqual(ret_val, -1, "Didn't return -1 when trying to discard too many cards"); + assertEqual(cardCount(G2.hand[p], G2.handCount[p], copper), + cardCount(G.hand[p], G.handCount[p], copper) - choice2, "Trashed the wrong number of cards"); + assert(containsCard(G2.playedCards, G2.playedCardCount, ambassador), "Ambassador card not discarded"); + assert(containsCard(G2.discard[p2], G2.discardCount[p2], copper), "Player 2 did not gain a copper"); + + printf("Test 2\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + p2 = 1; + G2.hand[p][0] = ambassador; + G2.hand[p][1] = ambassador; + choice1 = 0; // choose to discard ambassador + choice2 = 1; // choose to discard 1 of them + handPos = 0; // ambassador + ret_val = doAmbassador(choice1, choice2, &G2, handPos, p); + assertEqual(ret_val, -1, "Didn't return -1 when trying to discard ambassador card"); + assert(containsCard(G2.playedCards, G2.playedCardCount, ambassador), "Ambassador card not discarded"); + assert(containsCard(G2.discard[p2], G2.discardCount[p2], ambassador), "Player 2 did not gain an ambassador card"); + + printf("End of doAmbassador() Tests\n\n"); + return 0; +} diff --git a/projects/alghanmz/alghanmz-assignment-3/unittest4.c b/projects/alghanmz/alghanmz-assignment-3/unittest4.c new file mode 100644 index 000000000..0466e2d66 --- /dev/null +++ b/projects/alghanmz/alghanmz-assignment-3/unittest4.c @@ -0,0 +1,109 @@ +#include +#include +#include +#include "dominion.h" + +void doTribute(struct gameState *state, int currentPlayer, int nextPlayer, int tributeRevealedCards[2]); + +void assert(int a, char *s) { + if (!a) { + printf("Assert failed: %s\n", s); + } +} + +void assertEqual(int a, int b, char *s) { + if (a != b) { + printf("Assert failed: %s\n", s); + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int cardCount(int *container, int size, int card) { + int count = 0; + + for (int i=0; i < size; i++) { + if (container[i] == card) { + count++; + } + } + return count; +} + +int main() { + int seed = 47; + int p; + int p2; + int tributeRevealedCards[2]; + int result; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, tribute, great_hall }; + + // declare the game state + struct gameState G, G2; + + printf("\nBegin Testing doTribute():\n\n"); + initializeGame(2, k, seed, &G); + + printf("Test 1\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + p2 = 1; + G2.hand[p][0] = tribute; + G2.deckCount[p2] = 0; + G2.discardCount[p2] = 2; + G2.discard[p2][G2.discardCount[p2]-2] = copper; + G2.discard[p2][G2.discardCount[p2]-1] = estate; + doTribute(&G2, p, p2, tributeRevealedCards); + result = containsCard(G2.playedCards, G2.playedCardCount, tribute); + assert(result, "Tribute card not discarded"); + if (result) + assertEqual(G2.handCount[p], G.handCount[p]+1, "Didn't draw 2 cards"); + else + assertEqual(G2.handCount[p], G.handCount[p]+2, "Didn't draw 2 cards"); + assertEqual(G2.coins, G.coins+2, "Coins didn't increase by 2"); + + printf("Test 2\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + p2 = 1; + G2.hand[p][0] = tribute; + G2.deck[p2][G2.deckCount[p2]-2] = smithy; + G2.deck[p2][G2.deckCount[p2]-1] = estate; + doTribute(&G2, p, p2, tributeRevealedCards); + result = containsCard(G2.playedCards, G2.playedCardCount, tribute); + assert(result, "Tribute card not discarded"); + if (result) + assertEqual(G2.handCount[p], G.handCount[p]+1, "Didn't draw 2 cards"); + else + assertEqual(G2.handCount[p], G.handCount[p]+2, "Didn't draw 2 cards"); + assertEqual(G2.numActions, G.numActions+2, "Actions didn't increase by 2"); + + printf("Test 3\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + p2 = 1; + G2.hand[p][0] = tribute; + G2.deckCount[p2] = 0; + G2.discardCount[p2] = 1; + G2.discard[p2][0] = estate; + doTribute(&G2, p, p2, tributeRevealedCards); + result = containsCard(G2.playedCards, G2.playedCardCount, tribute); + assert(result, "Tribute card not discarded"); + if (result) + assertEqual(G2.handCount[p], G.handCount[p]+1, "Didn't draw 2 cards"); + else + assertEqual(G2.handCount[p], G.handCount[p]+2, "Didn't draw 2 cards"); + + printf("End of doTribute() Tests\n\n"); + return 0; +} diff --git a/projects/alghanmz/alghanmz-assignment-3/unittest5.c b/projects/alghanmz/alghanmz-assignment-3/unittest5.c new file mode 100644 index 000000000..d5040c060 --- /dev/null +++ b/projects/alghanmz/alghanmz-assignment-3/unittest5.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include "dominion.h" + +int doMine(int choice1, int choice2, struct gameState *state, int handPos, int currentPlayer); + +void assert(int a, char *s) { + if (!a) { + printf("Assert failed: %s\n", s); + } +} + +void assertEqual(int a, int b, char *s) { + if (a != b) { + printf("Assert failed: %s\n", s); + } +} + +int containsCard(int *container, int size, int card) { + for (int i=0; i < size; i++) { + if (container[i] == card) { + return 1; + } + } + return 0; +} + +int cardCount(int *container, int size, int card) { + int count = 0; + + for (int i=0; i < size; i++) { + if (container[i] == card) { + count++; + } + } + return count; +} + +int main() { + int seed = 47; + int p; + int handPos; + int choice1; + int choice2; + int ret_val; + + // card array + int k[10] = { adventurer, council_room, feast, gardens, mine + , remodel, smithy, village, ambassador, great_hall }; + + // declare the game state + struct gameState G, G2; + + printf("\nBegin Testing doMine():\n\n"); + initializeGame(2, k, seed, &G); + + printf("Test 1\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = curse; + G2.hand[p][1] = mine; + choice1 = 0; // choose to trash curse + choice2 = silver; // choose to gain a silver + handPos = 1; // mine + ret_val = doMine(choice1, choice2, &G2, handPos, p); + assertEqual(ret_val, -1, "Didn't return -1 when trying to trash a curse"); + + printf("Test 2\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = copper; + G2.hand[p][1] = mine; + G2.hand[p][2] = copper; + G2.hand[p][3] = estate; + G2.hand[p][4] = estate; + choice1 = 0; // choose to trash copper + choice2 = silver; // choose to gain a silver + handPos = 1; // mine + ret_val = doMine(choice1, choice2, &G2, handPos, p); + assert(containsCard(G2.playedCards, G2.playedCardCount, mine), "Mine card not discarded"); + assert(containsCard(G2.hand[p], G2.handCount[p], silver), "Silver not gained to hand"); + assert(containsCard(G2.playedCards, G2.playedCardCount, copper), "Copper card not discarded"); + + printf("Test 3\n"); + memcpy(&G2, &G, sizeof(G)); + p = 0; + G2.hand[p][0] = smithy; + G2.hand[p][1] = mine; + choice1 = 0; // choose to trash smithy + choice2 = silver; // choose to gain a silver + handPos = 1; // mine + ret_val = doMine(choice1, choice2, &G2, handPos, p); + assertEqual(ret_val, -1, "Didn't return -1 when trying to trash a smithy"); + + printf("End of doMine() Tests\n\n"); + return 0; +} diff --git a/projects/alghanmz/alghanmz-assignment-3/unittestresults.out b/projects/alghanmz/alghanmz-assignment-3/unittestresults.out new file mode 100644 index 000000000..e7b35ea86 --- /dev/null +++ b/projects/alghanmz/alghanmz-assignment-3/unittestresults.out @@ -0,0 +1,963 @@ + +Begin Testing doBaron(): + +Test 1 +Assert failed: Number of buys not increased by 1 +Assert failed: Baron card not discarded +Test 2 +Assert failed: Number of buys not increased by 1 +Assert failed: Baron card not discarded +Test 3 +Assert failed: Number of buys not increased by 1 +Assert failed: Coins not increased by 4 +Assert failed: Baron card not discarded +End of doBaron() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:0.00% of 20 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 28 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:0.00% of 17 +Branches executed:0.00% of 16 +Taken at least once:0.00% of 16 +Calls executed:0.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:0.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:0.00% of 2 +No branches +Calls executed:0.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:83.87% of 62 +Branches executed:95.65% of 46 +Taken at least once:80.43% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:21.78% of 583 +Branches executed:21.03% of 409 +Taken at least once:16.87% of 409 +Calls executed:13.40% of 97 +Creating 'dominion.c.gcov' + + +Begin Testing doMinion(): + +Test 1 +Test 2 +Assert failed: Current player should have exactly 4 cards +Assert failed: A player with less than 5 cards discarded hand +End of doMinion() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:92.31% of 13 +Branches executed:100.00% of 6 +Taken at least once:66.67% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:0.00% of 20 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 28 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:93.55% of 62 +Branches executed:100.00% of 46 +Taken at least once:89.13% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:28.47% of 583 +Branches executed:26.89% of 409 +Taken at least once:22.49% of 409 +Calls executed:20.62% of 97 +Creating 'dominion.c.gcov' + + +Begin Testing doAmbassador(): + +Test 1 +Assert failed: Didn't return -1 when trying to discard too many cards +Test 2 +Assert failed: Didn't return -1 when trying to discard ambassador card +End of doAmbassador() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:92.31% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:90.00% of 20 +Branches executed:100.00% of 22 +Taken at least once:77.27% of 22 +Calls executed:100.00% of 3 + +Function 'doTribute' +Lines executed:0.00% of 28 +Branches executed:0.00% of 30 +Taken at least once:0.00% of 30 +Calls executed:0.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:93.55% of 62 +Branches executed:100.00% of 46 +Taken at least once:89.13% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:31.56% of 583 +Branches executed:32.27% of 409 +Taken at least once:26.89% of 409 +Calls executed:23.71% of 97 +Creating 'dominion.c.gcov' + + +Begin Testing doTribute(): + +Test 1 +Assert failed: Tribute card not discarded +Assert failed: Didn't draw 2 cards +Test 2 +Assert failed: Tribute card not discarded +Assert failed: Didn't draw 2 cards +Assert failed: Actions didn't increase by 2 +Test 3 +Assert failed: Tribute card not discarded +Assert failed: Didn't draw 2 cards +End of doTribute() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:92.31% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:90.00% of 20 +Branches executed:100.00% of 22 +Taken at least once:77.27% of 22 +Calls executed:100.00% of 3 + +Function 'doTribute' +Lines executed:82.14% of 28 +Branches executed:100.00% of 30 +Taken at least once:70.00% of 30 +Calls executed:100.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:0.00% of 14 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +Calls executed:0.00% of 4 + +Function 'getCost' +Lines executed:0.00% of 30 +Branches executed:0.00% of 28 +Taken at least once:0.00% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:93.55% of 62 +Branches executed:100.00% of 46 +Taken at least once:89.13% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:35.51% of 583 +Branches executed:39.61% of 409 +Taken at least once:32.03% of 409 +Calls executed:25.77% of 97 +Creating 'dominion.c.gcov' + + +Begin Testing doMine(): + +Test 1 +Assert failed: Didn't return -1 when trying to trash a curse +Test 2 +Assert failed: Silver not gained to hand +Test 3 +End of doMine() Tests + +Function 'updateCoins' +Lines executed:81.82% of 11 +Branches executed:100.00% of 8 +Taken at least once:75.00% of 8 +No calls + +Function 'gainCard' +Lines executed:61.54% of 13 +Branches executed:100.00% of 6 +Taken at least once:50.00% of 6 +Calls executed:100.00% of 1 + +Function 'discardCard' +Lines executed:92.31% of 13 +Branches executed:100.00% of 6 +Taken at least once:83.33% of 6 +No calls + +Function 'cardEffect' +Lines executed:0.00% of 133 +Branches executed:0.00% of 93 +Taken at least once:0.00% of 93 +Calls executed:0.00% of 44 + +Function 'doAmbassador' +Lines executed:90.00% of 20 +Branches executed:100.00% of 22 +Taken at least once:77.27% of 22 +Calls executed:100.00% of 3 + +Function 'doTribute' +Lines executed:82.14% of 28 +Branches executed:100.00% of 30 +Taken at least once:70.00% of 30 +Calls executed:100.00% of 2 + +Function 'printHand' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'printDeck' +Lines executed:0.00% of 6 +Branches executed:0.00% of 2 +Taken at least once:0.00% of 2 +Calls executed:0.00% of 3 + +Function 'doMinion' +Lines executed:100.00% of 17 +Branches executed:100.00% of 16 +Taken at least once:93.75% of 16 +Calls executed:100.00% of 6 + +Function 'doBaron' +Lines executed:100.00% of 22 +Branches executed:100.00% of 10 +Taken at least once:100.00% of 10 +Calls executed:100.00% of 2 + +Function 'getEstateCard' +Lines executed:85.71% of 7 +Branches executed:100.00% of 4 +Taken at least once:50.00% of 4 +Calls executed:75.00% of 4 + +Function 'doMine' +Lines executed:85.71% of 14 +Branches executed:100.00% of 12 +Taken at least once:58.33% of 12 +Calls executed:100.00% of 4 + +Function 'getCost' +Lines executed:16.67% of 30 +Branches executed:100.00% of 28 +Taken at least once:10.71% of 28 +No calls + +Function 'drawCard' +Lines executed:36.36% of 22 +Branches executed:33.33% of 6 +Taken at least once:16.67% of 6 +Calls executed:0.00% of 1 + +Function 'getWinners' +Lines executed:0.00% of 24 +Branches executed:0.00% of 22 +Taken at least once:0.00% of 22 +Calls executed:0.00% of 2 + +Function 'scoreFor' +Lines executed:0.00% of 42 +Branches executed:0.00% of 42 +Taken at least once:0.00% of 42 +Calls executed:0.00% of 3 + +Function 'isGameOver' +Lines executed:0.00% of 10 +Branches executed:0.00% of 8 +Taken at least once:0.00% of 8 +No calls + +Function 'endTurn' +Lines executed:0.00% of 20 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 3 + +Function 'whoseTurn' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'fullDeckCount' +Lines executed:0.00% of 9 +Branches executed:0.00% of 12 +Taken at least once:0.00% of 12 +No calls + +Function 'supplyCount' +Lines executed:100.00% of 2 +No branches +No calls + +Function 'handCard' +Lines executed:0.00% of 3 +No branches +Calls executed:0.00% of 1 + +Function 'numHandCards' +Lines executed:100.00% of 2 +No branches +Calls executed:100.00% of 1 + +Function 'buyCard' +Lines executed:0.00% of 13 +Branches executed:0.00% of 6 +Taken at least once:0.00% of 6 +Calls executed:0.00% of 4 + +Function 'playCard' +Lines executed:0.00% of 14 +Branches executed:0.00% of 10 +Taken at least once:0.00% of 10 +Calls executed:0.00% of 3 + +Function 'shuffle' +Lines executed:93.75% of 16 +Branches executed:100.00% of 8 +Taken at least once:87.50% of 8 +Calls executed:100.00% of 2 + +Function 'initializeGame' +Lines executed:93.55% of 62 +Branches executed:100.00% of 46 +Taken at least once:89.13% of 46 +Calls executed:100.00% of 5 + +Function 'kingdomCards' +Lines executed:0.00% of 13 +No branches +No calls + +Function 'newGame' +Lines executed:0.00% of 3 +No branches +No calls + +Function 'compare' +Lines executed:83.33% of 6 +Branches executed:100.00% of 4 +Taken at least once:75.00% of 4 +No calls + +File 'dominion.c' +Lines executed:38.42% of 583 +Branches executed:49.39% of 409 +Taken at least once:34.47% of 409 +Calls executed:29.90% of 97 +Creating 'dominion.c.gcov' + diff --git a/projects/alghanmz/aljanahaDominion/Makefile b/projects/alghanmz/aljanahaDominion/Makefile new file mode 100644 index 000000000..5541801f3 --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/Makefile @@ -0,0 +1,31 @@ +CFLAGS= -Wall -fpic -coverage -lm -std=c99 + +rngs.o: rngs.h rngs.c + gcc -c rngs.c -g $(CFLAGS) + +dominion.o: dominion.h dominion.c rngs.o + gcc -c dominion.c -g $(CFLAGS) + +playdom: dominion.o playdom.c + gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS) +#To run playdom you need to entere: ./playdom like ./playdom 10*/ + +testDrawCard: testDrawCard.c dominion.o rngs.o + gcc -o testDrawCard -g testDrawCard.c dominion.o rngs.o $(CFLAGS) + +interface.o: interface.h interface.c + gcc -c interface.c -g $(CFLAGS) + +runtests: testDrawCard + ./testDrawCard &> unittestresult.out + gcov dominion.c >> unittestresult.out + cat dominion.c.gcov >> unittestresult.out + + +player: player.c interface.o + gcc -o player player.c -g dominion.o rngs.o interface.o $(CFLAGS) + +all: playdom player + +clean: + rm -f *.o playdom.exe playdom player player.exe *.gcov *.gcda *.gcno *.so *.out testDrawCard testDrawCard.exe diff --git a/projects/alghanmz/aljanahaDominion/READM.md b/projects/alghanmz/aljanahaDominion/READM.md new file mode 100644 index 000000000..c3599f6ad --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/READM.md @@ -0,0 +1,2 @@ +run make all #To compile the dominion code +run ./playdom 30 # to run playdom code diff --git a/projects/alghanmz/aljanahaDominion/dominion.c b/projects/alghanmz/aljanahaDominion/dominion.c new file mode 100644 index 000000000..c94e2edb9 --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/dominion.c @@ -0,0 +1,1373 @@ +#include "dominion.h" +#include "dominion_helpers.h" +#include "rngs.h" +#include +#include +#include + +int compare(const void* a, const void* b) { + if (*(int*)a > *(int*)b) + return 1; + if (*(int*)a < *(int*)b) + return -1; + return 0; +} + +struct gameState* newGame() { + struct gameState* g = malloc(sizeof(struct gameState)); + return g; +} + +int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + int k8, int k9, int k10) { + int* k = malloc(10 * sizeof(int)); + k[0] = k1; + k[1] = k2; + k[2] = k3; + k[3] = k4; + k[4] = k5; + k[5] = k6; + k[6] = k7; + k[7] = k8; + k[8] = k9; + k[9] = k10; + return k; +} + +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 shuffle(int player, struct gameState *state) { + + + int newDeck[MAX_DECK]; + int newDeckPos = 0; + int card; + int i; + + if (state->deckCount[player] < 1) + return -1; + qsort ((void*)(state->deck[player]), state->deckCount[player], sizeof(int), compare); + /* SORT CARDS IN DECK TO ENSURE DETERMINISM! */ + + while (state->deckCount[player] > 0) { + card = floor(Random() * state->deckCount[player]); + newDeck[newDeckPos] = state->deck[player][card]; + newDeckPos++; + for (i = card; i < state->deckCount[player]-1; i++) { + state->deck[player][i] = state->deck[player][i+1]; + } + state->deckCount[player]--; + } + for (i = 0; i < newDeckPos; i++) { + state->deck[player][i] = newDeck[i]; + state->deckCount[player]++; + } + + return 0; +} + +int playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state) +{ + int card; + int coin_bonus = 0; //tracks coins gain from actions + + //check if it is the right phase + if (state->phase != 0) + { + return -1; + } + + //check if player has enough actions + if ( state->numActions < 1 ) + { + return -1; + } + + //get card played + card = handCard(handPos, state); + + //check if selected card is an action + if ( card < adventurer || card > treasure_map ) + { + return -1; + } + + //play card + if ( cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0 ) + { + return -1; + } + + //reduce number of actions + state->numActions--; + + //update coins (Treasure cards may be added with card draws) + updateCoins(state->whoseTurn, state, coin_bonus); + + return 0; +} + +int buyCard(int supplyPos, struct gameState *state) { + int who; + if (DEBUG) { + printf("Entering buyCard...\n"); + } + + // I don't know what to do about the phase thing. + + who = state->whoseTurn; + + if (state->numBuys < 1) { + if (DEBUG) + printf("You do not have any buys left\n"); + return -1; + } else if (supplyCount(supplyPos, state) <1) { + if (DEBUG) + printf("There are not any of that type of card left\n"); + return -1; + } else if (state->coins < getCost(supplyPos)) { + if (DEBUG) + printf("You do not have enough money to buy that. You have %d coins.\n", state->coins); + return -1; + } else { + state->phase=1; + //state->supplyCount[supplyPos]--; + gainCard(supplyPos, state, 0, who); //card goes in discard, this might be wrong.. (2 means goes into hand, 0 goes into discard) + + state->coins = (state->coins) - (getCost(supplyPos)); + state->numBuys--; + if (DEBUG) + printf("You bought card number %d for %d coins. You now have %d buys and %d coins.\n", supplyPos, getCost(supplyPos), state->numBuys, state->coins); + } + + //state->discard[who][state->discardCount[who]] = supplyPos; + //state->discardCount[who]++; + + return 0; +} + +int numHandCards(struct gameState *state) { + return state->handCount[ whoseTurn(state) ]; +} + +int handCard(int handPos, struct gameState *state) { + int currentPlayer = whoseTurn(state); + return state->hand[currentPlayer][handPos]; +} + +int supplyCount(int card, struct gameState *state) { + return state->supplyCount[card]; +} + +int fullDeckCount(int player, int card, struct gameState *state) { + int i; + int count = 0; + + for (i = 0; i < state->deckCount[player]; i++) + { + if (state->deck[player][i] == card) count++; + } + + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == card) count++; + } + + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->discard[player][i] == card) count++; + } + + return count; +} + +int whoseTurn(struct gameState *state) { + return state->whoseTurn; +} + +int endTurn(struct gameState *state) { + int k; + int i; + int currentPlayer = whoseTurn(state); + + //Discard hand + for (i = 0; i < state->handCount[currentPlayer]; i++) { + state->discard[currentPlayer][state->discardCount[currentPlayer]++] = state->hand[currentPlayer][i];//Discard + state->hand[currentPlayer][i] = -1;//Set card to -1 + } + state->handCount[currentPlayer] = 0;//Reset hand count + + //Code for determining the player + if (currentPlayer < (state->numPlayers - 1)) { + state->whoseTurn = currentPlayer + 1;//Still safe to increment + } + else { + state->whoseTurn = 0;//Max player has been reached, loop back around to player 1 + } + + state->outpostPlayed = 0; + state->phase = 0; + state->numActions = 1; + state->coins = 0; + state->numBuys = 1; + state->playedCardCount = 0; + state->handCount[state->whoseTurn] = 0; + + //int k; move to top + //Next player draws hand + for (k = 0; k < 5; k++) { + drawCard(state->whoseTurn, state);//Draw a card + } + + //Update money + updateCoins(state->whoseTurn, state, 0); + + return 0; +} + +int isGameOver(struct gameState *state) { + int i; + int j; + + //if stack of Province cards is empty, the game ends + if (state->supplyCount[province] == 0) + { + return 1; + } + + //if three supply pile are at 0, the game ends + j = 0; + for (i = 0; i < 25; i++) + { + if (state->supplyCount[i] == 0) + { + j++; + } + } + if ( j >= 3) + { + return 1; + } + + return 0; +} + +int scoreFor (int player, struct gameState *state) { + + int i; + int score = 0; + //score from hand + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == curse) { + score = score - 1; + }; + if (state->hand[player][i] == estate) { + score = score + 1; + }; + if (state->hand[player][i] == duchy) { + score = score + 3; + }; + if (state->hand[player][i] == province) { + score = score + 6; + }; + if (state->hand[player][i] == great_hall) { + score = score + 1; + }; + if (state->hand[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + //score from discard + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->discard[player][i] == curse) { + score = score - 1; + }; + if (state->discard[player][i] == estate) { + score = score + 1; + }; + if (state->discard[player][i] == duchy) { + score = score + 3; + }; + if (state->discard[player][i] == province) { + score = score + 6; + }; + if (state->discard[player][i] == great_hall) { + score = score + 1; + }; + if (state->discard[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + //score from deck + for (i = 0; i < state->discardCount[player]; i++) + { + if (state->deck[player][i] == curse) { + score = score - 1; + }; + if (state->deck[player][i] == estate) { + score = score + 1; + }; + if (state->deck[player][i] == duchy) { + score = score + 3; + }; + if (state->deck[player][i] == province) { + score = score + 6; + }; + if (state->deck[player][i] == great_hall) { + score = score + 1; + }; + if (state->deck[player][i] == gardens) { + score = score + ( fullDeckCount(player, 0, state) / 10 ); + }; + } + + return score; +} + +int getWinners(int players[MAX_PLAYERS], struct gameState *state) { + int i; + int j; + int highScore; + int currentPlayer; + + //get score for each player + for (i = 0; i < MAX_PLAYERS; i++) + { + //set unused player scores to -9999 + if (i >= state->numPlayers) + { + players[i] = -9999; + } + else + { + players[i] = scoreFor (i, state); + } + } + + //find highest score + j = 0; + for (i = 0; i < MAX_PLAYERS; i++) + { + if (players[i] > players[j]) + { + j = i; + } + } + highScore = players[j]; + + //add 1 to players who had less turns + currentPlayer = whoseTurn(state); + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] == highScore && i > currentPlayer ) + { + players[i]++; + } + } + + //find new highest score + j = 0; + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] > players[j] ) + { + j = i; + } + } + highScore = players[j]; + + //set winners in array to 1 and rest to 0 + for (i = 0; i < MAX_PLAYERS; i++) + { + if ( players[i] == highScore ) + { + players[i] = 1; + } + else + { + players[i] = 0; + } + } + + return 0; +} + +int drawCard(int player, struct gameState *state) +{ int count; + int deckCounter; + if (state->deckCount[player] <= 0) { //Deck is empty + + //Step 1 Shuffle the discard pile back into a deck + int i; + //Move discard to deck + for (i = 0; i < state->discardCount[player]; i++) { + state->deck[player][i] = state->discard[player][i]; + state->discard[player][i] = -1; + } + + state->deckCount[player] = state->discardCount[player]; + state->discardCount[player] = 0;//Reset discard + + //Shufffle the deck + shuffle(player, state);//Shuffle the deck up and make it so that we can draw + + if (DEBUG) { //Debug statements + printf("Deck count now: %d\n", state->deckCount[player]); + } + + state->discardCount[player] = 0; + + //Step 2 Draw Card + count = state->handCount[player];//Get current player's hand count + + if (DEBUG) { //Debug statements + printf("Current hand count: %d\n", count); + } + + deckCounter = state->deckCount[player];//Create a holder for the deck count + + if (deckCounter == 0) + return -1; + + state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to hand + state->deckCount[player]--; + state->handCount[player]++;//Increment hand count + } + + else { + int count = state->handCount[player];//Get current hand count for player + int deckCounter; + if (DEBUG) { //Debug statements + printf("Current hand count: %d\n", count); + } + + deckCounter = state->deckCount[player];//Create holder for the deck count + state->hand[player][count] = state->deck[player][deckCounter - 1];//Add card to the hand + state->deckCount[player]--; + state->handCount[player]++;//Increment hand count + } + + return 0; +} + +int getCost(int cardNumber) +{ + switch( cardNumber ) + { + case curse: + return 0; + case estate: + return 2; + case duchy: + return 5; + case province: + return 8; + case copper: + return 0; + case silver: + return 3; + case gold: + return 6; + case adventurer: + return 6; + case council_room: + return 5; + case feast: + return 4; + case gardens: + return 4; + case mine: + return 5; + case remodel: + return 4; + case smithy: + return 4; + case village: + return 3; + case baron: + return 4; + case great_hall: + return 3; + case minion: + return 5; + case steward: + return 3; + case tribute: + return 5; + case ambassador: + return 3; + case cutpurse: + return 4; + case embargo: + return 2; + case outpost: + return 5; + case salvager: + return 4; + case sea_hag: + return 4; + case treasure_map: + return 4; + } + + return -1; +} + +int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) +{ + int i; + int j; + int k; + int x; + int index; + int currentPlayer = whoseTurn(state); + int nextPlayer = currentPlayer + 1; + + int tributeRevealedCards[2] = {-1, -1}; + int temphand[MAX_HAND];// moved above the if statement + int drawntreasure=0; + int cardDrawn; + int z = 0;// this is the counter for the temp hand + if (nextPlayer > (state->numPlayers - 1)) { + nextPlayer = 0; + } + + + //uses switch to select card and perform actions + switch( card ) + { + case adventurer: + while(drawntreasure<2) { + if (state->deckCount[currentPlayer] <1) { //if the deck is empty we need to shuffle discard and add to deck + shuffle(currentPlayer, state); + } + drawCard(currentPlayer, state); + cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card. + if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold) + drawntreasure++; + else { + temphand[z]=cardDrawn; + state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one). + z++; + } + } + while(z-1>=0) { + state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn + z=z-1; + } + return 0; + + case council_room: + //+4 Cards + for (i = 0; i < 4; i++) + { + drawCard(currentPlayer, state); + } + + //+1 Buy + state->numBuys++; + + //Each other player draws a card + for (i = 0; i < state->numPlayers; i++) + { + if ( i != currentPlayer ) + { + drawCard(i, state); + } + } + + //put played card in played card pile + discardCard(handPos, currentPlayer, state, 0); + + return 0; + + case feast: + //gain card with cost up to 5 + //Backup hand + for (i = 0; i <= state->handCount[currentPlayer]; i++) { + temphand[i] = state->hand[currentPlayer][i];//Backup card + state->hand[currentPlayer][i] = -1;//Set to nothing + } + //Backup hand + + //Update Coins for Buy + updateCoins(currentPlayer, state, 5); + x = 1;//Condition to loop on + while( x == 1) {//Buy one card + if (supplyCount(choice1, state) <= 0) { + if (DEBUG) + printf("None of that card left, sorry!\n"); + + if (DEBUG) { + printf("Cards Left: %d\n", supplyCount(choice1, state)); + } + } + else if (state->coins < getCost(choice1)) { + printf("That card is too expensive!\n"); + + if (DEBUG) { + printf("Coins: %d < %d\n", state->coins, getCost(choice1)); + } + } + else { + + if (DEBUG) { + printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + } + + gainCard(choice1, state, 0, currentPlayer);//Gain the card + x = 0;//No more buying cards + + if (DEBUG) { + printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]); + } + + } + } + + //Reset Hand + for (i = 0; i <= state->handCount[currentPlayer]; i++) { + state->hand[currentPlayer][i] = temphand[i]; + temphand[i] = -1; + } + //Reset Hand + + return 0; + + case gardens: + return -1; + + case mine: + j = state->hand[currentPlayer][choice1]; //store card we will trash + + if (state->hand[currentPlayer][choice1] < copper || state->hand[currentPlayer][choice1] > gold) + { + return -1; + } + + if (choice2 > treasure_map || choice2 < curse) + { + return -1; + } + + if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) ) + { + return -1; + } + + gainCard(choice2, state, 2, currentPlayer); + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + //discard trashed card + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == j) + { + discardCard(i, currentPlayer, state, 0); + break; + } + } + + return 0; + + case remodel: + j = state->hand[currentPlayer][choice1]; //store card we will trash + + if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) ) + { + return -1; + } + + gainCard(choice2, state, 0, currentPlayer); + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + //discard trashed card + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == j) + { + discardCard(i, currentPlayer, state, 0); + break; + } + } + + + return 0; + + case smithy: + //+3 Cards + for (i = 0; i < 3; i++) + { + drawCard(currentPlayer, state); + } + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case village: + //+1 Card + drawCard(currentPlayer, state); + + //+2 Actions + state->numActions = state->numActions + 2; + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case baron: + state->numBuys++;//Increase buys by 1! + if (choice1 > 0) { //Boolean true or going to discard an estate + int p = 0;//Iterator for hand! + int card_not_discarded = 1;//Flag for discard set! + while(card_not_discarded) { + if (state->hand[currentPlayer][p] == estate) { //Found an estate card! + state->coins += 4;//Add 4 coins to the amount of coins + state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p]; + state->discardCount[currentPlayer]++; + for (; p < state->handCount[currentPlayer]; p++) { + state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1]; + } + state->hand[currentPlayer][state->handCount[currentPlayer]] = -1; + state->handCount[currentPlayer]--; + card_not_discarded = 0;//Exit the loop + } + else if (p > state->handCount[currentPlayer]) { + if(DEBUG) { + printf("No estate cards in your hand, invalid choice\n"); + printf("Must gain an estate if there are any\n"); + } + if (supplyCount(estate, state) > 0) { + gainCard(estate, state, 0, currentPlayer); + + state->supplyCount[estate]--;//Decrement estates + if (supplyCount(estate, state) == 0) { + isGameOver(state); + } + } + card_not_discarded = 0;//Exit the loop + } + + else { + p++;//Next card + } + } + } + + else { + if (supplyCount(estate, state) > 0) { + gainCard(estate, state, 0, currentPlayer);//Gain an estate + + state->supplyCount[estate]--;//Decrement Estates + if (supplyCount(estate, state) == 0) { + isGameOver(state); + } + } + } + + + return 0; + + case great_hall: + //+1 Card + drawCard(currentPlayer, state); + + //+1 Actions + state->numActions++; + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case minion: + //+1 action + state->numActions++; + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + + if (choice1) + { + state->coins = state->coins + 2; + } + else if (choice2) //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4 + { + //discard hand + while(numHandCards(state) > 0) + { + discardCard(handPos, currentPlayer, state, 0); + } + + //draw 4 + for (i = 0; i < 4; i++) + { + drawCard(currentPlayer, state); + } + + //other players discard hand and redraw if hand size > 4 + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + if ( state->handCount[i] > 4 ) + { + //discard hand + while( state->handCount[i] > 0 ) + { + discardCard(handPos, i, state, 0); + } + + //draw 4 + for (j = 0; j < 4; j++) + { + drawCard(i, state); + } + } + } + } + + } + return 0; + + case steward: + if (choice1 == 1) + { + //+2 cards + drawCard(currentPlayer, state); + drawCard(currentPlayer, state); + } + else if (choice1 == 2) + { + //+2 coins + state->coins = state->coins + 2; + } + else + { + //trash 2 cards in hand + discardCard(choice2, currentPlayer, state, 1); + discardCard(choice3, currentPlayer, state, 1); + } + + //discard card from hand + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case tribute: + if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1) { + if (state->deckCount[nextPlayer] > 0) { + tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + state->deckCount[nextPlayer]--; + } + else if (state->discardCount[nextPlayer] > 0) { + tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1]; + state->discardCount[nextPlayer]--; + } + else { + //No Card to Reveal + if (DEBUG) { + printf("No cards to reveal\n"); + } + } + } + + else { + if (state->deckCount[nextPlayer] == 0) { + for (i = 0; i < state->discardCount[nextPlayer]; i++) { + state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck + state->deckCount[nextPlayer]++; + state->discard[nextPlayer][i] = -1; + state->discardCount[nextPlayer]--; + } + + shuffle(nextPlayer,state);//Shuffle the deck + } + tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + state->deckCount[nextPlayer]--; + tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1]; + state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1; + state->deckCount[nextPlayer]--; + } + + if (tributeRevealedCards[0] == tributeRevealedCards[1]) { //If we have a duplicate card, just drop one + state->playedCards[state->playedCardCount] = tributeRevealedCards[1]; + state->playedCardCount++; + tributeRevealedCards[1] = -1; + } + + for (i = 0; i <= 2; i ++) { + if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) { //Treasure cards + state->coins += 2; + } + + else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall) { //Victory Card Found + drawCard(currentPlayer, state); + drawCard(currentPlayer, state); + } + else { //Action Card + state->numActions = state->numActions + 2; + } + } + + return 0; + + case ambassador: + j = 0; //used to check if player has enough cards to discard + + if (choice2 > 2 || choice2 < 0) + { + return -1; + } + + if (choice1 == handPos) + { + return -1; + } + + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (i != handPos && i == state->hand[currentPlayer][choice1] && i != choice1) + { + j++; + } + } + if (j < choice2) + { + return -1; + } + + if (DEBUG) + printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]); + + //increase supply count for choosen card by amount being discarded + state->supplyCount[state->hand[currentPlayer][choice1]] += choice2; + + //each other player gains a copy of revealed card + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + gainCard(state->hand[currentPlayer][choice1], state, 0, i); + } + } + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + + //trash copies of cards returned to supply + for (j = 0; j < choice2; j++) + { + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1]) + { + discardCard(i, currentPlayer, state, 1); + break; + } + } + } + + return 0; + + case cutpurse: + + updateCoins(currentPlayer, state, 2); + for (i = 0; i < state->numPlayers; i++) + { + if (i != currentPlayer) + { + for (j = 0; j < state->handCount[i]; j++) + { + if (state->hand[i][j] == copper) + { + discardCard(j, i, state, 0); + break; + } + if (j == state->handCount[i]) + { + for (k = 0; k < state->handCount[i]; k++) + { + if (DEBUG) + printf("Player %d reveals card number %d\n", i, state->hand[i][k]); + } + break; + } + } + + } + + } + + //discard played card from hand + discardCard(handPos, currentPlayer, state, 0); + + return 0; + + + case embargo: + //+2 Coins + state->coins = state->coins + 2; + + //see if selected pile is in play + if ( state->supplyCount[choice1] == -1 ) + { + return -1; + } + + //add embargo token to selected supply pile + state->embargoTokens[choice1]++; + + //trash card + discardCard(handPos, currentPlayer, state, 1); + return 0; + + case outpost: + //set outpost flag + state->outpostPlayed++; + + //discard card + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case salvager: + //+1 buy + state->numBuys++; + + if (choice1) + { + //gain coins equal to trashed card + state->coins = state->coins + getCost( handCard(choice1, state) ); + //trash card + discardCard(choice1, currentPlayer, state, 1); + } + + //discard card + discardCard(handPos, currentPlayer, state, 0); + return 0; + + case sea_hag: + for (i = 0; i < state->numPlayers; i++) { + if (i != currentPlayer) { + state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--]; + state->deckCount[i]--; + state->discardCount[i]++; + state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse + } + } + return 0; + + case treasure_map: + //search hand for another treasure_map + index = -1; + for (i = 0; i < state->handCount[currentPlayer]; i++) + { + if (state->hand[currentPlayer][i] == treasure_map && i != handPos) + { + index = i; + break; + } + } + if (index > -1) + { + //trash both treasure cards + discardCard(handPos, currentPlayer, state, 1); + discardCard(index, currentPlayer, state, 1); + + //gain 4 Gold cards + for (i = 0; i < 4; i++) + { + gainCard(gold, state, 1, currentPlayer); + } + + //return success + return 1; + } + + //no second treasure_map found in hand + return -1; + } + + return -1; +} + +int discardCard(int handPos, int currentPlayer, struct gameState *state, int trashFlag) +{ + + //if card is not trashed, added to Played pile + if (trashFlag < 1) + { + //add card to played pile + state->playedCards[state->playedCardCount] = state->hand[currentPlayer][handPos]; + state->playedCardCount++; + } + + //set played card to -1 + state->hand[currentPlayer][handPos] = -1; + + //remove card from player's hand + if ( handPos == (state->handCount[currentPlayer] - 1) ) //last card in hand array is played + { + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + else if ( state->handCount[currentPlayer] == 1 ) //only one card in hand + { + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + else + { + //replace discarded card with last card in hand + state->hand[currentPlayer][handPos] = state->hand[currentPlayer][ (state->handCount[currentPlayer] - 1)]; + //set last card to -1 + state->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1; + //reduce number of cards in hand + state->handCount[currentPlayer]--; + } + + return 0; +} + +int gainCard(int supplyPos, struct gameState *state, int toFlag, int player) +{ + //Note: supplyPos is enum of choosen card + + //check if supply pile is empty (0) or card is not used in game (-1) + if ( supplyCount(supplyPos, state) < 1 ) + { + return -1; + } + + //added card for [whoseTurn] current player: + // toFlag = 0 : add to discard + // toFlag = 1 : add to deck + // toFlag = 2 : add to hand + + if (toFlag == 1) + { + state->deck[ player ][ state->deckCount[player] ] = supplyPos; + state->deckCount[player]++; + } + else if (toFlag == 2) + { + state->hand[ player ][ state->handCount[player] ] = supplyPos; + state->handCount[player]++; + } + else + { + state->discard[player][ state->discardCount[player] ] = supplyPos; + state->discardCount[player]++; + } + + //decrease number in supply pile + state->supplyCount[supplyPos]--; + + return 0; +} + +int updateCoins(int player, struct gameState *state, int bonus) +{ + int i; + + //reset coin count + state->coins = 0; + + //add coins for each Treasure card in player's hand + for (i = 0; i < state->handCount[player]; i++) + { + if (state->hand[player][i] == copper) + { + state->coins += 1; + } + else if (state->hand[player][i] == silver) + { + state->coins += 2; + } + else if (state->hand[player][i] == gold) + { + state->coins += 3; + } + } + + //add bonus + state->coins += bonus; + + return 0; +} + + +//end of dominion.c + diff --git a/projects/alghanmz/aljanahaDominion/dominion.h b/projects/alghanmz/aljanahaDominion/dominion.h new file mode 100644 index 000000000..f9d9039b8 --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/dominion.h @@ -0,0 +1,131 @@ +#ifndef _DOMINION_H +#define _DOMINION_H + +// Code from various sources, baseline from Kristen Bartosz + +#define MAX_HAND 500 +#define MAX_DECK 500 + +#define MAX_PLAYERS 4 + +#define DEBUG 0 + +/* http://dominion.diehrstraits.com has card texts */ +/* http://dominion.isotropic.org has other stuff */ + +/* hand# means index of a card in current active player's hand */ + +enum CARD +{ curse = 0, + estate, + duchy, + province, + + copper, + silver, + gold, + + adventurer, + /* If no/only 1 treasure found, stop when full deck seen */ + council_room, + feast, /* choice1 is supply # of card gained) */ + gardens, + mine, /* choice1 is hand# of money to trash, choice2 is supply# of + money to put in hand */ + remodel, /* choice1 is hand# of card to remodel, choice2 is supply# */ + smithy, + village, + + baron, /* choice1: boolean for discard of estate */ + /* Discard is always of first (lowest index) estate */ + great_hall, + minion, /* choice1: 1 = +2 coin, 2 = redraw */ + steward, /* choice1: 1 = +2 card, 2 = +2 coin, 3 = trash 2 (choice2,3) */ + tribute, + + ambassador, /* choice1 = hand#, choice2 = number to return to supply */ + cutpurse, + embargo, /* choice1 = supply# */ + outpost, + salvager, /* choice1 = hand# to trash */ + sea_hag, + treasure_map +}; + +struct gameState { + int numPlayers; //number of players + int supplyCount[treasure_map+1]; //this is the amount of a specific type of card given a specific number. + int embargoTokens[treasure_map+1]; + int outpostPlayed; + int outpostTurn; + int whoseTurn; + int phase; + int numActions; /* Starts at 1 each turn */ + int coins; /* Use as you see fit! */ + int numBuys; /* Starts at 1 each turn */ + int hand[MAX_PLAYERS][MAX_HAND]; + int handCount[MAX_PLAYERS]; + int deck[MAX_PLAYERS][MAX_DECK]; + int deckCount[MAX_PLAYERS]; + int discard[MAX_PLAYERS][MAX_DECK]; + int discardCount[MAX_PLAYERS]; + int playedCards[MAX_DECK]; + int playedCardCount; +}; + +/* All functions return -1 on failure, and DO NOT CHANGE GAME STATE; + unless specified for other return, return 0 on success */ + +struct gameState* newGame(); + +int* kingdomCards(int k1, int k2, int k3, int k4, int k5, int k6, int k7, + int k8, int k9, int k10); + +int initializeGame(int numPlayers, int kingdomCards[10], int randomSeed, + struct gameState *state); +/* Responsible for initializing all supplies, and shuffling deck and + drawing starting hands for all players. Check that 10 cards selected + are in fact (different) kingdom cards, and that numPlayers is valid. + +Cards not in game should initialize supply position to -1 */ + +int shuffle(int player, struct gameState *state); +/* Assumes all cards are now in deck array (or hand/played): discard is + empty */ + +int playCard(int handPos, int choice1, int choice2, int choice3, + struct gameState *state); +/* Play card with index handPos from current player's hand */ + +int buyCard(int supplyPos, struct gameState *state); +/* Buy card with supply index supplyPos */ + +int numHandCards(struct gameState *state); +/* How many cards current player has in hand */ + +int handCard(int handNum, struct gameState *state); +/* enum value of indexed card in player's hand */ + +int supplyCount(int card, struct gameState *state); +/* How many of given card are left in supply */ + +int fullDeckCount(int player, int card, struct gameState *state); +/* Here deck = hand + discard + deck */ + +int whoseTurn(struct gameState *state); + +int endTurn(struct gameState *state); +/* Must do phase C and advance to next player; do not advance whose turn + if game is over */ + +int isGameOver(struct gameState *state); + +int scoreFor(int player, struct gameState *state); +/* Negative here does not mean invalid; scores may be negative, + -9999 means invalid input */ + +int getWinners(int players[MAX_PLAYERS], struct gameState *state); +/* Set array position of each player who won (remember ties!) to + 1, others to 0 */ + +#endif diff --git a/projects/alghanmz/aljanahaDominion/dominion_helpers.h b/projects/alghanmz/aljanahaDominion/dominion_helpers.h new file mode 100644 index 000000000..0887fda15 --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/dominion_helpers.h @@ -0,0 +1,15 @@ +#ifndef _DOMINION_HELPERS_H +#define _DOMINION_HELPERS_H + +#include "dominion.h" + +int drawCard(int player, struct gameState *state); +int updateCoins(int player, struct gameState *state, int bonus); +int discardCard(int handPos, int currentPlayer, struct gameState *state, + int trashFlag); +int gainCard(int supplyPos, struct gameState *state, int toFlag, int player); +int getCost(int cardNumber); +int cardEffect(int card, int choice1, int choice2, int choice3, + struct gameState *state, int handPos, int *bonus); + +#endif diff --git a/projects/alghanmz/aljanahaDominion/hw.c b/projects/alghanmz/aljanahaDominion/hw.c new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/hw.c @@ -0,0 +1 @@ + diff --git a/projects/alghanmz/aljanahaDominion/interface.c b/projects/alghanmz/aljanahaDominion/interface.c new file mode 100644 index 000000000..58cc5ba58 --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/interface.c @@ -0,0 +1,425 @@ +/* Interactive Dominion Interface + +Sam Heinith CS362 +1/26/2010 +*/ + +#include +#include +#include +#include +#include "rngs.h" +#include "interface.h" +#include "dominion.h" + + +void cardNumToName(int card, char *name) { + switch(card) { + case curse: + strcpy(name,"Curse"); + break; + case estate: + strcpy(name,"Estate"); + break; + case duchy: + strcpy(name,"Duchy"); + break; + case province: + strcpy(name,"Province"); + break; + case copper: + strcpy(name,"Copper"); + break; + case silver: + strcpy(name,"Silver"); + break; + case gold: + strcpy(name,"Gold"); + break; + case adventurer: + strcpy(name,"Adventurer"); + break; + case council_room: + strcpy(name,"Council Room"); + break; + case feast: + strcpy(name,"Feast"); + break; + case gardens: + strcpy(name,"Gardens"); + break; + case mine: + strcpy(name,"Mine"); + break; + case remodel: + strcpy(name,"Remodel"); + break; + case smithy: + strcpy(name,"Smithy"); + break; + case village: + strcpy(name,"Village"); + break; + case baron: + strcpy(name,"Baron"); + break; + case great_hall: + strcpy(name,"Great Hall"); + break; + case minion: + strcpy(name,"Minion"); + break; + case steward: + strcpy(name,"Steward"); + break; + case tribute: + strcpy(name,"Tribute"); + break; + case ambassador: + strcpy(name,"Ambassador"); + break; + case cutpurse: + strcpy(name,"Cutpurse"); + break; + case embargo: + strcpy(name,"Embargo"); + break; + case outpost: + strcpy(name,"Outpost"); + break; + case salvager: + strcpy(name,"Salvager"); + break; + case sea_hag: + strcpy(name,"Sea Hag"); + break; + case treasure_map: + strcpy(name,"Treasure Map"); + break; + + default: + strcpy(name,"?"); + } + +} + + + +int getCardCost(int card) { + int cost; + switch(card) { + case curse: + cost = CURSE_COST; + break; + case estate: + cost = ESTATE_COST; + break; + case duchy: + cost = DUCHY_COST; + break; + case province: + cost = PROVINCE_COST; + break; + case copper: + cost = COPPER_COST; + break; + case silver: + cost = SILVER_COST; + break; + case gold: + cost = GOLD_COST; + break; + case adventurer: + cost = ADVENTURER_COST; + break; + case council_room: + cost = COUNCIL_ROOM_COST; + break; + case feast: + cost = FEAST_COST; + break; + case gardens: + cost = GARDEN_COST; + break; + case mine: + cost = MINE_COST; + break; + case remodel: + cost = REMODEL_COST; + break; + case smithy: + cost = SMITHY_COST; + break; + case village: + cost = VILLAGE_COST; + break; + case baron: + cost = BARON_COST; + break; + case great_hall: + cost = GREAT_HALL_COST; + break; + case minion: + cost = MINION_COST; + break; + case steward: + cost = STEWARD_COST; + break; + case tribute: + cost = TRIBUTE_COST; + break; + case ambassador: + cost = AMBASSADOR_COST; + break; + case cutpurse: + cost = CUTPURSE_COST; + break; + case embargo: + cost = EMBARGO_COST; + break; + case outpost: + cost = OUTPOST_COST; + break; + case salvager: + cost = SALVAGER_COST; + break; + case sea_hag: + cost = SEA_HAG_COST; + break; + case treasure_map: + cost = TREASURE_MAP_COST; + break; + default: + cost = ONETHOUSAND; + } + return cost; +} + + + + + + +void printHand(int player, struct gameState *game) { + int handCount = game->handCount[player]; + int handIndex; + printf("Player %d's hand:\n", player); + if(handCount > 0) printf("# Card\n"); + for(handIndex = 0; handIndex < handCount; handIndex++) { + int card = game->hand[player][handIndex]; + char name[MAX_STRING_LENGTH]; + cardNumToName(card, name); + printf("%-2d %-13s\n", handIndex, name); + } + printf("\n"); +} + + + +void printDeck(int player, struct gameState *game) { + int deckCount = game->deckCount[player]; + int deckIndex; + printf("Player %d's deck: \n", player); + if(deckCount > 0) printf("# Card\n"); + for(deckIndex = 0; deckIndex < deckCount; deckIndex++) { + int card = game->deck[player][deckIndex]; + char name[MAX_STRING_LENGTH]; + cardNumToName(card, name); + printf("%-2d %-13s\n", deckIndex, name); + } + printf("\n"); +} + +void printPlayed(int player, struct gameState *game) { + int playedCount = game->playedCardCount; + int playedIndex; + printf("Player %d's played cards: \n", player); + if(playedCount > 0) printf("# Card\n"); + for(playedIndex = 0; playedIndex < playedCount; playedIndex++) { + int card = game->playedCards[playedIndex]; + char name[MAX_STRING_LENGTH]; + cardNumToName(card, name); + printf("%-2d %-13s \n", playedIndex, name); + } + printf("\n"); +} + + + +void printDiscard(int player, struct gameState *game) { + int discardCount = game->discardCount[player]; + int discardIndex; + printf("Player %d's discard: \n", player); + if(discardCount > 0) printf("# Card\n"); + for(discardIndex = 0; discardIndex < discardCount; discardIndex++) { + int card = game->discard[player][discardIndex]; + char name[MAX_STRING_LENGTH]; + cardNumToName(card, name); + printf("%-2d %-13s \n", discardIndex, name); + } + printf("\n"); +} + + + + +void printSupply(struct gameState *game) { + int cardNum, cardCost, cardCount; + char name[MAX_STRING_LENGTH]; + printf("# Card Cost Copies\n"); + for(cardNum = 0; cardNum < NUM_TOTAL_K_CARDS; cardNum++) { + cardCount = game->supplyCount[cardNum]; + if(cardCount == -1) continue; + cardNumToName(cardNum, name); + cardCost = getCardCost(cardNum); + printf("%-2d %-13s %-5d %-5d", cardNum, name, cardCost, cardCount); + printf("\n"); + } + printf("\n"); +} + + +void printState(struct gameState *game) { + int numActions = game->numActions; + int numCoins = game->coins; + int numBuys = game->numBuys; + int currentPlayer = game->whoseTurn; + int phase = game->phase; + char phaseName[MAX_STRING_LENGTH]; + phaseNumToName(phase,phaseName); + printf("Player %d:\n%s phase\n%d actions\n%d coins\n%d buys\n\n", currentPlayer, phaseName, numActions, numCoins, numBuys); +} + +void printScores(struct gameState *game) { + int playerNum, score[MAX_PLAYERS]; + int numPlayers = game->numPlayers; + for(playerNum = 0; playerNum < numPlayers; playerNum++) { + score[playerNum] = scoreFor(playerNum,game); + printf("Player %d has a score of %d\n", playerNum, score[playerNum]); + } +} + + +void printHelp(void) { + printf("Commands are: \n\ + add [Supply Card Number] - add any card to your hand (teh hacks)\n\ + buy [Supply Card Number] - buy a card at supply position\n\ + end - end your turn\n\ + init [Number of Players] [Number of Bots] - initialize the game\n\ + num - print number of cards in your hand\n\ + play [Hand Index] [Choice] [Choice] [Choice] - play a card from your hand\n\ + resign - end the game showing the current scores\n\ + show - show your current hand\n\ + stat - show your turn's status\n\ + supp - show the supply\n\ + whos - whos turn\n\ + exit - exit the interface"); + printf("\n\n"); + +} + + +void phaseNumToName(int phase, char *name) { + switch(phase) { + case ACTION_PHASE: + strcpy(name,"Action"); + break; + case BUY_PHASE: + strcpy(name,"Buy"); + break; + case CLEANUP_PHASE: + strcpy(name,"Cleanup"); + break; + } +} + + +int addCardToHand(int player, int card, struct gameState *game) { + if(card >= adventurer && card < NUM_TOTAL_K_CARDS) { + int handTop = game->handCount[player]; + game->hand[player][handTop] = card; + game->handCount[player]++; + return SUCCESS; + } else { + return FAILURE; + } + +} + +void selectKingdomCards(int randomSeed, int kingCards[NUM_K_CARDS]) { + int i, used, card, numSelected = 0; + SelectStream(1); + PutSeed((long)randomSeed); + + + while(numSelected < NUM_K_CARDS) { + used = FALSE; + card = floor(Random() * NUM_TOTAL_K_CARDS); + if(card < adventurer) continue; + for(i = 0; i < numSelected; i++) { + if(kingCards[i] == card) { + used = TRUE; + break; + } + } + if(used == TRUE) continue; + kingCards[numSelected] = card; + numSelected++; + } +} + + +int countHandCoins(int player, struct gameState *game) { + int card, index, coinage = 0; + + for(index = 0; index < game->handCount[player]; index++) { + card = game->hand[player][index]; + switch(card) { + case copper: + coinage += COPPER_VALUE; + break; + case silver: + coinage += SILVER_VALUE; + break; + case gold: + coinage += GOLD_VALUE; + break; + } + } + return coinage; +} + + +void executeBotTurn(int player, int *turnNum, struct gameState *game) { + int coins = countHandCoins(player, game); + + printf("*****************Executing Bot Player %d Turn Number %d*****************\n", player, *turnNum); + printSupply(game); + //sleep(1); //Thinking... + + if(coins >= PROVINCE_COST && supplyCount(province,game) > 0) { + buyCard(province,game); + printf("Player %d buys card Province\n\n", player); + } + else if(supplyCount(province,game) == 0 && coins >= DUCHY_COST ) { + buyCard(duchy,game); + printf("Player %d buys card Duchy\n\n", player); + } + else if(coins >= GOLD_COST && supplyCount(gold,game) > 0) { + buyCard(gold,game); + printf("Player %d buys card Gold\n\n", player); + } + else if(coins >= SILVER_COST && supplyCount(silver,game) > 0) { + buyCard(silver,game); + printf("Player %d buys card Silver\n\n", player); + + } + + + if(player == (game->numPlayers -1)) (*turnNum)++; + endTurn(game); + if(! isGameOver(game)) { + int currentPlayer = whoseTurn(game); + printf("Player %d's turn number %d\n\n", currentPlayer, (*turnNum)); + } +} diff --git a/projects/alghanmz/aljanahaDominion/interface.h b/projects/alghanmz/aljanahaDominion/interface.h new file mode 100644 index 000000000..6f7bacac2 --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/interface.h @@ -0,0 +1,128 @@ +/* Interactive Dominion Interface + + Sam Heinith CS362 + 1/26/2010 +*/ + + + +#ifndef _INTERFACE_H +#define _INTERFACE_H + + + +#include "dominion.h" + +//Last card enum (Treasure map) card number plus one for the 0th card. +#define NUM_TOTAL_K_CARDS (treasure_map + 1) +#define NUM_K_CARDS 10 +#define NUM_V_CARDS_2 8 +#define NUM_V_CARDS_3or4 12 +#define NUM_C_CARDS_2 10 +#define NUM_C_CARDS_3 20 +#define NUM_C_CARDS_4 30 +#define NUM_COPPER 60 +#define NUM_SILVER 40 +#define NUM_GOLD 30 +#define UNUSED -1 +#define START_COPPER 7 +#define START_ESTATE 3 +#define HANDSIZE 5 + +#define COMPARE(string1, string2) strncmp(string1, string2, 4) +#define MAX_STRING_LENGTH 32 +#define TRUE 1 +#define FALSE 0 + +#define SUCCESS 0 +#define FAILURE -1 + +#define MATCH 0 +#define WINNER 1 +#define NOT_WINNER 0 + +//The Game Phases +#define ACTION_PHASE 0 +#define BUY_PHASE 1 +#define CLEANUP_PHASE 2 + +#define COPPER_VALUE 1 +#define SILVER_VALUE 2 +#define GOLD_VALUE 3 + +//From Dominion List Spoiler +#define COPPER_COST 0 +#define SILVER_COST 3 +#define GOLD_COST 6 +#define ESTATE_COST 2 +#define DUCHY_COST 5 +#define PROVINCE_COST 8 +#define CURSE_COST 0 +#define ADVENTURER_COST 6 +#define COUNCIL_ROOM_COST 5 +#define FEAST_COST 4 +#define GARDEN_COST 4 +#define MINE_COST 5 +#define MONEYLENDER_COST 4 +#define REMODEL_COST 4 +#define SMITHY_COST 4 +#define VILLAGE_COST 3 +#define WOODCUTTER_COST 3 +#define BARON_COST 4 +#define GREAT_HALL_COST 3 +#define MINION_COST 5 +#define SHANTY_TOWN_COST 3 +#define STEWARD_COST 3 +#define TRIBUTE_COST 5 +#define WISHING_WELL_COST 3 +#define AMBASSADOR_COST 3 +#define CUTPURSE_COST 4 +#define EMBARGO_COST 2 +#define OUTPOST_COST 5 +#define SALVAGER_COST 4 +#define SEA_HAG_COST 4 +#define TREASURE_MAP_COST 4 +#define ONETHOUSAND 1000 + + +int addCardToHand(int player, int card, struct gameState *game); + +int countHandCoins(int player, struct gameState *game); + + +void executeBotTurn(int player, int *turnNum, struct gameState *game); + +void phaseNumToName(int phase, char *name); +void cardNumToName(int card, char *name); + +int getCardCost(int card); + +void printHelp(void); + +void printHand(int player, struct gameState *game); + +void printDeck(int player, struct gameState *game); + +void printDiscard(int player, struct gameState *game); + +void printPlayed(int player, struct gameState *game); + +void printState(struct gameState *game); + +void printSupply(struct gameState *game); + +void printGameState(struct gameState *game); + +void printScores(struct gameState *game); + +void selectKingdomCards(int randomSeed, int kingdomCards[NUM_K_CARDS]); + + + +#endif + + + + + + diff --git a/projects/alghanmz/aljanahaDominion/playdom.c b/projects/alghanmz/aljanahaDominion/playdom.c new file mode 100644 index 000000000..336d9a661 --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/playdom.c @@ -0,0 +1,135 @@ +#include "dominion.h" +#include +#include "rngs.h" +#include + +int main (int argc, char** argv) { + struct gameState G; + int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, + sea_hag, tribute, smithy + }; + + printf ("Starting game.\n"); + + initializeGame(2, k, atoi(argv[1]), &G); + + int money = 0; + int smithyPos = -1; + int adventurerPos = -1; + int i=0; + + int numSmithies = 0; + int numAdventurers = 0; + + while (!isGameOver(&G)) { + money = 0; + smithyPos = -1; + adventurerPos = -1; + for (i = 0; i < numHandCards(&G); i++) { + if (handCard(i, &G) == copper) + money++; + else if (handCard(i, &G) == silver) + money += 2; + else if (handCard(i, &G) == gold) + money += 3; + else if (handCard(i, &G) == smithy) + smithyPos = i; + else if (handCard(i, &G) == adventurer) + adventurerPos = i; + } + + if (whoseTurn(&G) == 0) { + if (smithyPos != -1) { + printf("0: smithy played from position %d\n", smithyPos); + playCard(smithyPos, -1, -1, -1, &G); + printf("smithy played.\n"); + money = 0; + i=0; + while(i= 8) { + printf("0: bought province\n"); + buyCard(province, &G); + } + else if (money >= 6) { + printf("0: bought gold\n"); + buyCard(gold, &G); + } + else if ((money >= 4) && (numSmithies < 2)) { + printf("0: bought smithy\n"); + buyCard(smithy, &G); + numSmithies++; + } + else if (money >= 3) { + printf("0: bought silver\n"); + buyCard(silver, &G); + } + + printf("0: end turn\n"); + endTurn(&G); + } + else { + if (adventurerPos != -1) { + printf("1: adventurer played from position %d\n", adventurerPos); + playCard(adventurerPos, -1, -1, -1, &G); + money = 0; + i=0; + while(i= 8) { + printf("1: bought province\n"); + buyCard(province, &G); + } + else if ((money >= 6) && (numAdventurers < 2)) { + printf("1: bought adventurer\n"); + buyCard(adventurer, &G); + numAdventurers++; + } else if (money >= 6) { + printf("1: bought gold\n"); + buyCard(gold, &G); + } + else if (money >= 3) { + printf("1: bought silver\n"); + buyCard(silver, &G); + } + printf("1: endTurn\n"); + + endTurn(&G); + } + } // end of While + + printf ("Finished game.\n"); + printf ("Player 0: %d\nPlayer 1: %d\n", scoreFor(0, &G), scoreFor(1, &G)); + + return 0; +} diff --git a/projects/alghanmz/aljanahaDominion/player.c b/projects/alghanmz/aljanahaDominion/player.c new file mode 100644 index 000000000..0a169d126 --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/player.c @@ -0,0 +1,205 @@ +/* Interactive Dominion Interface + Version 7 + + Sam Heinith CS362 + Questions/Comments: + heiniths@onid.orst.edu + 1/26/2010 +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include "dominion.h" +#include "interface.h" +#include "rngs.h" + + +int main2(int argc, char *argv[]) { + //Default cards, as defined in playDom + int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy}; + struct gameState g; + initializeGame(2,k,1,&g); + printf ("SUCCESSFUL INIT\n"); + getchar(); + return 0; +} + +int main(int argc, char* argv[]) { + char *add = "add"; + char *buyC = "buy"; + char *endT = "end"; + char *exit = "exit"; + char *help = "help"; + char *init = "init"; + char *numH = "num"; + char *play = "play"; + char *resign = "resi"; + char *show = "show"; + char *stat = "stat"; + char *supply = "supp"; + char *whos = "whos"; + + char command[MAX_STRING_LENGTH]; + char line[MAX_STRING_LENGTH]; + char cardName[MAX_STRING_LENGTH]; + + //Array to hold bot presence + int isBot[MAX_PLAYERS] = { 0, 0, 0, 0}; + + int players[MAX_PLAYERS]; + int playerNum; + int outcome; + int currentPlayer; + int gameOver = FALSE; + int gameStarted = FALSE; + int turnNum = 0; + + int randomSeed = atoi(argv[1]); + + //Default cards, as defined in playDom + int kCards[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy}; + + struct gameState g; + struct gameState * game = &g; + + memset(game,0,sizeof(struct gameState)); + + if(argc != 2) { + printf("Usage: player [integer random number seed]\n"); + return EXIT_SUCCESS; + } + + if(randomSeed <= 0) { + printf("Usage: player [integer random number seed]\n"); + return EXIT_SUCCESS; + } + + initializeGame(2,kCards,randomSeed,game); + + printf("Please enter a command or \"help\" for commands\n"); + + + while(TRUE) { + int arg0 = UNUSED; + int arg1 = UNUSED; + int arg2 = UNUSED; + int arg3 = UNUSED; + + outcome = FAILURE; + strcpy(line,""); + strcpy(command,""); + strcpy(cardName,""); + + currentPlayer = whoseTurn(game); + + //If you are getting a seg fault comment this if block out + gameOver = isGameOver(game); + if(gameStarted == TRUE && gameOver == TRUE) { + printScores(game); + getWinners(players, game); + printf("After %d turns, the winner(s) are:\n", turnNum); + for(playerNum = 0; playerNum < game->numPlayers; playerNum++) { + if(players[playerNum] == WINNER) printf("Player %d\n", playerNum); + } + for(playerNum = 0; playerNum < game->numPlayers; playerNum++) { + printHand(playerNum, game); + printPlayed(playerNum, game); + printDiscard(playerNum, game); + printDeck(playerNum, game); + } + + break; //Exit out of the game/while loop + } + + + if(isBot[currentPlayer] == TRUE) { + executeBotTurn(currentPlayer, &turnNum, game); + continue; + } + + printf("$ "); + fgets(line, MAX_STRING_LENGTH, stdin); + sscanf(line, "%s %d %d %d %d", command, &arg0, &arg1, &arg2, &arg3); + + + if(COMPARE(command, add) == 0) { + outcome = addCardToHand(currentPlayer, arg0, game); + cardNumToName(arg0, cardName); + printf("Player %d adds %s to their hand\n\n", currentPlayer, cardName); + } else if(COMPARE(command, buyC) == 0) { + outcome = buyCard(arg0, game); + cardNumToName(arg0, cardName); + if(outcome == SUCCESS) { + printf("Player %d buys card %d, %s\n\n", currentPlayer, arg0, cardName); + } else { + printf("Player %d cannot buy card %d, %s\n\n", currentPlayer, arg0, cardName); + } + } else if(COMPARE(command, endT) == 0) { + if(gameStarted == TRUE) { + if(currentPlayer == (game->numPlayers -1)) turnNum++; + endTurn(game); + currentPlayer = whoseTurn(game); + printf("Player %d's turn number %d\n\n", currentPlayer, turnNum); + } + + } else if(COMPARE(command, exit) == 0) { + break; + } else if(COMPARE(command, help) == 0) { + printHelp(); + } else if(COMPARE(command, init) == 0) { + int numHuman = arg0 - arg1; + for(playerNum = numHuman; playerNum < arg0; playerNum++) { + isBot[playerNum] = TRUE; + } + // selectKingdomCards(randomSeed, kCards); //Comment this out to use the default card set defined in playDom. + outcome = initializeGame(arg0, kCards, randomSeed, game); + printf("\n"); + if(outcome == SUCCESS) { + gameStarted = TRUE; + currentPlayer = whoseTurn(game); + printf("Player %d's turn number %d\n\n", currentPlayer, turnNum); + } + + } else if(COMPARE(command, numH) == 0) { + int numCards = numHandCards(game); + printf("There are %d cards in your hand.\n", numCards); + } else if(COMPARE(command, play) == 0) { + int card = handCard(arg0,game); + outcome = playCard(arg0, arg1, arg2, arg3, game); + cardNumToName(card, cardName); + if(outcome == SUCCESS) { + printf("Player %d plays %s\n\n", currentPlayer, cardName); + } else { + printf("Player %d cannot play card %d\n\n", currentPlayer, arg0); + } + + } else if(COMPARE(command, resign) == 0) { + endTurn(game); + printScores(game); + break; + } else if(COMPARE(command, show) == 0) { + if(gameStarted == FALSE) continue; + printHand(currentPlayer, game); + printPlayed(currentPlayer, game); + //printDiscard(currentPlayer, game); + //printDeck(currentPlayer, game); + } else if(COMPARE(command, stat) == 0) { + if(gameStarted == FALSE) continue; + printState(game); + } else if(COMPARE(command, supply) == 0) { + printSupply(game); + } else if(COMPARE(command, whos) == 0) { + int playerNum = whoseTurn(game); + printf("Player %d's turn\n", playerNum); + } + } + + return EXIT_SUCCESS; + +} diff --git a/projects/alghanmz/aljanahaDominion/rngs.c b/projects/alghanmz/aljanahaDominion/rngs.c new file mode 100644 index 000000000..a85bbc961 --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/rngs.c @@ -0,0 +1,183 @@ +/* ------------------------------------------------------------------------- + * This is an ANSI C library for multi-stream random number generation. + * The use of this library is recommended as a replacement for the ANSI C + * rand() and srand() functions, particularly in simulation applications + * where the statistical 'goodness' of the random number generator is + * important. The library supplies 256 streams of random numbers; use + * SelectStream(s) to switch between streams indexed s = 0,1,...,255. + * + * The streams must be initialized. The recommended way to do this is by + * using the function PlantSeeds(x) with the value of x used to initialize + * the default stream and all other streams initialized automatically with + * values dependent on the value of x. The following convention is used + * to initialize the default stream: + * if x > 0 then x is the state + * if x < 0 then the state is obtained from the system clock + * if x = 0 then the state is to be supplied interactively. + * + * The generator used in this library is a so-called 'Lehmer random number + * generator' which returns a pseudo-random number uniformly distributed + * 0.0 and 1.0. The period is (m - 1) where m = 2,147,483,647 and the + * smallest and largest possible values are (1 / m) and 1 - (1 / m) + * respectively. For more details see: + * + * "Random Number Generators: Good Ones Are Hard To Find" + * Steve Park and Keith Miller + * Communications of the ACM, October 1988 + * + * Name : rngs.c (Random Number Generation - Multiple Streams) + * Authors : Steve Park & Dave Geyer + * Language : ANSI C + * Latest Revision : 09-22-98 + * ------------------------------------------------------------------------- + */ + +#include +#include +#include "rngs.h" + +#define MODULUS 2147483647 /* DON'T CHANGE THIS VALUE */ +#define MULTIPLIER 48271 /* DON'T CHANGE THIS VALUE */ +#define CHECK 399268537 /* DON'T CHANGE THIS VALUE */ +#define STREAMS 256 /* # of streams, DON'T CHANGE THIS VALUE */ +#define A256 22925 /* jump multiplier, DON'T CHANGE THIS VALUE */ +#define DEFAULT 123456789 /* initial seed, use 0 < DEFAULT < MODULUS */ + +static long seed[STREAMS] = {DEFAULT}; /* current state of each stream */ +static int stream = 0; /* stream index, 0 is the default */ +static int initialized = 0; /* test for stream initialization */ + + +double Random(void) +/* ---------------------------------------------------------------- + * Random returns a pseudo-random real number uniformly distributed + * between 0.0 and 1.0. + * ---------------------------------------------------------------- + */ +{ + const long Q = MODULUS / MULTIPLIER; + const long R = MODULUS % MULTIPLIER; + long t; + + t = MULTIPLIER * (seed[stream] % Q) - R * (seed[stream] / Q); + if (t > 0) + seed[stream] = t; + else + seed[stream] = t + MODULUS; + return ((double) seed[stream] / MODULUS); +} + + +void PlantSeeds(long x) +/* --------------------------------------------------------------------- + * Use this function to set the state of all the random number generator + * streams by "planting" a sequence of states (seeds), one per stream, + * with all states dictated by the state of the default stream. + * The sequence of planted states is separated one from the next by + * 8,367,782 calls to Random(). + * --------------------------------------------------------------------- + */ +{ + const long Q = MODULUS / A256; + const long R = MODULUS % A256; + int j; + int s; + + initialized = 1; + s = stream; /* remember the current stream */ + SelectStream(0); /* change to stream 0 */ + PutSeed(x); /* set seed[0] */ + stream = s; /* reset the current stream */ + for (j = 1; j < STREAMS; j++) { + x = A256 * (seed[j - 1] % Q) - R * (seed[j - 1] / Q); + if (x > 0) + seed[j] = x; + else + seed[j] = x + MODULUS; + } +} + + +void PutSeed(long x) +/* --------------------------------------------------------------- + * Use this function to set the state of the current random number + * generator stream according to the following conventions: + * if x > 0 then x is the state (unless too large) + * if x < 0 then the state is obtained from the system clock + * if x = 0 then the state is to be supplied interactively + * --------------------------------------------------------------- + */ +{ + char ok = 0; + + if (x > 0) + x = x % MODULUS; /* correct if x is too large */ + if (x < 0) + x = ((unsigned long) time((time_t *) NULL)) % MODULUS; + if (x == 0) + while (!ok) { + printf("\nEnter a positive integer seed (9 digits or less) >> "); + scanf("%ld", &x); + ok = (0 < x) && (x < MODULUS); + if (!ok) + printf("\nInput out of range ... try again\n"); + } + seed[stream] = x; +} + + +void GetSeed(long *x) +/* --------------------------------------------------------------- + * Use this function to get the state of the current random number + * generator stream. + * --------------------------------------------------------------- + */ +{ + *x = seed[stream]; +} + + +void SelectStream(int index) +/* ------------------------------------------------------------------ + * Use this function to set the current random number generator + * stream -- that stream from which the next random number will come. + * ------------------------------------------------------------------ + */ +{ + stream = ((unsigned int) index) % STREAMS; + if ((initialized == 0) && (stream != 0)) /* protect against */ + PlantSeeds(DEFAULT); /* un-initialized streams */ +} + + +void TestRandom(void) +/* ------------------------------------------------------------------ + * Use this (optional) function to test for a correct implementation. + * ------------------------------------------------------------------ + */ +{ + long i; + long x; + double u; + char ok = 0; + + SelectStream(0); /* select the default stream */ + PutSeed(1); /* and set the state to 1 */ + for(i = 0; i < 10000; i++) { + u = Random(); + if (ok) + printf(" %f \n\n", u); + + } + GetSeed(&x); /* get the new state value */ + ok = (x == CHECK); /* and check for correctness */ + + SelectStream(1); /* select stream 1 */ + PlantSeeds(1); /* set the state of all streams */ + GetSeed(&x); /* get the state of stream 1 */ + ok = ok && (x == A256); /* x should be the jump multiplier */ + if (ok) + printf("\n The implementation of rngs.c is correct.\n\n"); + else + printf("\n\a ERROR -- the implementation of rngs.c is not correct.\n\n"); +} diff --git a/projects/alghanmz/aljanahaDominion/rngs.h b/projects/alghanmz/aljanahaDominion/rngs.h new file mode 100644 index 000000000..c9f3f451a --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/rngs.h @@ -0,0 +1,19 @@ +/* ----------------------------------------------------------------------- + * Name : rngs.h (header file for the library file rngs.c) + * Author : Steve Park & Dave Geyer + * Language : ANSI C + * Latest Revision : 09-22-98 + * ----------------------------------------------------------------------- + */ + +#if !defined( _RNGS_ ) +#define _RNGS_ + +double Random(void); +void PlantSeeds(long x); +void GetSeed(long *x); +void PutSeed(long x); +void SelectStream(int index); +void TestRandom(void); + +#endif diff --git a/projects/alghanmz/aljanahaDominion/rt.c b/projects/alghanmz/aljanahaDominion/rt.c new file mode 100644 index 000000000..5805bb9b4 --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/rt.c @@ -0,0 +1,27 @@ +#include "rngs.h" +#include +#include + +int main(int argc, char** argv) { + if (argc < 3) { + printf ("Not enough inputs: seed target\n"); + } + + SelectStream(1); + PutSeed((long)atoi(argv[1])); + + int done = 0; + int c = 1000000000; + + while (!done) { + c = floor(Random() * 1000000000); + // if (c % 100000 == 0) { + // printf ("c = %d\n", c); + // } + if (c == atoi(argv[2])) { + printf ("Found the bug!\n"); + done = 1; + } + } +} + diff --git a/projects/alghanmz/aljanahaDominion/testdrawcard.c b/projects/alghanmz/aljanahaDominion/testdrawcard.c new file mode 100644 index 000000000..da5379646 --- /dev/null +++ b/projects/alghanmz/aljanahaDominion/testdrawcard.c @@ -0,0 +1,74 @@ +#include "dominion.h" +#include "dominion_helpers.h" +#include +#include +#include +#include "rngs.h" + +#define DEBUG 0 +#define NOISY_TEST 1 + +int checkDrawCard(int p, struct gameState *post) { + struct gameState pre; + memcpy (&pre, post, sizeof(struct gameState)); + + int r; + // printf ("drawCard PRE: p %d HC %d DeC %d DiC %d\n", + // p, pre.handCount[p], pre.deckCount[p], pre.discardCount[p]); + + r = drawCard (p, post); + + //printf ("drawCard POST: p %d HC %d DeC %d DiC %d\n", + // p, post->handCount[p], post->deckCount[p], post->discardCount[p]); + + if (pre.deckCount[p] > 0) { + pre.handCount[p]++; + pre.hand[p][pre.handCount[p]-1] = pre.deck[p][pre.deckCount[p]-1]; + pre.deckCount[p]--; + } else if (pre.discardCount[p] > 0) { + memcpy(pre.deck[p], post->deck[p], sizeof(int) * pre.discardCount[p]); + memcpy(pre.discard[p], post->discard[p], sizeof(int)*pre.discardCount[p]); + pre.hand[p][post->handCount[p]-1] = post->hand[p][post->handCount[p]-1]; + pre.handCount[p]++; + pre.deckCount[p] = pre.discardCount[p]-1; + pre.discardCount[p] = 0; + } + + assert (r == 0); + + assert(memcmp(&pre, post, sizeof(struct gameState)) == 0); +} + +int main () { + + int i, n, r, p, deckCount, discardCount, handCount; + + int k[10] = {adventurer, council_room, feast, gardens, mine, + remodel, smithy, village, baron, great_hall + }; + + struct gameState G; + + printf ("Testing drawCard.\n"); + + printf ("RANDOM TESTS.\n"); + + SelectStream(2); + PutSeed(3); + + for (n = 0; n < 2000; n++) { + for (i = 0; i < sizeof(struct gameState); i++) { + ((char*)&G)[i] = floor(Random() * 256); + } + p = floor(Random() * 2); + G.deckCount[p] = floor(Random() * MAX_DECK); + G.discardCount[p] = floor(Random() * MAX_DECK); + G.handCount[p] = floor(Random() * MAX_HAND); + checkDrawCard(p, &G); + } + + printf ("ALL TESTS OK\n"); + + exit(0); + +} diff --git a/projects/alghanmz/p.txt b/projects/alghanmz/p.txt new file mode 100644 index 000000000..44ee501f8 --- /dev/null +++ b/projects/alghanmz/p.txt @@ -0,0 +1 @@ +cout << "H" diff --git a/projects/alghanmz/quiz/Makefile b/projects/alghanmz/quiz/Makefile new file mode 100644 index 000000000..05c227e31 --- /dev/null +++ b/projects/alghanmz/quiz/Makefile @@ -0,0 +1,9 @@ +testme: testme.c + gcc -o testme -coverage testme.c + +runtests: testme + ./testme + gcov testme.c + +clean: + rm -f *.o testme *.gcov *.gcda *.gcno diff --git a/projects/alghanmz/quiz/hw.c b/projects/alghanmz/quiz/hw.c new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/projects/alghanmz/quiz/hw.c @@ -0,0 +1 @@ + diff --git a/projects/alghanmz/quiz/testme b/projects/alghanmz/quiz/testme new file mode 100644 index 000000000..8b40b8efc Binary files /dev/null and b/projects/alghanmz/quiz/testme differ diff --git a/projects/alghanmz/quiz/testme.c b/projects/alghanmz/quiz/testme.c new file mode 100644 index 000000000..c193162a9 --- /dev/null +++ b/projects/alghanmz/quiz/testme.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +char inputChar() +{ + // TODO: rewrite this function + int c = rand() % 96 + 32; + return (char) c; +} + +char *inputString() +{ + // TODO: rewrite this function + static char str[6]; + int i; + + for (i=0; i < 5; i++) + str[i] = inputChar(); + str[5] = '\0'; + return str; +} + +void testme() +{ + int tcCount = 0; + char *s; + char c; + int state = 0; + time_t start = time(NULL); + while (time(NULL) - start < 5) + { + tcCount++; + c = inputChar(); + s = inputString(); + printf("Iteration %d: c = %c, s = %s, state = %d\n", tcCount, c, s, state); + + if (c == '[' && state == 0) state = 1; + if (c == '(' && state == 1) state = 2; + if (c == '{' && state == 2) state = 3; + if (c == ' '&& state == 3) state = 4; + if (c == 'a' && state == 4) state = 5; + if (c == 'x' && state == 5) state = 6; + if (c == '}' && state == 6) state = 7; + if (c == ')' && state == 7) state = 8; + if (c == ']' && state == 8) state = 9; + if (s[0] == 'r' && s[1] == 'e' + && s[2] == 's' && s[3] == 'e' + && s[4] == 't' && s[5] == '\0' + && state == 9) + { + printf("error "); + exit(200); + } + } +} + + +int main(int argc, char *argv[]) +{ + srand(time(NULL)); + testme(); + return 0; +} diff --git a/projects/alghanmz/quiz/testme.c.gcov b/projects/alghanmz/quiz/testme.c.gcov new file mode 100644 index 000000000..b06c4bb33 --- /dev/null +++ b/projects/alghanmz/quiz/testme.c.gcov @@ -0,0 +1,70 @@ + -: 0:Source:testme.c + -: 0:Graph:testme.gcno + -: 0:Data:testme.gcda + -: 0:Runs:3 + -: 0:Programs:1 + -: 1:#include + -: 2:#include + -: 3:#include + -: 4:#include + -: 5: + 7296396: 6:char inputChar() + -: 7:{ + -: 8: // TODO: rewrite this function + 7296396: 9: int c = rand() % 96 + 32; + 7296396: 10: return (char) c; + -: 11:} + -: 12: + 1216066: 13:char *inputString() + -: 14:{ + -: 15: // TODO: rewrite this function + -: 16: static char str[6]; + -: 17: int i; + -: 18: + 7296396: 19: for (i=0; i < 5; i++) + 6080330: 20: str[i] = inputChar(); + 1216066: 21: str[5] = '\0'; + 1216066: 22: return str; + -: 23:} + -: 24: + 3: 25:void testme() + -: 26:{ + 3: 27: int tcCount = 0; + -: 28: char *s; + -: 29: char c; + 3: 30: int state = 0; + 3: 31: time_t start = time(NULL); + 3: 32: while (time(NULL) - start < 7) + -: 33: { + 1216066: 34: tcCount++; + 1216066: 35: c = inputChar(); + 1216066: 36: s = inputString(); + 1216066: 37: printf("Iteration %d: c = %c, s = %s, state = %d\n", tcCount, c, s, state); + -: 38: + 1216066: 39: if (c == '[' && state == 0) state = 1; + 1216066: 40: if (c == '(' && state == 1) state = 2; + 1216066: 41: if (c == '{' && state == 2) state = 3; + 1216066: 42: if (c == ' '&& state == 3) state = 4; + 1216066: 43: if (c == 'a' && state == 4) state = 5; + 1216066: 44: if (c == 'x' && state == 5) state = 6; + 1216066: 45: if (c == '}' && state == 6) state = 7; + 1216066: 46: if (c == ')' && state == 7) state = 8; + 1216066: 47: if (c == ']' && state == 8) state = 9; + 1216066: 48: if (s[0] == 'r' && s[1] == 'e' + 111: 49: && s[2] == 's' && s[3] == 'e' + #####: 50: && s[4] == 't' && s[5] == '\0' + #####: 51: && state == 9) + -: 52: { + #####: 53: printf("error "); + #####: 54: exit(200); + -: 55: } + -: 56: } + 3: 57:} + -: 58: + -: 59: + 3: 60:int main(int argc, char *argv[]) + -: 61:{ + 3: 62: srand(time(NULL)); + 3: 63: testme(); + 3: 64: return 0; + -: 65:} diff --git a/projects/alghanmz/quiz/testme.gcda b/projects/alghanmz/quiz/testme.gcda new file mode 100644 index 000000000..237cfdc55 Binary files /dev/null and b/projects/alghanmz/quiz/testme.gcda differ diff --git a/projects/alghanmz/quiz/testme.gcno b/projects/alghanmz/quiz/testme.gcno new file mode 100644 index 000000000..c60697222 Binary files /dev/null and b/projects/alghanmz/quiz/testme.gcno differ