Пример #1
0
int main(){
	int playerOne = 0;
    int runStatus;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;

	//Initialize game
	runStatus = initializeGame(2, k, 1, &G);

	//Check if initialize successful
	assert(runStatus == 0);

	//Set hand of first player
	//1 smithy card
	G.handCount[playerOne] = 1;
	G.hand[playerOne][0] = smithy;
	G.hand[playerOne][1] = -1;
	G.hand[playerOne][2] = -1;
	G.hand[playerOne][3] = -1;
	G.hand[playerOne][4] = -1;
	G.hand[playerOne][5] = -1;
	G.hand[playerOne][6] = -1;
	G.playedCardCount = 0;
	
	//Play smithyCard with no cards except for smithy card
	smithyCard(playerOne, &G, 0);
	if(G.handCount[playerOne] != 3)
		printf("cardtest2.c: FAIL, testing for smithy card with no prior card except for smithy\r\nG.handCount[playerOne] == %d\r\nExpected:G.handCount[playerOne] == 3\r\n", G.handCount[playerOne]);
	if(G.playedCardCount != 1)
		printf("cardtest2.c: FAIL, testing for smithy card with no prior card except for smithy\r\nG.playedCardCount == %d\r\nExpected:G.playedCardCount == 1\r\n", G.playedCardCount);
	if(G.playedCards[0] != smithy)
		printf("cardtest2.c: FAIL, testing for smithy card with no prior card except for smithy\r\nG.playedCards[0] is not smithy\r\nExpected:G.playedCards[0] == smithy\r\n");

	//Play smithyCard with 3 other cards and 1 smithy card
	G.hand[playerOne][3] = smithy;
	G.handCount[playerOne]++;
	G.playedCardCount = 0;
	G.playedCards[0] = -1;
	smithyCard(playerOne, &G, 3);

	//Deck is empty, should only get 2 more cards
	if(G.handCount[playerOne] != 5)
		printf("cardtest2.c: FAIL, testing for smithy card with 3 other cards and 1 smithy card to be played\r\nG.handCount[playerOne] == %d\r\nExpected:G.handCount[playerOne] == 5\r\n", G.handCount[playerOne]);
	if(G.playedCardCount != 1)
		printf("cardtest2.c: FAIL, testing for smithy card with 3 other cards and 1 smithy card to be played\r\nG.playedCardCount == %d\r\nExpected:G.playedCardCount == 1\r\n", G.playedCardCount);
	if(G.playedCards[0] != smithy)
		printf("cardtest2.c: FAIL, testing for smithy card with 3 other cards and 1 smithy card to be played\r\nG.playedCards[0] is not smithy\r\nExpected:G.playedCards[0] == smithy\r\n");

	//printf("All test passed for smithy card, cardtest2.c\n");
	printf("All tests passed for smithy card, cardtest2.c\r\n\r\n");
	printf("--------------------\r\n\r\n");
	return 0;
}
Пример #2
0
int checkSmithyCard(int p, struct gameState *post) {
  
  struct gameState pre;
  post->whoseTurn = p;
  memcpy (&pre, post, sizeof(struct gameState));


  int r;
  
  int handPos = rand() % pre.handCount[p];
  r = smithyCard(post, handPos);
  int drawNum = 0;

  while(drawNum < 3)
  {
    drawCard(p, &pre);
    drawNum++;  
  }
   
  assert (r == 0);
  discardCard(handPos, p, &pre, 0);
   printf("After drawing three cards, tester handCount: %d, drawn cards: %d, %d, %d \n", pre.handCount[p], pre.hand[p][pre.handCount[p]-1], pre.hand[p][pre.handCount[p]-2], pre.hand[p][pre.handCount[p]-3]);
    printf("After drawing three cards, testee handCount: %d, drawn cards: %d, %d, %d \n", post->handCount[p], post->hand[p][post->handCount[p]-1], post->hand[p][post->handCount[p]-2], post->hand[p][post->handCount[p]-3]);
    
  if (memcmp(&pre, post, sizeof(struct gameState)) == 0) {
    printf("Testing smithyCard() passed for player: %d\n", p);
  } else {
    printf("Testing smithyCard() failed for player: %d\n", p);
  }
  return 0;
}
Пример #3
0
int main(){

	int r, oldHandCount;
	int p = 0; 
	struct gameState G;
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, treasure_map, tribute, smithy};

	printf("Testing Smithy Card\n");

	r = initializeGame(2, k, 1, &G);
	
	oldHandCount = G.handCount[p];
	
	printf("initializeGame() returned %d, Expected %d\n", r, 0);
	check(r == 0);
	
	G.hand[p][0] = smithy;
	
	r = smithyCard(&G, p, 0);
	printf("smithyCard() returned %d, Expected %d\n", r, 0);
	check(r == 0);
	
	printf("G.handCount[0] = %d, Expected %d\n", G.handCount[p], oldHandCount + 3);
	check(G.handCount[p] == oldHandCount + 3);

	printf("G.discardCount = %d, Expected %d\n", G.discardCount[p], 1);
	check(G.discardCount[p] == 1);

  return 0;
}
Пример #4
0
int main(){
	
	struct gameState G;
	int player = 0;
    int k[10] = {mine, remodel, adventurer, steward, smithy, village, council_room, feast, baron, great_hall};
   
    printf("\n===Testing function: smithyCard() === \n");

    int runCheck;
    runCheck = initializeGame(2, k, 1, &G);

    int originalHand; //This will hold our original hand count to keep track when testing Smithy
    originalHand = G.handCount[player];
    int rightHandCount = originalHand + 3; //This is what our count SHOULD be in the end
    G.hand[player][1] = smithy; //Sets the smithy card to a known position
	
 	smithyCard(&G, player, 1);
 	int newHand;
 	newHand = G.handCount[player];
	if(runCheck == 0){
		printf("smithyCard() ran successfully!\n");
		if(newHand == rightHandCount){
			printf("smithyCard() resulted in hand count of %d, expected %d - Pass!\n", newHand, rightHandCount);
		} else {
			printf("smithyCard() resulted in hand count of %d, expected %d - Fail!\n", newHand, rightHandCount);
		}
	} else {
		printf("smithyCard() failed to run!\n");
	}

	return 0;  
}
Пример #5
0
int main(int argc, char** argv){
  struct gameState g;
  int i;
  srand(time(NULL));
  int cardPlays;
  int seed = 0;
  int handPos = 0;
  
  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
           sea_hag, tribute, smithy};
  
  cardPlays = 10;
  seed = (rand() % 65535);
  
  initializeGame(2,k,seed,&g);
  
  for(i = 0; i < cardPlays; i ++){
    g.whoseTurn = 0;
	handPos = (rand() % g.handCount[0]);
	printf("g.handcount = %d\n",g.handCount[0]);
	smithyCard(&g, handPos, 0);
	printf("g.handcount = %d\n",g.handCount[0]);
  }
   return 0;

  
}
Пример #6
0
int main(int argc, char ** argv)
{
	srand(time(NULL));
	//Generating player:
	int out;
	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);
	// generating a random state
	memcpy(&testG, &G, sizeof(struct gameState));
	int count;
	count = testG.handCount[thisPlayer];
	for(int i = 0; i < count; i++)
		testG.hand[thisPlayer][i] = estate;
	for(int i = 0; i < 25; i++)
		testG.supplyCount[i] = 10;
	testG.hand[thisPlayer][0] = gold;	
	testG.hand[thisPlayer][1] = silver;	
	testG.hand[thisPlayer][2] = copper;	
	testG.discardCount[thisPlayer] = 0;
	// Starting test
	printf("\n\nTesting card: %s\n\n", UNITTEST);

	printf("Test 1: Checking the function.\n");
	smithyCard(&testG, rand() % 4);
	out = getCost(smithy);
	printf("smithy function should return cost of smithy card : %d.\n",out);
	assert(out==4);
	printf("New Hand count is: %d.\n",testG.handCount[thisPlayer]);
	if(testG.handCount[thisPlayer] < 7)
		printf("Test 1 failed, it needs to return: %d\n", 5 - 1 + 3);
	else
		printf("Test 1 Passed\n");

	printf("Test 2: Discard Pile.\n");
	printf("Discard count is: %d.\n",testG.discardCount[thisPlayer]);
	if(testG.discardCount[thisPlayer] == 1 )
		printf("Test 2 passed.\n");
	else
		printf("Test 2 failed, discard count is not correct.\n");
	return 0;	//No bugs found
}
Пример #7
0
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
{
   int i;
   int j;
   int k;
   int x;
   int index;
   int currentPlayer = whoseTurn(state);
   int nextPlayer = currentPlayer + 1;

   int tributeRevealedCards[2] = {-1, -1};
   int temphand[MAX_HAND];// moved above the if statement
   int drawntreasure = 0;/*=0*/;
   int cardDrawn;
   int z = 0;// this is the counter for the temp hand
   if (nextPlayer > (state->numPlayers - 1)){
      nextPlayer = 0;
   }

   //uses switch to select card and perform actions
   switch( card ) 
   {
      case adventurer:
         return adventurerCard(state, drawntreasure, currentPlayer);

      case council_room:
         council_room_test(currentPlayer, state, handPos);
         return 0;

      case feast:
         return feastCard(state, drawntreasure, currentPlayer);

      case gardens:
         return -1;

      case mine:
         return mineCard(state, drawntreasure, currentPlayer);

      case remodel:
         return remodel_test(currentPlayer, state, handPos, choice1, choice2);

      case smithy:
         return smithyCard(state, currentPlayer, handPos);

      case village:
         village_test(currentPlayer, state, handPos);
         return 0; 

      case baron:
         return baronCard(state, choice1, currentPlayer);

      case great_hall:
         great_hall_test(currentPlayer, state, handPos);
          return 0;

      case minion:
         //+1 action
         state->numActions++;

         //discard card from hand
         discardCard(handPos, currentPlayer, state, 0);

         if (choice1)           //+2 coins
         {
            state->coins = state->coins + 2;
         }

         else if (choice2)              //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4
         {
            //discard hand
            while(numHandCards(state) > 0)
            {
               discardCard(handPos, currentPlayer, state, 0);
            }

            //draw 4
            for (i = 0; i < 4; i++)
            {
               drawCard(currentPlayer, state);
            }

            //other players discard hand and redraw if hand size > 4
            for (i = 0; i < state->numPlayers; i++)
            {
               if (i != currentPlayer)
               {
                  if ( state->handCount[i] > 4 )
                  {
                     //discard hand
                     while( state->handCount[i] > 0 )
                     {
                        discardCard(handPos, i, state, 0);
                     }

                     //draw 4
                     for (j = 0; j < 4; j++)
                     {
                        drawCard(i, state);
                     }
                  }
               }
            }

         }
         return 0;

      case steward:

         steward_test(currentPlayer, state, handPos, choice1, choice2, choice3);
         return 0;

      case tribute:
         if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1){
            if (state->deckCount[nextPlayer] > 0){
               tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
               state->deckCount[nextPlayer]--;
            }
            else if (state->discardCount[nextPlayer] > 0){
               tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1];
               state->discardCount[nextPlayer]--;
            }
            else{
               //No Card to Reveal
               if (DEBUG){
                  printf("No cards to reveal\n");
               }
            }
         }

         else{
            if (state->deckCount[nextPlayer] == 0){
               for (i = 0; i < state->discardCount[nextPlayer]; i++){
                  state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck
                  state->deckCount[nextPlayer]++;
                  state->discard[nextPlayer][i] = -1;
                  state->discardCount[nextPlayer]--;
               }

               shuffle(nextPlayer,state);//Shuffle the deck
            } 
            tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
            state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
            state->deckCount[nextPlayer]--;
            tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
            state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
            state->deckCount[nextPlayer]--;
         }    

         if (tributeRevealedCards[0] == tributeRevealedCards[1]){//If we have a duplicate card, just drop one 
            state->playedCards[state->playedCardCount] = tributeRevealedCards[1];
            state->playedCardCount++;
            tributeRevealedCards[1] = -1;
         }

         for (i = 0; i < 2; i ++){
            if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold){//Treasure cards
               state->coins += 2;
            }

            else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall){//Victory Card Found
               drawCard(currentPlayer, state);
               drawCard(currentPlayer, state);
            }
            else{//Action Card
               state->numActions = state->numActions + 2;
            }
         }

         return 0;

      case ambassador:
         j = 0;         //used to check if player has enough cards to discard

         if (choice2 > 2 || choice2 < 0)
         {
            return -1;                          
         }

         if (choice1 == handPos)
         {
            return -1;
         }

         for (i = 0; i < state->handCount[currentPlayer]; i++)
         {
            if (i != handPos && i == state->hand[currentPlayer][choice1] && i != choice1)
            {
               j++;
            }
         }
         if (j < choice2)
         {
            return -1;                          
         }

         if (DEBUG) 
            printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]);

         //increase supply count for choosen card by amount being discarded
         state->supplyCount[state->hand[currentPlayer][choice1]] += choice2;

         //each other player gains a copy of revealed card
         for (i = 0; i < state->numPlayers; i++)
         {
            if (i != currentPlayer)
            {
               gainCard(state->hand[currentPlayer][choice1], state, 0, i);
            }
         }

         //discard played card from hand
         discardCard(handPos, currentPlayer, state, 0);                 

         //trash copies of cards returned to supply
         for (j = 0; j < choice2; j++)
         {
            for (i = 0; i < state->handCount[currentPlayer]; i++)
            {
               if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1])
               {
                  discardCard(i, currentPlayer, state, 1);
                  break;
               }
            }
         }                      

         return 0;

      case cutpurse:

         updateCoins(currentPlayer, state, 2);
         for (i = 0; i < state->numPlayers; i++)
         {
            if (i != currentPlayer)
            {
               for (j = 0; j < state->handCount[i]; j++)
               {
                  if (state->hand[i][j] == copper)
                  {
                     discardCard(j, i, state, 0);
                     break;
                  }
                  if (j == state->handCount[i])
                  {
                     for (k = 0; k < state->handCount[i]; k++)
                     {
                        if (DEBUG)
                           printf("Player %d reveals card number %d\n", i, state->hand[i][k]);
                     }  
                     break;
                  }             
               }

            }

         }                              

         //discard played card from hand
         discardCard(handPos, currentPlayer, state, 0);                 

         return 0;


      case embargo: 
         //+2 Coins
         state->coins = state->coins + 2;

         //see if selected pile is in play
         if ( state->supplyCount[choice1] == -1 )
         {
            return -1;
         }

         //add embargo token to selected supply pile
         state->embargoTokens[choice1]++;

         //trash card
         discardCard(handPos, currentPlayer, state, 1);         
         return 0;

      case outpost:
         //set outpost flag
         state->outpostPlayed++;

         //discard card
         discardCard(handPos, currentPlayer, state, 0);
         return 0;

      case salvager:
         //+1 buy
         state->numBuys++;

         if (choice1)
         {
            //gain coins equal to trashed card
            state->coins = state->coins + getCost( handCard(choice1, state) );
            //trash card
            discardCard(choice1, currentPlayer, state, 1);      
         }

         //discard card
         discardCard(handPos, currentPlayer, state, 0);
         return 0;

      case sea_hag:
         for (i = 0; i < state->numPlayers; i++){
            if (i != currentPlayer){
               state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--];                           state->deckCount[i]--;
               state->discardCount[i]++;
               state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse
            }
         }
         return 0;

      case treasure_map:
         //search hand for another treasure_map
         index = -1;
         for (i = 0; i < state->handCount[currentPlayer]; i++)
         {
            if (state->hand[currentPlayer][i] == treasure_map && i != handPos)
            {
               index = i;
               break;
            }
         }
         if (index > -1)
         {
            //trash both treasure cards
            discardCard(handPos, currentPlayer, state, 1);
            discardCard(index, currentPlayer, state, 1);

            //gain 4 Gold cards
            for (i = 0; i < 4; i++)
            {
               gainCard(gold, state, 1, currentPlayer);
            }

            //return success
            return 1;
         }

         //no second treasure_map found in hand
         return -1;
   }

   return -1;
}
Пример #8
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] = smithy; //5th card in hand is smithy

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

	/*Checking handcount and cards in hand before playing smithy*/
	printf("Hand count before Smithy 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, "Smithy") == 0){
			cardStatus = 1;	//Card is present in hand
		}
	}

	/*Check if smithy 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);
	}

	smithyCard(p, GS, 4);	//Play smithy card

	cardStatus = 0; //Reset to zero

	/*Checking handcount and cards in hand after playing smithy*/
	printf("Hand count after Smithy 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, "Smithy") == 0){
			cardStatus = 1;	//Card is present in hand
		}
	}

	/*Check if smithy 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 +3 cards after discard is 5 cards*/
	if(GS->handCount[p] == 7){
		printf("Test PASSED, Player %d drew +3 cards\n\n", p);
	} else {
		printf("Test FAILED, Player %d drew incorrect amount of cards\n\n", p);
	}

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

/*Check if smithy card has been discarded from hand after card effects*/
	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, "Smithy") != 0){
			cardStatus = 0;	//Card is NOT present in hand
		}
	}

	printf("\nTesting if card is discarded from hand...\n");
	if(cardStatus == 0){
		printf("Test PASSED, Smithy is discarded from player %d's hand after use\n\n", p);
	} else {
		printf("Test FAILED, Smithy card is NOT discarded from player %d's hand after use\n\n", p);
	}

	return 0;

}
Пример #9
0
void checkSmithy() {
	printf("Testing Smithy.\n");
	printf("SIMPLE FIXED TESTS.\n");
	
	// initialize necessary variables
	int k[10] = { adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall };
	int r, handPos = 0, player = 0;
	struct gameState pre, post;

	r = initializeGame(2, k, 1, &post); // initialize game state

	//assert(r == 0); //optional assert

	// set up deck and hand for testing
	post.hand[player][handPos] = smithy;

	memcpy(&pre, &post, sizeof(struct gameState)); // save unaltered game state

	r = smithyCard(player, &post, handPos); // call adventure card function to perform test

	//assert(r == 0); //optional assert
	
	// Test hand count is as expected (2 more: +3 draw, -smithy discard)
	if (post.handCount[player] == pre.handCount[player] + 2) {
		if (NOISY_TEST) printf("TEST PASSED: Resulting hand count: %d, Expected hand count: %d\n", post.handCount[player], pre.handCount[player] + 2);
	}
	else {
		if (NOISY_TEST) printf("TEST FAILED: Resulting hand count: %d, Expected hand count: %d\n", post.handCount[player], pre.handCount[player] + 2);
	}

	// Test deck count is as expected (3 less: -3 draw)
	if (post.deckCount[player] == pre.deckCount[player] - 3) {
		if (NOISY_TEST) printf("TEST PASSED: Resulting deck count: %d, Expected deck count: %d\n", post.deckCount[player], pre.deckCount[player] - 3);
	}
	else {
		if (NOISY_TEST) printf("TEST FAILED: Resulting deck count: %d, Expected deck count: %d\n", post.deckCount[player], pre.deckCount[player] - 3);
	}

	// Test discard count is as expected (1 more: +adventurer discard)
	if (post.discardCount[player] == pre.discardCount[player] + 1) {
		if (NOISY_TEST) printf("TEST PASSED: Resulting discard count: %d, Expected discard count: %d\n", post.discardCount[player], pre.discardCount[player] + 1);
	}
	else {
		if (NOISY_TEST) printf("TEST FAILED: Resulting discard count: %d, Expected discard count: %d\n", post.discardCount[player], pre.discardCount[player] + 1);
	}

	// Test smithy card is last card in discard pile
	if (post.discard[player][post.discardCount[player] - 1] == smithy) {
		if (NOISY_TEST) printf("TEST PASSED: Smithy is the last card in the discard pile\n");
	}
	else {
		if (NOISY_TEST) printf("TEST FAILED: Smithy is not the last card in the discard pile\n");
	}

	// Optional asserts for testing	
	//assert(post->handCount[player] == pre.handCount[player] + 2);
	//assert(post->deckCount[player] == pre.deckCount[player] - 3);
	//assert(post->discardCount[player] == pre.discardCount[player] + 1);
	//assert(post->discard[player][post->discardCount[player] - 1] == smithy);	

	printf("ALL TESTS DONE\n");
}
Пример #10
0
int main(int argc, char** argv){
  struct gameState g;
  int i,j;
  srand(time(NULL));
  int cardPlays;
  int seed = 0;
  int treasureCardsPre = 0;
  int treasureCardsPost = 0;
  int handCountPre = 0;
  int handCountPost = 0;
  int randomPlayer;
  int seedTracker = 0;
  int numberOfPlayers = 0;
  int handPosition = 0;
  
  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
           sea_hag, tribute, smithy};
  
  cardPlays = 300;

  for(i = 0; i < cardPlays; i ++){
	handPosition = 0; 
	seedTracker = 0;
	seed = (rand() % 65535);
	numberOfPlayers = ((rand() % 3) + 2);
    initializeGame(numberOfPlayers,k,seed,&g);
  
    treasureCardsPre = 0;
    treasureCardsPost = 0;
    handCountPre = 0;
    handCountPost = 0;
    randomPlayer = ((rand() % numberOfPlayers));
	
	printf("Number of players = %d\n", numberOfPlayers);
	printf("Random player drawn for = %d\n", randomPlayer);
	//printf("hand count of player = %d\n",g.handCount[randomPlayer]);  had a print statement here to make sure cards in hand was the right amount
    for(j = 0; j < g.handCount[randomPlayer];j++){
		if(g.hand[randomPlayer][j] == copper || g.hand[randomPlayer][j] == silver || g.hand[randomPlayer][j] == gold){
		  treasureCardsPre++; 
		} else {
			handPosition = j;
		}
		handCountPre = j + 1;
	}
    
  
  printf("treasure cards pre = %d\n",  treasureCardsPre);
  printf("cards in hand pre = %d\n", handCountPre);
  smithyCard(&g, handPosition, randomPlayer);
 
    for(j = 0; j < g.handCount[randomPlayer];j++){
		if(g.hand[randomPlayer][j] == copper || g.hand[randomPlayer][j] == silver || g.hand[randomPlayer][j] == gold){
		  treasureCardsPost++; 
		  handCountPost = j + 1;
		}
		
	}
   
   printf("treasure cards post = %d\n",  treasureCardsPost);
   printf("cards in hand post = %d\n", handCountPost);
   printf("hand position of smithy card = %d\n", handPosition);
   if((treasureCardsPre) > treasureCardsPost){
	   printf("Error on Smithy Card: Treasure cards pre: %d Treasure Cards post: %d\n", treasureCardsPre,treasureCardsPost);
	   seedTracker++;
	   printf("Game seed = %d\n", seed);
   }
   if((handCountPre +3) != handCountPost){
	   printf("Error on Smithy Card: Hand cards pre: %d Hand Cards post: %d\n", handCountPre,handCountPost);
	   if(seedTracker == 0){
		   printf("Game seed = %d\n", seed);
	   }
   }
   printf("---------------------------\n");
   
  }
   
  

   return 0;
}
Пример #11
0
int main(int argc, char* argv[]){
  int x;
  int player = 0; //player 1 = 0; initialize to something, will change later
  struct gameState *state = newGame();
  int i, j;
  int myHandCount;
  int myDeckCount;
  int myPlayCount;
  printf("Testing SMITHY Card Function:\n");
  srand(time(NULL));
//initialize hands for 2 players
initGameState(state);
  
  for(i = 0; i < 2000; i++){ //start with 5 for testing
	  SelectStream(2);
	  PutSeed(2);
    player = rand() % 2;
	state->whoseTurn = player;
	state->deckCount[player] = rand() % MAX_DECK;
	state->playedCardCount = rand() % MAX_DECK;
	state->handCount[player] = rand() % MAX_HAND;
    
   //put smithy card in the player's hand
   state->hand[player][0] = smithy;
   //randomize rest of the cards in the player's hand
   for(j = 1; j < state->handCount[player] - 1; j++){
      state->hand[player][j] = rand() %27;
   }
   //randomize cards in the discard pile
   for(j = 0; j < state->playedCardCount; j++){
	   state->discard[player][j] = rand() % 27;
   }
   //randomize cards in the deck
   for(j = 0; j < state->deckCount[player]; j++){
      state->discard[player][j] = rand() % 27;
   }

//initialize values of players deck counts
//save teh details of what the state was before playing the smithy card.
//This is used to track my expectations of how the card SHOULD play because the state is going to change as the card is played
   myHandCount = state->handCount[player];
   myDeckCount = state->deckCount[player];
   myPlayCount = state->playedCardCount;

   printf("Starting handCount = %d\n", myHandCount);
   printf("Starting deckCount = %d\n", myDeckCount);
   printf("Starting playedCardCount = %d\n", myPlayCount);

//play the smithy card
   smithyCard(player, state, 0);

/*******************************************************************
 * TESTING HAND, DECK, DISCARD AND PLAY
*******************************************************************/

//myHandCount should now = original handCount + 3 -1
x = myHandCount + 3 - 1;
if(state->handCount[player] == x){
  printf("Testing myHandCount: TEST PASSED\n");
} else{
printf("Testing myHandCount: TEST FAILED: expected: %d, actual: %d\n", x, state->handCount[player]);
}

//myDeckCount should now = original deckCount + 1
x = myDeckCount - 3;//because 3 were taken from my deck and added to my hand 
if(state->deckCount[player] == x) {//if it is correct
  printf("Testing myDeckCount: TEST PASSED\n");
} else {
  printf("Testing myDeckCount: TEST FAILED: expected %d, actual %d\n", x, state->deckCount[player]);
}

//myPlayCount should now = original playCount + 1
x = myPlayCount + 1;
if(state->playedCardCount == x) {//if it is correct
  printf("Testing myPlayCount: TEST PASSED\n");
} else {
  printf("Testing myPlayCount: TEST FAILED: expected %d, actual %d\n", x, state->playedCardCount);
}
} //end of for loop

return 0;
}
Пример #12
0
int main() {
	int seed = 1000;
    int numPlayer = 2;
    int r,i;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;

	printf ("TESTING playSmithy():\n");
 	for (i=0;i<50;i++)
	{
		memset(&G, 23, sizeof(struct gameState));   // clear the game state
		r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
		G.handCount[0] = 0;                 // set the number of cards on hand to 5 for player 0

	#if (NOISY_TEST == 1)
		printf("Set starting values:\n handcount=0\n numBuys=0\n coins=0\n playedCardCount=0\n\n");
		
		printf("****Testing 1 Smithy play****\n");
	#endif
		smithyCard(1,&G,0);
	#if (NOISY_TEST == 1)
		printf("Hand Count = %d, expected = 3", G.handCount[0]);
		if (G.handCount[0]==3)
		{
			printf("....PASS\n\n");
		}
		else{
			printf("....FAIL\n\n");
		}
		printf("Number of Cards Played = %d, expected = 1", G.playedCardCount);
		if (G.playedCardCount==1)
		{
			printf("....PASS\n\n");
		}
		else{
			printf("....FAIL\n\n");
		}
		printf("****Testing another Smithy play****\n");
	#endif
		smithyCard(1,&G,0);
	#if (NOISY_TEST == 1)
		printf("Hand Count = %d, expected = 6", G.handCount[0]);
		if (G.handCount[0]==6)
		{
			printf("....PASS\n\n");
		}
		else{
			printf("....FAIL\n\n");
		}
		printf("Number of Cards Played = %d, expected = 2", G.playedCardCount);
		if (G.playedCardCount==2)
		{
			printf("....PASS\n\n");
		}
		else{
			printf("....FAIL\n\n");
		}
		printf("****Testing another Smithy play****\n");
	#endif
		smithyCard(1,&G,0);
	#if (NOISY_TEST == 1)
		printf("Hand Count = %d, expected = 9", G.handCount[0]);
		if (G.handCount[0]==9)
		{
			printf("....PASS\n\n");
		}
		else{
			printf("....FAIL\n\n");
		}
		printf("Number of Cards Played = %d, expected = 3", G.playedCardCount);	
		if (G.playedCardCount==3)
		{
			printf("....PASS\n\n");
		}
		else{
			printf("....FAIL\n\n");
		}
		printf("****Testing another Smithy play****\n");
	#endif
		smithyCard(1,&G,0);
	#if (NOISY_TEST == 1)
		printf("Hand Count = %d, expected = 15", G.handCount[0]);
		if (G.handCount[0]==15)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf("Number of Cards Played = %d, expected = 4", G.playedCardCount);	
		if (G.playedCardCount==4)
		{
			printf("....PASS\n\n"); 
		}
		else{
			printf("....FAIL\n\n");
		}
	#endif
		endTurn(&G);
	#if (NOISY_TEST == 1)
		printf("****Testing other player's hand****\n");
		printf("Buys = %d, expected = 1", G.numBuys);
		if (G.numBuys==1)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf("Hand Count = %d, expected = 0", G.handCount[0]);
		if (G.handCount[0]==0)
		{
			printf("....PASS\n\n");
		}
		else{
			printf("....FAIL\n\n");
		}
	#endif	
	}
	printf("Testing completed\n");
    return 0;
}
Пример #13
0
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
{
  	int currentPlayer = whoseTurn(state);
  	int nextPlayer = currentPlayer + 1;
  	int tributeRevealedCards[2] = {-1, -1};
  	int temphand[MAX_HAND];// moved above the if statement
  	int drawntreasure=0;
  	int cardDrawn;
  	int z = 0;// this is the counter for the temp hand

  	if (nextPlayer > (state->numPlayers - 1))
  	{
    	nextPlayer = 0;
  	}

	switch( card )
	{
	  case adventurer:
    	return adventurerCard(&drawntreasure, state, &cardDrawn, &currentPlayer, temphand, &z);
	
	  case council_room:
		return council_roomCard(&currentPlayer, state, &handPos);
	
	  case feast:
    	return feastCard(state, temphand, &currentPlayer, &choice1);
	
	  case gardens:
		return -1;

	  case mine:
    	return mineCard(state, &currentPlayer, &choice1, &choice2, &handPos);
		
	  case remodel:
    	return remodelCard(state, &currentPlayer, &choice1, &choice2, &handPos);
	
	  case smithy:
    	return smithyCard(state, &currentPlayer, &handPos);
	
	  case village:
    	return villageCard(state, &currentPlayer, &handPos);
 	
 	  case baron:
    	return baronCard(state, &currentPlayer, &choice1);

	  case great_hall:
    	return great_hallCard(state, &currentPlayer, &handPos);
	
	  case minion:
    	return minionCard(state, &currentPlayer, &handPos, &choice1, &choice2);
	
	  case steward:
    	return stewardCard(state, &currentPlayer, &handPos,  &choice1, &choice2, &choice3);

	  case tribute:
    	return tributeCard(state, &currentPlayer, &handPos, &nextPlayer, tributeRevealedCards); 

	  case ambassador:
    	return ambassadorCard(state, &currentPlayer, &handPos, &choice1, &choice2);
		
	  case cutpurse:
    	return cutpurseCard(state, &currentPlayer, &handPos);

	  case embargo:
    	return embargoCard(state, &currentPlayer, &handPos, &choice1);

	  case outpost:
    	return outpostCard(state, &currentPlayer, &handPos);

	  case salvager:
    	return salvagerCard(state, &currentPlayer, &handPos, &choice1);

	  case sea_hag:
    	return sea_hagCard(state, &currentPlayer);

	  case treasure_map:
    	return treasure_mapCard(state, &currentPlayer, &handPos);
	}

	return -1;
}
Пример #14
0
int main(){
	int randomPlayer, seed, i, j, numPlayers;
    int runStatus;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;

	srand(time(NULL));
	for (i = 0; i < 2000; i++)
	{
		seed = (rand()%100) + 1;
		//Pick a random player 0,1,2,3
		randomPlayer = (rand()% 4);
		//Random number of players 2,3,4
		numPlayers = (rand()% 3) + 2;
		if (randomPlayer > numPlayers - 1)
			numPlayers = randomPlayer + 1;
		//Initialize game
		runStatus = initializeGame(numPlayers, k, seed, &G);

		//Check if initialize successful
		assert(runStatus == 0);

		//Set player turn
		G.whoseTurn = randomPlayer;

		//Set random game state
		//Hand count 0-20
		G.handCount[randomPlayer] = (rand() % 21);
		//Deck count 10-100
		G.deckCount[randomPlayer] = (rand() % 91) + 10;
		//Discard count 0-20
		G.discardCount[randomPlayer] = (rand() % 21);
		//Played count 0-20
		G.playedCardCount = (rand() % 21);

		//Sets card to hand, deck, discard pile
		for(j = 0; j < G.handCount[randomPlayer]; j++)
		{
			G.hand[randomPlayer][j] = rand() % 27;
		}
		for(j = 0; j < G.deckCount[randomPlayer]; j++)
		{
			G.deck[randomPlayer][j] = rand() % 27;
		}
		for(j = 0; j < G.discardCount[randomPlayer]; j++)
		{
			G.discard[randomPlayer][j] = rand() % 27;
		}

		//Add a smithy card to be played
		G.hand[randomPlayer][G.handCount[randomPlayer]] = smithy;
		G.handCount[randomPlayer]++;

		//Set defaults for card counts
		int cardCount = G.handCount[randomPlayer];
		int pCardCount = G.playedCardCount;
		int dCardCount = G.discardCount[randomPlayer];
		int coinCount = 0;
		int deCardCount = G.deckCount[randomPlayer];

		//Loop through hand to count how many treasures for coin count
		for(j = 0; j < G.handCount[randomPlayer]; j++){
			if(G.hand[randomPlayer][j] == copper)
				coinCount++;
			else if(G.hand[randomPlayer][j] == silver)
				coinCount+=2;
			else if(G.hand[randomPlayer][j] == gold)
				coinCount+=3;
		}

		//Coin count check
		updateCoins(randomPlayer, &G, 0);
		assert(G.coins == coinCount);

		//Loops through the first 3 cards at the top of the deck for treasure cards
		for(j = G.deckCount[randomPlayer] - 1; j >= G.deckCount[randomPlayer] - 3; j--){
			if(G.deck[randomPlayer][j] == copper)
				coinCount++;
			else if(G.deck[randomPlayer][j] == silver)
				coinCount+=2;
			else if(G.deck[randomPlayer][j] == gold)
				coinCount+=3;
		}

		//Play smithyCard, add one to played pile, add (3-1) cards to hand count, remove 3 from deck count
		smithyCard(randomPlayer, &G, G.handCount[randomPlayer]-1);
		pCardCount++;
		cardCount+=2;
		deCardCount-=3;

		//Update coin count
		updateCoins(randomPlayer, &G, 0);


		if(G.handCount[randomPlayer] != cardCount)
			printf("randomtestcard.c: FAIL\r\nG.handCount[randomPlayer] == %d\r\nExpected:G.handCount[randomPlayer] == %d\r\n", G.handCount[randomPlayer], cardCount);
		if(G.playedCardCount != pCardCount)
			printf("randomtestcard.c: FAIL\r\nG.playedCardCount == %d\r\nExpected:G.playedCardCount == %d\r\n", G.playedCardCount, pCardCount);
		if(G.discardCount[randomPlayer] != dCardCount)
			printf("randomtestcard.c: FAIL\r\nG.discardCount[randomPlayer] == %d\r\nExpected:G.discardCount[randomPlayer] == %d\r\n", G.discardCount[randomPlayer], dCardCount);
		if(G.deckCount[randomPlayer] != deCardCount)
			printf("randomtestcard.c: FAIL\r\nG.deckCount == %d\r\nExpected:G.deckCount == %d\r\n", G.deckCount[randomPlayer], deCardCount);
		if(G.coins != coinCount)
			printf("randomtestcard.c: FAIL\r\nG.coins == %d\r\nExpected:G.coins == %d\r\n", G.coins, coinCount);

		printf("All tests passed for smithy card, randomtestcard.c, iteration %d\r\n\r\n", i+1);
		printf("--------------------\r\n\r\n");
	}
	return 0;
}
Пример #15
0
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
{
  int i;
  int j;
  int k;
  int x;
  int index;
  int currentPlayer = whoseTurn(state);
  int nextPlayer = currentPlayer + 1;

  int tributeRevealedCards[2] = {-1, -1};
  int temphand[MAX_HAND];// moved above the if statement
  int drawntreasure=0;
  int cardDrawn;
  int z = 0;// this is the counter for the temp hand
  if (nextPlayer > (state->numPlayers - 1)){
    nextPlayer = 0;
  }
  
	
  //uses switch to select card and perform actions
  switch( card ) 
    {
    case adventurer:
       return adventurerCard(currentPlayer, state, choice1, choice2, drawntreasure, z, cardDrawn, temphand, handPos);
			
    case council_room:
      //+4 Cards
      for (i = 0; i < 4; i++)
	{
	  drawCard(currentPlayer, state);
	}
			
      //+1 Buy
      state->numBuys++;
			
      //Each other player draws a card
      for (i = 0; i < state->numPlayers; i++)
	{
	  if ( i != currentPlayer )
	    {
	      drawCard(i, state);
	    }
	}
			
      //put played card in played card pile
      discardCard(handPos, currentPlayer, state, 0);
			
      return 0;
			
    case feast:
      return feastCard(state,temphand,currentPlayer,choice1);
		
    case gardens:
      return -1;
			
    case mine:
    j = state->hand[currentPlayer][choice1];  //store card we will trash

      if (state->hand[currentPlayer][choice1] < copper || state->hand[currentPlayer][choice1] > gold)
	{
	  return -1;
	}
		
      if (choice2 > treasure_map || choice2 < curse)
	{
	  return -1;
	}

      if ( (getCost(state->hand[currentPlayer][choice1]) + 3) > getCost(choice2) )
	{
	  return -1;
	}

      gainCard(choice2, state, 2, currentPlayer);

      //discard card from hand
      discardCard(handPos, currentPlayer, state, 0);

      //discard trashed card
      for (i = 0; i > state->handCount[currentPlayer]; i++)
	{
	  if (state->hand[currentPlayer][i] == j)
	    {
	      discardCard(i, currentPlayer, state, 0);			
	      break;
	    }
	}			
    return 0;


    case remodel:
      return remodelCard(currentPlayer, state, choice1, choice2, handPos);
		
    case smithy:
      return smithyCard(currentPlayer, state, handPos); 

    case village:
      //+1 Card
      drawCard(currentPlayer, state);
			
      //+2 Actions
      state->numActions = state->numActions + 2;
			
      //discard played card from hand
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
		
    case baron:
      state->numBuys++;//Increase buys by 1!
      if (choice1 > 0){//Boolean true or going to discard an estate
	int p = 0;//Iterator for hand!
	int card_not_discarded = 1;//Flag for discard set!
	while(card_not_discarded){
	  if (state->hand[currentPlayer][p] == estate){//Found an estate card!
	    state->coins += 4;//Add 4 coins to the amount of coins
	    state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p];
	    state->discardCount[currentPlayer]++;
	    for (;p < state->handCount[currentPlayer]; p++){
	      state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1];
	    }
	    state->hand[currentPlayer][state->handCount[currentPlayer]] = -1;
	    state->handCount[currentPlayer]--;
	    card_not_discarded = 0;//Exit the loop
	  }
	  else if (p > state->handCount[currentPlayer]){
	    if(DEBUG) {
	      printf("No estate cards in your hand, invalid choice\n");
	      printf("Must gain an estate if there are any\n");
	    }
	    if (supplyCount(estate, state) > 0){
	      gainCard(estate, state, 0, currentPlayer);
	      state->supplyCount[estate]--;//Decrement estates
	      if (supplyCount(estate, state) == 0){
		isGameOver(state);
	      }
	    }
	    card_not_discarded = 0;//Exit the loop
	  }
			    
	  else{
	    p++;//Next card
	  }
	}
      }
			    
      else{
	if (supplyCount(estate, state) > 0){
	  gainCard(estate, state, 0, currentPlayer);//Gain an estate
	  state->supplyCount[estate]--;//Decrement Estates
	  if (supplyCount(estate, state) == 0){
	    isGameOver(state);
	  }
	}
      }
	    
      
      return 0;
		
    case great_hall:
      //+1 Card
      drawCard(currentPlayer, state);
			
      //+1 Actions
      state->numActions++;
			
      //discard card from hand
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
		
    case minion:
      //+1 action
      state->numActions++;
			
      //discard card from hand
      discardCard(handPos, currentPlayer, state, 0);
			
      if (choice1)		//+2 coins
	{
	  state->coins = state->coins + 2;
	}
			
      else if (choice2)		//discard hand, redraw 4, other players with 5+ cards discard hand and draw 4
	{
	  //discard hand
	  while(numHandCards(state) > 0)
	    {
	      discardCard(handPos, currentPlayer, state, 0);
	    }
				
	  //draw 4
	  for (i = 0; i < 4; i++)
	    {
	      drawCard(currentPlayer, state);
	    }
				
	  //other players discard hand and redraw if hand size > 4
	  for (i = 0; i < state->numPlayers; i++)
	    {
	      if (i != currentPlayer)
		{
		  if ( state->handCount[i] > 4 )
		    {
		      //discard hand
		      while( state->handCount[i] > 0 )
			{
			  discardCard(handPos, i, state, 0);
			}
							
		      //draw 4
		      for (j = 0; j < 4; j++)
			{
			  drawCard(i, state);
			}
		    }
		}
	    }
				
	}
      return 0;
		
    case steward:
      if (choice1 == 1)
	{
	  //+2 cards
	  drawCard(currentPlayer, state);
	  drawCard(currentPlayer, state);
	}
      else if (choice1 == 2)
	{
	  //+2 coins
	  state->coins = state->coins + 2;
	}
      else
	{
	  //trash 2 cards in hand
	  discardCard(choice2, currentPlayer, state, 1);
	  discardCard(choice3, currentPlayer, state, 1);
	}
			
      //discard card from hand
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
		
    case tribute:
      if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1){
	if (state->deckCount[nextPlayer] > 0){
	  tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
	  state->deckCount[nextPlayer]--;
	}
	else if (state->discardCount[nextPlayer] > 0){
	  tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1];
	  state->discardCount[nextPlayer]--;
	}
	else{
	  //No Card to Reveal
	  if (DEBUG){
	    printf("No cards to reveal\n");
	  }
	}
      }
	    
      else{
	if (state->deckCount[nextPlayer] == 0){
	  for (i = 0; i < state->discardCount[nextPlayer]; i++){
	    state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck
	    state->deckCount[nextPlayer]++;
	    state->discard[nextPlayer][i] = -1;
	    state->discardCount[nextPlayer]--;
	  }
			    
	  shuffle(nextPlayer,state);//Shuffle the deck
	} 
	tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
	state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
	state->deckCount[nextPlayer]--;
	tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
	state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
	state->deckCount[nextPlayer]--;
      }    
		       
      if (tributeRevealedCards[0] == tributeRevealedCards[1]){//If we have a duplicate card, just drop one 
	state->playedCards[state->playedCardCount] = tributeRevealedCards[1];
	state->playedCardCount++;
	tributeRevealedCards[1] = -1;
      }

      for (i = 0; i <= 2; i ++){
	if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold){//Treasure cards
	  state->coins += 2;
	}
		    
	else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall){//Victory Card Found
	  drawCard(currentPlayer, state);
	  drawCard(currentPlayer, state);
	}
	else{//Action Card
	  state->numActions = state->numActions + 2;
	}
      }
	    
      return 0;
		
    case ambassador:
      return ambassadorCard(choice1, choice2, handPos, state, currentPlayer);
	
    case cutpurse: 
      updateCoins(currentPlayer, state, 2);
      for (i = 0; i < state->numPlayers; i++)
	{
	  if (i != currentPlayer)
	    {
	      for (j = 0; j < state->handCount[i]; j++)
		{
		  if (state->hand[i][j] == copper)
		    {
		      discardCard(j, i, state, 0);
		      break;
		    }
		  if (j == state->handCount[i])
		    {
		      for (k = 0; k < state->handCount[i]; k++)
			{
			  if (DEBUG)
			    printf("Player %d reveals card number %d\n", i, state->hand[i][k]);
			}	
		      break;
		    }		
		}
					
	    }
				
	}				

      //discard played card from hand
      discardCard(handPos, currentPlayer, state, 0);			
      return 0;
		
    case embargo: 
      //+2 Coins
      state->coins = state->coins + 2;

      //see if selected pile is in play
      if ( state->supplyCount[choice1] == -1 )
	{
	  return -1;
	}
			
      //add embargo token to selected supply pile
      state->embargoTokens[choice1]++;
			
      //trash card
      discardCard(handPos, currentPlayer, state, 1);		
      return 0;
		
    case outpost:
      //set outpost flag
      state->outpostPlayed++;
			
      //discard card
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
		
    case salvager:
      //+1 buy
      state->numBuys++;
			
      if (choice1)
	{
	  //gain coins equal to trashed card
	  state->coins = state->coins + getCost( handCard(choice1, state) );
	  //trash card
	  discardCard(choice1, currentPlayer, state, 1);	
	}
			
      //discard card
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
		
    case sea_hag:
      for (i = 0; i < state->numPlayers; i++){
	if (i != currentPlayer){
	  state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--];			    state->deckCount[i]--;
	  state->discardCount[i]++;
	  state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse
	}
      }
      return 0;
		
    case treasure_map:
      //search hand for another treasure_map
      index = -1;
      for (i = 0; i < state->handCount[currentPlayer]; i++)
	{
	  if (state->hand[currentPlayer][i] == treasure_map && i != handPos)
	    {
	      index = i;
	      break;
	    }
	}
      if (index > -1)
	{
	  //trash both treasure cards
	  discardCard(handPos, currentPlayer, state, 1);
	  discardCard(index, currentPlayer, state, 1);

	  //gain 4 Gold cards
	  for (i = 0; i < 4; i++)
	    {
	      gainCard(gold, state, 1, currentPlayer);
	    }
				
	  //return success
	  return 1;
	}
			
      //no second treasure_map found in hand
      return -1;
    }
	
  return -1;
}
Пример #16
0
int main(){
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
           sea_hag, tribute, smithy};
	struct gameState G; 
	int seed = 3000;
	int r, i;
	int SmithyHand[10];
	
	for(i =0; i < 10; i++){
		SmithyHand[i] = smithy;
	}
	
	r = initializeGame(2,k,seed,&G);	
	//Test One
	printf("Testing Smithy Where the player has 2 cards in their hand \n");
	G.handCount[0] = 2;
	G.discardCount[0] = 2;
	G.deckCount[0] = 2;
	memcpy(G.hand[0],SmithyHand,sizeof(int) * 2);
	memcpy(G.deck[0],SmithyHand,sizeof(int) * 2);
	memcpy(G.discard[0],SmithyHand,sizeof(int) * 2);
	smithyCard(0,&G,0);
	printf("Player One has %d in their hand\n",G.handCount[0]);
	if(G.handCount[0] == 5)
	{
		printf("TEST ONE PASSED \n");
		
	} else {
	
		printf("TEST ONE FAILED! \n ");
	}
	
	//Test Two
	printf("Testing Smithy Where the player has 4 cards in their hand \n");
	G.handCount[0] = 4;
	G.discardCount[0] = 2;
	G.deckCount[0] = 2;
	memcpy(G.hand[0],SmithyHand,sizeof(int) * 4);
	memcpy(G.deck[0],SmithyHand,sizeof(int) * 2);
	memcpy(G.discard[0],SmithyHand,sizeof(int) * 2);
	smithyCard(0,&G,0);
	printf("Player One has %d in their hand\n",G.handCount[0]);
	if(G.handCount[0] == 7)
	{
		printf("TEST TWO PASSED \n");
		
	} else {
	
		printf("TEST TWO FAILED! \n");
	}
	
		//Test Three
	printf("Testing Smithy Where the player has 0 cards in their hand. Shouldn't work because the player does not have a Smithy card \n");
	G.handCount[1] = 0;
	G.discardCount[1] = 2;
	G.deckCount[1] = 2;
	memcpy(G.deck[1],SmithyHand,sizeof(int) * 2);
	memcpy(G.discard[1],SmithyHand,sizeof(int) * 2);
	memcpy(G.hand[1],SmithyHand,sizeof(int) * 0);
	smithyCard(1,&G,0);
	printf("Player One has %d in their hand\n",G.handCount[1]);
	if(G.handCount[1] == 3)
	{
		printf("TEST THREE PASSED \n");
		
	} else {
	
		printf("TEST ONE FAILED! \n");
	}
	
	//Test Three
	printf("Testing Smithy Where the player has 1 cards in their hand.\n");
	G.handCount[0] = 1;
	G.discardCount[0] = 2;
	G.deckCount[0] = 2;
	memcpy(G.hand[0],SmithyHand,sizeof(int) * 1);
	memcpy(G.deck[0],SmithyHand,sizeof(int) * 2);
	memcpy(G.discard[0],SmithyHand,sizeof(int) * 2);
	smithyCard(0,&G,0);
	printf("Player One has %d in their hand\n",G.handCount[0]);
	if(G.handCount[0] == 4)
	{
		printf("TEST FOUR PASSED \n");
		
	} else {
	
		printf("TEST FOUR FAILED! \n ");
	}
	return 0;
}
Пример #17
0
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
{
  int i;
  int j;
  int k;
  int x;
  int index;
  int currentPlayer = whoseTurn(state);
  int nextPlayer = currentPlayer + 1;
  int tributeRevealedCards[2] = {-1, -1};
  int temphand[MAX_HAND];// moved above the if statement
  int z = 0;// this is the counter for the temp hand
  if (nextPlayer > (state->numPlayers - 1)){
    nextPlayer = 0;
  }
  
  
  //uses switch to select card and perform actions
  switch( card ) 
    {
    case adventurer:
      adventurerCard(state, currentPlayer);
            break;

    case council_room:
      councilCard(state, currentPlayer, handPos);
            break;
      
    case feast:
      //gain card with cost up to 5
      //Backup hand
      for (i = 0; i <= state->handCount[currentPlayer]; i++){
  temphand[i] = state->hand[currentPlayer][i];//Backup card
  state->hand[currentPlayer][i] = -1;//Set to nothing
      }
      //Backup hand

      //Update Coins for Buy
      updateCoins(currentPlayer, state, 5);
      x = 1;//Condition to loop on
      while( x == 1) {//Buy one card
  if (supplyCount(choice1, state) <= 0){
    if (DEBUG)
      printf("None of that card left, sorry!\n");

    if (DEBUG){
      printf("Cards Left: %d\n", supplyCount(choice1, state));
    }
  }
  else if (state->coins < getCost(choice1)){
    printf("That card is too expensive!\n");

    if (DEBUG){
      printf("Coins: %d < %d\n", state->coins, getCost(choice1));
    }
  }
  else{

    if (DEBUG){
      printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]);
    }

    gainCard(choice1, state, 0, currentPlayer);//Gain the card
    x = 0;//No more buying cards

    if (DEBUG){
      printf("Deck Count: %d\n", state->handCount[currentPlayer] + state->deckCount[currentPlayer] + state->discardCount[currentPlayer]);
    }

  }
      }     

      //Reset Hand
      for (i = 0; i <= state->handCount[currentPlayer]; i++){
  state->hand[currentPlayer][i] = temphand[i];
  temphand[i] = -1;
      }
      //Reset Hand
            
      return 0;
      
    case gardens:
      return -1;
      
    case mine:
      mineCard(state, currentPlayer, handPos, choice1, choice2);
            break;
      
    case remodel:
      j = state->hand[currentPlayer][choice1];  //store card we will trash

      if ( (getCost(state->hand[currentPlayer][choice1]) + 2) > getCost(choice2) )
  {
    return -1;
  }

      gainCard(choice2, state, 0, currentPlayer);

      //discard card from hand
      discardCard(handPos, currentPlayer, state, 0);

      //discard trashed card
      for (i = 0; i < state->handCount[currentPlayer]; i++)
  {
    if (state->hand[currentPlayer][i] == j)
      {
        discardCard(i, currentPlayer, state, 0);      
        break;
      }
  }


      return 0;
    
    case smithy:
        smithyCard(state, currentPlayer, handPos);
            break;

    case village:
      //+1 Card
      drawCard(currentPlayer, state);
      
      //+2 Actions
      state->numActions = state->numActions + 2;
      
      //discard played card from hand
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
    
    case baron:
      state->numBuys++;//Increase buys by 1!
      if (choice1 > 0){//Boolean true or going to discard an estate
  int p = 0;//Iterator for hand!
  int card_not_discarded = 1;//Flag for discard set!
  while(card_not_discarded){
    if (state->hand[currentPlayer][p] == estate){//Found an estate card!
      state->coins += 4;//Add 4 coins to the amount of coins
      state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p];
      state->discardCount[currentPlayer]++;
      for (;p < state->handCount[currentPlayer]; p++){
        state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1];
      }
      state->hand[currentPlayer][state->handCount[currentPlayer]] = -1;
      state->handCount[currentPlayer]--;
      card_not_discarded = 0;//Exit the loop
    }
    else if (p > state->handCount[currentPlayer]){
      if(DEBUG) {
        printf("No estate cards in your hand, invalid choice\n");
        printf("Must gain an estate if there are any\n");
      }
      if (supplyCount(estate, state) > 0){
        gainCard(estate, state, 0, currentPlayer);
        state->supplyCount[estate]--;//Decrement estates
        if (supplyCount(estate, state) == 0){
    isGameOver(state);
        }
      }
      card_not_discarded = 0;//Exit the loop
    }
          
    else{
      p++;//Next card
    }
  }
      }
          
      else{
  if (supplyCount(estate, state) > 0){
    gainCard(estate, state, 0, currentPlayer);//Gain an estate
    state->supplyCount[estate]--;//Decrement Estates
    if (supplyCount(estate, state) == 0){
      isGameOver(state);
    }
  }
      }
      
      
      return 0;
    
    case great_hall:
      //+1 Card
      drawCard(currentPlayer, state);
      
      //+1 Actions
      state->numActions++;
      
      //discard card from hand
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
    
    case minion:
      minionCard(state, currentPlayer, handPos, choice1, choice2);
            break;
    
    case steward:
      if (choice1 == 1)
  {
    //+2 cards
    drawCard(currentPlayer, state);
    drawCard(currentPlayer, state);
  }
      else if (choice1 == 2)
  {
    //+2 coins
    state->coins = state->coins + 2;
  }
      else
  {
    //trash 2 cards in hand
    discardCard(choice2, currentPlayer, state, 1);
    discardCard(choice3, currentPlayer, state, 1);
  }
      
      //discard card from hand
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
    
    case tribute:
      if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1){
  if (state->deckCount[nextPlayer] > 0){
    tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
    state->deckCount[nextPlayer]--;
  }
  else if (state->discardCount[nextPlayer] > 0){
    tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1];
    state->discardCount[nextPlayer]--;
  }
  else{
    //No Card to Reveal
    if (DEBUG){
      printf("No cards to reveal\n");
    }
  }
      }
      
      else{
  if (state->deckCount[nextPlayer] == 0){
    for (i = 0; i < state->discardCount[nextPlayer]; i++){
      state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck
      state->deckCount[nextPlayer]++;
      state->discard[nextPlayer][i] = -1;
      state->discardCount[nextPlayer]--;
    }
          
    shuffle(nextPlayer,state);//Shuffle the deck
  } 
  tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
  state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
  state->deckCount[nextPlayer]--;
  tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
  state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
  state->deckCount[nextPlayer]--;
      }    
           
      if (tributeRevealedCards[0] == tributeRevealedCards[1]){//If we have a duplicate card, just drop one 
  state->playedCards[state->playedCardCount] = tributeRevealedCards[1];
  state->playedCardCount++;
  tributeRevealedCards[1] = -1;
      }

      for (i = 0; i <= 2; i ++){
  if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold){//Treasure cards
    state->coins += 2;
  }
        
  else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall){//Victory Card Found
    drawCard(currentPlayer, state);
    drawCard(currentPlayer, state);
  }
  else{//Action Card
    state->numActions = state->numActions + 2;
  }
      }
      
      return 0;
    
    case ambassador:
      j = 0;    //used to check if player has enough cards to discard

      if (choice2 > 2 || choice2 < 0)
  {
    return -1;        
  }

      if (choice1 == handPos)
  {
    return -1;
  }

      for (i = 0; i < state->handCount[currentPlayer]; i++)
  {
    if (i != handPos && i == state->hand[currentPlayer][choice1] && i != choice1)
      {
        j++;
      }
  }
      if (j < choice2)
  {
    return -1;        
  }

      if (DEBUG) 
  printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]);

      //increase supply count for choosen card by amount being discarded
      state->supplyCount[state->hand[currentPlayer][choice1]] += choice2;
      
      //each other player gains a copy of revealed card
      for (i = 0; i < state->numPlayers; i++)
  {
    if (i != currentPlayer)
      {
        gainCard(state->hand[currentPlayer][choice1], state, 0, i);
      }
  }

      //discard played card from hand
      discardCard(handPos, currentPlayer, state, 0);      

      //trash copies of cards returned to supply
      for (j = 0; j < choice2; j++)
  {
    for (i = 0; i < state->handCount[currentPlayer]; i++)
      {
        if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1])
    {
      discardCard(i, currentPlayer, state, 1);
      break;
    }
      }
  }     

      return 0;
    
    case cutpurse:

      updateCoins(currentPlayer, state, 2);
      for (i = 0; i < state->numPlayers; i++)
  {
    if (i != currentPlayer)
      {
        for (j = 0; j < state->handCount[i]; j++)
    {
      if (state->hand[i][j] == copper)
        {
          discardCard(j, i, state, 0);
          break;
        }
      if (j == state->handCount[i])
        {
          for (k = 0; k < state->handCount[i]; k++)
      {
        if (DEBUG)
          printf("Player %d reveals card number %d\n", i, state->hand[i][k]);
      } 
          break;
        }   
    }
          
      }
        
  }       

      //discard played card from hand
      discardCard(handPos, currentPlayer, state, 0);      

      return 0;

    
    case embargo: 
      //+2 Coins
      state->coins = state->coins + 2;
      
      //see if selected pile is in play
      if ( state->supplyCount[choice1] == -1 )
  {
    return -1;
  }
      
      //add embargo token to selected supply pile
      state->embargoTokens[choice1]++;
      
      //trash card
      discardCard(handPos, currentPlayer, state, 1);    
      return 0;
    
    case outpost:
      //set outpost flag
      state->outpostPlayed++;
      
      //discard card
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
    
    case salvager:
      //+1 buy
      state->numBuys++;
      
      if (choice1)
  {
    //gain coins equal to trashed card
    state->coins = state->coins + getCost( handCard(choice1, state) );
    //trash card
    discardCard(choice1, currentPlayer, state, 1);  
  }
      
      //discard card
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
    
    case sea_hag:
      for (i = 0; i < state->numPlayers; i++){
  if (i != currentPlayer){
    state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]--];          state->deckCount[i]--;
    state->discardCount[i]++;
    state->deck[i][state->deckCount[i]--] = curse;//Top card now a curse
  }
      }
      return 0;
    
    case treasure_map:
      //search hand for another treasure_map
      index = -1;
      for (i = 0; i < state->handCount[currentPlayer]; i++)
  {
    if (state->hand[currentPlayer][i] == treasure_map && i != handPos)
      {
        index = i;
        break;
      }
  }
      if (index > -1)
  {
    //trash both treasure cards
    discardCard(handPos, currentPlayer, state, 1);
    discardCard(index, currentPlayer, state, 1);

    //gain 4 Gold cards
    for (i = 0; i < 4; i++)
      {
        gainCard(gold, state, 1, currentPlayer);
      }
        
    //return success
    return 1;
  }
      
      //no second treasure_map found in hand
      return -1;
      default:break;
    }
  
  return -1;
}
Пример #18
0
int main() {
  
	int pos =0;
	int numPlayers = 2;
	int seed = 1004;
	struct gameState G, storeG;
	int r;
	int thisPlayer = 0;
	int kcards[10] = {adventurer, minion, cutpurse, steward, smithy,
			   council_room, village, mine, tribute, ambassador};
	memset(&G, 23, sizeof(struct gameState));   // clear the game state
	r = initializeGame(numPlayers, kcards, seed, &G);;

	printf ("TESTING smithy:\n");

	memcpy(&storeG, &G, sizeof(struct gameState));  //copy gameState before smithy.

	//play smithy card
	smithyCard(pos, thisPlayer, &G);
	
	#if (NOISY == 1)
	//deck should have -3 cards
	if (G.deckCount[thisPlayer] == (storeG.deckCount[thisPlayer]- 3))
	{
		printf("deckCount PASSED\n");
	}
	else {
		printf("deckCount Failed\n");
	}
	
	//smithy should be removed from hand
	if (G.hand[thisPlayer][pos] != storeG.hand[thisPlayer][pos])
	{
		printf("smithy removed from hand PASSED\n");
	}
	else {
		printf("smithy removed from hand FAILED\n");
	}

	//player's turn should not change
	if (G.whoseTurn == storeG.whoseTurn)
	{
		printf("player turn PASSED\n");
	}
	else{
		printf("player turn FAILED\n");
	}

	//hand should have +2 cards
	if (G.handCount[thisPlayer] == (storeG.handCount[thisPlayer] + 2))
	{
		printf("handCount PASSED\n");
	}
	else {
		printf("handCount FAILED\n");
	}
   
	#endif
	
	printf("\nAll tests completed. \n");

    return 0;
}