int main(int argc, int argv[])
{
	struct gameState G;
  	struct gameState *p=&G;

  	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
	       sea_hag, tribute, smithy};
  
  	printf ("Testing council_room card.\n");
  
  	int r = initializeGame(2, k, 5, p);
  	massert (r == 0,"initializeGame failed\n");

  	int player = whoseTurn(p);
  	int handPos = 0;
  	int coin_bonus=0;

  	G.handCount[player]=4;
  	G.hand[player][0]=council_room;
  	G.hand[player][1]=village;
  	G.hand[player][2]=minion;
  	G.hand[player][3]=mine;

  	G.numBuys=0;

  	int card = handCard(handPos,p);
  	massert(card>=adventurer&&card<=treasure_map,"invalid card\n");
  	massert(card==council_room,"incorrect card\n");

  	int test=cardEffect(card,-1,-1,-1,p,handPos,&coin_bonus);
  	massert(test==0,"cardEffect failed\n");
  	massert(G.handCount[player]==7,"incorrect had count\n");
  	massert(G.numBuys==1,"numBuys incorrect value\n");
  	massert(G.hand[player][0]!=council_room,"council_room is not discarded\n");

  	if(passed==0)
  		printf("---Test Passed!\n");

  	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;
}
예제 #3
0
int main () {
  struct gameState G;
  int r;

  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
	       sea_hag, tribute, smithy};
  printf("cardtest1:\n");
  r = initializeGame(2, k, 10, &G);
  assert (r == 0);
  //Set up 1 cards to be drawn by great_hall
  G.deck[0][0] = 100;
  G.deckCount[0] = 1;
  //Set up card to discard
  G.hand[0][0] = 50;
  G.handCount[0] = 1;
 
  r = cardEffect(great_hall, -1, -1, -1, &G, 0, NULL);
  if(r == -1) {
	  printf("\tFAILURE: cardEffect\n");
	  return 1;
  } else {
	  printf("\tPASS: cardEffect\n");
  }
  if(G.handCount[0] != 1) {
	  printf("\tFAILURE: handCount\n");
	  return 1;
  } else {
	  printf("\tPASS: handCount\n");
  }
  
  if(G.hand[0][0] != 100){
	  printf("\tFAILURE: hand\n");
	  return 1;
  } else {
	  printf("\tPASS: hand\n");
  }
   printf("SUCCESS.\n\n");
  return 0;
}
예제 #4
0
int main(int argc, char** argv)
{
   struct gameState gameInstance;
   int actions;
   int t;

   int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse,
			       sea_hag, steward, smithy};

   printf("Test: Village\n");

   initializeGame(2, k, 5, &gameInstance);
   actions = gameInstance.numActions;
   t = cardEffect(village, 0, 0, 0, &gameInstance, 0, NULL);

   myAssert(gameInstance.numActions == actions + 2);
   myAssert(t == 0);

   printf("\n\n\n\n");

   return 0;
}
예제 #5
0
int main(){
	int i;
	int j;
	int handPos;
	int randomCard;
	int handCount;
	int ret = 0;
	struct gameState *state = malloc(sizeof(struct gameState));
	time_t t;

	printf("Unit test 8 outpost card in dominion.c \n");
	srand((unsigned)time(&t));
	for(i = 0; i < MAX_PLAYERS; i++){
		state->outpostPlayed = 0;
		state->deckCount[i] = 0;
		state->handCount[i] = 0;
		handPos = 0;
		state->whoseTurn = i;
		handPos = rand()%(MAX_HAND) + 1; 
		for(j = 0; j < handPos; j++){
			randomCard = rand()%(treasure_map+1); 
			state->hand[i][j] = randomCard;
			state->handCount[i]++;
		}
		for(j = 0; j < (MAX_DECK-handPos); j++){
			state->deck[i][j] = randomCard;
			state->deckCount[i]++;
		}
		state->hand[i][handPos] = outpost; 
		state->handCount[i]++;
		handCount = state->handCount[i]-1;
		ret = cardEffect(outpost, 0, 0, 0, state, handPos, 0);
		assert(ret == 0);
		assert(state->outpostPlayed == 1);
		assert(handCount == state->handCount[i]);
	}
	printf("All tests passed! \n\n");
	return 0;
}
예제 #6
0
int main (int argc, char** argv) {
	struct gameState x;
	int i;	
	
	int y[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, feast, smithy};

	printf ("gardens\n");

	initializeGame(2, y, 2, &x);

	i = cardEffect(gardens, 0, 0, 0, &x, 0, 0);

	assert(i == -1);

	assert(x.numActions == 1);
	
	assert(numHandCards(&x) == 5);

	assert(x.numBuys ==1); //nothing should change

	return (0);
}
예제 #7
0
int main(){
	struct gameState g;
	int i, ret, bonus;
	bonus = 0;
	
	  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
	       sea_hag, tribute,smithy};

	printf ("Starting game.\n");
	
	initializeGame(2, k, 5, &g);
		   
	//g.coins = 0;
	g.embargoTokens[smithy] = 0;
	g.hand[0][0] = embargo;
	
	printf("handcount is %d \n", g.handCount[0]);
	printf("coin is %d \n", g.coins);
	
	assert(g.handCount[0] == 5);
	assert(g.coins == 4);
	
	//cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus)
	//playCard(0,smithy,-1,-1, &g);
	cardEffect(embargo, smithy, -1, -1, &g, 0, &bonus);
	
	printf("handcount is %d \n", g.handCount[0]);
	printf("coin is %d \n", g.coins);
	printf("g.embargoTokens[smithy] is : %d \n", g.embargoTokens[smithy]);
	assert( g.embargoTokens[smithy] == 1);
	assert(g.coins == 6);
	
	//assert(g.handCount[0] == 8);
	//assert(g.numBuys == 2);
	
	//assert(g.handCount[0] == 9);
	printf ("embargo switch statement works \n");
	return 0;
}
int main() {
    int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse,
		     sea_hag, tribute, smithy};
    int players, player, handCount, deckCount, seed, handPos, coinBonus;
    struct gameState state;
        
    srand(time(NULL));

	printf("Running Random Adventurer Test\n");

	for (int i = 0; i < MAX_TESTS; i++) {

		players = rand() % (MAX_PLAYERS - 2) + 2;
		seed = rand();
		coinBonus = 0;
		handPos = rand() % 4;
		player = i % (players);

		initializeGame(players, k, seed, &state); //initialize Gamestate

		// Initiate valid state variables
		state.deckCount[player] = rand() % MAX_DECK;   //Pick random deck size out of MAX DECK size
		state.discardCount[player] = rand() % MAX_DECK;
		state.handCount[player] = rand() % MAX_HAND;
        
        // Copy state variables
		handCount = state.handCount[player];
		deckCount = state.deckCount[player];
        
		cardEffect(adventurer, 1, 1, 1, &state, handPos, &coinBonus);
        int result = validateStateAfterAdventurerDraw(&state, player, handCount, deckCount);
		assert(result == 1);
	}

	printf("Tests Complete\n");

	return 0;
}
예제 #9
0
void testDiscardFail()
{
	int turn1 = G->whoseTurn;
	int turn2 = turn1 + 1;

	//Assign first hand draw (deck must be identifiable)
	G->hand[turn1][0] = copper;
	G->hand[turn1][1] = baron;
	G->hand[turn1][2] = copper;
	G->hand[turn1][3] = copper;
	G->hand[turn1][4] = copper;

	//Each Deck position should be different (identification)
	G->deck[turn1][0] = estate;
	G->deck[turn1][1] = silver;
	G->deck[turn1][2] = gold;
	G->deck[turn1][3] = village;
	G->deck[turn1][4] = minion;

	//Set 2nd player to keep deck identifiable
	G->deck[turn2][0] = estate;
	G->deck[turn2][1] = estate;
	G->deck[turn2][2] = copper;
	G->deck[turn2][3] = copper;
	G->deck[turn2][4] = copper;
	G->deck[turn2][5] = tribute;
	G->deck[turn2][6] = salvager;
	G->deck[turn2][7] = adventurer;
	G->deck[turn2][8] = baron;
	G->deck[turn2][9] = remodel;

	printf("\n*********Before card effect (With Failed Discard)***********\n");
	displayState(G);
	cardEffect(baron, 1, 0, 0, G, 0, 0);
	printf("\n*********After card effect(With Failed Discard)***********\n");
	displayState(G);
	return;
}
int main(int argc, char *argv[]) {
        srand(atoi(argv[1]));
        struct gameState g;

        int k[10] = {smithy,adventurer,gardens,embargo,cutpurse,mine,ambassador,
                     outpost,baron,tribute};

        int numPlayers = rand() % MAX_PLAYERS;
        int seed = atoi(argv[1]);

        int numTests = 300;

        for(int i = 0; i < numTests; i++) {
                initializeGame(numPlayers, k, seed, &g);

                // g.deckCount[g.whoseTurn] = rand() % MAX_DECK;
                // g.discardCount[g.whoseTurn] = rand() % MAX_DECK;
                // g.handCount[g.whoseTurn] = rand() % MAX_HAND;

                int startingHand = numHandCards(&g);
                int startingDeck = g.deckCount[g.whoseTurn];

                myassert(!cardEffect(adventurer, 0, 0, 0, &g, 0, 0),
                         "Adventurer returned the wrong value.");

                myassert(numHandCards(&g) == startingHand + 2,
                         "Wrong number of treasure cards drawn by adventurer.");

                int endingDiscard = g.discardCount[g.whoseTurn];

                myassert(g.deckCount[g.whoseTurn] == startingDeck - endingDiscard - 2,
                         "Wrong number of treasure cards taken from deck by adventurer.");

                seed++;
        }

        checkasserts();
}
예제 #11
0
int playCard(int handPos, int choice1, int choice2, int choice3, gameState *state) {
    // disallow improper phase or too few actions
    if (state->phase != 0 || state->numActions < 1)
        return -1;

    //get card played
    int card = handCard(handPos, state);

    //check if selected card is an action
    if (card < adventurer || card > treasure_map)
        return -1;

    //play card
    int coin_bonus = 0; 		//tracks coins gain from actions
    if (cardEffect(card, choice1, choice2, choice3, state, handPos, &coin_bonus) < 0)
        return -1;

    //update actions and coins (Treasure cards may be added with card draws)
    state->numActions--;
    updateCoins(state->whoseTurn, state, coin_bonus);

    return 0;
}
int main () {
  struct gameState state;
  struct gameState *g = &state;
  int card_returnValue;
  int r;
  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
	       sea_hag, tribute, smithy};
		   
    srand(time(NULL));
    r = rand();
	printf("-----\nCard Test 2: Gardens\n-----\n");
  // initialize game 
  int returnValue = initializeGame(2, k, r, g);
  // make sure initialization is completed
  assert (returnValue == 0);
  // check return value 
	card_returnValue = cardEffect(gardens, 0, 0, 0, g, 0, 0);
	assert(card_returnValue==-1);
	printf("Test passed\n");
	printf("Card Test 2: Gardens completed\n");

  return 0;
}
예제 #13
0
int main() {
    printf("%sTesting Smithy Card...%s\n", YELLOW, CLEAR);
    int i = 0;
    struct gameState state;
    int game;

    printf("%s\nSetting up game...%s\n", YELLOW, CLEAR);
    game = initializeGame(2, kingdomCards(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 5, &state);
    assertTrue(game == 0, "Game is initialized");
    
    printf("%s\nSetting card to smithy...%s\n", YELLOW, CLEAR);
    state.hand[0][0] = 13;
    assertTrue(state.hand[0][0] == 13, "Test card is smithy");

    printf("%s\nSaving initial hand count...%s\n", YELLOW, CLEAR);
    int currentHandNum = state.handCount[0];

    printf("%s\nCalling smithy card...%s\n", YELLOW, CLEAR);
    cardEffect(13, 0, 0, 0, &state, i, NULL);

    assertTrue(state.handCount[0] == currentHandNum+2, "+3 cards, discard 1");
	return 0;
}
예제 #14
0
int main(int argc, char *argv[]){
   struct gameState *state1 = malloc(sizeof(struct gameState)), 
	            *state2 = malloc(sizeof(struct gameState));
   int testseed, loops = 10000, i, handpos, bonus = 0, choice1, choice2, choice3;
   char str[100];

   if(argc > 1)
      testseed = atoi(argv[1]);
   else
      testseed = time(NULL);
   srand(testseed);

   if (argc > 2)
      loops = atoi(argv[2]);

   printf("Testing great hall %d times...\n", loops);
   
   for(i = 0; i < loops; i++){
//      printf("test %d\n", i + 1);
      if(initialize(state1, &handpos, &testseed))
	 printf("failed to initialize game states\n");
      else{
	 memcpy(state2, state1, sizeof(struct gameState));
	 memset(str, '\0', sizeof(char) * 100);
	 sprintf(str, "Great hall card failed (number of players = %d, handpos = %d, original deck count = %d",state1->numPlayers, handpos, state1->deckCount[state1->whoseTurn]);
//	 myassert(impliment(state1), "testing implimentation failed\n");
	 impliment(state1, handpos);
	 cardEffect(card, 0, 0, 0, state2, handpos, &bonus);
	 sprintf(str, "%s error number %d)\n",str, check(state1, state2));
	 myassert(check(state1, state2), str);
      }
   }

   (numFails()) ? printf("%d of %d tests FAILED\n", numFails(), loops) : printf("Test SUCCESSFUL\n");

   return 0;
}
//-------------------------------------------------------------------
//TEST
//-------------------------------------------------------------------
int testCardEffect_Smithy(int player, int testCard, int testCardPos, struct gameState *game) {
	int testChoice1 = -1, testChoice2 = -1, testChoice3 = -1, testBonus = 0; // Vars passed to cardEffect
	int prevValue = 0/*, success = 1*/, allPass = 1;
	int oriPlayer = 0;

	// Store Original Values
	oriPlayer = game->whoseTurn;

	/* After playing smithy player should have 3 new cards and smithy should be in their played cards pile */
	prevValue = game->handCount[player];
	cardEffect(testCard, testChoice1, testChoice2, testChoice3, game, testCardPos, &testBonus);
	//assert(game->handCount[player] == (prevValue + 2));		// 3 new cards - 1 smithy card = 2 card difference
	printf("Part 1...");
	if (allPass) {
		allPass = f_Assert((game->handCount[player] == (prevValue + 2)), "");
	}
	else {
		f_Assert((game->handCount[player] == (prevValue + 2)), "");
	}

	//assert(game->playedCards[game->playedCardCount - 1] == testCard);	// Smithy was the last card discarded
	printf("Part 2...");
	if (allPass) {
		allPass = f_Assert((game->playedCards[game->playedCardCount - 1] == testCard), "");
	}
	else {
		f_Assert((game->playedCards[game->playedCardCount - 1] == testCard), "");
	}

	// Restore original values
	game->whoseTurn = oriPlayer;

	// If all tests passed success = 1
	if (allPass) { printf("Unit test was successfully completed.\n"); }

	return allPass;
}
void oracle(struct gameState state, int handCount, int discardCount, int actionCount)
{
	cardEffect(village, 1, 1, 1, &state, 0, 0);

	printf("handCount- B: %d  A: %d\n", handCount, state.handCount[0]);
	printf("discardCount- B: %d  A: %d\n", discardCount, state.discardCount[0]);
	printf("actionCount- B: %d  A: %d\n", actionCount, state.numActions);

	if(state.handCount[0] != handCount)
	{
		printf("Failed: handcount incorrect\n");
	}
	if(state.discardCount[0] != discardCount +1)
	{
		printf("Failed: discardcount incorrect\n");
	}
	if(state.numActions != actionCount+2)
	{
		printf("Failed: actioncount incorrect\n");
	}
	printf("\n");

	return;
}
void oracle(struct gameState state, int deckCount, int discardCount)
{
	int treasure, i;
	treasure = 0;
	i = 0;

	printf("Deck Treasures Located At: ");
	for(i = 0; i < deckCount; i++)
	{
		if(state.deck[0][i] == copper || state.deck[0][i] == silver || state.deck[0][i] == gold)
		{
			printf("%d ", i);
		}
	}
	printf("\n");

	cardEffect(adventurer, 1, 1, 1, &state, 0, 0);

	printf("Deck Count- B: %d  A: %d\n", deckCount, state.deckCount[0]);
	printf("Discard Count- B: %d  A: %d\n\n", discardCount, state.discardCount[0]);

	return;

}
예제 #18
0
int main (int argc, char** argv) {
	struct gameState x;
	int i;	
	
	int y[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, feast, smithy};

	printf ("feast\n");

	initializeGame(2, y, 2, &x);

	i = cardEffect(feast, village, 0, 0, &x, 0, 0);

	assert(i == 0);

	assert(x.numActions == 1);
	
	assert(numHandCards(&x) == 5);

	assert(x.numBuys ==1);

	assert(fullDeckCount(0, village, &x) == 1);

	return (0);
}
예제 #19
0
int main(){
printf("Random Test 1 (Council Room) Starting \n");
	
	int k[10] = {adventurer, council_room, embargo, village, minion, mine, cutpurse, 
	       sea_hag, tribute, smithy};
	int  i, j, n, players, player, handCount, deckCount, seed, address;
	struct gameState state1;
	struct gameState state2;
	struct gameState state3;
	
	for(i=0;i < MAX_TESTS;i++){
		seed = rand();
		players = rand() % 4;
		initializeGame(players,k,seed,&state1);
		
		state1.deckCount[player] = rand() % MAX_DECK;
		state1.discardCount[player] = rand() % MAX_DECK;
		state1.handCount[player] = rand() % MAX_HAND;
		
		handCount = state1.handCount[player];
		deckCount = state1.deckCount[player];
		
		cardEffect(council_room,1,1,1,&state1);
		
	}
	
	for(i=0;i < MAX_TESTS;i++){
		seed = rand();
		players = rand() % 4;
		initializeGame(players,k,seed,&state2);
		
		state2.deckCount[player] = rand() % MAX_DECK;
		state2.discardCount[player] = rand() % MAX_DECK;
		state2.handCount[player] = rand() % MAX_HAND;
		
		handCount = state2.handCount[player];
		deckCount = state2.deckCount[player];
		
		cardEffect(council_room,1,1,1,&state2);
		
	}
	
	for(i=0;i < MAX_TESTS;i++){
		seed = rand();
		players = rand() % 4;
		initializeGame(players,k,seed,&state3);
		
		state3.deckCount[player] = rand() % MAX_DECK;
		state3.discardCount[player] = rand() % MAX_DECK;
		state3.handCount[player] = rand() % MAX_HAND;
		
		handCount = state3.handCount[player];
		deckCount = state3.deckCount[player];
		
		cardEffect(council_room,1,1,1,&state3);
		
	}
	
	printf("Random Test 1 Complete \n");
	
	return 0;
}
예제 #20
0
파일: cardtest4.c 프로젝트: cr8zd/cs362w16
int main()
{
	int i, j, m;
	int handPos, choice1, choice2, choice3, bonus, player;
	handPos = choice1 = choice2 = choice3 = bonus = player = 0;
	int trash1, trash2;
	int seed = 1000;
	int numPlayers = 2;
	int k[10] = {adventurer, council_room, steward, gardens, mine, remodel, smithy, village, baron, great_hall};

	struct gameState state, controlState;

	initializeGame(numPlayers, k, seed, &state);

	printf("\nTESTING Steward cardEffect\n");

	//************** Test choice1 = 1: +2 cards **************
	printf("\nTesting Choice: Draw Two Cards\n");

	//Set gameState, choice, and call cardEffect
	memcpy(&controlState, &state, sizeof(struct gameState));
	choice1 = 1;
	cardEffect(steward, choice1, choice2, choice3, &state, handPos, &bonus);

	//Test handCount incremented by one
	printf("Testing Hand Count\n");
	if(state.handCount[player] == controlState.handCount[player] + 1)
	{
		printf("PASS: Expected Value: %d  Actual Value: %d\n", controlState.handCount[player] + 1, state.handCount[player]);
	}
	else
	{
		printf("FAIL: Expected Value: %d  Actual Value: %d\n", controlState.handCount[player] + 1, state.handCount[player]);
	}

	//Test deckCount decremented by two
	printf("Testing Deck Count\n");
	if(state.deckCount[player] == controlState.deckCount[player] - 2)
	{
		printf("PASS: Expected Value: %d  Actual Value: %d\n", controlState.deckCount[player] - 2, state.deckCount[player]);
	}
	else
	{
		printf("FAIL: Expected Value: %d  Actual Value: %d\n", controlState.deckCount[player] - 2, state.deckCount[player]);
	}

	//Test coins unchanged
	printf("Testing Coin Count\n");
	if(state.coins == controlState.coins)
	{
		printf("PASS: Expected Value: %d  Actual Value: %d\n", controlState.coins, state.coins);
	}
	else
	{
		printf("FAIL: Expected Value: %d  Actual Value: %d\n", controlState.coins, state.coins);
	}


	//************** Test choice1 = 2: +2 coins **************
	printf("\nTesting Choice: Two Coins\n");

	//Reset game state, set choice, and call cardEffect
	memcpy(&state, &controlState, sizeof(struct gameState));
	choice1 = 2;
	cardEffect(steward, choice1, choice2, choice3, &state, handPos, &bonus);

	//Test handCount decremented by one
	printf("Testing Hand Count\n");
	if(state.handCount[player] == controlState.handCount[player] - 1)
	{
		printf("PASS: Expected Value: %d  Actual Value: %d\n", controlState.handCount[player] - 1, state.handCount[player]);
	}
	else
	{
		printf("FAIL: Expected Value: %d  Actual Value: %d\n", controlState.handCount[player] - 1, state.handCount[player]);
	}

	//Test deckCount unchanged
	printf("Testing Deck Count\n");
	if(state.deckCount[player] == controlState.deckCount[player])
	{
		printf("PASS: Expected Value: %d  Actual Value: %d\n", controlState.deckCount[player], state.deckCount[player]);
	}
	else
	{
		printf("FAIL: Expected Value: %d  Actual Value: %d\n", controlState.deckCount[player], state.deckCount[player]);
	}

	//Test coins incremented by two
	printf("Testing Coin Count\n");
	if(state.coins == controlState.coins + 2)
	{
		printf("PASS: Expected Value: %d  Actual Value: %d\n", controlState.coins + 2, state.coins);
	}
	else
	{
		printf("FAIL: Expected Value: %d  Actual Value: %d\n", controlState.coins + 2, state.coins);
	}


	//************** Test choice1 = 3: trash two cards **************
	printf("\nTesting Choice: Trash Two Cards\n");
	choice1 = 3;

	//Reset gameState
	memcpy(&state, &controlState, sizeof(struct gameState));

	//Trash each possible combination
	for(i = 1; i < state.handCount[player]; i++)
	{
		for(j = i + 1; j < state.handCount[player]; j++)
		{
			state.hand[player][0] = steward;
			state.hand[player][1] = estate;
			state.hand[player][2] = smithy;
			state.hand[player][3] = silver;
			state.hand[player][4] = copper;

			printf("Starting hand:\n");
			for(m = 0; m < state.handCount[player]; m++)
			{
				printf("%d: %d\n", m, state.hand[player][m]);
			}

			choice2 = j;
			choice3 = i;
			trash1 = state.hand[player][i];
			trash2 = state.hand[player][j];
			cardEffect(steward, choice1, choice2, choice3, &state, handPos, &bonus);

			printf("Removing: %d, %d\n", trash1, trash2);
			printf("Cards remaining:\n");

			for(m = 0; m < state.handCount[player]; m++)
			{
				printf("%d: %d\n", m, state.hand[player][m]);
				assert(state.hand[player][m] != trash1);
				assert(state.hand[player][m] != trash2);
			}

			printf("PASS: Trashed cards removed from hand\n");

			//Reset gameState
			memcpy(&state, &controlState, sizeof(struct gameState));
		}
	}

	//Test handcount, deckcount, and coins after trashing

	//Reset game state, set choice, and call cardEffect
	memcpy(&state, &controlState, sizeof(struct gameState));
	choice1 = 3;
	choice2 = 1;
	choice3 = 2;
	cardEffect(steward, choice1, choice2, choice3, &state, handPos, &bonus);

	//Test handCount decremented by three
	printf("\nTesting Hand Count\n");
	if(state.handCount[player] == controlState.handCount[player] - 3)
	{
		printf("PASS: Expected Value: %d  Actual Value: %d\n", controlState.handCount[player] - 3, state.handCount[player]);
	}
	else
	{
		printf("FAIL: Expected Value: %d  Actual Value: %d\n", controlState.handCount[player] - 3, state.handCount[player]);
	}

	//Test deckCount unchanged
	printf("Testing Deck Count\n");
	if(state.deckCount[player] == controlState.deckCount[player])
	{
		printf("PASS: Expected Value: %d  Actual Value: %d\n", controlState.deckCount[player], state.deckCount[player]);
	}
	else
	{
		printf("FAIL: Expected Value: %d  Actual Value: %d\n", controlState.deckCount[player], state.deckCount[player]);
	}

	//Test coins unchanged
	printf("Testing Coin Count\n");
	if(state.coins == controlState.coins)
	{
		printf("PASS: Expected Value: %d  Actual Value: %d\n", controlState.coins, state.coins);
	}
	else
	{
		printf("FAIL: Expected Value: %d  Actual Value: %d\n", controlState.coins, state.coins);
	}
	return 0;
}
예제 #21
0
int main() {
	
	int i, j, numPlayers, currPlayer, handCount, deckCount, discardCount, seed, numAction;
	int fails = 0;

	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};

	struct gameState state;
	
	printf("Starting Test for Village");

	for (i = 0; i < MAX_TESTS; i++) {
		printf("*** Test %d ***\n", (i + 1));
		numPlayers = 2 +(rand() % 3);

		currPlayer = rand() % numPlayers;
		seed = rand();

		j = initializeGame(numPlayers, k, seed, &state);
		assert(j == 0);
		state.whoseTurn = currPlayer;

		state.deckCount[currPlayer] = (rand() % MAX_DECK);
		state.discardCount[currPlayer] =(rand() % MAX_DECK);
		state.handCount[currPlayer] = (rand() % MAX_HAND);

		if (seed % 3 == 0) {
			state.deckCount[currPlayer] = 0;
		}

		discardCount = state.handCount[currPlayer];
		deckCount = state.deckCount[currPlayer];
		handCount = state.handCount[currPlayer];
		numAction = state.numActions;

		printf("Cards discarded: %d\n", discardCount);
		printf("Cards in deck: %d\n", deckCount);
		printf("Cards in hand: %d\n", handCount);
		printf("Actions left: %d\n", numAction);

		j = cardEffect(village, 0, 0, 0, &state, 0, 0);

		if (j != 0) {
			fails++;
			printf("cardEffect has return wrong value!\n");	
		}

		if (handCount != state.handCount[currPlayer]){
			fails++;
			printf("currPlayer did not discard and draw!\n");
		}

		if ((numAction + 2) != state.numActions) {
			fails++;
			printf("numActions did not increase by 1!\n");
		}

		else {
			printf("Pass!\n");
		}

	}
	printf("***** Test Complete! %d/%d tests fail! *****\n\n\n", fails,MAX_TESTS);

return 0;	
}
예제 #22
0
int main(int argc, char** argv) {

	  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
	       sea_hag, tribute, smithy};

	  int i, j, seed, players, testPlayer;
	  int handCount = 0, deckCount = 0, discardCount = 0, treasureCount = 0;
	  int temp;

	  struct gameState *state= NULL;

	  srand(time(NULL));

	  printf("Running Random Adventurer Test\n\n");

	  for (i = 0; i < MAX_TESTS; i++) {
		  
	   state = newGame();

	   players = (rand() % 3)+2; //2-4 players
	   testPlayer = rand() % players;
	   seed = rand();

	   printf("Test Number: %d\n", i);
	   printf("Player Count: %d\n", players);
	   printf("Test Player: %d\n", testPlayer);
	   printf("Seed: %d\n", seed);

	   initializeGame(players, k, seed, state);	//initialize Gamestate 
	   state->whoseTurn = testPlayer;

	   handCount = (rand() % (MAX_HAND - 5)) + 6; //random hand size between 5-500
	   state->handCount[testPlayer] = handCount;
	   printf("Hand Count: %d\n", handCount);

	   deckCount = (rand() % (MAX_DECK - 10)) + 11; //random deck size between 10-500
	   state->deckCount[testPlayer] = deckCount;
	   printf("Deck Count: %d\n", deckCount);

	   state->hand[testPlayer][0] = adventurer; //set first card to adventurer

	   for (j = 1; j < handCount; j++) //fill hand
	   {
		   state->hand[testPlayer][j] = rand() % 27;
	   }
	   // total implemented cards = 27
	   for (j = 0; j < deckCount; j++) //fill deck
	   {
		   state->deck[testPlayer][j] = rand() % 27;
	   }

	   for (j = 0; j < deckCount; j++) //count treasure cards in deck
	   {
		   temp = state->deck[testPlayer][j];
		   if (temp == copper || temp == silver || temp == gold)
		   {
			   treasureCount++;
		   }
	   }

	   if (treasureCount > 1)
	   {
		   //test draw 2 treasures
		   discardCount = state->discardCount[testPlayer];
		   cardEffect(adventurer, 0, 0, 0, state, 0, 0);
		   if (handCount + 2 == state->handCount[testPlayer])
		   {
			   printf("Draw 2 Test Passed\n");
		   }
		   else
			   printf("Draw 2 Test Failed\n");
	   }

	   else if (treasureCount == 1)
	   {
		   //test draw 1 treasures
		   discardCount = state->discardCount[testPlayer];
		   cardEffect(adventurer, 0, 0, 0, state, 0, 0);
		   if (handCount + 2 == state->handCount[testPlayer])
		   {
			   printf("Draw 1 Test Passed\n");
		   }
		   else
			   printf("Draw 1 Test Failed\n");
	   }
	   
	   else
	   {
		   //test draw 0 treasures
		   cardEffect(adventurer, 0, 0, 0, state, 0, 0);
		   if (handCount + 2 == state->handCount[testPlayer])
		   {
			   printf("Draw 0 Test Passed\n");
		   }
		   else
			   printf("Draw 0 Test Failed\n");
	   }


	   //confirm correctly discarded
	   if (discardCount <= state->discardCount[testPlayer])
	   {
		   printf("Discard Test Passed\n\n");
	   }
	   else
		   printf("Discard Test Failed\n\n"); 

	   //end tests. no tests for abnormal card behavior such as changing action count. 

	   free(state);

	  }
	  

	  printf("Tests Complete\n");

	  return 0;
}
int main() {

	  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
	       sea_hag, tribute, smithy};

	  int i, j, n, players, player, handCount, deckCount, seed, address;
	  //struct gameState state;
	  struct gameState state;
	  struct gameState stat;
	  struct gameState sta;

	  printf("Running Random Adventurer Test\n");

	  /*
										--- Author's Note ---
	  So, I had problems running out of memory when I used the same gameState variable more than 12 times, and
	  I honestly don't know why. I momentarily solved this problem by adding more for loops and creating more gamestates;
	  I was still able to get decent coverage, though not up to the amount of tests I originally had in mind.

	  */

	  for (i = 0; i < MAX_TESTS; i++) {

	   players = rand() % 4;

	   seed = rand();		//pick random seed
		
	   initializeGame(players, k, seed, &state);	//initialize Gamestate 

	   //Initiate valid state variables
		  state.deckCount[player] = rand() % MAX_DECK; //Pick random deck size out of MAX DECK size
		  state.discardCount[player] = rand() % MAX_DECK;
		  state.handCount[player] = rand() % MAX_HAND;


		  //Copy state variables
		  handCount = state.handCount[player];
		  deckCount = state.deckCount[player];

		  //1 in 3 chance of making empty deck for coverage
		  if (seed % 3 == 0) {

			state.deckCount[player] = 0;
		  }
		  cardEffect(adventurer, 1, 1, 1, &state);		//Run adventurer card
	  }
	  
	   for (i = 0; i < MAX_TESTS; i++) {

  		  players = rand() % 4;
		  seed = rand();		//pick random seed
		
		  initializeGame(players, k, seed, &stat);	//initialize Gamestate

		  //Initiate valid state variables
		  stat.deckCount[player] = rand() % MAX_DECK; //Pick random deck size out of MAX DECK size
		  stat.discardCount[player] = rand() % MAX_DECK;
		  stat.handCount[player] = rand() % MAX_HAND;


		  //Copy state variables
		  handCount = stat.handCount[player];
		  deckCount = stat.deckCount[player];

		  //1 in 3 chance of making empty deck for coverage
		  if (seed % 3 == 0) {

			stat.deckCount[player] = 0;
		  }

		  cardEffect(adventurer, 1, 1, 1, &stat);		//Run adventurer card
	  }

	   for (i = 0; i < MAX_TESTS; i++) {

  		  players = rand() % 4;
		  seed = rand();		//pick random seed
		
		  initializeGame(players, k, seed, &sta);	//initialize Gamestate

		  //Initiate valid state variables
		  sta.deckCount[player] = rand() % MAX_DECK; //Pick random deck size out of MAX DECK size
		  sta.discardCount[player] = rand() % MAX_DECK;
		  sta.handCount[player] = rand() % MAX_HAND;


		  //Copy state variables
		  handCount = sta.handCount[player];
		  deckCount = sta.deckCount[player];

		  //1 in 3 chance of making empty deck for coverage
		  if (seed % 3 == 0) {

			sta.deckCount[player] = 0;
		  }
		  cardEffect(adventurer, 1, 1, 1, &sta);		//Run adventurer card

	   }

	  printf("Tests Complete\n");

	  return 0;
}
예제 #24
0
int main(int argc, const char * argv[]) {
    
    // seed random
    srand(time(NULL));
    int seed;
    
    // game/test set-up values
    int numPlayer = 2;
    int maxHandCount = 5;
    int gameCards[10] = {sea_hag, council_room, feast, gardens, cutpurse, remodel, adventurer, smithy, baron, great_hall};
    struct gameState state;
    struct gameState preState;
    int gameStateCompareReturnValue;
    int tracker;
    int errors = 0;
    
    // card function parameters
    int choice1 = 0;
    int choice2 = 0;
    int choice3 = 0;
    int bonus = 0;
    int handPos;
    
    // loop variables
    int i, player, handCount;
    
    // arrays of all mines and adventurers
    int mines[MAX_HAND];
    int golds[MAX_HAND];
    for (i = 0; i < MAX_HAND; i++) {
        mines[i] = mine;
        golds[i] = gold;
    }
    
    printf ("TESTING Village Card:\n");
    
    // Perform each test on each player
    for (player = 0; player < numPlayer; ++player) {
        
        // Perform test on each hand count
        for (handCount = 1; handCount <= maxHandCount; ++handCount) {
            
#if (NOISY_TEST == 1)
            printf("Player: %i, Hand Count: %i\n", player + 1, handCount);
#endif
            // get index of Village card
            handPos = handCount - 1;
            
            // clear game state
            memset(&state, 23, sizeof(struct gameState));
            
            // initialize new game
            seed = rand() % 1000 + 1;
            assert(initializeGame(numPlayer, gameCards, seed, &state) == 0);
            
            // set current player
            state.whoseTurn = player;
            
            // set all cards in hand to Mine Cards
            memcpy(state.hand[player], mines, sizeof(int) * handCount);
            
            // set last card in current player's hand to Village Card
            state.hand[player][handPos] = village;
            
            // set players hand count
            state.handCount[player] = handCount;
            
            // save game state prior to discardCard() call
            preState = state;
            
            // call function to test
            assert(cardEffect(state.hand[player][handPos], choice1, choice2, choice3, &state, handPos, &bonus) == 0);
            
            
            
            
// BEG Test 1: Village is Discarded From Hand to Played Pile
#if (NOISY_TEST == 1)
            printf("Test 1: Village is Discarded From Hand to Played Pile\n");
#endif
            
#if (NOISY_TEST == 1)
            printf("Expected: Village Card Not In Hand\n");
#endif
            tracker = 0;
            for (i = 0; i < state.handCount[player]; ++i) {
                if (state.hand[player][i] == village)
                    tracker++;
            }
            
            if (tracker != 0) {
                printf("ERROR: Village Card Still In Hand\n");
                errors++;
            }
            
#if (NOISY_TEST == 1)
            if (tracker == 0)
                printf("Actual: Village Card Not In Hand\n");
#endif
            
            
#if (NOISY_TEST == 1)
            printf("Expected: Village Card in Played Pile\n");
#endif
            tracker = 0;
            for (i = 0; i < state.playedCardCount; ++i) {
                if (state.playedCards[i] == village)
                    tracker++;
            }
            
            if (tracker == 0) {
                printf("ERROR: Village Card Not In Played Pile\n");
                errors++;
            }
            
#if (NOISY_TEST == 1)
            if (tracker != 0)
                printf("Actual: Village Card in Played Pile\n");
#endif
// END Test 1: Village is Discarded From Hand to Played Pile
            

// BEG Test 2: One Card is Drawn From Deck
#if (NOISY_TEST == 1)
            printf("Test 2: One Card is Drawn From Deck\n");
#endif
            
#if (NOISY_TEST == 1)
            printf("Expected Deck Count: %i, Actual Deck Count: %i\n", preState.deckCount[player] - 1, state.deckCount[player]);
#endif
            
            if (preState.deckCount[player] - 1 > state.deckCount[player]) {
                printf("ERROR: More Than One Cards Drawn\n");
                errors++;
            }
            else if (preState.deckCount[player] - 1 < state.deckCount[player]) {
                printf("ERROR: Less Than One Cards Drawn\n");
                errors++;
            }
// END Test 2: One Card is Drawn From Deck
            
            
// BEG Test 3: One Card is Addded to Hand
#if (NOISY_TEST == 1)
            printf("Test 3: One Card is Added to Hand\n");
#endif
            tracker = 0;
            for (i = 0; i < state.handCount[player]; ++i) {
                if (state.hand[player][i] != village)
                    tracker++;
            }
            
#if (NOISY_TEST == 1)
            printf("Expected Hand Count: %i, Actual Hand Count: %i\n", preState.handCount[player], tracker);
#endif
            if (preState.handCount[player] > tracker) {
                printf("ERROR: Less Than One Card Added to Hand\n");
                errors++;
            }
            else if (preState.handCount[player] < tracker) {
                printf("ERROR: More Than One Card Added to Hand\n");
                errors++;
            }
// END Test 3: One Card is Addded to Hand
            
            
// BEG Test 4: Current Player's Actions Are Increased By Two
#if (NOISY_TEST == 1)
            printf("Test 4: Current Player's Actions Are Increased By Two\n");
#endif
            
#if (NOISY_TEST == 1)
            printf("Expected Num Actions: %i, Actual Num Actions: %i\n", preState.numActions + 2, state.numActions);
#endif
            if (preState.numActions + 2 != state.numActions) {
                printf("ERROR: Two Actions NOT Added To Current Player\n");
                errors++;
            }
// END Test 4: Current Player's Actions Are Increased By Two
            
            
            
// BEG Test 5: If Deck is Empty When Village Card is Played, Discard Pile is Added to Deck
#if (NOISY_TEST == 1)
            printf("Test 5: If Deck is Empty When Village Card is Played, Discard Pile is Added to Deck\n");
#endif
            // set deck count to zero
            state.deckCount[player] = 0;
            
            // set all cards in hand to Mine Cards
            memcpy(state.hand[player], mines, sizeof(int) * state.handCount[player]);
            
            // add village card to hand
            state.handCount[player]++;
            state.hand[player][handCount - 1] = village;
            
            // set discard pile to be 1 gold card
            state.discardCount[player] = 1;
            memcpy(state.discard[player], golds, sizeof(int) * state.discardCount[player]);
            
            // call function to test
            assert(cardEffect(state.hand[player][handPos], choice1, choice2, choice3, &state, state.handCount[player] - 1, &bonus) == 0);
            
            // scan hand and tally number of treasure cards
            tracker = 0;
            for (i = 0; i < state.handCount[player]; ++i) {
                if (state.hand[player][i] == gold) {
                    tracker++;
                }
            }
            
#if (NOISY_TEST == 1)
            printf("Expected Additional Cards In Hand: %i, Actual Additional Cards In Hand: %i\n", 1, tracker);
#endif
            assert(tracker == 1);
// END Test 5: If Deck is Empty When Village Card is Played, Discard Pile is Added to Deck
            
            
// BEG Test 6: Game State Is Not Altered Other Than Current Player's Hand & Count, Deck & Count, Actions, and Played Pile
#if (NOISY_TEST == 1)
            printf("Test 6: Game State Is Not Altered Other Than Current Player's Hand & Count, Deck & Count, Actions, and Played Pile\n");
#endif
            gameStateCompareReturnValue = compareGameStates(&preState, &state, MAX_DECK, maxHandCount, numPlayer, player);
            
#if (NOISY_TEST == 1)
            printf("Expected: Game State Compare Return Value = 0, Actual: Game State Compare Return Value = %i\n", gameStateCompareReturnValue);
#endif
            assert(gameStateCompareReturnValue == 0);
// END Test 6: Game State Is Not Altered Other Than Current Player's Hand & Count, Deck & Count, Actions, and Played Pile
            
        }
    }
    if (errors == 0)
        printf ("TESTING OF Village Card COMPLETED SUCCESSFULLY\n");
    else
        printf ("TESTING OF Village Card COMPLETED WITH ERRORS\n");
    return 0;
}
int main() {
	  int returnValGame, returnValEffect; 
	  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
	       sea_hag, tribute, smithy};

	  int i, j, n, players, player, handCount, deckCount, seed, address;
	  
	  //struct gameState state;
	  struct gameState state;
	  struct gameState stat;
	  struct gameState sta;

	  //printf("Running Random Adventurer Test\n");

	  /*
										--- Author's Note ---
	  So, I had problems running out of memory when I used the same gameState variable more than 12 times, and
	  I honestly don't know why. I momentarily solved this problem by adding more for loops and creating more gamestates;
	  I was still able to get decent coverage, though not up to the amount of tests I originally had in mind.

	  */
	  
	  //Loops 12 times for first set of tests 
	  for (i = 0; i < MAX_TESTS; i++) 
	  {
		  //Picks random # of players between 0 and 3
		  players = rand() % 4;
		  //Pick random sed 
	      seed = rand();		
		  //Initalizes game 
	      returnValGame = initializeGame(players, k, seed, &state);	
		  //Oracle for checking if the game is able to be initialized 
	      massert(returnValGame == 0, "The game was not able to be initialized\n");
	   //Initiate valid state variables
	      //Pick a random deck size between 0 and 499 
		  state.deckCount[player] = rand() % MAX_DECK; 
		  //Pick a random discard size between 0 and 499
		  state.discardCount[player] = rand() % MAX_DECK;
		  //Pick a random hand size between 0 and 499 
		  state.handCount[player] = rand() % MAX_HAND;


		  //Copy state variables
		  handCount = state.handCount[player];
		  deckCount = state.deckCount[player];

		  //1 in 3 chance of making empty deck for coverage
		  if (seed % 3 == 0) 
		  {
			state.deckCount[player] = 0;
		  }
		  //Activates adventurer card effect
		  returnValEffect = cardEffect(adventurer, 1, 1, 1, &state, 1, 1);	
		  //Oracle for checking if adventurer card effect worked 
		  massert(returnValEffect == 0, "The adventurer card effect did not work\n");
	  }

       //Loops 12 times for third set of tests 
	   for (i = 0; i < MAX_TESTS; i++) 
	   {
		  //Picks number of players between 0 and 3 
  		  players = rand() % 4;
		  //Pick random seed 
		  seed = rand();		
		  //Initializes game 
		  returnValGame = initializeGame(players, k, seed, &stat);	
          //Oracle for checking if the game is able to be initialized 
	      massert(returnValGame == 0, "The game was not able to be initialized\n");
		  //Initiate valid state variables
		  //Picks a random deck size between 0 and 499 
		  stat.deckCount[player] = rand() % MAX_DECK; 
		  //Picks a random discard size between 0 and 499 
		  stat.discardCount[player] = rand() % MAX_DECK;
		  //Picks a random hand size between 0 and 499 
		  stat.handCount[player] = rand() % MAX_HAND;


		  //Copy state variables
		  handCount = stat.handCount[player];
		  deckCount = stat.deckCount[player];

		  //1 in 3 chance of making empty deck for coverage
		  if (seed % 3 == 0) 
		  {
			stat.deckCount[player] = 0;
		  }
		  //Activates adventurer card effect 
		  cardEffect(adventurer, 1, 1, 1, &stat, 1, 1);
		  //Oracle for checking if adventurer card effect worked 
		  massert(returnValEffect == 0, "The adventurer card effect did not work\n");
		  //AdventurerCardEffect(&stat, 0);
	   }

       //Loops 12 times for third set of tests 
	   for (i = 0; i < MAX_TESTS; i++) 
	   {
		  //Picks number of players between 0 and 3 
  		  players = rand() % 4;
		  //Pick random seed 
		  seed = rand();		
		  //Initializes game 
		  returnValGame = initializeGame(players, k, seed, &sta);	
          //Oracle for checking if the game is able to be initialized 
	      massert(returnValGame == 0, "The game was not able to be initialized\n");
		  //Initiate valid state variables
		  //Picks a random deck size between 0 and 499 
		  sta.deckCount[player] = rand() % MAX_DECK; 
		  //Picks a random discard size between 0 and 499 
		  sta.discardCount[player] = rand() % MAX_DECK;
		  //Picks a random hand size between 0 and 499 
		  sta.handCount[player] = rand() % MAX_HAND;


		  //Copy state variables
		  handCount = sta.handCount[player];
		  deckCount = sta.deckCount[player];

		  //1 in 3 chance of making empty deck for coverage
		  if (seed % 3 == 0) 
		  {
			sta.deckCount[player] = 0;
		  }
		  //Activates adventurer card effect
		  cardEffect(adventurer, 1, 1, 1, &stat, 1, 1);		
		  //Oracle for checking if adventurer card effect worked 
		  massert(returnValEffect == 0, "The adventurer card effect did not work\n");

	   }

	  //printf("Tests Complete\n");

	  return 0;
}
예제 #26
0
int main() {

	int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};

	int i;
	int r = 0;
	int choice1 = 0, choice2 = 0, choice3 = 0;
	int numPlayers = 0, curPlayer = 0;
	int handPos = 0, handCount = 0, deckCount = 0;
	int seed;

	struct gameState G;//creating gameState G for new games

	srand(time(NULL));

	printf("Testing adventurer\n\n");//print out to screen which card we are testing 

	for (i = 0; i < MAX_TESTS; i++) 
	{
		//random values to cardEffect arguments
		numPlayers = rand()%5; //gives max of 4 players per game instructions
		if(numPlayers == 0 || numPlayers == 1) numPlayers += 2; //need to have 2-4 players
		curPlayer = rand()%numPlayers;//random number of players 
		seed = rand();//random seed
		choice1 = rand()%2;
		choice2 = rand()%2;
		choice3 = rand()%2;
		handPos = rand()%4;

		initializeGame(numPlayers, k, seed, &G);//initialize game with random number of players, cards, seed an new game 

		//random values to state variables
		G.deckCount[curPlayer] = rand()%MAX_DECK; 
		G.discardCount[curPlayer] = rand()%MAX_DECK;
		G.handCount[curPlayer] = rand()%MAX_HAND;
		deckCount = G.deckCount[curPlayer];//values for after test
		if (seed%3 == 0) G.deckCount[curPlayer] = 0;//checking for empty deck 

		int j;//checking for at least 2 treasure cards 
	    for (j = 0; j < G.handCount[curPlayer]; j++) gainCard(copper, &G, 2, curPlayer);

		r = cardEffect(adventurer, choice1, choice2, choice3, &G, handPos, 0);

		int x, treasure = 0, zero = 0;
		for(x = 0; x < G.handCount[curPlayer]; x++)
		{
			if(G.hand[curPlayer][x] == copper || G.hand[curPlayer][x] == silver || G.hand[curPlayer][x] == gold) treasure++;
			else if(G.hand[curPlayer][x] == 0) zero++; //new hand check
		}

		assert(r == 0);	//assert for cardEffect returned okay

		//treasure not increased by at least two, adventurer card failed
		if(treasure < 2 && zero != G.handCount[curPlayer] && G.handCount[curPlayer] != 0) 
		{
			printf("\tTest failed: treasure count (i = %d)\n", i);
			printf("\t\tG.handCount = %d\ttreasure = %d\n", G.handCount[curPlayer], treasure);
			for(x = 0; x < G.handCount[curPlayer]; x++)
			{
				printf("\tG.hand[curPlayer][x] = %d\n", G.hand[curPlayer][x]);
			}
			printf("\n");

		}

		if(G.handCount[curPlayer] < 0) //negative hand count, then error occured 
		{
			printf("\tTest failed: hand count (i = %d)\n", i);
			printf("\t\tG.handCount = %d\t handCount = %d\n\n", G.handCount[curPlayer], handCount);
		}

		if(deckCount < G.deckCount[curPlayer]+2 && deckCount != G.deckCount[curPlayer] && G.deckCount[curPlayer] != 0)
		{
			printf("\tTest failed: deck count (i = %d)\n", i);
			printf("\t\tG.deckCount = %d\t deckCount = %d\n\n", G.deckCount[curPlayer], deckCount);
		}

	}

	printf("**Test complete.\n");

	return 0;
}
예제 #27
0
int main() {
    int newCards = 0;
    int discarded = 1;
    int xtraCoins = 0;
    int shuffledCards = 0;

    int i, j, m;
    int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
    int remove1, remove2;
    int seed = 1000;
    int numPlayers = 2;
    int thisPlayer = 0;
	int secPlayer = 1;
	struct gameState G, testG;
	int k[10] = {adventurer, embargo, village, minion, mine, cutpurse,
			sea_hag, tribute, smithy, council_room};
	
	// Initialize a game with the steward card in Player 1's hand
	initializeGame(numPlayers, k, seed, &G);
	printf ("\n----------Testing the Steward card's basic requirements:----------\n");

	/*---------------------------------------------------------*/
	printf ("\n---Testing Choice 1: Player Receives 2 new cards---\n");
	memcpy(&testG, &G, sizeof(struct gameState));
	choice1 = 1;
	cardEffect(steward, choice1, choice2, choice3, &testG, handpos, &bonus);
	
	//receiving 2 new cards, no new coins
	newCards = 2;
	xtraCoins = 0;
	printf("hand count = %d, expected = %d\n", testG.handCount[thisPlayer], G.handCount[thisPlayer] + newCards - discarded);
	if(testG.handCount[thisPlayer] != G.handCount[thisPlayer] + newCards - discarded){
		printf("Failure: Hand count is incorrect.");
	}
		
	printf("deck count = %d, expected = %d\n", testG.deckCount[thisPlayer], G.deckCount[thisPlayer] - newCards + shuffledCards);
	if(testG.deckCount[thisPlayer] != G.deckCount[thisPlayer] - newCards + shuffledCards){
		printf("Failure: Deck count is incorrect.");
	}
	
	printf("coins = %d, expected = %d\n", testG.coins, G.coins + xtraCoins);
	if(testG.coins != G.coins + xtraCoins){
		printf("Failure: Coin count is incorrect.");
	}
	/*---------------------------------------------------------*/
	
	printf("\n---Testing Choice 2: Current player Receives 2 coins---\n");
	memcpy(&testG, &G, sizeof(struct gameState));
	choice1 = 2;
	cardEffect(steward, choice1, choice2, choice3, &testG, handpos, &bonus);

	//receiving 2 coins, no new cards
	newCards = 0;
	xtraCoins = 2;
	printf("hand count = %d, expected = %d\n", testG.handCount[thisPlayer], G.handCount[thisPlayer] + newCards - discarded);
	if(testG.handCount[thisPlayer] != G.handCount[thisPlayer] + newCards - discarded){
		printf("Failure: Hand count is incorrect.");
	}
	
	printf("deck count = %d, expected = %d\n", testG.deckCount[thisPlayer], G.deckCount[thisPlayer] - newCards + shuffledCards);
	if(testG.deckCount[thisPlayer] != G.deckCount[thisPlayer] - newCards + shuffledCards){
		printf("Failure: Deck count is incorrect.");
	}
	
	printf("coins = %d, expected = %d\n", testG.coins, G.coins + xtraCoins);
	if(testG.coins != G.coins + xtraCoins){
		printf("Failure: Coin count is incorrect.  Should have received 2 coins.");
	}
	/*---------------------------------------------------------*/

	printf("\n---Testing Choice 3: Player Trashes 2 cards---\n");
	choice1 = 3;

	// cycle through each eligible combination of 2 cards to trash
	for (i=1; i<G.handCount[thisPlayer]; i++) {
		for (j=i+1; j<G.handCount[thisPlayer]; j++) {

			G.hand[thisPlayer][0] = steward;
			G.hand[thisPlayer][1] = copper;
			G.hand[thisPlayer][2] = duchy;
			G.hand[thisPlayer][3] = estate;
			G.hand[thisPlayer][4] = feast;

			memcpy(&testG, &G, sizeof(struct gameState));

			printf("starting cards: ");
			for (m = 0; m < testG.handCount[thisPlayer]; m++) {
				printf("(%d)", testG.hand[thisPlayer][m]);
			}
			printf("; ");

			choice2 = j;
			choice3 = i;
			remove1 = testG.hand[thisPlayer][i];
			remove2 = testG.hand[thisPlayer][j];
			cardEffect(steward, choice1, choice2, choice3, &testG, handpos, &bonus);

			printf("removed: (%d)(%d); ", remove1, remove2);
			printf("ending cards: ");

			// Verify that the trashed cards were removed from the player's hand
			for (m = 0; m < testG.handCount[thisPlayer]; m++) {
				printf("(%d)", testG.hand[thisPlayer][m]);
				assert(testG.hand[thisPlayer][m] != remove1);
				assert(testG.hand[thisPlayer][m] != remove2);
			}
			printf(", expected: ");
			for (m = 1; m < G.handCount[thisPlayer]; m++) {
				if (G.hand[thisPlayer][m] != G.hand[thisPlayer][i] && G.hand[thisPlayer][m] != G.hand[thisPlayer][j]) {
					printf("(%d)", G.hand[thisPlayer][m]);
				}
			}
			printf("\n");

			// Verify that the remaining number of cards is correct
			newCards = 0;
			xtraCoins = 0;
			discarded = 3;
			if (i==1 && j==2) {
				printf("hand count = %d, expected = %d\n", testG.handCount[thisPlayer], G.handCount[thisPlayer] + newCards - discarded);
				if(testG.handCount[thisPlayer] != G.handCount[thisPlayer] + newCards - discarded){
					printf("Failure: Hand count is incorrect.");
				}
				
				printf("deck count = %d, expected = %d\n", testG.deckCount[thisPlayer], G.deckCount[thisPlayer] - newCards + shuffledCards);
				if(testG.deckCount[thisPlayer] != G.deckCount[thisPlayer] - newCards + shuffledCards){
					printf("Failure: Deck count is incorrect.");
				}
			}
		}
	}
	
	/*---------------------------------------------------------*/
	
	printf ("\n----------Testing the Steward card's effect on Player 2:----------\n");
	// Checks whether player 1's Steward card affected player 2's hand count, deck count, or discard count.
	printf("hand count = %d, expected %d\n", testG.handCount[secPlayer], G.handCount[secPlayer]);
	if(testG.handCount[secPlayer] != G.handCount[secPlayer]){
		printf("Failure: Player 2's hand count was modified.\n\n");
	}
	
	printf("deck count = %d, expected %d\n", testG.deckCount[secPlayer], G.deckCount[secPlayer]);
	if(testG.deckCount[secPlayer] != G.deckCount[secPlayer]){
		printf("Failure: Player 2's deck count was modified.\n\n");
	}
	
	printf("discard count = %d, expected %d\n\n", testG.discardCount[secPlayer], G.discardCount[secPlayer]);
	if(testG.discardCount[secPlayer] != G.discardCount[secPlayer]){
		printf("Failure: Player 2's deck count was modified.\n\n");
	}
	printf("---Steward card's testing is complete--- \n\n");
	return 0;
}
예제 #28
0
파일: cardtest2.c 프로젝트: cr8zd/cs362w16
//set-up and initialization based on cardtest4.c, week 4 module CS362W16
int main() {
    int newCards = 0;
    int discarded = 1;
    int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
    int seed = 1000;
    int numPlayers = 2;
    int currentPlayer = 0;
    int nextPlayer = 1;
	int playedCards = 1;
	
	struct gameState G, testG;
	int k[10] = {adventurer, embargo, village, minion, mine, cutpurse,
			sea_hag, tribute, smithy, council_room};

	// initialize a game state and player cards
	initializeGame(numPlayers, k, seed, &G);

	printf("----------------- Testing cardtest2: %s ----------------\n", TESTCARD);

	// ----------- TEST 1: +2 cards --------------
	printf("TEST 1: +2 treasure cards\n");

	// copy the game state to a test case
	memcpy(&testG, &G, sizeof(struct gameState));
	cardEffect(adventurer, choice1, choice2, choice3, &testG, handpos, &bonus);
	newCards = 2;
	
	//check player hand count
	printf("hand count = %d, expected = %d\n", testG.handCount[currentPlayer], G.handCount[currentPlayer] + newCards - discarded);
	if (testG.handCount[currentPlayer] == G.handCount[currentPlayer] + newCards - discarded) 
        printf("PASSED - player hand count matches\n");    
	else 	
        printf("FAILED - player hand count does not match\n");
	
	//check player deck count
	printf("deck count = %d, expected = %d\n", testG.deckCount[currentPlayer], G.deckCount[currentPlayer] - newCards);
	if (testG.deckCount[currentPlayer] == G.deckCount[currentPlayer] - newCards)  
        printf("PASSED - player deck count did not change\n");
    else 
        printf("FAILED - player deck count changed\n");
	
	//check next player hand count
	printf("hand count = %d, expected = %d\n", testG.handCount[nextPlayer], G.handCount[nextPlayer]);
    if (testG.handCount[nextPlayer] == G.handCount[nextPlayer])
        printf("PASSED - next player hand count matches\n");    
	else 	
        printf("FAILED - next player hand count does not match\n");
	
	//check next player deck count
	printf("deck count = %d, expected = %d\n", testG.deckCount[nextPlayer], G.deckCount[nextPlayer]);
	if (testG.deckCount[nextPlayer] == G.deckCount[nextPlayer])  
        printf("PASSED - next player deck count does not change\n");
    else 
        printf("FAILED - next player deck count changed\n");
	
	//check that card is added to played cards count
	printf("played card count = %d, expected = %d\n", testG.playedCardCount, G.playedCardCount + playedCards);
	if (testG.playedCardCount == G.playedCardCount + playedCards)
		printf("PASSED - played card count matches\n");
	else
		printf("FAILED - played card count does not match\n");
	
	/*
	//check that coin amount increased
	if (testG.coins > G.coins)
		printf("PASSED - coin amount increased by %d\n", testG.coins  - G.coins );
	else printf("FAILED - coin amount did not increase\n");
	*/
	
	//check victory card piles
	printf("estate = %d, expected = %d\n", testG.supplyCount[estate], G.supplyCount[estate]);
	if (testG.supplyCount[estate] == G.supplyCount[estate])  
        printf("PASSED - supply count matches\n");
    else 
        printf("FAILED - supply count does not match\n");
	
	printf("duchy = %d, expected = %d\n", testG.supplyCount[duchy], G.supplyCount[duchy]);
	if (testG.supplyCount[duchy] == G.supplyCount[duchy])  
        printf("PASSED - supply count matches\n");
    else 
        printf("FAILED - supply count does not match\n");
	
	printf("province = %d, expected = %d\n", testG.supplyCount[province], G.supplyCount[province]);
	if (testG.supplyCount[province] == G.supplyCount[province])  
        printf("PASSED - supply count matches\n");
    else 
        printf("FAILED - supply count does not match\n");
	
	printf("adventurer card testing completed.\n");
	
	return 0;
}
예제 #29
0
int main (int argc, char** argv)
{
	printf("Random test minion.\n");

	struct gameState G;
	int k[10] = {adventurer, council_room, feast, gardens, mine, 
		remodel, smithy, village, baron, great_hall};

	int cards[17] = {curse, estate, duchy, province, copper, silver,
 	gold, adventurer, council_room, feast, gardens, mine, 
	remodel, smithy, village, baron, minion};

	srand(time(NULL));

	int rand_seed = rand() % 10 + 1;
	int num_players = rand() % 3 + 2;// 2 to 4 players

	initializeGame(num_players, k, rand_seed, &G);

	int player = rand() % num_players;
	G.whoseTurn = player;

	int num_cards_hand = 0;
	int num_cards_deck = 0;
	int num_cards_discard = 0;
	int rand_card = 0;
	int choice1 = 0;
	int temp = 0;
	int minion_pos = 0;
	int old_sum = 0;
	int new_sum = 0;

	int before_hand_count[num_players];
	int before_deck_count[num_players];
	int before_discard_count[num_players];

	for (int a = 0; a < NUM_TESTS; a++)
	{
		G.coins = 0;
		G.numActions = 0;
		for (int n = 0; n < G.numPlayers; n++)
		{
			//Clear hand
			for (int i = 0; i < G.handCount[n]; i++)
			{
				G.hand[n][i] = -1;
			}
			G.handCount[n] = 0;

			//Clear deck
			for (int i = 0; i < G.deckCount[n]; i++)
			{
				G.deck[n][i] = -1;
			}
			G.deckCount[n] = 0;

			//Clear discard pile
			for (int i = 0; i < G.discardCount[n]; i++)
			{
				G.discard[n][i] = -1;
			}
			G.discardCount[n] = 0;

			//Populate hand
			num_cards_hand = rand() % 9 + 2;
			before_hand_count[n] = num_cards_hand;
			G.handCount[n] = num_cards_hand;

			for (int i = 0; i < G.handCount[n]; i++)
			{
				rand_card = rand() % 17;
				G.hand[n][i] = cards[rand_card];
			}

			//Populate deck
			num_cards_deck = rand() % 9 + 2;
			before_deck_count[n] = num_cards_deck;
			G.deckCount[n] = num_cards_deck;
			for (int i = 0; i < G.deckCount[n]; i++)
			{
				rand_card = rand() % 17;
				G.deck[n][i] = cards[rand_card];
			}

			//Populate discard pile
			num_cards_discard = rand() % 9 + 2;
			before_discard_count[n] = num_cards_discard;
			G.discardCount[n] = num_cards_discard;
			for (int i = 0; i < G.discardCount[n]; i++)
			{
				rand_card = rand() % 17;
				G.discard[n][i] = cards[rand_card];
			}
		}


		minion_pos = rand() % G.handCount[player];
		G.hand[player][minion_pos] = minion;

		printf("Playing minion card\n");
		temp = rand() % 4;
		if(temp == 3)
			choice1 = 1;
		else
			choice1 = 2;
				
		int ret_val = cardEffect(minion, choice1, 0, 0, &G, minion_pos,0);

		if(choice1 == 1)
		{
			assert(G.coins == 2 && "Coins != 2");
		}
		else if(choice1 == 2)
		{
			//Check Player
			old_sum = before_hand_count[player] + before_discard_count[player] + before_deck_count[player];
			new_sum = G.handCount[player] + G.discardCount[player] + G.deckCount[player];
			assert(new_sum == old_sum 
				&& "Sum of cards before and after minion card are not equal (Player)");
			
			//Check other players		
			for (int n = 0; n < G.numPlayers; n++)
			{
				if(n != player)
				{
					if(before_hand_count[n] > 4)
					{
						assert(G.handCount[n] == 4 
							&& "Incorrect new handCount");
		
						old_sum = before_hand_count[n] + before_discard_count[n] + before_deck_count[n];
						new_sum = G.handCount[n] + G.discardCount[n] + G.deckCount[n];
						assert(new_sum == old_sum 
							&& "Sum of cards before and after minion card are not equal");
					}
				}
			}
		}
	}
	printf("All tests passed.\n");
}
예제 #30
0
int main() {
    int newCards = 0;
    int discarded = 1;
    int xtraCoins = 0;
    int shuffledCards = 0;
    
    int i, j, m;
    int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
    int remove1, remove2;
    int seed = 1000;
    int numPlayers = 2;
    int thisPlayer = 0;
    struct gameState G, testG;
    int k[10] = {adventurer, embargo, village, minion, mine, cutpurse,
        sea_hag, tribute, smithy, council_room};
    
    // initialize a game state and player cards
    initializeGame(numPlayers, k, seed, &G);
    
    printf("----------------- Testing Card: %s ----------------\n", TESTCARD);
    
    // ----------- TEST 1: +1 card,--------------
    printf("TEST 1: +1 card\n");
    
    // copy the game state to a test case
    memcpy(&testG, &G, sizeof(struct gameState));
    choice1 = 1;
    cardEffect(great_hall, choice1, choice2, choice3, &testG, handpos, &bonus);
    
    newCards = 1;
    xtraCoins = 0;
    printf("hand count = %d, expected = %d\n", testG.handCount[thisPlayer], G.handCount[thisPlayer] + newCards - discarded);
    printf("deck count = %d, expected = %d\n", testG.deckCount[thisPlayer], G.deckCount[thisPlayer] - newCards + shuffledCards);
    printf("coins = %d, expected = %d\n", testG.coins, G.coins + xtraCoins);
    assert(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded);
    assert(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards + shuffledCards);
    assert(testG.coins == G.coins + xtraCoins);
    
    
    // ----------- TEST 2: +1 actions,--------------
    printf("TEST 2: +1 actions\n");
    
    // copy the game state to a test case
    memcpy(&testG, &G, sizeof(struct gameState));
    
    int actionsBackup = testG.numActions;
    
    
    
    choice1 = 1;
    cardEffect(great_hall, choice1, choice2, choice3, &testG, handpos, &bonus);
    
    assert(testG.numActions == actionsBackup + 1);
    
    printf("Number of actions expected: %d\n", actionsBackup + 1);
    printf("Number of actions found: %d\n", testG.numActions);
    
    
    printf("\n >>>>> SUCCESS: Testing complete %s <<<<<\n\n", TESTCARD);
    
    
    return 0;
}