Exemple #1
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 smithy()\n");

	// copy the game state to a test case
	memcpy(&testG, &G, sizeof(struct gameState));
	choice1 = 1;
	cardEffect(smithy, choice1, choice2, choice3, &testG, handpos, &bonus);

	newCards = 3;
	xtraCoins = 0;

	printf("Test 1: player 0 draws the correct number of cards (3 cards)\n");
	if (testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded)
	{
		printf("PASS: test = %d, expected = %d\n", testG.handCount[thisPlayer], G.handCount[thisPlayer] + newCards - discarded);
	}
	else
	{
		printf("FAIL: test = %d, expected = %d\n", testG.handCount[thisPlayer], G.handCount[thisPlayer] + newCards - discarded);
	}
	
	printf("Test 1: correct number of cards in player 0 deck (1 card discarted)\n");
	if (testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards + shuffledCards)
	{
		printf("PASS: test = %d, expected = %d\n", testG.deckCount[thisPlayer], G.deckCount[thisPlayer] - newCards + shuffledCards);
	}
	else
	{
		printf("FAIL: test = %d, expected = %d\n", testG.deckCount[thisPlayer], G.deckCount[thisPlayer] - newCards + shuffledCards);
	}
	printf("Test 2: player 0 draws cards from the correct pile\n");
	if (testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards)
	{
		printf("PASS: test = %d, expected = %d\n", testG.deckCount[thisPlayer],G.deckCount[thisPlayer] - newCards);
	}
	else
	{
		printf("FAIL: test = %d, expected = %d\n", testG.deckCount[thisPlayer],G.deckCount[thisPlayer] - newCards);
	}
	printf("Test 3: player 1 deck remains unchanged\n");
	if (testG.deckCount[1] == G.deckCount[1] )
	{
		printf("PASS: test = %d, expected = %d\n",testG.deckCount[1],G.deckCount[1]);
	}
	else
	{
		printf("FAIL: test = %d, expected = %d\n",testG.deckCount[1],G.deckCount[1]);
	}

	
	printf("\nTesting complete \n\n");

	return 0;
}
Exemple #2
0
int main() {
    int i;
    int j;
    int l;
    //Used to print out correct name of card being tested in printf statement.
    const char* cardNames[] =
    {"curse", "estate", "duchy", "province", "copper", "silver", "gold", "adventurer", "council_room",
      "feast", "gardens", "mine", "remodel", "smithy", "village", "baron", "great_hall", "minion", "steward",
     "tribute", "ambassador", "cutpurse", "embargo", "outpost", "salvager", "sea_hag", "treasure_map" };
    
    int nameCards[MAX_HAND][MAX_HAND];
    int testAllCards;
    int deckCards;
    int handCards;
    int discardCards;
    int seed = 1000;
    int numPlayer = 2;
    int p, r;
    int countCopper = 0;
    int whoseTurnIsIt = 0;
    int smithyFound = 0;
    int supplyCountCheck = 0;
    int treasure[3] = {4,5,6};
    int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
    int pointCards[6] = {0,1,2,3,16,10}; //Used to orginize point cards used
    int pointValue[6] = {-1,1,3,6,1,0}; //Used to orginize the point values that go with pointcards
    int score; //keeps return number for fullDeckCount(p, allCards, &G)
     int k[10] = {adventurer, council_room, feast, gardens, mine
                , remodel, smithy, village, baron, great_hall};
    struct gameState G, testG, sizeS;
    int totalCards = 5;
    //Make Array called nameCards, that holds decks full of same card name
    for (i = 0; i < MAX_HAND; i++) {
       for (j = 0; j < MAX_HAND; j++) {
      nameCards[i][j] = i;
       }
    }
    
    
    printf ("TESTING cutpurse card:\n\n");
    

    
    
    
    
    
    
    
    printf("TEST 1:Current player +2 treasure\n");

       for(numPlayer = 2; numPlayer < 5;numPlayer++) {
         printf("    Testing with %d players\n",numPlayer);
         
         
          memset(&G, 23, sizeof(struct gameState));   // clear the game state
          r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
          
          G.coins = 0;
          
          G.whoseTurn = 0; //player 1s turn
          
          //put 5 treasure cards in deck
          for (i = 0; i < 6; i++) {
            G.deck[0][i] = cutpurse; 
          }

          G.deckCount[0] = 5;
          

          //Fill hand with 5 cutpurse cards
          for (i = 0; i < 6; i++) {
            G.hand[0][i] = cutpurse; //village
          }
          G.handCount[0] = 5;
          
          
          
          
          
          //run card
          handpos = 3, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
          cardEffect(cutpurse, choice1, choice2, choice3, &G, handpos, &bonus);
          

 
          printf("         Player 1 coins = %d,expected 2\n", G.coins);
          if(G.coins != 2)
             printf("            TEST FAILED\n");

       }
       
       
       
       
       
       
       
       printf("TEST 2:Each other player discards a Copper card\n");
      
       for(numPlayer = 2; numPlayer < 5;numPlayer++) {
         printf("    Testing with %d players\n",numPlayer);
         
  
         for( whoseTurnIsIt = 0;  whoseTurnIsIt < numPlayer; whoseTurnIsIt++) {
            printf("       Player %d playing cutpurse card \n",whoseTurnIsIt +1);
                             
             memset(&G, 23, sizeof(struct gameState));   // clear the game state
             r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
             
             G.coins = 0;
             
             G.whoseTurn = whoseTurnIsIt; //current player
             
             //put 5 treasure cards in deck
             for (i = 0; i < 6; i++) {
               G.deck[whoseTurnIsIt][i] = cutpurse; 
             }

             G.deckCount[0] = 5;
             
             
             
             

             //Fill hand with 4 cutpurse cards and 1 copper
             for (i = 0; i < 6; i++) {
               G.hand[whoseTurnIsIt][i] = cutpurse; //village
             }
             G.hand[whoseTurnIsIt][0] = copper;
             G.handCount[whoseTurnIsIt] = 5;
             
             
             //Fill other players hands with 5 copper cards
             for(j=0;j < numPlayer;j++) {
                if(j != whoseTurnIsIt) {
                for (i = 0; i < 6; i++) {
                   G.hand[j][i] = copper; //copper
                }
                G.handCount[j] = 5;
                }
             }
             
             
             
             
             //run card
             handpos = 3, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
             cardEffect(cutpurse, choice1, choice2, choice3, &G, handpos, &bonus);
             
             
             for(j=0; j < numPlayer;j++) {
                //Count copper cards
                countCopper = 0;
                for (i = 0; i < 6; i++) {
                     if(G.hand[j][i] == copper){
                        countCopper++;
                     }
                }

               if(j == whoseTurnIsIt) {
                      printf("          Current player %d copper card, expected 1\n", countCopper);
                      if(countCopper != 1)
                         printf("               TEST FAILED\n");
                      
               }else{
                  
                        printf("           Player %d had %d copper card, expected 4\n", j+1, countCopper);
                         if(countCopper != 4)
                            printf("               TEST FAILED\n");
                     
                 
               }
             }
             
         }
       }
       
       
       
       
       
       printf("TEST 3:If other players don't have a copper, hands should remain the same.\n");
      
       for(numPlayer = 2; numPlayer < 5;numPlayer++) {
         printf("    Testing with %d players\n",numPlayer);
         
  
         for( whoseTurnIsIt = 0;  whoseTurnIsIt < numPlayer; whoseTurnIsIt++) {
            printf("       Player %d playing cutpurse card \n",whoseTurnIsIt +1);
                             
             memset(&G, 23, sizeof(struct gameState));   // clear the game state
             r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
             
             G.coins = 0;
             
             G.whoseTurn = whoseTurnIsIt; //current player
             
             //put 5 treasure cards in deck
             for (i = 0; i < 6; i++) {
               G.deck[whoseTurnIsIt][i] = cutpurse; 
             }

             G.deckCount[0] = 5;
             
             
             
             

             //Fill hand with 4 cutpurse cards and 1 copper
             for (i = 0; i < 6; i++) {
               G.hand[whoseTurnIsIt][i] = cutpurse; //village
             }
             G.hand[whoseTurnIsIt][0] = copper;
             G.handCount[whoseTurnIsIt] = 5;
             
             
             //Fill other players hands with 5 village cards
             for(j=0;j < numPlayer;j++) {
                if(j != whoseTurnIsIt) {
                for (i = 0; i < 6; i++) {
                   G.hand[j][i] = village; //village
                }
                G.handCount[j] = 5;
                }
             }
             
             
             
             
             //run card
             handpos = 3, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
             cardEffect(cutpurse, choice1, choice2, choice3, &G, handpos, &bonus);
             
             
             for(j=0; j < numPlayer;j++) {

               if(j == whoseTurnIsIt) {
                      // printf("          Current player hand count %d, expected 1\n", G.handCount[j]);
                      // if(countCopper != 1)
                         // printf("               TEST FAILED\n");
                      
               }else{
                  
                        printf("           Player %d had %d copper card, expected 5\n", j+1, G.handCount[j]);
                        assert(G.handCount[j] == 5);
                         

               }
             }
        

        
         }
       }
       
       
       
       
       
       printf("TEST 4: Card supply is unaffected when played.\n");
      
       for(numPlayer = 2; numPlayer < 5;numPlayer++) {
         printf("    Testing with %d players\n",numPlayer);
         
  
         for( whoseTurnIsIt = 0;  whoseTurnIsIt < numPlayer; whoseTurnIsIt++) {
            printf("       Player %d playing cutpurse card \n",whoseTurnIsIt +1);
                             
             memset(&G, 23, sizeof(struct gameState));   // clear the game state
             r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
             
             G.coins = 0;
             
             G.whoseTurn = whoseTurnIsIt; //current player
             
             //put 5 treasure cards in deck
             for (i = 0; i < 6; i++) {
               G.deck[whoseTurnIsIt][i] = cutpurse; 
             }

             G.deckCount[0] = 5;
             
             
             
             

             //Fill hand with 4 cutpurse cards and 1 copper
             for (i = 0; i < 6; i++) {
               G.hand[whoseTurnIsIt][i] = cutpurse; //village
             }
             G.hand[whoseTurnIsIt][0] = copper;
             G.handCount[whoseTurnIsIt] = 5;
             
             
             //Fill other players hands with 5 village cards
             for(j=0;j < numPlayer;j++) {
                if(j != whoseTurnIsIt) {
                for (i = 0; i < 4; i++) {
                   G.hand[j][i] = village; //village
                }
                G.handCount[j] = 3;
                }
             }
             
             //SUPPLY COUNT BEFORE
             memcpy(sizeS.supplyCount, G.supplyCount, sizeof(G.supplyCount));   // clear the game state
             
             
             //run card
             handpos = 3, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
             cardEffect(cutpurse, choice1, choice2, choice3, &G, handpos, &bonus);
             
             
             supplyCountCheck = memcmp(sizeS.supplyCount, G.supplyCount, sizeof(G.supplyCount));
             printf("    Total memcmp is %d,expected 0\n", supplyCountCheck);
             assert(supplyCountCheck == 0);
        

        
         }
       }
     
     
     
/*      printf("TEST 2: Actions increased by 2.\n");

       
       memset(&G, 23, sizeof(struct gameState));   // clear the game state
       r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
       
       
       G.whoseTurn = 0; //player 1s turn
       
       //put 5 treasure cards in deck
       for (i = 0; i < 6; i++) {
         G.deck[0][i] = copper; 
       }

       G.deckCount[0] = 5;
       

       //Fill hand with 5 village cards
       for (i = 0; i < 6; i++) {
         G.hand[0][i] =village; //village
       }
       G.handCount[0] = 5;
       
       //Set actions to 1
       G.numActions = 1;
       
       //run card
       handpos = 3, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
       cardEffect(village, choice1, choice2, choice3, &G, handpos, &bonus);
       

       
       printf("     Current Actions %d ,expected 3\n", G.numActions);
       assert(G.numActions == 3);
       
     printf("TEST 3: Increase current players hand +1 card and +2 actions with different player sizes.\n");

       
       for(numPlayer = 2; numPlayer < 5;numPlayer++) {
       printf("    Testing with %d players\n",numPlayer);
       
       
          memset(&G, 23, sizeof(struct gameState));   // clear the game state
          r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
          
          
          G.whoseTurn = 0; //player 1s turn
          
          //put 5 treasure cards in deck
          for (i = 0; i < 6; i++) {
            G.deck[0][i] = copper; 
          }

          G.deckCount[0] = 5;
          

          //Fill hand with 5 village cards
          for (i = 0; i < 6; i++) {
            G.hand[0][i] =village; //village
          }
          G.handCount[0] = 5;
          
          //Set actions to 1
          G.numActions = 1;
          
          //run card
          handpos = 3, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
          cardEffect(village, choice1, choice2, choice3, &G, handpos, &bonus);
          

          
          printf("     Current Actions %d ,expected 3\n", G.numActions);
          if(G.numActions != 3) {
            printf("       TEST FAIL\n");
          };
          printf("     Total %d cards in hand,expected 5\n", G.handCount[0]);
          assert(G.handCount[0] == 5);
       
       }
       
       
       
       
       
       
       printf("TEST 4: Play village card when players deck is empty.\n");

       
       for(numPlayer = 2; numPlayer < 5;numPlayer++) {
       printf("    Testing with %d players\n",numPlayer);
       
       
          memset(&G, 23, sizeof(struct gameState));   // clear the game state
          r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
          
          
          G.whoseTurn = 0; //player 1s turn
          
          //put 5 treasure cards in deck
          // for (i = 0; i < 6; i++) {
            // G.deck[0][i] = copper; 
          // }

          G.deckCount[0] = 0;
          

          //Fill hand with 5 village cards
          for (i = 0; i < 6; i++) {
            G.hand[0][i] =village; //village
          }
          G.handCount[0] = 5;
          
          //Set actions to 1
          G.numActions = 1;
          
          
          
          //Fill discard deck with 5 copper cards
          for (i = 0; i < 6; i++) {
            G.discard[0][i] = copper; //copper
          }
          G.discardCount[0] = 5;
          
          
          
          
          //run card
          handpos = 3, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
          cardEffect(village, choice1, choice2, choice3, &G, handpos, &bonus);
          

          
          printf("     Current deck count %d, hand count %d, and actions %d;expected 4,5,&3\n", G.deckCount[0], G.handCount[0],G.numActions);
       if(G.deckCount[0] != 4 || G.handCount[0] != 5 || G.numActions != 3 ) {
            printf("       TEST FAIL\n");
          };
     
       
       } */
       
       
       
       
 
    
    
    

    return 0;
}
Exemple #3
0
int main()
{
    //gs1 will hold state after initialization, gs2 will be state after draw card
    struct gameState *gs1 = malloc(sizeof(struct gameState));
    struct gameState *gs2 = malloc(sizeof(struct gameState));
    //Cards used in test instance of game
    int gameCards[10] = {smithy, adventurer, council_room, feast, gardens, mine, remodel,
        village, baron, great_hall};
    int numPlayers;
    int numCards = 10;
    int seed = 100;
    int i, j;           //Index variables
    int activePlayerPass = 1;
    int nonActivePlayerPass = 1;
    
    //Test discardCard() for all players in all game sizes
    printf("Beginning tests for discardCard().\n");
    for (numPlayers = 2; numPlayers <= 4; numPlayers++)
    {
        //Initialize a game
        if (initializeGame(numPlayers, gameCards, seed, gs1) == -1)
        {
            printf("Game state failed to initialize. No testing completed.\n");
            return -1;
        }
        
        //Test for each player in game
        for (i = 0; i < numPlayers; i++ )
        {
            //Test for each card in hand
            for (j = 0; j < gs1->handCount[i]; j++)
            {
                //Make copy of current game state to use in comparison testing
                memcpy(gs2, gs1, sizeof(struct gameState));
                
                //Card to discard will be randomly chosen
                int handPos = rand() % 3;
                int player = gs1->whoseTurn;
                
                if (discardCard(handPos, player, gs1, 0) == -1)
                {
                    printf("Error in call to drawCard() for player %d on card % in hand.\n", i, j);
                }
                else
                {
                    if (testDiscardPlayer(player, gs2, gs1) == -1)
                    {
                        activePlayerPass = -1;
                    }
                    if (testNonDiscardPlayers(player, gs2, gs1) == -1)
                    {
                        nonActivePlayerPass = 1;
                    }
                }
                
                //Return game state to condition before call to function for next test
                memcpy(gs1, gs2, sizeof(struct gameState));
            }
            if (activePlayerPass != -1)
                printf ("PASS all tests for player %d in %d player game.\n", i + 1, numPlayers);
        }
        if (nonActivePlayerPass != -1)
            printf ("PASS all tests for non-discarding players in %d player game.\n", numPlayers);
    }
    
    //Test special cases of drawCard()
    //Trash flag is set to 1
    printf("Beginning test for special case where trash flag is set to 1.\n");
    for (numPlayers = 2; numPlayers <= 4; numPlayers++)
    {
        if (initializeGame(numPlayers, gameCards, seed, gs1) == -1)
        {
            printf("Game state failed to initialized. Testing with trashFlag = 1 aborted.\n");
            return -1;
        }
        memcpy(gs2, gs1, sizeof(struct gameState));
               
        //Card to discard will be randomly chosen
        int handPos = rand() % 3;
        int player = gs1->whoseTurn;
       
        if (discardCard(handPos, player, gs1, 1) == -1)
        {
            printf("Error in call to drawCard() for player %d on card % in hand.\n", i, j);
        }
        else
        {
            //Increment playedCardCount for test purposes. Any error will still be caught
            gs1->playedCardCount++;
            
            if (testDiscardPlayer(player, gs2, gs1) == -1)
                activePlayerPass = -1;
            if (testNonDiscardPlayers(player, gs2, gs1) == -1)
                nonActivePlayerPass = 1;
        }
        
        if (activePlayerPass != -1)
               printf("PASS all tests for discarding player in %d person game.\n", numPlayers);
        if (nonActivePlayerPass != -1)
               printf("PASS all tests for non-discarding players in %d person game.\n", numPlayers);
               
       
       //Return game state to condition before call to function for next test
       memcpy(gs1, gs2, sizeof(struct gameState));
    }
    
    //Player only has one card in hand
    printf("Beginning test for special case where player has only one card in hand.\n");
    for (numPlayers = 2; numPlayers <= 4; numPlayers++)
    {
        if (initializeGame(numPlayers, gameCards, seed, gs1) == -1)
        {
            printf("Game state failed to initialized. Testing with trashFlag = 1 aborted.\n");
            return -1;
        }
        
        //Card to discard will be randomly chosen
        int handPos = rand() % 3;
        int player = gs1->whoseTurn;
        //Player only has one card
        gs1->handCount[player] = 1;
        
        memcpy(gs2, gs1, sizeof(struct gameState));
               
        if (discardCard(handPos, player, gs1, 0) == -1)
        {
            printf("Error in call to drawCard() for player %d on card % in hand.\n", i, j);
        }
        else
        {
            if (testDiscardPlayer(player, gs2, gs1) == -1)
            {
                activePlayerPass = -1;
            }
            if (testNonDiscardPlayers(player, gs2, gs1) == -1)
            {
                nonActivePlayerPass = 1;
            }
        }
                          
        if (activePlayerPass != -1)
        {
            printf("PASS all tests for discarding player in %d person game.\n", numPlayers);
        }
        if (nonActivePlayerPass != -1)
        {
            printf("PASS all tests for non-discarding players in %d person game.\n", numPlayers);
        }
               
        //Return game state to condition before call to function for next test
        memcpy(gs1, gs2, sizeof(struct gameState));
    }
    
    return 0;
}
int main() {
	int k[10] = {0,0,0,0,0,0,0,0,0,0};
	time_t t;
	srand((unsigned) time(&t));	
	int i, j, players, seed;
	struct gameState state;
        int card = 0;
	FILE *fp;
	char name[100];
	//Set number of players between two and four	
	players = rand() % 3 + 2;
	state.numPlayers = players;	
	  
	  //set random seed 
	seed = rand();		
	
	 //intialize kingdom cards and supply
	int same = 0;
	for(i = 0; i < 10; i++){
		card = rand() % 20 + adventurer;
		for(j = 0; j < 10; j++){
			if(card == k[j]){
				same = 1;
				break;
			}
			else{
			 same = 0;	
			}	
		}
		if(same){
			i--;	
		} 	
		else{
			k[i] = card;
		}
	}
		
	initializeGame(players, k, seed,&state);
	fp = fopen("gameResults.out", "w");
	fprintf(fp,"After Initalization\n");
	printf("After Initalization\n");
	fclose(fp);


	int hc = 0;
	struct trackers track; 

	int cardToBuy = 0;
	int choice1, choice2, choice3;
	int coinBonus;	
	while(!isGameOver(&state)){
		coinBonus = 0;	
		fp = fopen("gameResults.out", "a");
		printf("--------TURN %d--------\n",track.turns);	
		fprintf(fp, "--------TURN %d--------\n",track.turns);
//		print_Supply(&state);	
		fclose(fp);

		track.hasAction = 0;
		track.ableToPlay = -1;
		track.cardPlace = 0;
		card = 0;
	
		i = state.whoseTurn;
		track.hasAction = 0;
		printPlayerInfo(i,&state);
		printPlayerInfoGR(i,&state);
		printGameInfo(i,&state);
		
		//Determine if they have an action
		for(j = 0; j < state.handCount[i]; j++){
			card = state.hand[i][j];
			if(card >= adventurer && card <= treasure_map){
				track.hasAction = 1;
				track.cardPlace = j;
				cardNumToName(card,name);
//				printf("%s is >= %d and <= %d\n",name, adventurer, treasure_map);
				break;
			}
	//		printf("Looking at card %d\n",card);
		}
		
		if(track.hasAction){
			printf("Player has at least one action card to start\n");
			fp = fopen("gameResults.out", "a");
			fprintf(fp,"Player has at least one action card to start\n");
			fclose(fp);
		}	
		//play Actions
		while (state.numActions > 0 && track.hasAction){
			choice1 = rand() % state.handCount[i];
			choice2 = rand() % 20 + adventurer;
			choice3 = rand() % 20 + adventurer;
					

			printf("Card to Play %s\n",name);
			fp = fopen("gameResults.out", "a");
			fprintf(fp,"Card to play: %s\n",name);
			fclose(fp);

			//protection against the feast infinite loop
	//		if(card == feast){
	//			printf("You are trying to play a feast. There is an infinite loop in most dominion implementations\n");
	//			discardCard(track.cardPlace,i, &state,0); 
	//		}
			//try to play the card
	//		else{	
				track.ableToPlay = playCard(track.cardPlace,choice1,choice2,choice3,&state);
	//		}
			//the card will return a -1 if their is an error
			//trying to play the card  
			if(track.ableToPlay == -1){
				printf("You cannot play that card\n");
				fp = fopen("gameResults.out", "a");
				fprintf(fp,"You cannot play that card: %d\n",state.numActions);
				fclose(fp);
				discardCard(track.cardPlace,i, &state,0); 
			}

			printf("Actions after playing card %d\n",state.numActions);	
			fp = fopen("gameResults.out", "a");
			fprintf(fp,"Game after playing card: %d\n",state.numActions);
			fclose(fp);

			printf("Hand after: ");
			for(hc = 0; hc < state.handCount[i]; hc++){
				printf("%d, ",state.hand[i][hc]);	
			}
			printf("\n");
			//don't keep looking for actions if their used up	
			if (state.numActions <= 0){
				break;
			}
			//otherwise, try to look for another action to play
			card = lookForAction(i,&state, &track);
			cardNumToName(card,name);	
			if(track.hasAction){
				printf("Player has at least one action card\n");
			}	
		}

		coinBonus = state.coins;
		fp = fopen("gameResults.out", "a");
		fprintf(fp,"Player %d has %d coin now\n",i+1,state.coins);
		fclose(fp);
		tryBuyCard(&state);
		fp = fopen("gameResults.out", "a");
		fprintf(fp,"Player %d has %d coin now after buy\n",i+1,state.coins);
		fclose(fp);
		//Entering the Buy Phase
		//pick a card to try to buy
	
		//Game info after the play 
		printPlayerInfoGR(i,&state);
		printGameInfo(i,&state);
		fp = fopen("gameResults.out", "a");
		for(i = 0; i < state.numPlayers; i ++){
			fprintf(fp,"score for player %d: %d\n",i+1, scoreFor(i, &state));
			track.estateScore = track.duchyScore = track.provinceScore = 0;
			for(j = 0; j < state.handCount[i]; j++){
				card  = state.hand[i][j];
				if(card == estate){
					track.estateScore ++;
				}
				else if(card == duchy){
					track.duchyScore ++;
				}
				else if(card == province){
					track.provinceScore ++;
				}	
			} 	
			for(j = 0; j < state.deckCount[i]; j++){
				card  = state.deck[i][j];
				if(card == estate){
					track.estateScore ++;
				}
				else if(card == duchy){
					track.duchyScore ++;
				}
				else if(card == province){
					track.provinceScore ++;
				}
			}	
			for(j = 0; j < state.discardCount[i]; j++){
				card  = state.discard[i][j];
				if(card == estate){
					track.estateScore ++;
				}
				else if(card == duchy){
					track.duchyScore ++;
				}
				else if(card == province){
					track.provinceScore ++;
				}	
			}
			fprintf(fp,"estate %d, duchy %d, province %d \n",track.estateScore, track.duchyScore, track.provinceScore);
		}
		fclose(fp);		
	  


		//turn is over
		endTurn(&state);
		track.turns ++;
	}
	//when the Game is Over, print out the scores		
	for(i = 0; i < state.numPlayers; i ++){
		printf("score for player %d: %d\n",i+1, scoreFor(i, &state));	
	}		
	  
	printf("Tests Complete\n");
	return 0;
}
Exemple #5
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: Current player receives two cards, both of which are treasure cards --------------
	printf("TEST 1: Current player receives two cards, both of which are treasure cards\n\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;
	xtraCoins = 0;

	printf("hand count = %d, expected = %d\n", testG.handCount[thisPlayer], G.handCount[thisPlayer] + newCards - discarded);
	//Assert fails- Player has one too many cards on hand
	//assert(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded);

	int treasureCardsTest = 0;
	int treasureCardsCopy = 0;

	for (i = 0; i < testG.handCount[thisPlayer]; i++)
	{
		if ((testG.hand[thisPlayer][i] == copper) || (testG.hand[thisPlayer][i] == silver) || (testG.hand[thisPlayer][i] == gold))
		{
			treasureCardsTest++;
		}
	}

	for (i = 0; i < G.handCount[thisPlayer]; i++)
	{
		if ((G.hand[thisPlayer][i] == copper) || (G.hand[thisPlayer][i] == silver) || (G.hand[thisPlayer][i] == gold))
		{
			treasureCardsCopy++;
		}
	}

	printf("treasure cards on hand = %d, expected = %d\n", treasureCardsTest, (treasureCardsCopy + 2));
	assert(treasureCardsTest == (treasureCardsCopy + 2));


	printf("\n");
	// ----------- TEST 2: No state change for other players --------------
	printf("TEST 2: No state change for other players\n\n");

	for (i = 0; i < MAX_PLAYERS; i++)
	{
		if (i != thisPlayer)
		{
			if (i >= numPlayers)
			{
				printf("Note: Player not currently in use.\n");
			}

			printf("Asserting here that cards in player %d's hand haven't changed.\n", i);
			for (j = 0; j < MAX_HAND; j++)
			{
				assert(testG.hand[i][j] == G.hand[i][j]);
			}

			printf("Player %d: hand count = %d, expected = %d\n", i, testG.handCount[i], G.handCount[i]);
			assert(testG.handCount[i] == G.handCount[i]);

			printf("Asserting here that cards in player %d's deck haven't changed.\n", i);
			for (j = 0; j < MAX_DECK; j++)
			{
				assert(testG.deck[i][j] == G.deck[i][j]);
			}

			printf("Player %d: deck count = %d, expected = %d\n", i, testG.deckCount[i], G.deckCount[i]);
			assert(testG.deckCount[i] == G.deckCount[i]);

			printf("Asserting here that cards in player %d's discard pile haven't changed.\n", i);
			for (j = 0; j < MAX_DECK; j++)
			{
				assert(testG.discard[i][j] == G.discard[i][j]);
			}

			printf("Player %d: discard count = %d, expected = %d\n", i, testG.discardCount[i], G.discardCount[i]);
			assert(testG.discardCount[i] == G.discardCount[i]);
			printf("\n");
		}
	}

	printf("\n");
	// ----------- TEST 3: No state changes for victory card piles & kingdom card piles --------------
	printf("TEST 3: No state changes for victory card piles & kingdom card piles\n\n");

	for(i = 0; i < (treasure_map + 1); i++)
	{
		printf("Card %d: supply count = %d, expected = %d\n", i, testG.supplyCount[i], G.supplyCount[i]);
		assert(testG.supplyCount[i] == G.supplyCount[i]);
	}

	printf("\n");

	for(i = 0; i < (treasure_map + 1); i++)
	{
		printf("Card %d: embargo tokens = %d, expected = %d\n", i, testG.embargoTokens[i], G.embargoTokens[i]);
		assert(testG.embargoTokens[i] == G.embargoTokens[i]);
	}

	printf("\n");
	// ----------- TEST 4: All cards drawn should be discarded (put in played cards) except for the two treasure cards --------------
	printf("TEST 4: All cards drawn should be discarded except for the two treasure cards\n\n");

	// copy the game state to a test case 
	memcpy(&testG, &G, sizeof(struct gameState));

	//setting two adventurer cards, so player draws something other than coins.
	testG.deck[thisPlayer][testG.deckCount[thisPlayer] - 1] = 7;
	testG.deck[thisPlayer][testG.deckCount[thisPlayer] - 2] = 7;

	cardEffect(adventurer, choice1, choice2, choice3, &testG, handpos, &bonus);

	printf("discarded cards = %d, expected = %d\n", testG.discardCount[thisPlayer], (G.deckCount[thisPlayer] - testG.deckCount[thisPlayer] - 2));
	//Assert fails: too many cards in discard pile
	//assert(testG.playedCardCount == (G.deckCount[thisPlayer] - testG.deckCount[thisPlayer] - 2));


	printf("\n");
	// ----------- TEST 5: No treasure cards should be discarded--------------
	printf("TEST 5: No treasure cards should be discarded\n\n");

	printf("Asserting that no discarded cards are treasure cards\n");
	for (i = 0; i < testG.discardCount[thisPlayer]; i++)
	{
		assert((testG.discard[thisPlayer][i] != copper) && (testG.discard[thisPlayer][i] != silver) && (testG.discard[thisPlayer][i] != gold));
	}


	printf("\n >>>>> SUCCESS: Testing complete %s <<<<<\n\n", TESTCARD);

	return 0;
}
Exemple #6
0
int main()
{

        printf("This is testing the get cost function\n");
        int seed = 1000;
        int numPlayer = 2;

        int p, r, handCount;

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

        p =0;
        handCount=1;

        memset(&G, 23, sizeof(struct gameState));

        r = initializeGame(numPlayer, k, seed, &G);
	//initializing a new game

        G.handCount[p] = handCount;

        if(r==-1)
        {
                exit(0);
        }

	//testing for a normal value
	int i;

        i = getCost(2);
        if (i==5)
	{
	printf("This test passed.\n");
	}
        else
	printf("This test failed.\n");
	
	//testing if value is above any card level value

	int v;
	v = getCost(30);
	if (v==-1)
	{
	 printf("This test passed.\n");
        }
        else
        printf("This test failed.\n");
	//testing another value
	v = getCost(10);
	        if (v==4)
        {
         printf("This test passed.\n");
        }
        else
        printf("This test failed.\n");

        //one more test to make sure the correct
        //value is returned 
        v = getCost(25);
        if (v!=6)
        {
         printf("This test passed.\n");
        }
        else
        printf("This test failed.\n");

        return 0;
}
Exemple #7
0
int main() {

	srand(time(NULL));
	int gameSeed = rand() % 1000 + 1;
	int p = 0; //player 1
	int numPlayer = 4;
	int k[10] = {adventurer, council_room, feast, gardens, mine,
				 remodel, smithy, village, baron, great_hall};

	struct gameState* GS = newGame();

	initializeGame(numPlayer, k, gameSeed, GS);

	GS->hand[p][4] = great_hall; //5th card in hand is great_hall

	printf("Playing Great Hall card and testing...\n");

	/*Checking handcount and cards in hand before playing great_hall*/
	printf("Hand count before Great Hall is %d...\n", GS->handCount[p]);
	int i = 0, cardStatus;
	char c[25];
	for(i = 0; i < GS->handCount[p]; i++){
		cardNumToName(GS->hand[p][i], c);	//Converts card number to string
		printf( "%s, ", c);
		if(strcmp(c, "Great Hall") == 0){
			cardStatus = 1;	//Card is present in hand
		}
	}

	/*Check if great_hall card is in hand before use*/
	if(cardStatus == 1){
		printf("\nTest PASSED, card is present in player %d's hand\n\n", p);
	} else {
		printf("\nTest FAILED, card is NOT present in player %d's hand\n\n", p);
	}

	great_hallCard(p, GS, 4);	//Play great_hall card

	cardStatus = 0; //Reset to zero

	/*Checking handcount and cards in hand after playing village*/
	printf("Hand count after Great Hall is %d...\n", GS->handCount[p]);
	for(i = 0; i < GS->handCount[p]; i++){
		cardNumToName(GS->hand[p][i], c);	//Converts card number to string
		printf( "%s, ", c);
		if(strcmp(c, "Great Hall") == 0){
			cardStatus = 1;	//Card is present in hand
		}
	}

	/*Check if great_hall card is in hand*/
	if(cardStatus == 0){
		printf("\nTest PASSED, card is NOT present in player %d's hand\n\n", p);
	} else {
		printf("\nTest FAILED, card is present in player %d's hand\n\n", p);
	}

	printf("Testing for correct number of cards drawn...\n");
	/*Check current state player's handcount +1 cards after discard is 5 cards*/
	if(GS->handCount[p] == 5){
		printf("Test PASSED, Player %d drew +1 cards\n\n", p);
	} else {
		printf("Test FAILED, Player %d drew incorrect amount of cards\n\n", p);
	}

	printf("Testing for correct number of actions...\n");
	/*Check if numActions is incremented*/
	if(GS->numActions == 2){
		printf("Test PASSED, Player %d has +1 numActions\n\n", p);
	} else {
		printf("Test FAILED, Player %d has incorrect number of numActions\n\n", p);
	}

	printf("Checking if card is in played pile...\n");
	/*Check if card is in played pile*/
	if(GS->playedCards[p] == great_hall){
		printf("Test PASSED, Great Hall is in played pile\n\n");
	} else {
		printf("Test FAILED, Great Hall is NOT in played pile\n\n");
	}

	return 0;

}
Exemple #8
0
int main()
{
    const char* funcName = "scoreFor()";
    struct gameState* game = newGame();
    int* cardsInPlay = kingdomCards(adventurer, baron, smithy, mine, remodel, feast, steward, village, salvager, treasure_map);

    if(initializeGame(2, cardsInPlay, time(NULL), game) == -1)
    {
        printf("Couldn't intialize game!\n");
        exit(0);
    }

    int thisPlayer = whoseTurn(game);
    int otherPlayer = whoseTurn(game)^1;

    printf("**************Starting test on method: %s**************\n\n", funcName);
    // Initial Test to see if there are unexpected changes to the game
    struct gameState* initialState = malloc(sizeof(struct gameState));
    memcpy(initialState, game, sizeof(struct gameState));

    // Each player starts with three estate cards, so their score should be 3
    if( scoreFor(thisPlayer, game) != 3)
        printf("Error -%s shows this player's initial score is not 3!\n", funcName);

    /* Begin testing for unexpected changes in game state */
    if( initialState->numPlayers != game->numPlayers )
        printf("Error -%s changed the number of players!\n", funcName);

    int i;        // There are 26 possible cards, make sure the same are still in play
    for(i=0; i<=26; i++)
    {
        if( initialState->supplyCount[i] != game->supplyCount[i] )
        {
            if(i != adventurer)
                printf("Error -%s changed the number of other kingdom cards!\n", funcName);
        }
    }
    for(i=0; i<=26; i++)
    {
        if(initialState->embargoTokens[i] != game->embargoTokens[i])
            printf("Error -%s changed the Embargo Tokens in play!\n", funcName);
    }
    if( initialState->outpostPlayed != game->outpostPlayed)
        printf("Error -%s changed the \"Outpost Played\" status!\n", funcName);
    if( initialState->outpostTurn != game->outpostTurn)
        printf("Error -%s changed the \"Outpost Turn\" status!\n", funcName);
    if( initialState->whoseTurn != game->whoseTurn)
        printf("Error -%s changed the whose turn it is!\n", funcName);
    if( initialState->phase != game->phase)
        printf("Error -%s changed the game phase!\n", funcName);
    if( initialState->numActions != game->numActions)
        printf("Error -%s changed the number of actions for this turn!\n", funcName);
    if( initialState->coins != game->coins)
        printf("Error -%s changed the \"coins\" variable!\n", funcName);
    if( initialState->numBuys != game->numBuys)
        printf("Error -%s changed the number of Buy phases available!\n", funcName);
    if( initialState->handCount[thisPlayer] != game->handCount[thisPlayer])
        printf("Error -%s changed the number of cards in this player's hand!\n", funcName);
        // Toggle the bit to check for the other player's hand
    if( initialState->handCount[otherPlayer] != game->handCount[otherPlayer])
        printf("Error -%s changed the number of cards in the other player's hand!\n", funcName);

    for(i=0; i< game->handCount[thisPlayer]; i++)
    {
        if( initialState->hand[thisPlayer][i] != game->hand[thisPlayer][i])
            printf("Error -%s changed the cards in this player's hand!\n(If turn isn't changed)\n", funcName);
    }
    for(i=0; i<game->handCount[otherPlayer]; i++)
    {
        if( initialState->hand[otherPlayer][i] != game->hand[otherPlayer][i])
            printf("Error -%s changed the cards in the other player's hand!\n(If turn isn't changed)\n", funcName);
    }

    if(initialState->deckCount[thisPlayer] != game->deckCount[thisPlayer])
        printf("Error -%s changed the deck count for this player!\n", funcName);
    if(initialState->deckCount[otherPlayer] != game->deckCount[otherPlayer])
        printf("Error -%s changed the deck count for the other player!\n", funcName);


    for(i=0; i<game->deckCount[thisPlayer]; i++)
    {
        if(initialState->deck[thisPlayer][i] != game->deck[thisPlayer][i])
            printf("Error -%s changed the contents of this player's deck!\n", funcName);
    }
    for(i=0; i<game->deckCount[otherPlayer]; i++)
    {
        if(initialState->deck[otherPlayer][i] != game->deck[otherPlayer][i])
            printf("Error -%s changed the contents of the other player's deck!\n", funcName);
    }

    if(game->discardCount[thisPlayer] != initialState->discardCount[thisPlayer])
        printf("Error -%s changed the count for this player's discard pile!\n", funcName);
    if(initialState->discardCount[otherPlayer] != game->discardCount[otherPlayer])
        printf("Error -%s changed the count of the other player's discard pile!\n", funcName);


    for(i=0; i<initialState->discardCount[thisPlayer]; i++)
    {
        if(initialState->discard[thisPlayer][i] != game->discard[thisPlayer][i])
            printf("Error -%s changed the contents of this player's discard!\n", funcName);
    }
    for(i=0; i<game->discardCount[otherPlayer]; i++)
    {
        if(initialState->discard[otherPlayer][i] != game->discard[otherPlayer][i])
            printf("Error -%s changed the contents of the other player's discard!\n", funcName);
    }

    if(initialState->playedCardCount != game->playedCardCount)
        printf("Error -%s changed the count of played cards!\n", funcName);

    for(i=0; i<game->playedCardCount; i++)
    {
        if(initialState->playedCards[i] != game->playedCards[i])
            printf("Error -%s changed the cards in the \"Played Cards\" stack!\n", funcName);
    }

    /* End testing for unexpected changes in game state */

    // Testing for scores in the cards in hand.  Set all cards to copper and
    // record the score to compare against.
    for(i=0; i<5; i++)
        game->hand[thisPlayer][i] = copper;
    int previousScore = scoreFor(thisPlayer, game);
    game->hand[thisPlayer][0] = curse;
    if( scoreFor(thisPlayer, game) != previousScore - 1 )
        printf("Error -%s didn't properly subtract for a curse card in hand!\n", funcName);

    previousScore = scoreFor(thisPlayer, game);
    game->hand[thisPlayer][1] = estate;
    if( scoreFor(thisPlayer, game) != previousScore + 1 )
        printf("Error -%s didn't properly add for an estate card in hand!\n", funcName);

    previousScore = scoreFor(thisPlayer, game);
    game->hand[thisPlayer][2] = duchy;
    if( scoreFor(thisPlayer, game) != previousScore + 3 )
        printf("Error -%s didn't properly add for a duchy card in hand!\n", funcName);

    previousScore = scoreFor(thisPlayer, game);
    game->hand[thisPlayer][3] = province;
    if( scoreFor(thisPlayer, game) != previousScore + 6 )
        printf("Error -%s didn't properly add for a province card!\n", funcName);

    previousScore = scoreFor(thisPlayer, game);
    game->hand[thisPlayer][4] = great_hall;
    if( scoreFor(thisPlayer, game) != previousScore + 1 )
        printf("Error -%s didn't properly add for a duchy card in hand!\n", funcName);

    // Reset to score 0 for hand
    for(i=0; i<game->handCount[thisPlayer]; i++)
        game->hand[thisPlayer][i] = copper;
    previousScore = scoreFor(thisPlayer, game);

    //Should have 10 cards (none gained or trashed), so gardens should add 1
    game->hand[thisPlayer][0] = gardens;
    if( scoreFor(thisPlayer, game) != previousScore + 1 )
        printf("Error -%s didn't properly add 1 to score for a gardens card in hand!\n", funcName);

    // Trash a copper from the hand and gardens should add none
    previousScore = scoreFor(thisPlayer, game);
    game->hand[thisPlayer][game->handCount[thisPlayer]] = -1;
    game->handCount[thisPlayer]--;

    if( scoreFor(thisPlayer, game) != previousScore - 1)
        printf("Error -%s didn't properly add 0 to score for a gardens card in hand!\n", funcName);

    // Add it back for ease of testing (even 10 cards)
    game->hand[thisPlayer][game->handCount[thisPlayer]] = copper;
    game->handCount[thisPlayer]++;

    // Put all 10 adventurer cards in deck
    previousScore = scoreFor(thisPlayer, game);
    for(i=0; i < 10; i++)
    {
        game->deck[thisPlayer][game->deckCount[thisPlayer]] = adventurer;
        game->deckCount[thisPlayer]++;
    }
    //Should have 20 cards now, so gardens should add 2
    if( scoreFor(thisPlayer, game) != previousScore + 2 )
        printf("Error -%s didn't properly add 2 for a gardens card in hand!\n", funcName);

    // Reset to 10 cards again
    for(i=0; i < 10 ; i++)
    {
        game->deckCount[thisPlayer]--;
        game->deck[thisPlayer][game->deckCount[thisPlayer]] = -1;
    }


    /* Repeat all tests for cards in the discard */

    memcpy(initialState, game, sizeof(struct gameState));

    // Set up to only have 10 cards by removing one from the deck count and adding a gardens to the discard
    game->deck[thisPlayer][game->deckCount[thisPlayer]] = -1;
    game->deckCount[thisPlayer]--;

    // Reset to score 0 for hand
    for(i=0; i<game->handCount[thisPlayer]; i++)
        game->hand[thisPlayer][i] = copper;
    previousScore = scoreFor(thisPlayer, game);

    //Should have 10 cards so gardens should add 1
    game->discard[thisPlayer][0] = gardens;
    game->discardCount[thisPlayer]++;
    if( scoreFor(thisPlayer, game) != previousScore + 1 )
        printf("Error -%s didn't properly add 1 to score for a gardens card in discard!\n", funcName);

    // Trash a copper from the hand and gardens should add none
    previousScore = scoreFor(thisPlayer, game);
    game->hand[thisPlayer][game->handCount[thisPlayer]] = -1;
    game->handCount[thisPlayer]--;

    if( scoreFor(thisPlayer, game) != previousScore - 1)
        printf("Error -%s didn't properly add 0 to score for a gardens card in discard!\n", funcName);

    // Add it back for ease of testing (even 10 cards)
    game->hand[thisPlayer][game->handCount[thisPlayer]] = copper;
    game->handCount[thisPlayer]++;

    // Put all 10 adventurer cards in deck
    previousScore = scoreFor(thisPlayer, game);
    for(i=0; i < 10; i++)
    {
        game->deck[thisPlayer][game->deckCount[thisPlayer]] = adventurer;
        game->deckCount[thisPlayer]++;
    }

    //Should have 20 cards now, so gardens should add 2
    if( scoreFor(thisPlayer, game) != previousScore + 2 )
        printf("Error -%s didn't properly add 2 for a gardens card in discard!\n", funcName);

    // Done testing gardens, on to the simpler tests
    previousScore = scoreFor(thisPlayer, game);
    game->discard[thisPlayer][0] = curse;
    game->discardCount[thisPlayer]++;
    if( scoreFor(thisPlayer, game) != previousScore - 1 )
        printf("Error -%s didn't properly subtract for a curse card in discard!\n", funcName);

    previousScore = scoreFor(thisPlayer, game);
    game->discard[thisPlayer][1] = estate;
    game->discardCount[thisPlayer]++;
    if( scoreFor(thisPlayer, game) != previousScore + 1 )
        printf("Error -%s didn't properly add for an estate card in discard!\n", funcName);

    previousScore = scoreFor(thisPlayer, game);
    game->discard[thisPlayer][2] = duchy;
    game->discardCount[thisPlayer]++;
    if( scoreFor(thisPlayer, game) != previousScore + 3 )
        printf("Error -%s didn't properly add for a duchy card in discard!\n", funcName);

    previousScore = scoreFor(thisPlayer, game);
    game->discard[thisPlayer][3] = province;
    game->discardCount[thisPlayer]++;
    if( scoreFor(thisPlayer, game) != previousScore + 6 )
        printf("Error -%s didn't properly add for a province card in discard!\n", funcName);

    previousScore = scoreFor(thisPlayer, game);
    game->discard[thisPlayer][4] = great_hall;
    game->discardCount[thisPlayer]++;
    if( scoreFor(thisPlayer, game) != previousScore + 1 )
        printf("Error -%s didn't properly add for a great_hall card in discard!\n", funcName);

    // We added cards to the discard and removed from deck, so reset state to the initial state
    free(game);
    game = initialState;
    initialState = NULL;

    /* Repeat all tests for cards in the deck */

    game->deck[thisPlayer][game->deckCount[thisPlayer]] = copper; // So when we put a gardens in this position we don't remove an estate

    // Reset to score 0 for hand
    for(i=0; i<game->handCount[thisPlayer]; i++)
        game->hand[thisPlayer][i] = copper;
    previousScore = scoreFor(thisPlayer, game);

    //Should have 10 cards so gardens should add 1
    game->deck[thisPlayer][game->deckCount[thisPlayer]] = gardens;
    if( scoreFor(thisPlayer, game) != previousScore + 1 )
        printf("Error -%s didn't properly add 1 to score for a gardens card in deck!\n", funcName);

    // Trash a copper from the hand and gardens should add none
    previousScore = scoreFor(thisPlayer, game);
    game->hand[thisPlayer][game->handCount[thisPlayer]] = -1;
    game->handCount[thisPlayer]--;

    if( scoreFor(thisPlayer, game) != previousScore -1 )
        printf("Error -%s didn't properly add 0 to score for a gardens card in deck!\n", funcName);

    // Add it back for ease of testing (even 10 cards)
    game->hand[thisPlayer][game->handCount[thisPlayer]] = copper;
    game->handCount[thisPlayer]++;

    // Put all 10 adventurer cards in deck
    previousScore = scoreFor(thisPlayer, game);
    for(i=0; i < 10; i++)
    {
        game->deck[thisPlayer][game->deckCount[thisPlayer]] = adventurer;
        game->deckCount[thisPlayer]++;
    }

    //Should have 20 cards now, so gardens should add 2
    if( scoreFor(thisPlayer, game) != previousScore + 2 )
        printf("Error -%s didn't properly add 2 for a gardens card in deck!\n", funcName);

    // On to the other victory cards...
    previousScore = scoreFor(thisPlayer, game);
    game->deck[thisPlayer][game->deckCount[thisPlayer]] = curse;
    game->deckCount[thisPlayer]++;
    if( scoreFor(thisPlayer, game) != previousScore - 1 )
        printf("Error -%s didn't properly subtract for a curse card in deck!\n", funcName);

    previousScore = scoreFor(thisPlayer, game);
    game->deck[thisPlayer][game->deckCount[thisPlayer]] = estate;
    game->deckCount[thisPlayer]++;
    if( scoreFor(thisPlayer, game) != previousScore + 1 )
        printf("Error -%s didn't properly add for an estate card in deck!\n", funcName);

    previousScore = scoreFor(thisPlayer, game);
    game->deck[thisPlayer][game->deckCount[thisPlayer]] = duchy;
    game->deckCount[thisPlayer]++;
    if( scoreFor(thisPlayer, game) != previousScore + 3 )
        printf("Error -%s didn't properly add for a duchy card in deck!\n", funcName);

    previousScore = scoreFor(thisPlayer, game);
    game->deck[thisPlayer][game->deckCount[thisPlayer]] = province;
    game->deckCount[thisPlayer]++;
    if( scoreFor(thisPlayer, game) != previousScore + 6 )
        printf("Error -%s didn't properly add for a province card in deck!\n", funcName);

    previousScore = scoreFor(thisPlayer, game);
    game->deck[thisPlayer][game->deckCount[thisPlayer]] = great_hall;
    game->deckCount[thisPlayer]++;
    if( scoreFor(thisPlayer, game) != previousScore + 1 )
        printf("Error -%s didn't properly add for a great_hall card in deck!\n", funcName);






    free(initialState);
    free(game);
    printf("\n\n********** End of test reached for function %s. Any errors found are shown above.**********\n", funcName);
    return 0;
}
int main(int argc, char** argv){

    int i, j, random, boolean, players, temp, money, act_x, vil_x, action, buy;

    if(argc != 2)
    {
        printf("Usage: ./testdominion [random seed]");
        return 0;
    }
    else
    {
        random = atoi(argv[1]);
    }

    srand(random);

    struct gameState g;
    struct gameState* p = &g;

    int k[10];

    for(i = 0; i < 10; i++)
    {
        temp = (rand() % 20) + 7; 
        boolean = 1;
        for(j = 0; j < i; j++)
            if(k[j] == temp)
                boolean = 0;
        if(boolean)     //If the number does not already exist
            k[i] = temp;
        else            //If the number already exists in the array
            i--;
    }

    int not_bought[10];
    int not_played[10];

    for(i = 0; i < 10; i++)
    {
        not_bought[i] = k[i];
        not_played[i] = k[i];
    }

    players = (rand() % 3) + 2;

    int r = initializeGame(players, k, random, p);

    while(!isGameOver(p))        //Loop that continues for game
    {
        for(i = 0; i < players; i++)
        {                                           //Loop the loops through each player
            action = 1;
            buy = 1;
            money = 0;            
            while(action)             //Loop that continues for each players actions
            {
                vil_x = -1;
                act_x = -1;
                for(j = 0; j < numHandCards(p); j++)    //Loop runs through hand
                {
                    if(handCard(j, p) == village)
                    {
                        vil_x = j;
                        break;
                    }
                    else if(!played(not_played, p, handCard(j, p)))
                        act_x = j;
                }
                if(vil_x > -1)
                {
                    playCard(j, -1, -1, -1, p);
                    printf("Player %d played a village\n", j);
                }
                else if(act_x > -1)
                {
                    play(act_x, p);
                    action = 0;
                }
                else
                    action = 0;
            }

            buy_card(p, not_bought, k);

            endTurn(p);
        }
    }
    print_state(p, players);
    printf("\n");
    return 0;
}
int main()
{
  int i;
  int cards[10] = {adventurer, council_room, feast, gardens, mine,
   remodel, smithy, village, baron, great_hall};

  int testCount = 100;
  printf("*-------\nBegin Adventurer Card Random Testing\n-------*\n");

  //Set up the random number generator
  int seed = 12125;
  SelectStream(1);
  PutSeed((long)seed);

  for(i = 0; i < testCount; ++i)
  {
    int j, pos, preTreasure = 0, postTreasure = 0, err = 0;
    //Build a gamestate to test with
    struct gameState *state = malloc(sizeof(struct gameState));
    struct gameState *prev = malloc(sizeof(struct gameState));
    seed = floor((Random() * 12125) + 1);

    int numPlayer = floor((Random() * 3) + 2);
    initializeGame(numPlayer, cards, seed, state);

    state->whoseTurn = floor(Random() * numPlayer);
    state->handCount[state->whoseTurn] = floor(Random() * (MAX_HAND / 3));
    state->deckCount[state->whoseTurn] = floor(Random() * (MAX_DECK / 3));
    state->discardCount[state->whoseTurn] = floor(Random() * (MAX_DECK / 3));
    state->playedCardCount = floor(Random() * 5);

    //Fill the hand with random cards 0 - 17
    for(j = 0; j < state->handCount[state->whoseTurn]; ++j)
    {
      state->hand[state->whoseTurn][j] = floor(Random() * 17);
    }

    //Fill the deck with random cards 0 - 17
    for(j = 0; j < state->deckCount[state->whoseTurn]; ++j)
    {
      state->deck[state->whoseTurn][j] = floor(Random() * 17);
    }

    //Fill the discard pile with random cards 0 - 17
    for(j = 0; j < state->discardCount[state->whoseTurn]; ++j)
    {
      state->discard[state->whoseTurn][j] = floor(Random() * 17);
    }

    //Randomly select a position, set that card to adventurer for our use
    pos = floor(Random() * state->handCount[state->whoseTurn]);
    state->hand[state->whoseTurn][pos] = adventurer;

    printf("\nPre-State:\nhandCount: %i\ndeckCount: %i\ndiscardCount: %i\n",
      state->handCount[state->whoseTurn],
      state->deckCount[state->whoseTurn],
      state->discardCount[state->whoseTurn]);

    printf("Cardpos: %i\nPlayer: %i\nplayedCardCount: %i\n",
      pos,
      state->whoseTurn,
      state->playedCardCount);

    //Copy the gamestate
    memcpy(prev, state, sizeof(struct gameState));

    //Call the adventurer card
    cardAdventurer(state->whoseTurn, state);

    //Count up the treasure cards in the players hand before playing the adventurer
    for(j = 0; j < prev->handCount[prev->whoseTurn]; ++j)
    {
      if(prev->hand[prev->whoseTurn][j] == copper ||
         prev->hand[prev->whoseTurn][j] == silver ||
         prev->hand[prev->whoseTurn][j] == gold)
      {
        ++preTreasure;
      }
    }

    //Count up the treasure cards in the players hand after playing the adventurer
    for(j = 0; j < state->handCount[state->whoseTurn]; ++j)
    {
      if(state->hand[state->whoseTurn][j] == copper ||
         state->hand[state->whoseTurn][j] == silver ||
         state->hand[state->whoseTurn][j] == gold)
      {
        ++postTreasure;
      }
    }

    if((prev->deckCount[prev->whoseTurn] + prev->discardCount[prev->whoseTurn] - 2) !=
     (state->deckCount[state->whoseTurn] + state->discardCount[state->whoseTurn]))
    {
      printf("FAILURE: The total number of cards in the deck and discard are incorrect.\n");
      printf("Prev: %i, Post: %i, Seed: %i\n",
        prev->deckCount[prev->whoseTurn] + prev->discardCount[prev->whoseTurn],
        state->deckCount[state->whoseTurn] + state->discardCount[state->whoseTurn],
        seed);
      err = 1;
    }

    if((prev->playedCardCount + 1) != state->playedCardCount)
    {
      printf("FAILURE: The total number of played cards was not properly incremented.\n");
      printf("Prev: %i, Post: %i, Seed: %i\n",
        prev->playedCardCount,
        state->playedCardCount,
        seed);
      err = 2;
    }

    if((preTreasure + 2) != postTreasure)
    {
      printf("FAILURE: The number of treasure cards in the players hand is incorrect.\n");
      printf("Prev: %i, Post: %i, Seed: %i\n",
        preTreasure + 2,
        postTreasure,
        seed);
      err = 3;
    }

    if(prev->handCount[prev->whoseTurn] + 2 != state->handCount[state->whoseTurn])
    {
      printf("FAILURE: The handCount was not properly incremented.\n");
      printf("Prev: %i, Post: %i, Seed: %i\n",
        prev->handCount[prev->whoseTurn],
        state->handCount[state->whoseTurn],
        seed);
      err = 4;
    }

    if(err == 0)
    {
      printf("PASSED.\n");
    }
  }

  printf("*-------\nEnd Adventurer Card Random Testing\n-------*\n");
  return 0;
}
Exemple #11
0
int main()
{
     int r;
     int player;
     int numPlayer = 2;

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

#if (NOISY_TEST == 1)
     const char* cards[] = //All 27 cards in game
     {
          "curse",
          "estate",
          "duchy",
          "province",
          "copper",
          "silver",
          "gold",
          "adventurer",
          "council_room",
          "feast",
          "gardens",
          "mine",
          "remodel",
          "smithy",
          "village",
          "baron",
          "great_hall",
          "minion",
          "steward",
          "tribute",
          "ambassador",
          "cutpurse",
          "embargo",
          "outpost",
          "salvager",
          "sea_hag",
          "treasure_map"
     };
#endif

     struct gameState prevState; //untouched game state to compare with after running tests
     struct gameState postState; //game state that will be used for tests


     int testResult;

     int numTests = 1; //how many test iterations to run.
     int failedTests = 0;
     int passedTests = 0;

     printf("==============================================\r\n");
     printf("    Beginning testing for playSmithy()\r\n");
     printf("==============================================\r\n");


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

          memset(&prevState, 23, sizeof(struct gameState));   // clear the game state
          r = initializeGame(numPlayer, k, seed, &prevState); // initialize a new game

          for (player = 0; player < numPlayer; player++)
          {
    
               prevState.handCount[player] = 1;        // set the number of cards on hand
               int smithyHand[1];
               smithyHand[0] = smithy;
               memcpy(prevState.hand[player], smithyHand, sizeof(int));

               prevState.deckCount[player] = 5;        // set the number of cards in deck
               int mixedDeck[5];
               mixedDeck[0] = copper;
               mixedDeck[1] = silver;
               mixedDeck[2] = gold;
               mixedDeck[3] = gardens;
               mixedDeck[4] = tribute;
               memcpy(prevState.deck[player], mixedDeck, sizeof(int) * 5);

               memcpy(&postState, &prevState, sizeof(struct gameState)); //create clone of game state to run tests on
               playSmithy(player, &postState, 0);

               //Check that exactly 3 cards were indeed added to current player's hand by comparing handCount value
#if (NOISY_TEST == 1)
               printf("---------------------------------------------------------------------------------------------------------------------------\r\n");
               printf("Testing that player[%d] handCount has increased by 2...\r\n", player);
#endif

               testResult = postState.handCount[player]; 

               if (testResult == prevState.handCount[player] + 2) //+2 due to smithy needing being discarded
               {
                    passedTests++;
               }
               else//failed
               {
                    failedTests++;
               }
#if (NOISY_TEST == 1)
               printf("handCount = %d, Expected = %d\r\n", testResult, prevState.handCount[player] + 2);
               printf("Testing that player[%d] playedCardCount has increased by 1..\r\n", player);
#endif
               //Check that playedCardCount increased by 1

               testResult = postState.playedCardCount;

               if (testResult == prevState.playedCardCount + 1) //passed
               {
                    passedTests++;
               }
               else//failed
               {
                    failedTests++;
               }
#if (NOISY_TEST == 1)
               printf("playedCardCount = %d, Expected = %d\r\n", testResult, prevState.playedCardCount + 1);
               printf("Checking that the smithy card was added to the played cards pile...\r\n");
#endif
               //Check that the smithy card was added to the played cards pile

               testResult = findCard(player, &postState, smithy, 0);

               if (testResult == -1) //failed, if variable is still -1, smithy was not found
               {
                    failedTests++;
               }
               else//passed
               {
                    passedTests++;
               }

#if (NOISY_TEST == 1)
               if (testResult == -1) //failed
               {
                    printf("Failed! Smithy card was not found in played cards pile!\r\n");
               }
               else//passed
               {
                    printf("Passed! Smithy card was found in played cards pile at position %d!\r\n", testResult);
               }
               printf("Checking that smithy card is not in player[%d]'s hand...\r\n", player);
#endif
               //Check that smithy card is not in player's hand

               testResult = findCard(player, &postState, smithy, 1);

               if (testResult == -1) //passed, if variable is still -1, smithy was not found
               {
                    passedTests++;
               }
               else//failed
               {
                    failedTests++;
               }

#if (NOISY_TEST == 1)
               if (testResult == -1) //passed
               {
                    printf("Passsed! Smithy card was not found in the player's hand!\r\n");
               }
               else//failed
               {
                    printf("Failed! Smithy card was found in player's hand at position %d!\r\n", testResult);
               }
               printf("Checking that the 3 cards added came from the player's own deck...\r\n");
#endif
               //Check that the 3 cards added came from the player's own deck


               //debug
               //int y;
               //for (y = 0; y < postState.handCount[player]; y++)
               //{
                    //printf("%s Card at position %d \r\n", cards[postState.hand[player][y]], y);
              // }

               int card;
               int cardCount = 0;
               int foundCards[MAX_DECK];
               int j;
               for (j = 0; j < 5; j++)
               {

                    if (j == 0) 
                    { 
                         card = copper; 
                    }
                    if (j == 1) 
                    { 
                         card = silver;
                    }
                    if (j == 2)
                    { 
                         card = gold;
                    }
                    if (j == 3)
                    { 
                         card = gardens;
                    }
                    if (j == 4)
                    { 
                         card = tribute;
                    }

                    testResult = findCard(player, &postState,card, 1);

                    if (testResult != -1) //card found
                    {
                         cardCount++;
                         foundCards[cardCount - 1] = card;

#if (NOISY_TEST == 1)
                         printf("Found %s card in player[%d]'s hand at position %d! Number of cards found: %d\r\n", cards[card], player, testResult, cardCount);
#endif
                    }
               }

               if (cardCount == 3) //passed
               {
                    passedTests++;
               }
               else//failed
               {
                   failedTests++;
               }

#if (NOISY_TEST == 1)
               printf("cardCount = %d, Expected = 3\r\n", cardCount);
#endif

               //check that the found cards are not in the deck anymore
               for (j = 0; j < cardCount; j++)
               {
                    testResult = findCard(player, &postState, foundCards[j], 2);

                    if (testResult == -1) //card not found
                    {
                         passedTests++;                         
                    }
                    else
                    {
                         failedTests++;
#if (NOISY_TEST == 1)
                         printf("Found %s card in player[%d]'s deck at position %d\r\n", cards[card], player, testResult);
#endif
                    }
               }
          }
     }
     
     printf("---------------------------------------------------------------------------------------------------------------------------\r\n");
     printf("%d out of %d tests passed!\r\n", passedTests, passedTests + failedTests);
     printf("%d out of %d tests failed!\r\n", failedTests, passedTests + failedTests);

     return 0;
}
Exemple #12
0
int main() {
    int seed = 1000;
    int numPlayers = 4;
    int handNum, handPos, player, trashFlag, result;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G, testG;
    initializeGame(numPlayers, k, seed, &G);
    int hands[3][15] = {{copper, gold, village, estate, smithy}, {gold}, {silver, province, copper, copper, feast, baron, remodel, copper, smithy, province, duchy, estate, copper, mine, gardens}};
    int handCounts[3] = {5, 1, 8};

    printf("\n----------------- Testing Function: %s ----------------\n", TESTFUNCTION);
    memcpy(&testG, &G, sizeof(struct gameState));

    for (player = 0; player < numPlayers; player++) //for each of the players
    {
        G.whoseTurn = player;        
        for (handNum = 0; handNum < 3; handNum++) //for each of the 3 predefined hands
        {
            memcpy(&G.hand[player], &hands[handNum], sizeof(hands[handNum])); //load new hand
            G.handCount[player] = handCounts[handNum]; //load new handCount
            for (handPos = 0; handPos < handCounts[handNum]; handPos++) //for every card in the hand
            {
                for (trashFlag = 0; trashFlag < 2; trashFlag ++)
                {
                    memcpy(&testG, &G, sizeof(struct gameState)); //restore game state
                    discardCard(handPos, player, &testG, trashFlag);
#if (NOISY_TEST == 1)                    
                    printf("handCount = %d, expected = %d\n", testG.handCount[player], G.handCount[player] - 1);
#endif
                    assert(testG.handCount[player] == handCounts[handNum] - 1);
#if (NOISY_TEST == 1)
                    printf("playedCardCount = %d, expected = %d\n", testG.playedCardCount, G.playedCardCount + 1 - trashFlag);
#endif                    
                    assert(testG.playedCardCount == G.playedCardCount + 1 - trashFlag);

                    if (trashFlag == 0) //if it wasn't trashed, it should be in the played cards pile
                    {
#if (NOISY_TEST == 1)                        
                        printf("playedCard = %d, expected = %d\n", testG.playedCards[0], hands[handNum][handPos]);
#endif                        
                        assert(testG.playedCards[0] == hands[handNum][handPos]);
                    }

                    //restore values and check that the rest of the game was left intact
                    testG.handCount[player] = G.handCount[player];
                    testG.playedCardCount = G.playedCardCount;
                    memcpy(&testG.hand[player], &G.hand[player], sizeof(G.hand[player]));
                    if (trashFlag == 0)
                    {
                        memcpy(&testG.playedCards, &G.playedCards, sizeof(G.playedCards));
                    }
                    result = memcmp(&testG, &G, sizeof(struct gameState));
#if (NOISY_TEST == 1)                    
                    printf("memcmp result = %d, expected = %d\n", result, 0);
#endif                          
                    assert(result == 0);



                }
            }
        }
    }
 
    printf("All tests passed!\n");

    return 0;
}
Exemple #13
0
/*******************************************************************************
** Function: main
** Description: entrypoint for unit test.
** Parameters: None
** Pre-Conditions: None
** Post-Conditions: Exit code 0 if all tests succeeded, otherwise 1.
*******************************************************************************/
int main()
{
	int players;
	int player;
	int handpos, deckpos;
	int bonus;
	struct gameState pre;
	struct gameState post;
	struct gameState state;

	int i;
	int result;
	int treasures;
	int handDeltas[treasure_map + 1]; /* array of all card types */
	int discardDeltas[treasure_map + 1]; /* array of all card types */

	int passes = 0; /* tests passed */
	int failures = 0; /* tests failed */

	if (OUTPUTLEVEL > 0) printf("\n*** BEGIN " FILENAME " (cardEffect unit test for " xstr(CARDUNDERTEST) ") ***\n");

	/* test games with each allowed number of players */
	for (players = 2; players <= MAX_PLAYERS; players++)
	{
		/* initialize a standard game, using a pre-defined set of kingdom cards and random seed */
		initializeGame(players, Kingdom, SEED, &state);

		/* reset all players' hands and decks */
		for (player = 0; player < players; player++)
		{
			state.deckCount[player] += state.handCount[player];
			state.handCount[player] = 0;
		}

		/* test each player */
		for (player = 0; player < players; player++)
		{
			/* 1) Ensure that card effect picks gold from revealed cards */

			/* get a fresh copy of the base gamestate */
			copyGameState(&pre, &state);

			/* stack the current player's hand with the card under test and set current player */
			pre.handCount[player] = HANDCOUNT;
			for (handpos = 0; handpos < pre.handCount[player]; handpos++) pre.hand[player][handpos] = CARDUNDERTEST;
			pre.whoseTurn = player;

			/* deck: 3 gold cards, discard : empty */
			pre.discardCount[player] = 0;
			pre.deckCount[player] = 3;
			for (deckpos = 0; deckpos < pre.deckCount[player]; deckpos++) pre.deck[player][deckpos] = gold;
			if (OUTPUTLEVEL > 1) printf("Card Configuration: deck 3 gold cards, discard empty.\n");

			/* test several hand positions */
			for (handpos = 0; handpos < pre.handCount[player]; handpos++)
			{
				/* test hand positions at either end of the hand and in the middle, skip others */
				if (
					!(handpos == 0 ||
						handpos == pre.handCount[player] / 2 ||
						handpos == (pre.handCount[player] - 1))
					) continue;

				/* retain a copy the initial game state for post-comparison */
				copyGameState(&post, &pre);

				/* perform the card effect */
				bonus = 0;
				cardEffect(CARDUNDERTEST, 0, 0, 0, &post, handpos, &bonus);

				if (OUTPUTLEVEL > 1) printf("Test Standard Conditions\n");
				testStandardConditions(players, player, handpos, &pre, &post, &passes, &failures);

				if (OUTPUTLEVEL > 1) printf("Test Extra Conditions\n");

				/* verify exactly 2 gold treasures drawn */
				if (OUTPUTLEVEL > 1) printf("Test: Exactly 2 golds added to hand...\n");
				deltaPlayerCardTypesInHand(&pre, &post, player, handDeltas);
				result = TRUE;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == gold)
					{
						if (handDeltas[i] != 2) result = FALSE;
					}
					else if (i == CARDUNDERTEST) /* card that was played */
					{
						if (handDeltas[i] != -1) result = FALSE;
					}
					else
					{
						if (handDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE, &passes, &failures);

				/* verify discard state is unchanged */
				if (OUTPUTLEVEL > 1) printf("Test: Player discard state unchanged...\n");
				result = deltaPlayerDiscardCount(&pre, &post, player);
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == 0, &passes, &failures);
			}

			/* 2) Ensure that card effect picks silver from revealed cards */

			/* get a fresh copy of the base gamestate */
			copyGameState(&pre, &state);

			/* stack the current player's hand with the card under test and set current player */
			pre.handCount[player] = HANDCOUNT;
			for (handpos = 0; handpos < pre.handCount[player]; handpos++) pre.hand[player][handpos] = CARDUNDERTEST;
			pre.whoseTurn = player;

			/* deck: 3 silver cards, discard : empty */
			pre.deckCount[player] = 3;
			pre.discardCount[player] = 0;
			for (deckpos = 0; deckpos < pre.deckCount[player]; deckpos++) pre.deck[player][deckpos] = silver;
			if (OUTPUTLEVEL > 1) printf("Card Configuration: deck 3 silver cards, discard empty.\n");

			/* test several hand positions */
			for (handpos = 0; handpos < pre.handCount[player]; handpos++)
			{
				/* test hand positions at either end of the hand and in the middle, skip others */
				if (
					!(handpos == 0 ||
						handpos == pre.handCount[player] / 2 ||
						handpos == (pre.handCount[player] - 1))
					) continue;

				/* retain a copy the initial game state for post-comparison */
				copyGameState(&post, &pre);

				/* perform the card effect */
				bonus = 0;
				cardEffect(CARDUNDERTEST, 0, 0, 0, &post, handpos, &bonus);

				if (OUTPUTLEVEL > 1) printf("Test Standard Conditions\n");
				testStandardConditions(players, player, handpos, &pre, &post, &passes, &failures);

				if (OUTPUTLEVEL > 1) printf("Test Extra Conditions\n");

				/* verify exactly 2 silver treasures drawn */
				if (OUTPUTLEVEL > 1) printf("Test: Exactly 2 silvers added to hand...\n");
				deltaPlayerCardTypesInHand(&pre, &post, player, handDeltas);
				result = TRUE;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == silver)
					{
						if (handDeltas[i] != 2) result = FALSE;
					}
					else if (i == CARDUNDERTEST) /* card that was played */
					{
						if (handDeltas[i] != -1) result = FALSE;
					}
					else
					{
						if (handDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE, &passes, &failures);

				/* verify discard state is unchanged */
				if (OUTPUTLEVEL > 1) printf("Test: Player discard state unchanged...\n");
				result = deltaPlayerDiscardCount(&pre, &post, player);
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == 0, &passes, &failures);
			}

			/* 3) Ensure that card effect picks copper from revealed cards */

			/* get a fresh copy of the base gamestate */
			copyGameState(&pre, &state);

			/* stack the current player's hand with the card under test and set current player */
			pre.handCount[player] = HANDCOUNT;
			for (handpos = 0; handpos < pre.handCount[player]; handpos++) pre.hand[player][handpos] = CARDUNDERTEST;
			pre.whoseTurn = player;

			/* deck: 3 copper cards, discard : empty */
			pre.discardCount[player] = 0;
			pre.deckCount[player] = 3;
			for (deckpos = 0; deckpos < pre.deckCount[player]; deckpos++) pre.deck[player][deckpos] = copper;
			if (OUTPUTLEVEL > 1) printf("Card Configuration: deck 3 copper cards, discard empty.\n");

			/* test several hand positions */
			for (handpos = 0; handpos < pre.handCount[player]; handpos++)
			{
				/* test hand positions at either end of the hand and in the middle, skip others */
				if (
					!(handpos == 0 ||
						handpos == pre.handCount[player] / 2 ||
						handpos == (pre.handCount[player] - 1))
					) continue;

				/* retain a copy the initial game state for post-comparison */
				copyGameState(&post, &pre);

				/* perform the card effect */
				bonus = 0;
				cardEffect(CARDUNDERTEST, 0, 0, 0, &post, handpos, &bonus);

				if (OUTPUTLEVEL > 1) printf("Test Standard Conditions\n");
				testStandardConditions(players, player, handpos, &pre, &post, &passes, &failures);

				if (OUTPUTLEVEL > 1) printf("Test Extra Conditions\n");

				/* verify exactly 2 copper treasures drawn */
				if (OUTPUTLEVEL > 1) printf("Test: Exactly 2 coppers added to hand...\n");
				deltaPlayerCardTypesInHand(&pre, &post, player, handDeltas);
				result = TRUE;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == copper)
					{
						if (handDeltas[i] != 2) result = FALSE;
					}
					else if (i == CARDUNDERTEST) /* card that was played */
					{
						if (handDeltas[i] != -1) result = FALSE;
					}
					else
					{
						if (handDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE, &passes, &failures);

				/* verify discard state is unchanged */
				if (OUTPUTLEVEL > 1) printf("Test: Player discard state unchanged...\n");
				result = deltaPlayerDiscardCount(&pre, &post, player);
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == 0, &passes, &failures);
			}

			/* 
			 * 4) Ensure that card effect picks only treasure cards when mixed
			 *    with non-treasure cards; also, does not skip treasure cards
			 */

			/* get a fresh copy of the base gamestate */
			copyGameState(&pre, &state);

			/* stack the current player's hand with the card under test and set current player */
			pre.handCount[player] = HANDCOUNT;
			for (handpos = 0; handpos < pre.handCount[player]; handpos++) pre.hand[player][handpos] = CARDUNDERTEST;
			pre.whoseTurn = player;

			/* deck: 1 estate on top, followed by gold, estate, silver, estate, copper, estate; discard: empty */
			pre.discardCount[player] = 0;
			pre.deckCount[player] = 7;
			pre.deck[player][6] = estate; /* top of deck */
			pre.deck[player][5] = gold;
			pre.deck[player][4] = estate;
			pre.deck[player][3] = silver;
			pre.deck[player][2] = estate;
			pre.deck[player][1] = copper;
			pre.deck[player][0] = estate;

			if (OUTPUTLEVEL > 1) printf("Card Configuration: 1 estate on top, followed by gold, estate, silver, estate, copper, estate; discard: empty.\n");

			/* test several hand positions */
			for (handpos = 0; handpos < pre.handCount[player]; handpos++)
			{
				/* test hand positions at either end of the hand and in the middle, skip others */
				if (
					!(handpos == 0 ||
						handpos == pre.handCount[player] / 2 ||
						handpos == (pre.handCount[player] - 1))
					) continue;

				/* retain a copy the initial game state for post-comparison */
				copyGameState(&post, &pre);

				/* perform the card effect */
				bonus = 0;
				cardEffect(CARDUNDERTEST, 0, 0, 0, &post, handpos, &bonus);

				if (OUTPUTLEVEL > 1) printf("Test Standard Conditions\n");
				testStandardConditions(players, player, handpos, &pre, &post, &passes, &failures);

				if (OUTPUTLEVEL > 1) printf("Test Extra Conditions\n");

				/* verify discard contains only 1 estate card */
				if (OUTPUTLEVEL > 1) printf("Test: Added 1 estate to discard...\n");
				deltaPlayerCardTypesInDiscard(&pre, &post, player, discardDeltas);
				result = TRUE;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == estate)
					{
						if (discardDeltas[i] != 1) result = FALSE;
					}
					else
					{
						if (discardDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE, &passes, &failures);

				/* verify hand added 1 gold, 1 silver card */
				if (OUTPUTLEVEL > 1) printf("Test: Added 1 gold, 1 silver to hand...\n");
				deltaPlayerCardTypesInHand(&pre, &post, player, handDeltas);
				result = TRUE;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == silver)
					{
						if (handDeltas[i] != 1) result = FALSE;
					}
					else if (i == gold)
					{
						if (handDeltas[i] != 1) result = FALSE;
					}
					else if (i == CARDUNDERTEST) /* card that was played */
					{
						if (handDeltas[i] != -1) result = FALSE;
					}
					else
					{
						if (handDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE, &passes, &failures);
			}


			/*
			* 5) Ensure that card effect picks only treasure cards when mixed
			*    with non-treasure cards; also, does not skip treasure cards
			*/

			/* get a fresh copy of the base gamestate */
			copyGameState(&pre, &state);

			/* stack the current player's hand with the card under test and set current player */
			pre.handCount[player] = HANDCOUNT;
			for (handpos = 0; handpos < pre.handCount[player]; handpos++) pre.hand[player][handpos] = CARDUNDERTEST;
			pre.whoseTurn = player;

			/* deck: 1 estate on top, followed by copper, estate, silver, estate, gold, estate; discard: empty */
			pre.discardCount[player] = 0;
			pre.deckCount[player] = 7;
			pre.deck[player][6] = estate; /* top of deck */
			pre.deck[player][5] = copper;
			pre.deck[player][4] = estate;
			pre.deck[player][3] = silver;
			pre.deck[player][2] = estate;
			pre.deck[player][1] = gold;
			pre.deck[player][0] = estate;

			if (OUTPUTLEVEL > 1) printf("Card Configuration: 1 estate on top, followed by copper, estate, silver, estate, gold, estate; discard: empty.\n");

			/* test several hand positions */
			for (handpos = 0; handpos < pre.handCount[player]; handpos++)
			{
				/* test hand positions at either end of the hand and in the middle, skip others */
				if (
					!(handpos == 0 ||
						handpos == pre.handCount[player] / 2 ||
						handpos == (pre.handCount[player] - 1))
					) continue;

				/* retain a copy the initial game state for post-comparison */
				copyGameState(&post, &pre);

				/* perform the card effect */
				bonus = 0;
				cardEffect(CARDUNDERTEST, 0, 0, 0, &post, handpos, &bonus);

				if (OUTPUTLEVEL > 1) printf("Test Standard Conditions\n");
				testStandardConditions(players, player, handpos, &pre, &post, &passes, &failures);

				if (OUTPUTLEVEL > 1) printf("Test Extra Conditions\n");

				/* verify discard contains only 1 estate card */
				if (OUTPUTLEVEL > 1) printf("Test: Added 1 estate to discard...\n");
				deltaPlayerCardTypesInDiscard(&pre, &post, player, discardDeltas);
				result = TRUE;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == estate)
					{
						if (discardDeltas[i] != 1) result = FALSE;
					}
					else
					{
						if (discardDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE, &passes, &failures);

				/* verify hand added 1 copper, 1 silver card */
				if (OUTPUTLEVEL > 1) printf("Test: Added 1 copper, 1 silver to hand...\n");
				deltaPlayerCardTypesInHand(&pre, &post, player, handDeltas);
				result = TRUE;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == copper)
					{
						if (handDeltas[i] != 1) result = FALSE;
					}
					else if (i == silver)
					{
						if (handDeltas[i] != 1) result = FALSE;
					}
					else if (i == CARDUNDERTEST) /* card that was played */
					{
						if (handDeltas[i] != -1) result = FALSE;
					}
					else
					{
						if (handDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE, &passes, &failures);
			}

			/* 6) Ensure card effect causes deck to be reshuffled when cards run out */

			/* get a fresh copy of the base gamestate */
			copyGameState(&pre, &state);

			/* stack the current player's hand with the card under test and set current player */
			pre.handCount[player] = HANDCOUNT;
			for (handpos = 0; handpos < pre.handCount[player]; handpos++) pre.hand[player][handpos] = CARDUNDERTEST;
			pre.whoseTurn = player;

			/* deck: empty, discard 1 gold, 1 silver, 1 copper */
			pre.deckCount[player] = 0;
			pre.discardCount[player] = 3;
			pre.discard[player][2] = gold;
			pre.discard[player][1] = silver;
			pre.discard[player][0] = copper;

			if (OUTPUTLEVEL > 1) printf("Card Configuration: deck empty, discard contains 1 gold, 1 silver, 1 copper.\n");

			/* test several hand positions */
			for (handpos = 0; handpos < pre.handCount[player]; handpos++)
			{
				/* test hand positions at either end of the hand and in the middle, skip others */
				if (
					!(handpos == 0 ||
						handpos == pre.handCount[player] / 2 ||
						handpos == (pre.handCount[player] - 1))
					) continue;

				/* retain a copy the initial game state for post-comparison */
				copyGameState(&post, &pre);

				/* perform the card effect */
				bonus = 0;
				cardEffect(CARDUNDERTEST, 0, 0, 0, &post, handpos, &bonus);

				if (OUTPUTLEVEL > 1) printf("Test Standard Conditions\n");
				testStandardConditions(players, player, handpos, &pre, &post, &passes, &failures);

				if (OUTPUTLEVEL > 1) printf("Test Extra Conditions\n");

				/* verify discard is empty */
				if (OUTPUTLEVEL > 1) printf("Test: Discard is empty...\n");
				result = post.discardCount[player];
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == 0, &passes, &failures);

				/* verify 2 treasures in hand */
				if (OUTPUTLEVEL > 1) printf("Test: 2 treasure cards added to hand...\n");
				deltaPlayerCardTypesInHand(&pre, &post, player, handDeltas);
				result = TRUE;
				treasures = 0;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == copper || i == silver || i == gold)
					{
						if (handDeltas[i] < 0) result = FALSE;
						treasures += handDeltas[i];
					}
					else if (i == CARDUNDERTEST) /* card that was played */
					{
						if (handDeltas[i] != -1) result = FALSE;
					}
					else
					{
						if (handDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE && treasures == 2, &passes, &failures);
			}

			/* 7) Ensure card effect will draw a single treasure card */
			/* get a fresh copy of the base gamestate */
			copyGameState(&pre, &state);

			/* stack the current player's hand with the card under test and set current player */
			pre.handCount[player] = HANDCOUNT;
			for (handpos = 0; handpos < pre.handCount[player]; handpos++) pre.hand[player][handpos] = CARDUNDERTEST;
			pre.whoseTurn = player;

			/* deck: 1 gold; discard: empty */
			pre.discardCount[player] = 0;
			pre.deckCount[player] = 1;
			pre.deck[player][0] = gold;

			if (OUTPUTLEVEL > 1) printf("Card Configuration: deck 1 gold, discard empty.\n");

			/* test several hand positions */
			for (handpos = 0; handpos < pre.handCount[player]; handpos++)
			{
				/* test hand positions at either end of the hand and in the middle, skip others */
				if (
					!(handpos == 0 ||
						handpos == pre.handCount[player] / 2 ||
						handpos == (pre.handCount[player] - 1))
					) continue;

				/* retain a copy the initial game state for post-comparison */
				copyGameState(&post, &pre);

				/* perform the card effect */
				bonus = 0;
				cardEffect(CARDUNDERTEST, 0, 0, 0, &post, handpos, &bonus);

				if (OUTPUTLEVEL > 1) printf("Test Standard Conditions\n");
				testStandardConditions(players, player, handpos, &pre, &post, &passes, &failures);

				if (OUTPUTLEVEL > 1) printf("Test Extra Conditions\n");

				/* verify discard is empty */
				if (OUTPUTLEVEL > 1) printf("Test: Discard is empty...\n");
				result = post.discardCount[player];
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == 0, &passes, &failures);

				/* verify exactly 1 gold in hand */
				if (OUTPUTLEVEL > 1) printf("Test: 1 gold card added to hand...\n");
				deltaPlayerCardTypesInHand(&pre, &post, player, handDeltas);
				result = TRUE;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == gold)
					{
						if (handDeltas[i] != 1) result = FALSE;
					}
					else if (i == CARDUNDERTEST) /* card that was played */
					{
						if (handDeltas[i] != -1) result = FALSE;
					}
					else
					{
						if (handDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE, &passes, &failures);
			}

			/* 8) Ensure card effect will draw a single treasure card */
			/* get a fresh copy of the base gamestate */
			copyGameState(&pre, &state);

			/* stack the current player's hand with the card under test and set current player */
			pre.handCount[player] = HANDCOUNT;
			for (handpos = 0; handpos < pre.handCount[player]; handpos++) pre.hand[player][handpos] = CARDUNDERTEST;
			pre.whoseTurn = player;

			/* deck: 1 silver; discard: empty */
			pre.discardCount[player] = 0;
			pre.deckCount[player] = 1;
			pre.deck[player][0] = silver;

			if (OUTPUTLEVEL > 1) printf("Card Configuration: deck 1 silver, discard empty.\n");

			/* test several hand positions */
			for (handpos = 0; handpos < pre.handCount[player]; handpos++)
			{
				/* test hand positions at either end of the hand and in the middle, skip others */
				if (
					!(handpos == 0 ||
						handpos == pre.handCount[player] / 2 ||
						handpos == (pre.handCount[player] - 1))
					) continue;

				/* retain a copy the initial game state for post-comparison */
				copyGameState(&post, &pre);

				/* perform the card effect */
				bonus = 0;
				cardEffect(CARDUNDERTEST, 0, 0, 0, &post, handpos, &bonus);

				if (OUTPUTLEVEL > 1) printf("Test Standard Conditions\n");
				testStandardConditions(players, player, handpos, &pre, &post, &passes, &failures);

				if (OUTPUTLEVEL > 1) printf("Test Extra Conditions\n");

				/* verify discard is empty */
				if (OUTPUTLEVEL > 1) printf("Test: Discard is empty...\n");
				result = post.discardCount[player];
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == 0, &passes, &failures);

				/* verify exactly 1 silver in hand */
				if (OUTPUTLEVEL > 1) printf("Test: 1 silver card added to hand...\n");
				deltaPlayerCardTypesInHand(&pre, &post, player, handDeltas);
				result = TRUE;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == silver)
					{
						if (handDeltas[i] != 1) result = FALSE;
					}
					else if (i == CARDUNDERTEST) /* card that was played */
					{
						if (handDeltas[i] != -1) result = FALSE;
					}
					else
					{
						if (handDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE, &passes, &failures);
			}

			/* 9) Ensure card effect will draw a single treasure card */
			/* get a fresh copy of the base gamestate */
			copyGameState(&pre, &state);

			/* stack the current player's hand with the card under test and set current player */
			pre.handCount[player] = HANDCOUNT;
			for (handpos = 0; handpos < pre.handCount[player]; handpos++) pre.hand[player][handpos] = CARDUNDERTEST;
			pre.whoseTurn = player;

			/* deck: 1 copper; discard: empty */
			pre.discardCount[player] = 0;
			pre.deckCount[player] = 1;
			pre.deck[player][0] = copper;

			if (OUTPUTLEVEL > 1) printf("Card Configuration: deck 1 copper, discard empty.\n");

			/* test several hand positions */
			for (handpos = 0; handpos < pre.handCount[player]; handpos++)
			{
				/* test hand positions at either end of the hand and in the middle, skip others */
				if (
					!(handpos == 0 ||
						handpos == pre.handCount[player] / 2 ||
						handpos == (pre.handCount[player] - 1))
					) continue;

				/* retain a copy the initial game state for post-comparison */
				copyGameState(&post, &pre);

				/* perform the card effect */
				bonus = 0;
				cardEffect(CARDUNDERTEST, 0, 0, 0, &post, handpos, &bonus);

				if (OUTPUTLEVEL > 1) printf("Test Standard Conditions\n");
				testStandardConditions(players, player, handpos, &pre, &post, &passes, &failures);

				if (OUTPUTLEVEL > 1) printf("Test Extra Conditions\n");

				/* verify discard is empty */
				if (OUTPUTLEVEL > 1) printf("Test: Discard is empty...\n");
				result = post.discardCount[player];
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == 0, &passes, &failures);

				/* verify exactly 1 copper in hand */
				if (OUTPUTLEVEL > 1) printf("Test: 1 copper card added to hand...\n");
				deltaPlayerCardTypesInHand(&pre, &post, player, handDeltas);
				result = TRUE;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == copper)
					{
						if (handDeltas[i] != 1) result = FALSE;
					}
					else if (i == CARDUNDERTEST) /* card that was played */
					{
						if (handDeltas[i] != -1) result = FALSE;
					}
					else
					{
						if (handDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE, &passes, &failures);
			}

			/* Ensure card effect will draw no cards if no treasures are available */
			/* get a fresh copy of the base gamestate */
			copyGameState(&pre, &state);

			/* stack the current player's hand with the card under test and set current player */
			pre.handCount[player] = HANDCOUNT;
			for (handpos = 0; handpos < pre.handCount[player]; handpos++) pre.hand[player][handpos] = CARDUNDERTEST;
			pre.whoseTurn = player;

			/* deck: 5 estates, 0 treasures; discard: empty */
			pre.discardCount[player] = 0;
			pre.deckCount[player] = 5;
			for (deckpos = 0; deckpos < pre.deckCount[player]; deckpos++) pre.deck[player][deckpos] = estate;

			if (OUTPUTLEVEL > 1) printf("Card Configuration: deck 5 estates, discard empty.\n");

			/* test several hand positions */
			for (handpos = 0; handpos < pre.handCount[player]; handpos++)
			{
				/* test hand positions at either end of the hand and in the middle, skip others */
				if (
					!(handpos == 0 ||
						handpos == pre.handCount[player] / 2 ||
						handpos == (pre.handCount[player] - 1))
					) continue;

				/* retain a copy the initial game state for post-comparison */
				copyGameState(&post, &pre);

				/* perform the card effect */
				bonus = 0;
				cardEffect(CARDUNDERTEST, 0, 0, 0, &post, handpos, &bonus);

				if (OUTPUTLEVEL > 1) printf("Test Standard Conditions\n");
				testStandardConditions(players, player, handpos, &pre, &post, &passes, &failures);

				if (OUTPUTLEVEL > 1) printf("Test Extra Conditions\n");

				/* verify 0 treasures added to hand */
				if (OUTPUTLEVEL > 1) printf("Test: 0 treasure cards added to hand...\n");
				deltaPlayerCardTypesInHand(&pre, &post, player, handDeltas);
				result = TRUE;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == CARDUNDERTEST) /* card that was played */
					{
						if (handDeltas[i] != -1) result = FALSE;
					}
					else
					{
						if (handDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE, &passes, &failures);

				/* verify discard contains 5 estates */
				if (OUTPUTLEVEL > 1) printf("Test: 5 estates in discard...\n");
				deltaPlayerCardTypesInDiscard(&pre, &post, player, discardDeltas);
				result = TRUE;
				for (i = 0; i <= treasure_map; i++)
				{
					if (i == estate)
					{
						if (discardDeltas[i] != 5) result = FALSE;
					}
					else if (i == CARDUNDERTEST) /* card that was played */
					{
						if (discardDeltas[i] != -1) result = FALSE;
					}
					else
					{
						if (discardDeltas[i] != 0) result = FALSE;
					}
				}
				if (OUTPUTLEVEL > 1) printf("Result: ");
				updateTestResult(result == TRUE, &passes, &failures);
			}
		}
	}

	if (OUTPUTLEVEL > 0)
	{
		if (OUTPUTLEVEL > 1) printf("\n");
		printf("SUMMARY for " FILENAME " (" xstr(CARDUNDERTEST) "): ");
		if (failures == 0) printf("passed all %d tests.\nTesting Outcome: SUCCESS!\n", passes);
		else
		{
			printf("failed %d of %d tests.\n", failures, passes + failures);
			printf("Testing Outcome: FAILED!\n");
			if (OUTPUTLEVEL > 1) printf("See results output above.\n");
		}
		printf("*** END " FILENAME " (cardEffect unit test for " xstr(CARDUNDERTEST) ") ***\n");
	}

	return failures != 0 ? 1 : 0;
}
//Testing mine
int main() {
	
	int i, j, r, passes, choice1, choice2;
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
	       sea_hag, tribute, smithy};
	int supply[16] = {0,1,2,3,4,5,6,7,10,11,13,14,17,19,21,22};
	
	struct gameState G;
	r = initializeGame(2, k, 2, &G);
		assert(r == 0);
	
	//Try upgrading to every card
	for (i = 1; i < 4; i++) {
		for (j = 0; j < 16; j++) {
			r = initializeGame(2, k, 2, &G);
			assert(r == 0);
			
			G.hand[0][0] = mine;
			G.hand[0][1] = copper;
			G.hand[0][2] = silver;
			G.hand[0][3] = gold;
			G.hand[0][4] = smithy;
			G.handCount[0] = 5;
			G.numActions = 1;
			choice1 = i;
			choice2 = supply[j];
			
			//Only allow to upgrade the treasure card
			r = playCard(0, choice1, choice2, 0, &G);
			
			passes = 1;
			if (choice1 == copper &&
				(choice2 != copper || choice2 != silver) &&
				r == 0) {
				printf("Illegal move %d: traded in %d for %d. -- ", r, choice1, supply[j]);
				printf("Cost of copper is %d, and cost of %d is %d\n", getCost(copper), i, getCost(i));
				passes = 0;
			}
			if (choice1 == silver &&
				(choice2 != silver || choice2 != gold) &&
				r == 0) {
				printf("Illegal move %d: traded in %d for %d. -- ", r, choice1, supply[j]);
				printf("Cost of copper is %d, and cost of %d is %d\n", getCost(silver), i, getCost(G.hand[0][i]));
				passes = 0;
			}
			if (choice1 == silver &&
				(choice2 != silver || choice2 != gold) &&
				r == 0) {
				printf("Illegal move %d: traded in %d for %d. -- ", r, choice1, supply[j]);
				printf("Cost of copper is %d, and cost of %d is %d\n", getCost(silver), i, getCost(G.hand[0][i]));
				passes = 0;
			}
			if (choice1 == gold &&
				choice2 != gold &&
				r == 0) {
				printf("Illegal move %d: traded in %d for %d. -- ", r, choice1, supply[j]);
				printf("Cost of copper is %d, and cost of %d is %d\n", getCost(silver), i, getCost(G.hand[0][i]));
				passes = 0;
			}
		}
	}
	
	myAssert(passes);
	
	return 0;
}
Exemple #15
0
int main() {
    int i;
    int seed = 1000;
    int numPlayer = 2;

    int r, expecHand, expecDeck;
    

    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G, test;
  
    // arrays of all coppers, silvers, and golds
    int coppers[MAX_HAND];
    int silvers[MAX_HAND];
    int golds[MAX_HAND];
    
    int choice1 = 0;
    int choice2 = 0;
    int choice3 = 0;
    int bonus = 0;

    int discardCheck;

    for (i = 0; i < MAX_HAND; i++)
    {
        coppers[i] = copper;
        silvers[i] = silver;
        golds[i] = gold;
    }

    printf ("TESTING mine card:\n");
    int p = 0;
    int otherP = 1;
        
#if (NOISY_TEST == 1)
                printf("Test player %d playing a mine card with choice1 = copper, choice2 = silver\n", p);
#endif

                memset(&G, 23, sizeof(struct gameState));   // clear the game state

                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
                
                //store expected hand count for comparison after function execution
                expecHand = G.handCount[p] - 1;
                expecDeck = G.deckCount[p];
                G.hand[p][1] = copper;
                //save gamestate
                memcpy(&test, &G, sizeof(struct gameState));
                //call function to be tested 
                cardEffect(mine, 1, silver, choice3, &G, 0, &bonus);
                



#if (NOISY_TEST == 1)
                //print results of hand count check
                printf("hand count = %d, expected = %d\n", G.handCount[p], expecHand);
            

                //check if smithy card was successfully discarded
                if(G.hand[p][0] != mine)
                	discardCheck = 0;

                else
                	discardCheck = 1;

                //print result of discard test
                printf("Card discarded? %d\n", discardCheck);

        
#endif
                //check player's hand count 
               if(G.handCount[p] != expecHand){
                    printf("Tests FAILED: Wrong number of cards added to hand!\n");
                }

                else{
                    assert(G.handCount[p] == expecHand); 

                    printf("Tests PASSED: Right number of cards added to hand!\n");
                }

                //check if correct card discarded and print pass message
                if(discardCheck != 0){
                    printf("Tests FAILED: Mine card not discarded!\n");
                }

                else{
                    assert(discardCheck == 0);
                    printf("Tests PASSED: Mine card discarded!\n");
                }

                //check player's deck count
                if(G.deckCount[p] != expecDeck){
                    printf("Tests FAILED: Wrong number of cards removed from deck\n");
                }

                else{
                    assert(G.deckCount[p] == expecDeck);
                    printf("Tests PASSED: Right number of cards removed from deck!\n");

                }

                //check other player's deck count
                if(G.deckCount[otherP] != test.deckCount[otherP]){
                    printf("Tests FAILED: Deck of other player changed!\n");
                }

                else{
                    assert(G.deckCount[otherP] == test.deckCount[otherP]);
                    printf("Tests PASSED: Deck of other player not changed!\n");
                }

                //check other player's hand count
                if(G.handCount[otherP] != test.handCount[otherP]){
                    printf("Tests FAILED: Hand of other player changed!\n");
                }

                else{
                    assert(G.handCount[otherP] == test.handCount[otherP]);
                    printf("Tests PASSED: Hand of other player not changed!\n");
                }


                int cardDrawn = G.hand[p][G.handCount[p] - 1];
               

                if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold){
                    assert(cardDrawn == copper || cardDrawn == silver || cardDrawn == gold);
                    printf("Tests PASSED: Card drawn is a treasue card!\n");
                }

                else{
                    printf("Tests FAILED: Card drawn is not a treasure card!\n");

                }

                printf("\n");

#if (NOISY_TEST == 1)
                printf("Test player %d playing a mine card with choice1=gold, choice2=copper\n", p);
#endif

                memset(&G, 23, sizeof(struct gameState));   // clear the game state

                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
                
                //store expected hand count for comparison after function execution
                expecHand = G.handCount[p];
                G.hand[p][1] = gold;
                expecDeck = G.deckCount[p];
                //save gamestate
                memcpy(&test, &G, sizeof(struct gameState));
                //call function to be tested 
                cardEffect(mine, 1, copper, choice3, &G, 0, &bonus);

#if (NOISY_TEST == 1)
                //print results of hand count check
                printf("hand count = %d, expected = %d\n", G.handCount[p], expecHand);
            

                //check if smithy card was successfully discarded
                if(G.hand[p][0] != mine)
                    discardCheck = 0;

                else
                    discardCheck = 1;

                //print result of discard test
                printf("Card discarded? %d\n", discardCheck);

        
#endif
                //check player's hand count 
               if(G.handCount[p] != expecHand){
                    printf("Tests FAILED: Wrong number of cards added to hand!\n");
                }

                else{
                    assert(G.handCount[p] == expecHand); 

                    printf("Tests PASSED: Right number of cards added to hand!\n");
                }

                //check if correct card discarded and print pass message
                if(discardCheck != 0){
                    printf("Tests FAILED: Mine card not discarded!\n");
                }

                else{
                    assert(discardCheck == 0);
                    printf("Tests PASSED: Mine card discarded!\n");
                }

                //check player's deck count
                if(G.deckCount[p] != expecDeck){
                    printf("Tests FAILED: Wrong number of cards removed from deck\n");
                }

                else{
                    assert(G.deckCount[p] == expecDeck);
                    printf("Tests PASSED: Right number of cards removed from deck!\n");

                }

                //check other player's deck count
                if(G.deckCount[otherP] != test.deckCount[otherP]){
                    printf("Tests FAILED: Deck of other player changed!\n");
                }

                else{
                    assert(G.deckCount[otherP] == test.deckCount[otherP]);
                    printf("Tests PASSED: Deck of other player not changed!\n");
                }

                //check other player's hand count
                if(G.handCount[otherP] != test.handCount[otherP]){
                    printf("Tests FAILED: Hand of other player changed!\n");
                }

                else{
                    assert(G.handCount[otherP] == test.handCount[otherP]);
                    printf("Tests PASSED: Hand of other player not changed!\n");
                }


                cardDrawn = G.hand[p][G.handCount[p] - 1];
               

                if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold){
                    assert(cardDrawn == copper || cardDrawn == silver || cardDrawn == gold);
                    printf("Tests PASSED: Card drawn is a treasue card!\n");
                }

                else{
                    printf("Tests FAILED: Card drawn is not a treasure card!\n");

                }


               
                
                printf("\n");

#if (NOISY_TEST == 1)
                printf("Test player %d playing a mine card with choice1 not a treasure card\n", p);
#endif

                memset(&G, 23, sizeof(struct gameState));   // clear the game state

                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
                
                //store expected hand count for comparison after function execution
                expecHand = G.handCount[p];
                expecDeck = G.deckCount[p];
                G.hand[p][1] = estate;
                //save gamestate
                memcpy(&test, &G, sizeof(struct gameState));
                //call function to be tested 
                cardEffect(mine, 1, gold, choice3, &G, 0, &bonus);

#if (NOISY_TEST == 1)
                //print results of hand count check
                printf("hand count = %d, expected = %d\n", G.handCount[p], expecHand);
            

                //check if smithy card was successfully discarded
                if(G.hand[p][0] != mine)
                    discardCheck = 0;

                else
                    discardCheck = 1;

                //print result of discard test
                printf("Card discarded? %d\n", discardCheck);

        
#endif
                //check player's hand count 
               if(G.handCount[p] != expecHand){
                    printf("Tests FAILED: Wrong number of cards added to hand!\n");
                }

                else{
                    assert(G.handCount[p] == expecHand); 

                    printf("Tests PASSED: Right number of cards added to hand!\n");
                }

                //check if correct card discarded and print pass message
                if(discardCheck != 0){
                    printf("Tests FAILED: Mine card not discarded!\n");
                }

                else{
                    assert(discardCheck == 0);
                    printf("Tests PASSED: Mine card discarded!\n");
                }

                //check player's deck count
                if(G.deckCount[p] != expecDeck){
                    printf("Tests FAILED: Wrong number of cards removed from deck\n");
                }

                else{
                    assert(G.deckCount[p] == expecDeck);
                    printf("Tests PASSED: Right number of cards removed from deck!\n");

                }

                //check other player's deck count
                if(G.deckCount[otherP] != test.deckCount[otherP]){
                    printf("Tests FAILED: Deck of other player changed!\n");
                }

                else{
                    assert(G.deckCount[otherP] == test.deckCount[otherP]);
                    printf("Tests PASSED: Deck of other player not changed!\n");
                }

                //check other player's hand count
                if(G.handCount[otherP] != test.handCount[otherP]){
                    printf("Tests FAILED: Hand of other player changed!\n");
                }

                else{
                    assert(G.handCount[otherP] == test.handCount[otherP]);
                    printf("Tests PASSED: Hand of other player not changed!\n");
                }


                cardDrawn = G.hand[p][G.handCount[p] - 1];
               

                if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold){
                    assert(cardDrawn == copper || cardDrawn == silver || cardDrawn == gold);
                    printf("Tests PASSED: Card drawn is a treasue card!\n");
                }

                else{
                    printf("Tests FAILED: Card drawn is not a treasure card!\n");

                }


               
                
                printf("\n");





    return 0;
}
int main() {

  srand(time(NULL));

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

  int i, j, players, player, handCount, deckCount, seed;
  int result, beforeDiscard, numTreasure, numTreasureAfter;
  struct gameState state;

  printf("Running Random Treasure Map Test\n");

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

    players = rand() % 2 + 2;
    player = rand() % players;

    seed = rand();		//pick random seed

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

    state.whoseTurn = player;
    numTreasure = 0;
    numTreasureAfter = 0;

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

    //
    // Fill the player's deck, discard pile, and hand with random cards.
    //
    for (j = 0; j < state.deckCount[player]; j++){
      state.deck[player][j] = rand() % (treasure_map + 1);
    }
    for (j = 0; j < state.discardCount[player]; j++){
      state.discard[player][j] = rand() % (treasure_map + 1);
    }
    for (j = 0; j < state.handCount[player]; j++){
      state.hand[player][j] = rand() % (treasure_map + 1);
    }

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

    updateCoins(state.whoseTurn, &state, 0);
    beforeDiscard = state.discardCount[player];

    if(state.hand[player][0] != treasure_map){
      state.hand[player][0] = treasure_map;
    }

    for (j = 0; j < state.handCount[player]; j++){
      if (state.hand[player][j] == treasure_map){
        numTreasure++;
      }
    }

    result = cardEffect(treasure_map, 0, 0, 0, &state, 0, 0); // Run treasure_map

    updateCoins(state.whoseTurn, &state, 0);

    //
    // If the card fails, then it shouldn't have done anything.
    //
    if (result == -1){
      continue;
    }

    for (j = 0; j < state.handCount[player]; j++){
      if (state.hand[player][j] == treasure_map){
        numTreasureAfter++;
      }
    }
    if (numTreasure != numTreasureAfter + 2){
      printf("ERROR on %d\n", i);
      printf("NumTreasures does not match:%d %d\n", numTreasure, numTreasureAfter);
    }

    //
    // Check that the handcount went down two.
    //
    if (state.handCount[player] != handCount - 2){
      printf("ERROR on %d\n", i);
      printf("After HandCount: %d\nBefore handcount: %d\n", 
              state.handCount[player], 
              handCount);
    }
    //
    // Check that the discard pile did not change (trash the cards).
    //
    if (state.discardCount[player] != beforeDiscard){
      printf("ERROR on %d\n", i);
      printf("After discardCount: %d\nBefore discardCount: %d\n", 
              state.discardCount[player], 
              beforeDiscard);
    }

    //
    // Check that the deckcount went up 4.
    //
    if (state.deckCount[player] != deckCount + 4){
      printf("ERROR on %d\n", i);
      printf("After deckCount: %d\nBefore deckCount: %d\n", 
              state.deckCount[player], 
              deckCount);
    }

    //
    // Check that the top 4 cards in the deck are gold.
    //
    for(j = 0; j < 4; j++){
      if (state.deck[player][state.deckCount[player] - j - 1] != gold){
        printf("ERROR on %d\n", i);
        printf("There are not 4 golds at the top of the deck\n"); 
      }
    }
  }

  printf("Tests Complete\n");

  return 0;
}
Exemple #17
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: Current player receives 3 cards --------------
	printf("TEST 1: Current player receives 3 cards\n\n");

	// copy the game state to a test case 
	memcpy(&testG, &G, sizeof(struct gameState));

	cardEffect(smithy, choice1, choice2, choice3, &testG, handpos, &bonus);

	newCards = 3;
	xtraCoins = 0;

	printf("hand count = %d, expected = %d\n", testG.handCount[thisPlayer], G.handCount[thisPlayer] + newCards - discarded);
	
	//Assert fails- Player receives four cards
	//assert(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded);

	printf("\n");

	// ----------- TEST 2: 3 cards come from his/her own pile --------------
	printf("TEST 2: 3 cards come from his/her own pile\n\n");

	printf("deck count = %d, expected = %d\n", testG.deckCount[thisPlayer], G.deckCount[thisPlayer] - newCards + shuffledCards);

	//Assert fails- Four cards come from player's deck
	//assert(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards + shuffledCards);

	printf("\n");
	// ----------- TEST 3: No state changes for other players --------------
	printf("TEST 3: No state changes for other players\n\n");
	for (i = 0; i < MAX_PLAYERS; i++) 
	{
		if (i != thisPlayer) 
		{
			if (i >= numPlayers) 
			{
				printf("Note: Player not currently in use.\n");
			}

			printf("Asserting here that cards in player %d's hand haven't changed.\n", i);
			for (j = 0; j < MAX_HAND; j++) 
			{
				assert(testG.hand[i][j] == G.hand[i][j]);
			}

			printf("Player %d: hand count = %d, expected = %d\n", i, testG.handCount[i], G.handCount[i]);
			assert(testG.handCount[i] == G.handCount[i]);
			
			printf("Asserting here that cards in player %d's deck haven't changed.\n", i);
			for (j = 0; j < MAX_DECK; j++)
			{
				assert(testG.deck[i][j] == G.deck[i][j]);
			}

			printf("Player %d: deck count = %d, expected = %d\n", i, testG.deckCount[i], G.deckCount[i]);
			assert(testG.deckCount[i] == G.deckCount[i]);

			printf("Asserting here that cards in player %d's discard pile haven't changed.\n", i);
			for (j = 0; j < MAX_DECK; j++)
			{
				assert(testG.discard[i][j] == G.discard[i][j]);
			}

			printf("Player %d: discard count = %d, expected = %d\n", i, testG.discardCount[i], G.discardCount[i]);
			assert(testG.discardCount[i] == G.discardCount[i]);
			printf("\n");
		}
	}


	printf("\n");
	// ----------- TEST 4: No state changes for victory card piles & kingdom card piles --------------
	printf("TEST 4: No state changes for victory card piles & kingdom card piles\n\n");

	for (i = 0; i < (treasure_map + 1); i++)
	{
		printf("Card %d: supply count = %d, expected = %d\n", i, testG.supplyCount[i], G.supplyCount[i]);
		assert(testG.supplyCount[i] == G.supplyCount[i]);
	}

	printf("\n");

	for (i = 0; i < (treasure_map + 1); i++)
	{
		printf("Card %d: embargo tokens = %d, expected = %d\n", i, testG.embargoTokens[i], G.embargoTokens[i]);
		assert(testG.embargoTokens[i] == G.embargoTokens[i]);
	}

	printf("\n");
	// ----------- TEST 5: Check one card added to played card pile --------------
	printf("TEST 5: Check for correct number of played cards\n\n");

	printf("Played card count = %d, expected = %d\n", testG.playedCardCount, G.playedCardCount + 1);
	assert(testG.playedCardCount == (G.playedCardCount + 1));
	printf("\n");

	printf("\n");
	// ----------- TEST 6: Player should receive no extra coins --------------
	printf("TEST 6: Current player should receive no extra coins\n\n");

	printf("coins = %d, expected = %d\n", testG.coins, G.coins + xtraCoins);
	assert(testG.coins == (G.coins + xtraCoins));


	printf("\n >>>>> SUCCESS: Testing complete %s <<<<<\n\n", TESTCARD);

	return 0;
}
Exemple #18
0
int main() {
        /* initialize bare minimum game variables  */
        int seed = 101; // seed for game init
        int numPlayers = 2;     // number of players
        int kCards[10] = {adventurer, council_room, feast,      // kingdom cards
        gardens, mine, remodel, smithy, village, baron, great_hall};
        struct gameState gState;
        int r = initializeGame(numPlayers, kCards, seed, &gState);      // initialize a new game
        int s;  // exit status for function

        /* extra parameters specific to this function  */
        int currentPlayer;

        /*  game state variables used by this function  */   
        int card;
        int coins;
        int handCount;

        /*  counter variables  */


        // test over all players
        for(currentPlayer = 0; currentPlayer < numPlayers; currentPlayer++){
            // test over some choices of card to buy
            for(card = council_room; card < smithy; card++){
                // test over some initial hand counts
                for(handCount = 0; handCount < 3; handCount ++){
                    memset(&gState, 23, sizeof(struct gameState));          // clear the game state
                    r = initializeGame(numPlayers, kCards, seed, &gState);  // initialize the game

                    // set add'l game variables
                    initCopper(&gState, currentPlayer, handCount);	// initialze player's hand
                    gState.coins = 0;				// and 0 coins
                    gState.discardCount[currentPlayer] = 0;	// and 0 discards
                    updateCoins(currentPlayer, &gState, 0);	// and update for correct # of coins

                    // get # of coins before playing card
                    coins = gState.coins;

                    // call the function under test
                    s = cardFeast(&gState, currentPlayer, card);

                    // tests
                    // check for the purchased card in discard pile
                    if(findCard(&gState, currentPlayer, card) == 1){
                        printPass();
                    }
                    else printFail();
                    printTest("presence of purchased card in discard", 1, findCard(&gState, currentPlayer, card), currentPlayer);

                    // check # of coins
                    updateCoins(currentPlayer, &gState, 0);
                    if(coins == gState.coins){
                        printPass();
                    }
                    else printFail();
                    printTest("# of coins in game state", coins, gState.coins, currentPlayer);
                }
            }
        }
        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;
}
Exemple #20
0
int testAdven(int *hand, int player, int handCount, int handpos, int changeDeck){
	
	int i=0;
	struct gameState state;
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
	initializeGame(2,k,1000,&state);
	
	memcpy(state.hand[player], hand, sizeof(int)*handCount);
	state.handCount[player] = handCount;
	
	int deckCount = state.deckCount[player];

	//Use to add a mine card to the top of the deck to see if it is skipped
	if(changeDeck == 1){
		state.deck[player][state.deckCount[player]-1] = mine;
	}
	
	//Set the deck count to 0
	if(changeDeck == 2){
		state.deckCount[player]=0;
	}
	
	cardEffect(state.hand[player][handpos],0,0,0,&state,handpos,0);
	
	int count=0;
	
	for(i=0; i<handCount; i++){
		if(state.deck[player][i] == 7){
			count++;
		}
	}
	if(count>0){
		printf("\tTEST FAILED - The adventurer card should have been removed from the hand.\n");
	}
	else{
		printf("\tTEST PASSED - The adventurer card was removed from the hand.\n");
	}
	count=0;
	for(i=0; i<state.handCount[player]; i++){
		if(state.deck[player][i] == 4){
			count++;
		}
	}
	if(count == 2){
		printf("\tTEST FAILED - Not enough treasure cards were added to the hand.\n");
	}
	if(changeDeck == 1){
		if(deckCount-state.deckCount[0] > 2){
			printf("\tTEST PASSED - The mine card was correctly skipped.\n");
		}
		else{
			printf("\tTEST FAILED - The mine card was not skipped.\n");
		}
	}
	if(changeDeck == 0){
		if(deckCount-state.deckCount[0] > 1){
			printf("\tTEST PASSED - The deck was reduced by at least 2 cards.\n");
		}
		else{
			printf("\tTEST FAILED - The deck was not reduced by at least 2 cards.\n");
		}
	}
	count=0;
	for(i=0; i<state.handCount[player]; i++){
		if(state.deck[player][i] == -1){
			count++;
		}
	}
	if(count>0){
		printf("\tTEST FAILED - A card in the hand was replaced by a -1.\n");
	}
	else{
		printf("\tTEST PASSED - All cards were replaced with valid cards.\n");
	}

	return 0;
}
Exemple #21
0
int main() {
	struct gameState G;
	struct gameState testG;
	int k[10] = {adventurer, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy, council_room};
	int i; // Loop iterator
	int numPlayers = 2;
	int seed = 1000;
	int curPlayer = 0;
	int otherPlayer = 1;
	int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
	int newCards = 2;
	int testNum = 0;
	int handPassed = 0; //counter for correct currentPlayer handCount
	int deckPassed = 0; //counter for correct currentPlayer deckCount
	int otherHandPassed = 0; //counter for correct otherPlayer handCount
	int otherDeckPassed = 0; //counter for correct otherPlayer handCount
	int randHand, randDeck; //variable to store random number of currentPlayer handCount and deckCount
	int negRandHand = 0; // Counter for handCount > 500
	int negDeckHand = 0; // counter for deckCount > 500
	int overRandHand = 0; // counter for handCount < 0
	int overDeckHand = 0; // counter for deckCount < 0
	int zeroHand = 0; // counter for handCount == 0
	int zeroDeck = 0; // counter for deckCount == 0
	time_t t;
	
	// Initialize random number generator for testing
	srand((unsigned) time(&t));
	
    // initialize the game state and player cards
    initializeGame(numPlayers, k, seed, &G);
    printf("---------- Testing adventurer card ----------\n"); 

for (i = 0; i <100000; i++) {
	//printf("Test Number: %d\n", testNum);
    // copy the game state to a test case
    memcpy(&testG, &G, sizeof(struct gameState));
	
	// Generate random number of cards for testG hand
	randHand = rand() % MAX_HAND - 1;
	randDeck = rand() % MAX_DECK - 1;
	//printf("randHand: %d\n", randHand);
	//printf("randDeck: %d\n", randDeck);

	if (randHand < 0)
		negRandHand++;
	if (randDeck < 0)
		negDeckHand++;
	if (randHand == 0)
		zeroHand++;
	if (randDeck == 0)
		zeroDeck++;
	
	testG.handCount[curPlayer] = randHand;
	testG.deckCount[curPlayer] = randDeck;
	
	//play adventurer card on testG check handCount
    cardEffect(adventurer, choice1, choice2, choice3, &testG, handpos, &bonus);
    if ( testG.handCount[curPlayer] == G.handCount[curPlayer] + newCards){
		//printf("handCount: Passed\n");
		handPassed++;
	}
	else
		//printf("handCount: Failed\n");
    //check adventure card on testG check deckCount
    if ( testG.deckCount[curPlayer] <= G.deckCount[curPlayer]) {
		//printf("deckCount: Passed\n");
		deckPassed++;
	}
	else
		//printf("deckCount: Failed\n");
    //check that other players state is not changed
    if ( testG.handCount[otherPlayer] == G.handCount[otherPlayer]) {
		//printf("otherPlayer handCount: Passed\n");
		otherHandPassed++;
	}
	else
		//printf("otherPlayer handCount: Failed\n");
	//check adventure card on testG check deckCount
    if ( testG.deckCount[otherPlayer] == G.deckCount[otherPlayer]) {
		//printf("otherPlayer deckCount: Passed\n");
		otherDeckPassed++;
	}
	else
		//printf("otherPlayer deckCount: Failed\n");
	testNum++;
}
	printf("Total Tests: %d\n", testNum);
	printf("handCount Passed: %d\n", handPassed);
	printf("deckCount Passed: %d\n", deckPassed);
	printf("otherPlayer handCount Passed: %d\n", otherHandPassed);
	printf("otherPlayer deckCount Passed: %d\n", otherDeckPassed);
	printf("negRandHand: %d\n", negRandHand);
	printf("negDeckHand: %d\n", negDeckHand);
	printf("zeroHand: %d\n", zeroHand);
	printf("zeroHand: %d\n", zeroDeck);

	return 0;
}
int main (int argc, char** argv) {
  struct gameState G;
  struct gameState *p = &G;
  int *k,i, players, money = 0, chosenCard=0, playedCard=0, flag=0, buyc=0;
  

  printf ("Starting game.\n");
  k=randomKingdom();
 /* for(i=0; i<10; i++){
    printf("%d\n",k[i]);
  }*/
  players = rand() % 2 + 2;

  initializeGame(players, k, rand(), p);
  

  while (!isGameOver(p)) { //loop for every turn
    printf("#Player%d's turn ###################################\n", whoseTurn(p)+1);
    money = 0;

    printf("-Check hand for treaure.\n");
    for (i = 0; i < numHandCards(p); i++) { //check if the current player has any treasures
      if (handCard(i, p) == copper){
        money++;
        printf("get 1 coin with copper\n");
      }
      else if (handCard(i, p) == silver){
        money += 2;
        printf("get 2 coins with silver\n");
      }
      else if (handCard(i, p) == gold){
        money += 3;
        printf("get 3 coins with gold\n");

      }
    }
    printf("Current coins: %d\n", money);
    printf("Current num of cards (before) %d\n", p->handCount[whoseTurn(p));
      flag=1;
      for(i=0; i< p->handCount[whoseTurn(p)]; i++){
        if (p->hand[whoseTurn(p)][i]!=copper && p->hand[whoseTurn(p)][i] != silver && p->hand[whoseTurn(p)][i] != gold)
          flag=0;
      }
      if(flag==0){ //play a card
        while (flag==0){
          chosenCard=rand() % p->handCount[whoseTurn(p)];
          if (chosenCard!=copper && chosenCard != silver && chosenCard != gold)
            flag=1;
        }
        flag=0;

        playedCard=p->hand[whoseTurn(p)][chosenCard];
          printf("%s played from position %d\n", whichCard(playedCard), chosenCard); 
  	      playCard(chosenCard, 1, 1, 1, p); 
  	      printf("%s played.\n", whichCard(playedCard));
          printf("Current num of cards (after) %d\n", p->handCount[whoseTurn(p));
          if(playedCard==22){
            //printf("\n\n\nembargo\n\n\n\n\n");
            embargoTest(G, whoseTurn(p));
          }
  	      money = 0;
  	      i=0;
  	      while(i<numHandCards(p)){
  	       if (handCard(i, p) == copper){
  	         playCard(i, -1, -1, -1, p);
  	         money++;
  	       }
  	       else if (handCard(i, p) == silver){
  	         playCard(i, -1, -1, -1, p);
  	         money += 2;
  	       }
  	       else if (handCard(i, p) == gold){
  	         playCard(i, -1, -1, -1, p);
  	         money += 3;
  	       }
  	       i++;
  	     }
        }
      

      buyc=random()%2-2;
      if(buyc==-1){
        int x=0;
        x=random()%3;
        if(x==0)
          buyc=copper;
        else if(x==1)
          buyc=silver;
        else
          buyc=gold;
      }
      else{
        buyc = k[random()%10];
      }
      printf("attempting to buy %s\n", whichCard(buyc)); 
      buyCard(buyc, p);
      


      printf ("Player %d's current score: %d\n", whoseTurn(p)+1, scoreFor(whoseTurn(p), p));
      printf("Player %d's turn ends.\n", whoseTurn(p)+1);
	    endTurn(p);

  } // end of While

  printf ("Finished game.\n");
  printf(":FINAL RESULT:::::::::::::::::::::::::::::::\n");
  for (i=0; i<players; i++){
    printf ("Player %d's final score: %d\n", i+1, scoreFor(i, p));
  }

  return 0;
}
Exemple #23
0
int main() {
	printf("*** Card test for: %s ***\n", TEST_CARD);

	/* Smithy Card Modifications */
	int nActions = 0;  /* Number of additional actions */
	int nBuys = 0;  /* Number of additional buys */
	int nCards = 1;  /* Number of additional cards */
	int nCoins = 0;  /* Nmber of additional coins */
	int pCards = 1;  /* Number of cards played */
	int tCards = 1;  /* Numer of cards trashed */
	int handPos = 0;  /* Initial location of card */
	int choice1 = 1, choice2 = mine, choice3 = 0;  /* Card choice options */
	

	/* Initalize gamestate */
	struct gameState testGame;
	struct gameState origGame;
	int cards[10] = { adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall };
	int baseCards[7] = { curse, estate, duchy, province, copper, silver, gold };
	int bonus = 0;  /* Player's bonus */
	int testValue;
	int origValue;
	assert(initializeGame(PLAYERS, cards, RANDOM_SEED, &testGame) == 0);  /* Initalize game and verify completion */

	/* Initalize test counters */
	int passCount = 0;  /* Number of tests passed */
	int failCount = 0;  /* Number of tests failed */

	/* The remodal card trashes a card from the hand (choice1) and gains a card costing up to 2 more (choice2) */
	int testPlayer = 0;
	testGame.whoseTurn = testPlayer;
	testGame.hand[testPlayer][handPos] = remodel;  /* Add smithy to test player's hand */
	testGame.hand[testPlayer][choice1] = silver;  /* Add silver (cost=3) to test player's choice1 location */
	testGame.phase = 0;  /* Set phase to action */
	testGame.numActions = 1;  /* Set number of actions to 1*/
	memcpy(&origGame, &testGame, sizeof(struct gameState)); /* Copy to preserve original state */
	printf("\n--- Verify %s card effects are correct ---\n", TEST_CARD);
	if (cardEffect(remodel, choice1, choice2, choice3, &testGame, handPos, &bonus) == 0) { /* Play remodel card */
		printf("  PASS: cardEffect() method completed successfully\n");
		passCount++;
		
		/* Compare hand count with predicted */
		testValue = testGame.handCount[testPlayer];
		origValue = origGame.handCount[testPlayer] + nCards - pCards - tCards;
		if (testValue == origValue) {
			printf("  PASS: Hand Count - Actual = %d; Expected = %d\n", testValue, origValue);
			passCount++;
		}
		else {
			printf("  FAIL: Hand Count - Actual = %d; Expected = %d\n", testValue, origValue);
			failCount++;
		}
		
		/* Compare deck count with predicted */
		testValue = testGame.deckCount[testPlayer];
		origValue = origGame.deckCount[testPlayer] - nCards;
		if (testValue == origValue) {
			printf("  PASS: Deck Count - Actual = %d; Expected = %d\n", testValue, origValue);
			passCount++;
		}
		else {
			printf("  FAIL: Deck Count - Actual = %d; Expected = %d\n", testValue, origValue);
			failCount++;
		}

		/* Compare played count with predicted */
		testValue = testGame.playedCardCount;
		origValue = origGame.playedCardCount + pCards;
		if (testValue == origValue) {
			printf("  PASS: Played Count - Actual = %d; Expected = %d\n", testValue, origValue);
			passCount++;
		}
		else {
			printf("  FAIL: Played Count - Actual = %d; Expected = %d\n", testValue, origValue);
			failCount++;
		}

		/* Compare actions with predicted */
		testValue = testGame.numActions;
		origValue = origGame.numActions + nActions;
		if (testValue == origValue) {
			printf("  PASS: Action Count - Actual = %d; Expected = %d\n", testValue, origValue);
			passCount++;
		}
		else {
			printf("  FAIL: Action Count - Actual = %d; Expected = %d\n", testValue, origValue);
			failCount++;
		}

		/* Compare buys with predicted */
		testValue = testGame.numBuys;
		origValue = origGame.numBuys + nBuys;
		if (testValue == origValue) {
			printf("  PASS: Buy Count - Actual = %d; Expected = %d\n", testValue, origValue);
			passCount++;
		}
		else {
			printf("  FAIL: Buy Count - Actual = %d; Expected = %d\n", testValue, origValue);
			failCount++;
		}

		/* Compare coin count with predicted */
		testValue = testGame.coins;
		origValue = origGame.coins + nCoins;
		if (testValue == origValue) {
			printf("  PASS: Coin Count - Actual = %d; Expected = %d\n", testValue, origValue);
			passCount++;
		}
		else {
			printf("  FAIL: Coin Count - Actual = %d; Expected = %d\n", testValue, origValue);
			failCount++;
		}

		printf("\n--- Verify other players have not been effected ---\n");
		/* Verify other players were not effected */
		int passFlag = 1;
		for (int i = 0; i < PLAYERS; i++) {
			if (i == testPlayer) {
				printf("Player %d of %d is tested player\n", i+1, PLAYERS);
				continue;  /* Skip test player*/
			}
			printf("Verifying Player %d of %d\n", i+1, PLAYERS);
			
			/* Test other player's hand*/
			if (testGame.handCount[i] == origGame.handCount[i]) {
				passFlag = 1;
				for (int j = 0; j < testGame.handCount[i]; j++) {
					if (testGame.hand[i][j] != origGame.hand[i][j]) {
						passFlag = 0;
						break;
					}
				}
			}
			else {
				passFlag = 0;
			}
			if (passFlag == 1) {
				printf("  PASS: Player %d hand is uneffected\n", i + 1);
				passCount++;
			}
			else {
				printf("  FAIL: Player %d hand is effected\n", i + 1);
				failCount++;
			}

			/* Test other player's deck */
			if (testGame.deckCount[i] == origGame.deckCount[i]) {
				passFlag = 1;
				for (int j = 0; j < testGame.deckCount[i]; j++) {
					if (testGame.deck[i][j] != origGame.deck[i][j]) {
						passFlag = 0;
						break;
					}
				}
			}
			else {
				passFlag = 0;
			}
			if (passFlag == 1) {
				printf("  PASS: Player %d deck is uneffected\n", i+1);
				passCount++;
			}
			else {
				printf("  FAIL: Player %d deck is effected\n", i+1);
				failCount++;
			}

			/* Test other player's discard */
			if (testGame.discardCount[i] == origGame.discardCount[i]) {
				passFlag = 1;
				for (int j = 0; j < testGame.discardCount[i]; j++) {
					if (testGame.discard[i][j] != origGame.discard[i][j]) {
						passFlag = 0;
						break;
					}
				}
			}
			else {
				passFlag = 0;
			}
			if (passFlag == 1) {
				printf("  PASS: Player %d discard is uneffected\n", i + 1);
				passCount++;
			}
			else {
				printf("  FAIL: Player %d discard is effected\n", i + 1);
				failCount++;
			}
			
		}

		printf("\n--- Verify card supply has not been effected ---\n");
		/* Action Cards */
		passFlag = 1;
		for (int i = 0; i < 10; i++) { 
			testValue = supplyCount(cards[i], &testGame);
			origValue = supplyCount(cards[i], &origGame);
			if (testValue != origValue) {
				passFlag = 0;
				break;
			}
		}
		if (passFlag == 1) {
			printf("  PASS: Action Card Supply is uneffected\n");
			passCount++;
		}
		else {
			printf("  FAIL: Action Card Supply is effected\n");
			failCount++;
		}

		/* Basic Cards */
		passFlag = 1;
		for (int i = 0; i < 7; i++) {  
			testValue = supplyCount(baseCards[i], &testGame);
			origValue = supplyCount(baseCards[i], &origGame);
			if (testValue != origValue) {
				passFlag = 0;
				break;
			}
		}
		if (passFlag == 1) {
			printf("  PASS: Basic Card Supply is uneffected\n");
			passCount++;
		}
		else {
			printf("  FAIL: Basic Card Supply is effected\n");
			failCount++;
		}

	}
	else {
		printf("  FAIL: cardEffect() method did not complete successfully\n");
		failCount++;
	}

	/* Print overall results */
	printf("\n--- Overall test results ---\n");
	printf("  PASS: %d of %d\n", passCount, passCount + failCount);
	printf("  FAIL: %d of %d\n", failCount, passCount + failCount);

	return 0;
}
Exemple #24
0
int main() {
    int seed = 1000;
    int numPlayer = 2;
    int r;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;


    printf ("TESTING village():\n");

    memset(&G, 23, sizeof(struct gameState));   // clear the game state
    r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
    G.handCount[0] = 5;                 // set the number of cards on hand to 5 for player 0


#if (NOISY_TEST == 1)
    printf("Starting value for G.handCount = %d\n", G.handCount[0]);
    printf("Starting value for G.numActions = %d\n", G.numActions);
    printf("Starting value for G.discardCount = %d\n", G.discardCount[0]);
    printf("Starting value for G.playedCardCount = %d\n\n", G.playedCardCount);
    printf("Calling village card function\n");
#endif

    villageAction(0, 0, &G);

#if (NOISY_TEST == 1)
    printf("G.handCount = %d, expected = %d\n", G.handCount[0], 5);
    printf("G.numActions = %d, expected = %d\n", G.numActions, 3);
    printf("G.playedCardCount = %d, expected = %d\n\n", G.playedCardCount, 1);
#endif

    assert(G.handCount[0] == 5);
    assert(G.numActions == 3);	//assertion fails as Actions is incorrectly incremented by 1
    assert(G.playedCardCount == 1);

#if (NOISY_TEST == 1)
    printf("Calling village card function\n");
#endif

    villageAction(0, 0, &G);

#if (NOISY_TEST == 1)
    printf("G.handCount = %d, expected = %d\n", G.handCount[0], 5);
    printf("G.numActions = %d, expected = %d\n", G.numActions, 5);
    printf("G.playedCardCount = %d, expected = %d\n\n", G.playedCardCount, 2);
#endif

    assert(G.handCount[0] == 5);
    assert(G.numActions == 5);	//assertion fails as Actions is incorrectly incremented by 1
    assert(G.playedCardCount == 2);

#if (NOISY_TEST == 1)
    printf("Calling village card function with different hand position\n");
#endif

    villageAction(1, 0, &G);

#if (NOISY_TEST == 1)
    printf("G.handCount = %d, expected = %d\n", G.handCount[0], 5);
    printf("G.numActions = %d, expected = %d\n", G.numActions, 7);
    printf("G.playedCardCount = %d, expected = %d\n\n", G.playedCardCount, 3);
#endif

    assert(G.handCount[0] == 5);
    assert(G.numActions == 7);	//assertion fails as Actions is incorrectly incremented by 1
    assert(G.playedCardCount == 3);

#if (NOISY_TEST == 1)
    printf("Calling village card function with different hand position\n");
#endif

    villageAction(2, 0, &G);

#if (NOISY_TEST == 1)
    printf("G.handCount = %d, expected = %d\n", G.handCount[0], 5);
    printf("G.numActions = %d, expected = %d\n", G.numActions, 9);
    printf("G.playedCardCount = %d, expected = %d\n\n", G.playedCardCount, 4);
#endif

    assert(G.handCount[0] == 5);
    assert(G.numActions == 9);	//assertion fails as Actions is incorrectly incremented by 1
    assert(G.playedCardCount == 4);

    printf("All tests passed!\n");

    return 0;
}
int main (int argc, char** argv) {
  struct gameState G;

  int i, j, players, player, handCount, deckCount, discardCount, handPos, difference, numActions, seed, coinBefore, coinAfter, testPass, testFail;

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

  int timeseed = 1457764002;
  //passing seeds: 1457763919, 1457764029, 1457764086, 1457764120, 1457764222, 1457764246
  //failing seeds: 1457764002, 1457764064, 1457764169, 1457764183, 1457764197, 1457764270

  srand(timeseed);
  players = 2;
	player = rand() % players;
  seed = rand();

  initializeGame(players, k, seed, &G);

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

  for (j = 0; j < G.deckCount[player]; j++) {
    G.deck[player][j] = rand() % (treasure_map + 1);
  }
  for (j = 0; j < G.handCount[player]; j++) {
    G.hand[player][j] = rand() % (treasure_map + 1);
  }
  for (j = 0; j < G.discardCount[player]; j++) {
    G.discard[player][j] = rand() % (treasure_map + 1);
  }

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

  //test option 1
  G.hand[player][0] = steward;

  if (seed % 3 == 0) {
    G.deckCount[player] = 0;
  }

  int numCards = numHandCards(&G);
  cardEffect(steward, 1,0,0,&G,0,0);
  int numCardsAfter = numHandCards(&G);

  if(numCardsAfter - numCards == 1){
    testPass++;
  } else {
    testFail++;
  }
  //test option 2
  G.hand[player][0] = steward;

  coinBefore = G.coins;
  cardEffect(steward, 2,0,0,&G,0,0);
  coinAfter = G.coins;

  if((coinAfter-coinBefore == 2)){
    testPass++;
  } else {
    testFail++;
  }
  //test option 3
  G.hand[player][0] = steward;

  numCards = numHandCards(&G);
  cardEffect(steward, 3,0,0,&G,0,0);
  numCardsAfter = numHandCards(&G);

  if(numCards - numCardsAfter == 3){
    testPass++;
  } else {
    testFail++;
  }

  if (testFail > 0){
    printf("F\n");
  } else {
    printf("P\n");
  }
  return 0;
}
Exemple #26
0
int main(){
	int r = 1;
	int seed = 1000;
	int numPlayer = 2;
	struct gameState *G = malloc(sizeof(struct gameState));
	int prevTreasureCards = 0;
	int postTreasureCards = 0;
	
	int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
	
	if (NOISY_TEST) printf("*** %s Start \n", __FILE__);
	printf("=== Testing %s ===\n", __FILE__);
	
	printf ("Testing ADVENTURER Card \n");
	
	//initialize game, code taken from example
	memset(G, 23, sizeof(struct gameState)); //clears the game state
	r = initializeGame(numPlayer, k, seed, G); //initialize a new game
	assert(r == 0); //this checks that initializeGame() ran and returned 0
	
	int currentPlayer = whoseTurn(G);
	
	//assign Adventurer card to player's hand position 0
	G->hand[currentPlayer][0] = adventurer;
	
	//cards in hand before Adventurer is played
	int handCount = G->handCount[currentPlayer];
	
	/*there should be two more Treasure cards in hand after Adventurer is played*/
	
	//for loop to check number of Treasure cards before Adventurer is played
	int i;
	int currentCard;
	for (i = 0; i < handCount; i++){
		currentCard = G->hand[currentPlayer][i];
		if(currentCard == copper || currentCard == silver || currentCard == gold){
			prevTreasureCards++;
		}
	}
	
	//play Adventurer card
	newAdventurer(currentPlayer, G);
	
	//for loop to check number of Treasure cards after Adventurer is played
	handCount = G->handCount[currentPlayer];
	for (i = 0; i < handCount; i++){
		currentCard = G->hand[currentPlayer][i];
		if(currentCard == copper || currentCard == silver || currentCard == gold){
			postTreasureCards++;
		}
	}
	
	//Debugging purposes
	printf ("previous Treasure Cards: %d \n", prevTreasureCards);
	printf ("post-action Treasure Cards: %d \n", postTreasureCards);
	
	if (postTreasureCards != (prevTreasureCards + 2)){
		printf ("Player does not have correct amount of cards in hand after playing ADVENTURER card. Test FAILED. \n");
	}
	
	if(postTreasureCards == (prevTreasureCards + 2)){
		printf("All Tests PASSED \n");
	}
	free(G);
	if (NOISY_TEST) printf("*** %s Complete \n", __FILE__);
	return 0;
}
Exemple #27
0
int main(){

    int players = 2;
    int player = 0;
    int seed = 1000;
	struct gameState state;
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse,
               treasure_map, tribute, smithy};
    int init;
    int test;
    int handCount_test;
    int deckCount_test;
    int coin_test;
    int numAction_test;
    int success;

    printf("Starting Test: (minion card)\n");

    init = initializeGame(players, k, seed, &state);    //initialize game
    assert(init == 0);

    //set test variables for player 0
    handCount_test = state.handCount[player];   //set handcount test variable
    deckCount_test = state.deckCount[player];   //set deckcount test variable
    coin_test = state.coins;
    numAction_test = state.numActions;

    //set variables for player 1
    state.handCount[1] = 10;
    state.deckCount[1] = 5;

    //set test variables for player 1
    int handCount_test1 = state.handCount[1];
    int deckCount_test1 = state.deckCount[1];

    #if NOISY_TEST
        printf("/n/nBefore Test:\n");
        printf("state.numActions: %d\n", state.numActions);
        printf("state.coins: %d\n", state.coins);
        printf("state.handCount[player]: %d\n", state.handCount[player]);
        printf("state.deckCount[player]: %d\n", state.deckCount[player]);
        printf("state.handCount[player1]: %d\n", state.handCount[1]);
        printf("state.deckCount[player1]: %d\n", state.deckCount[1]);
    #endif

    //cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
    //test with no choices: should add action and discard 1 card from hand
    test = cardEffect(minion, 0, 0, 0, &state, 0, 0);
    assert(test == 0);
    numAction_test++;
    handCount_test--;
    //assert(numAction_test == state.numActions);
    //assert(handCount_test == state.handCount[player]);
    if (numAction_test == state.numActions && handCount_test == state.handCount[player]){
        success = 1;
    }
    else{
        printf("Failed: Bugs present in minion card\n");
        return 0;
    }

    #if NOISY_TEST
        printf("/n/nAfter 0 Test:\n");
        printf("state.numActions: %d\n", state.numActions);
        printf("state.coins: %d\n", state.coins);
        printf("state.handCount[player]: %d\n", state.handCount[player]);
        printf("state.deckCount[player]: %d\n", state.deckCount[player]);
    #endif


    //test with choice1: should add action, discard 1 card from hand, add 2 coins
    test = cardEffect(minion, 1, 0, 0, &state, 0, 0);
    assert(test == 0);
    numAction_test++;
    handCount_test--;
    coin_test = coin_test + 2;
    //assert(numAction_test == state.numActions);
    //assert(handCount_test == bstate.handCount[player]);
    //assert(coin_test == state.coins);
    if (numAction_test == state.numActions && handCount_test == state.handCount[player] && coin_test == state.coins){
        success = 1;
    }
    else{
        printf("Failed: Bugs present in minion card\n");
        return 0;
    }

    #if NOISY_TEST
        printf("/n/nAfter 1 Test:\n");
        printf("state.numActions: %d\n", state.numActions);
        printf("state.coins: %d\n", state.coins);
        printf("state.handCount[player]: %d\n", state.handCount[player]);
        printf("state.deckCount[player]: %d\n", state.deckCount[player]);
    #endif


    //test with no choices: should add action and discard all cards from hand and add 4 cards to to hand from deck
    //for the other player, should discard all cards, and draw 4 cards from their deck
    //state.discardCount[1] = 5;
    test = cardEffect(minion, 0, 1, 0, &state, 0, 0);
    assert(test == 0);
    numAction_test++;
    handCount_test = 4;
    deckCount_test = deckCount_test - 4;
    handCount_test1 = 4;
    deckCount_test1 = deckCount_test1 - 4;
    //assert(numAction_test == state.numActions);
    //assert(coin_test == state.coins);
    //assert(handCount_test == state.handCount[player]);
    //assert(deckCount_test == state.deckCount[player]);
    //assert(handCount_test1 == state.handCount[1]);
    //assert(deckCount_test1 == state.deckCount[1]);
    if (numAction_test == state.numActions && coin_test == state.coins && handCount_test == state.handCount[player] &&
        deckCount_test == state.deckCount[player] && handCount_test1 == state.handCount[1] && deckCount_test1 == state.deckCount[1]){
            success = 1;
    }
    else{
            printf("Failed: Bugs present in minion card\n");
            return 0;
    }

    #if NOISY_TEST
        printf("/n/nAfter 2 Test:\n");
        printf("state.numActions: %d\n", state.numActions);
        printf("state.coins: %d\n", state.coins);
        printf("state.handCount[player]: %d\n", state.handCount[player]);
        printf("state.deckCount[player]: %d\n", state.deckCount[player]);
        printf("state.handCount[1]: %d\n", state.handCount[1]);
        printf("state.deckCount[1]: %d\n", state.deckCount[1]);
    #endif

    printf("Test Complete\n");
    if (success == 1){
        printf("Success: No bugs found\n");
    }
    else{
        printf("Failed: Bugs present in minion card\n");
    }

    return 0;
}
void random_gamestate(struct gameState *state){
	int players = MAX_PLAYERS;
	//printf("starting random_gamestate function\n");	
	int game;	
	int k_index = 0;
	int duplicate = 0;
	int k[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};

	//printf("selecting kingdom cards\n");		
	//select 10 random, unique kingdom cards
	while(k[9] == -1){
		k[k_index] = (int)(Random()*27);//27 different kingdom cards
		//printf("k[%d] = %d\n", k_index, k[k_index]); 
		for(int i = 0; i < k_index; i++){
			if(k[i] == k[k_index]) 
				duplicate = 1;	
		}
		if(duplicate == 0)
			k_index++;
		else
			duplicate = 0;
		
	}

	game = initializeGame(players, k, 1000, state); //initialize game
	
	//printf("creating random hand\n");	
	//create random hand
	for(int p = 0; p < players; p++){
		int test_hand[MAX_HAND];
		int test_hand_size = (int)(Random() * MAX_HAND);
		for(int i = 0; i < test_hand_size; i++){
			int random = (int)(Random() * 10);
			test_hand[i] = k[random];//randomly select from k 
		}
		memcpy(state->hand[p], test_hand, sizeof(int) * MAX_HAND);
		state->handCount[p] = test_hand_size;
	}		

	//printf("creating random deck\n");	
	//create random deck
	for(int p = 0; p < players; p++){
		int test_deck[MAX_DECK];
		int test_deck_size = (int)(Random() * MAX_DECK);
		for(int i = 0; i < test_deck_size; i++){
			int random = (int)(Random() * 10);
			test_deck[i] = k[random];//randomly select from k 
		}
		memcpy(state->deck[p], test_deck, sizeof(int) * MAX_DECK);
		state->deckCount[p] = test_deck_size;
	}
	
	//printf("creating random discard\n");	
	//create random discard
	for(int p = 0; p < players; p++){
		int test_discard[MAX_DECK];
		int test_discard_size = (int)(Random() * MAX_DECK);
		for(int i = 0; i < test_discard_size; i++){
			int random = (int)(Random() * 10);
			test_discard[i] = k[random];//randomly select from k 
		}
		memcpy(state->discard[p], test_discard, sizeof(int) * MAX_DECK);
		state->discardCount[p] = test_discard_size;
	}

	//printf("creating random played cards\n");			
	//create random played cards
	int test_played[MAX_DECK];
	int test_played_size = (int)(Random() * MAX_DECK);
	for(int i = 0; i < test_played_size; i++){
		int random = (int)(Random() * 10);
		test_played[i] = k[random];//randomly select from k 
	}
	memcpy(state->playedCards, test_played, sizeof(int) * MAX_DECK);
	state->playedCardCount = test_played_size;	
}
int main(int argc, char**argv){

   struct gameState Game;
   struct gameState *Ga = &Game;
   int players, ranCard, i;
   int money, cardPos, curPlayer, useCard, returnCard, buyCa;
   int k[10];
   int pool[20] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall, minion, steward, tribute, ambassador, cutpurse, embargo, outpost, salvager, sea_hag, treasure_map};

   srand(atoi(argv[1]));
   players = rand()% 3 + 2;
   ranCard = rand() % 20;

   for(i=0;i<10;i++){
      k[i] = pool[(ranCard+i)%20];
   }

   printf("Starting Game\n");
   initializeGame(players,k,atoi(argv[1]),Ga);
   printf("Number of player %d\n",players);

   while(!isGameOver(Ga)){
      money = 0;
      cardPos = -1;
      curPlayer = whoseTurn(Ga);
      for(i=0;i<numHandCards(Ga);i++){
	 if (handCard(i,Ga) == copper)
	    money++;
	 else if(handCard(i,Ga) == silver)
	    money += 2;
	 else if(handCard(i,Ga) == gold)
	    money += 3;
	 else if(handCard(i,Ga) > 6)
	    cardPos = i;
      }
      if(cardPos != -1){
     	useCard = handCard(cardPos,Ga);
      	printf("Player %d: is playing card %d\n",curPlayer,useCard);
      	returnCard = playCard(cardPos,1,1,1,Ga);
      	if(returnCard== -1)
		 printf("Playing card Failed\n",useCard);
      	else
		 printf("Playing card %d Succeded\n",useCard);
      }
      buyCa = k[rand()%10];
      printf("Player %d has %d coins\n",curPlayer,money);

      if (money >= 8){
	 printf("Player %d is trying to buy province\n",curPlayer);
	 if(buyCard(province,Ga)==-1){
	    printf("Buying Province Failed\n");}
      }
      else if (money >= getCost(buyCa)){
	 printf("Player %d is trying to by card %d \n"layer,buyCa);
	 if(buyCard(buyCa,Ga)==-1){
	    printf("Buying %d Failed\n", buyCa);}
      }
      else if (money >= 6){
	 printf("Player %d is trying to buy gold\n",curPlayer);
	 if(buyCard(gold,Ga)==-1){
	    printf("Buying Gold Faile\n");}
      }
      else if (money >= 3){
	 printf("Player %d is trying to buy silver\n",curPlayer);
	 if (buyCard(silver,Ga)==-1){
	    printf("Buying Silver Failed\n");}
      }
      printf("Player %d has %d Cards in hand\n",curPlayer,numHandCards(Ga));
      printf("Player %d ends turn\n",curPlayer);
      endTurn(Ga);


   };
   
   for(i=0;i<players;i++){
      printf("Player %d Score: %d\n",i,scoreFor(i,Ga));
   }


   return 0;
}
Exemple #30
0
int main()
{	
	int i, r, j;
	int players = 4;
    int seed = rand() % 1000;
	int check;
	struct gameState G;
	struct gameState pre; 
	
	int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall}; 
   
    //Initialize game 
    memset(&G, 0, sizeof(struct gameState)); // zero game state
	r = initializeGame(players, k, seed, &G); // initializeGame returns 0 on success
	assert(r == 0);
	
	printf("Testing: village() in process...!\n");	
	
	//Initialize all player decks and hands
	for(i = 0; i < players; i++) {
		 
		//initialize and set hand
		G.handCount[i] = 5;
		
		G.hand[i][0] = village;
		G.hand[i][1] = feast;
		G.hand[i][2] = mine;
		G.hand[i][3] = smithy;
		G.hand[i][4] = baron;
		 
		//initialize and set deck
        G.deckCount[i] = 5;
		
        G.deck[i][0] = adventurer;
        G.deck[i][1] = council_room;
        G.deck[i][2] = copper;
        G.deck[i][3] = silver;
		G.deck[i][3] = gold;
		
	}
	
	memcpy(&pre, &G, sizeof(struct gameState));
	
	for(j = 0; j < G.numPlayers; j++) {
		
		//Set player turn
		G.whoseTurn = j;
	
		//Manually set pre game condition
		//Increase handCount since village adds +1 cards to hand
		//Increase numActions since village adds +2 actions to a player's turn
		pre.numActions = 1;	//Always starts at 1 for each turn
		pre.handCount[j] += 1;
		pre.numActions += 2; //village adds +2 actions
		                  
		//Test for +1 card, +2 action 
        check = villageCard(&G, 0);
		
		if(check != 0)
			printf("great_hall card function returned unsuccessful!\n");
		
		//Test for the same handCount: great_hall adds +1 cards into the players hand
		if(G.handCount[j] != pre.handCount[j]) {
			
			printf("Fail: pre.handCount = %d post.handCount = %d\n", pre.handCount[j], G.handCount[j]);
			printf("Player %d\n", j+1);
		}
		
		//Test for the same numActions: great_hall = +1 actions  
		if(G.numActions != pre.numActions) {
			printf("Fail: pre.numActions = %d post.numActions = %d\n", pre.numActions, G.numActions);
			printf("Player %d\n", j+1);
		}
		
	}
	
	printf("Testing: village() complete!\n");	

	return 0;
}