Ejemplo n.º 1
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 CouncilHand[10];
	int CopperHand[10];
	for(i =0; i < 10; i++){
		CouncilHand[i] = council_room;
		CopperHand[i] = copper;
	}
	
	r = initializeGame(2,k,seed,&G);	
	//Test One
	//Should fail because of the bug introduced (mentioned in refractor txt)
	printf("Testing Council_roomCard Where the player has 2 cards in their hand (testing drawing four) and 0 in their deck, 2 coppers in discard \n");
	G.handCount[0] = 2;
	G.discardCount[0] = 2;
	G.deckCount[0] = 0;
	memcpy(G.hand[0],CouncilHand,sizeof(int) * 2);
	memcpy(G.deck[0],CouncilHand,sizeof(int) * 0);
	memcpy(G.discard[0],CopperHand,sizeof(int) * 2);
	adventurerCard(0, &G);
	printf("Player One has %d in their hand\n",G.handCount[0]);
	if(G.handCount[0] == 4)
	{
		printf("TEST ONE PASSED \n");
		
	} else {
	
		printf("TEST ONE FAILED! \n ");
	}
	
	printf("Testing Council_roomCard Where the player has 2 cards in their hand (testing drawing four) and 2 coppers in their deck, 2 coppers in discard \n");
	G.handCount[0] = 2;
	G.discardCount[0] = 2;
	G.deckCount[0] = 0;
	memcpy(G.hand[0],CouncilHand,sizeof(int) * 2);
	memcpy(G.deck[0],CopperHand,sizeof(int) * 2);
	memcpy(G.discard[0],CopperHand,sizeof(int) * 2);
	adventurerCard(0, &G);
	printf("Player One has %d in their hand\n",G.handCount[0]);
	if(G.handCount[0] == 4)
	{
		printf("TEST TWO PASSED \n");
		
	} else {
	
		printf("TEST TWO FAILED! \n ");
	}
	
	
	return 0;
}
int main(int argc ,char** argv) {

	int seed = atoi(argv[1]);
	SelectStream(1);
	PutSeed(seed);
	int x,y,z,Players,before,after,failed,r1;
	int numberPassed = 0;
	int numberFailed = 0;
	int tests = 0;
	struct gameState g,reset;
	int k[10] ={adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};

	for( x=0; x < 100; x++)
	{
		Players = 2 + (rand() % (int)(MAX_PLAYERS - 2 + 1));
		//printf("	Round %d with Players: %d\n",i,Players);
		initializeGame(Players, k, seed, &g);

		for(z=0; z< 50; z++)
		{

			for (y = 0; y < Players; y++)
			{
				r1 = rand()%2;
				before=after=0;

				before=g.handCount[y];
				adventurerCard(&g, y, 0, 0);

				after=g.handCount[y];
				endTurn(&g);
				failed=myassert( ((before-after) == 1) ||((after - before) == 2) ||((after - before) == 1)||((after - before) == 0));
				if(r1)
				{
					// This case will help to bring the total branch coverage to 100%
					g.deckCount[y]=0;
				}
				if(failed)
				{
					numberFailed = numberFailed + 1;
				}
				else
				{
					numberPassed = numberPassed + 1;
				}
				tests = tests + 1;


			}
		}
		memcpy ( &g, &reset, sizeof(struct gameState) );
	}
	printf("Passed: %d, Failed: %d\n",numberPassed,numberFailed);
	checkasserts();
	
	return 0;
}
Ejemplo n.º 3
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;	//3
	testG.hand[thisPlayer][1] = silver;	//2
	testG.hand[thisPlayer][2] = copper;	//1
	testG.supplyCount[province] = rand() % 5 + 1;
	//Total should add up to 6
	// Starting test
	printf("\n\nTesting card: %s\n\n", UNITTEST);


	printf("Test 1: Checking the function.\n");
	updateCoins(thisPlayer,&testG,0);
	out = testG.coins;
	printf("This should return Adventurer new coins in card: %d (should be 6)\n",out);
	assert(out == 6);
	out = getCost(adventurer);
	adventurerCard(&testG);
	assert(out == 6);
	printf("This should return the value of Adventurer card: %d\n",out);
	out = updateCoins(thisPlayer,&testG,0);
	out = testG.coins;
	printf("This should return Adventurer new coins in card: %d (should be 8)\n",out);
	assert(out == 8);
	printf("Test 1 Passed\n");
	return 0;	//No bugs found
}
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
{
	int i;
	int j;
	int k;
	int index;
	int currentPlayer = whoseTurn(state);
	int nextPlayer = currentPlayer + 1;

	int tributeRevealedCards[2] = {-1, -1};
	int drawntreasure=0;
	if (nextPlayer > (state->numPlayers - 1)){
		nextPlayer = 0;
	}
  
	
	//uses switch to select card and perform actions
	switch( card ) 
		{
		case adventurer:
			return adventurerCard (drawntreasure, state, currentPlayer);
		case council_room:
			return councilRoomCard (currentPlayer, state, handPos);
		case feast:
			return feastCard (currentPlayer, state, choice1);			
		case gardens:
			return -1;			
		case mine:
			return mineCard (currentPlayer, state, choice1, choice2, handPos);
		case remodel:
			return remodelCard (currentPlayer, state, choice1, choice2, handPos);
		case smithy:
			//+3 Cards
			for (i = 0; i < 3; i++)
				{
					drawCard(currentPlayer, state);
				}
			
			//discard card from hand
			discardCard(handPos, currentPlayer, state, 0);
			return 0;
		
		case village:
			//+1 Card
			drawCard(currentPlayer, state);
			
			//+2 Actions
			state->numActions = state->numActions + 2;
			
			//discard played card from hand
			discardCard(handPos, currentPlayer, state, 0);
			return 0;
		
		case baron:
			state->numBuys++;//Increase buys by 1!
			if (choice1 > 0){//Boolean true or going to discard an estate
				int p = 0;//Iterator for hand!
				int card_not_discarded = 1;//Flag for discard set!
				while(card_not_discarded){
					if (state->hand[currentPlayer][p] == estate){//Found an estate card!
						state->coins += 4;//Add 4 coins to the amount of coins
						state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p];
						state->discardCount[currentPlayer]++;
						for (;p < state->handCount[currentPlayer]; p++){
							state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1];
						}
						state->hand[currentPlayer][state->handCount[currentPlayer]] = -1;
						state->handCount[currentPlayer]--;
						card_not_discarded = 0;//Exit the loop
					}
					else if (p > state->handCount[currentPlayer]){
						if(DEBUG) {
							printf("No estate cards in your hand, invalid choice\n");
							printf("Must gain an estate if there are any\n");
						}
						if (supplyCount(estate, state) > 0){
							gainCard(estate, state, 0, currentPlayer);
							state->supplyCount[estate]--;//Decrement estates
							if (supplyCount(estate, state) == 0){
								isGameOver(state);
							}
						}
						card_not_discarded = 0;//Exit the loop
					}
			    
					else{
						p++;//Next card
					}
				}
			}
			    
			else{
 /* MUTANT (rep_op) */				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:
			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]-1];
					state->discardCount[i]++;
					state->deck[i][state->deckCount[i]-1] = 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;
}
Ejemplo n.º 5
0
int main() 
{
   int i;
   int seed = 1000;
   int numPlayer = 2;
   int maxBonus = 10;
   int p, r, handCount;
   p = 0;

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

   int myDrawnTrs = 0;
   int z = 0;
   int myTempHand[MAX_HAND];
   int myDrawnCrd = 0;

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

   G.hand[0][1] = adventurer;
   // is adventurer 6 coins
   int cost = getCost(adventurer);
   printf("Test 1: Does adventurer cost 6 coins?\n");

   if (cost == 6)
      printf("Passed: Adventurer costs 6 coins.\n\n");
   else
      printf("Failed: Adventurer costs %d coins.\n\n", cost);

   // adventurer in hand
   printf("Test 2: Is Adventurer in hand?\n");

   int isAdventurer = 0;
   for (i = 0; i < G.handCount[0]; i++)
   {
      //printf("Where\n");
      if (G.hand[0][i] == adventurer)
      {
	 isAdventurer = 1;
	 i = G.handCount[0];
      }
   }

   if (isAdventurer == 1)
      printf("Passed: Adventurer in hand.\n\n");
   else
      printf("Failed: Adventurer is not in hand.\n\n");

   // use adventurer
   adventurerCard(0, &G, myDrawnTrs, z, myTempHand, myDrawnCrd);

   isAdventurer = 0;
   for (i = 0; i < G.handCount[0]; i++)
   {
      //printf("Where\n");
      if (G.hand[0][i] == adventurer)
      {
	 isAdventurer = 1;
	 i = G.handCount[0];
      }
   }

   // is adventurer in hand
   printf("Test 3: Is adventurer removed from hand?\n");
   if (isAdventurer == 1)
      printf("Failed: Adventurer not removed from hand.\n\n");
   else
      printf("Passed: Adventurer card removed from hand.\n\n");

   // does adventurer reveal 2 treasures
   printf("Test 4: Does adventurer put two treasures into hand?\n");

   // do the treasures go into your hand
   int flag = 0;

   int last = G.handCount[0] - 1;
   int nextLast = last - 1;
   if (G.hand[0][last] == copper)
   {
      if(G.hand[0][nextLast] == copper)
      {
	 flag = 1;
      } 
   }

   if (flag && G.handCount[0] == 7)
      printf("Passed: 2 treasure cards were added to the hand.\n\n");
   else
      printf("Failed: 2 treasure cards were not added to the last hand.\n\n") ;

   // do the other cards go into discard pile
   return 0;
}
Ejemplo n.º 6
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:
      adventurerCard(state, currentPlayer, temphand);
      return 0;
			
    case council_room:
      //+4 Cards
      for (i = 0; i < 4; i++)
	{
	  drawCard(currentPlayer, state);
	}
			
      //+1 Buy
      state->numBuys++;
			
      //Each other player draws a card
      for (i = 0; i < state->numPlayers; i++)
	{
	  if ( i != currentPlayer )
	    {
	      drawCard(i, state);
	    }
	}
			
      //put played card in played card pile
      discardCard(handPos, currentPlayer, state, 0);
			
      return 0;
			
    case feast:
      //gain card with cost up to 5
      //Backup hand
      for (i = 0; i <= state->handCount[currentPlayer]; i++){
	temphand[i] = state->hand[currentPlayer][i];//Backup card
	state->hand[currentPlayer][i] = -1;//Set to nothing
      }
      //Backup hand

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

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

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

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

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

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

	}
      }     

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

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

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

      gainCard(choice2, state, 2, currentPlayer);

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

      //discard trashed card
      for (i = 0; i < state->handCount[currentPlayer]; i++)
	{
	  if (state->hand[currentPlayer][i] == j)
	    {
	      discardCard(i, currentPlayer, state, 0);			
	      break;
	    }
	}
			
      return 0;
			
    case remodel:
      j = state->hand[currentPlayer][choice1];  //store card we will trash

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

      gainCard(choice2, state, 0, currentPlayer);

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

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


      return 0;
		
    case smithy:
      smithyCard(state, currentPlayer, handPos);
      return 0;
		
    case village:
      villageCard(state, currentPlayer, handPos);
      return 0;
		
    case baron:
          
      baronCard(state, currentPlayer, choice1);

      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:
      stewardCard(state, handPos, currentPlayer, 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;
}
Ejemplo n.º 7
0
int main() {

    printf("Test adventurer card:\n");

    srand(time(NULL));
    int numberPlayer = 2;
    int player1 = 0;
    int randomSeed = rand() % 1000 + 1;
    int k[10] = {adventurer, council_room, feast, gardens, mine,
                 remodel, smithy, village, baron, great_hall
                };
    struct gameState G;
    int temphand[MAX_HAND];
    int drawntreasure=0;
    int cardDrawn=0;
    int newDiscardCnt;
    int newHandCnt;

    //expect a 'healthy card' to reveal cards from deck until 2 Treasure cards are hit.
    //then put those card in your hand and discard the other revealed cards.

    //1) Test that 2 cards (1 card gained in hand because of this one played)
    // are accumulated in hand and all other cards are discarded.

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

    printf("Test case 1: Test that 2 cards (1 card gained in hand because of this one played)\n");
    printf("are accumulated in hand and all other cards are discarded.\n");

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

    int discardCnt;
    int handCount;

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

    //initialize game
    initializeGame(numberPlayer, k, randomSeed, &G);

    discardCnt=G.discardCount[player1];
    handCount=G.handCount[player1];

    adventurerCard(temphand, 0, cardDrawn, player1, drawntreasure, &G);

    newDiscardCnt=G.deckCount[player1];
    newHandCnt=G.handCount[player1];

    // printf("OLD HAND CNT: %d\n", handCount);
    // printf("NEW HAND CNT: %d\n", newHandCnt);

    printf("Test that cards are discarded...\n");

    if(newDiscardCnt != discardCnt) {
        printf("Discard test successful.\n");
    } else {
        printf("Discard test failed.\n");
    }

    printf("Test that player has right amount of cards in hand...\n");

    if(newHandCnt == (handCount+1)) {
        printf("Hand count test successful.\n");
    } else {
        printf("Hand count test failed:\n");
        printf("OLD HAND COUNT: %d\n", handCount);
        printf("NEW HAND COUNT: %d\n", newHandCnt);
    }

    //check the number of drawn treasure and make sure it's 2
    // if(drawntreasure == 2) {
    // 	printf("Correct number of treasure drawn.\n");
    // } else {
    // 	printf("Wrong number of treasure drawn.\n");
    // }

    //2)check to see if the last added cards in the hand are indeed treasures

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

    printf("Major Test case 2: Check to see if the last added cards in the hand are indeed treasures\n");

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

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

    // //initialize game
    // initializeGame(numberPlayer, k, randomSeed, &G);

    int newestCard1;
    int newestCard2;

    newestCard1=G.hand[player1][G.handCount[player1]-1];
    newestCard2=G.hand[player1][G.handCount[player1]-2];

    //Tresure cards are: copper=4, silver=5, gold=6
    printf("Newest card in hand is %d\n", newestCard1);
    printf("Second newest card is %d\n", newestCard2);

    // for(i=0; i<G.handCount[player1]; i++) {
    // 	printf("CARDS IN HAND: %d\n", G.hand[player1][i]);
    // }

    if((newestCard1 == copper || newestCard1 == silver || newestCard1 == gold) && (newestCard2 == copper || newestCard2 == silver || newestCard2 == gold)) {
        printf("TEST PASSED: Both cards obtained are both treasures\n");
    } else {
        printf("TEST FAILED: Both cards obtained are not both treasures\n");
    }



    return 0;




}
Ejemplo n.º 8
0
int main()
{
	int seed = 1000;
    int numPlayer = 2;
    int thisPlayer = 0;
    int cardsBeforeHand;
    int z = 0;
    int cardDrawn = 0;
    int drawntreasure = 0;
    int temphand[MAX_HAND];
    int k[10] = {adventurer, embargo, village, minion, mine, cutpurse,
			sea_hag, tribute, smithy, council_room};

	struct gameState G, testG;

	initializeGame(numPlayer, k, seed, &G);
	memcpy(&testG, &G, sizeof(struct gameState));

	printf("----------------- Testing Card: Adventurer ----------------\n");

	printf("----------- Test 1:  Player hand card count should increase by 2 ----------\n");
	cardsBeforeHand = testG.handCount[thisPlayer];
	adventurerCard(drawntreasure, &testG, thisPlayer, cardDrawn, z, temphand);
	if(testG.handCount[thisPlayer] == cardsBeforeHand + 2)
		printf("TEST PASSED \n");
	else
		printf("TEST FAILED \n");

	printf("----------- Test 2:  Deck count should decrease ----------\n");
	if(testG.deckCount[thisPlayer] < G.deckCount[thisPlayer])
		printf("TEST PASSED \n");
	else
		printf("TEST FAILED \n");		

	printf("----------- Test 3:  Discard should increase or remain unchanged ----------\n");
	if(testG.discardCount[thisPlayer] >= G.discardCount[thisPlayer])
		printf("TEST PASSED \n");
	else
		printf("TEST FAILED \n");

	printf("----------- Test 4:  Difference in deck amt should reflect discard + 2 ----------\n");
	if(testG.deckCount[thisPlayer] >= G.deckCount[thisPlayer])
		printf("TEST PASSED \n");
	else
		printf("TEST FAILED \n");

	printf("----------- Test 5:  Opponents state should remain unchanged ----------\n");
	thisPlayer = 1;
	printf("--- Opponent handcount unchanged? ---\n");
    if(testG.handCount[thisPlayer] == G.handCount[thisPlayer])
    	printf("TEST PASSED\n");
  	else
    	printf("TEST FAILED\n");
	
	int j;
	printf("--- Opponent hand unchanged? ---\n");
	for (j = 0; j < G.handCount[thisPlayer]; j++)
  	{
	    if(testG.hand[thisPlayer][j] == G.hand[thisPlayer][j])
	      printf("TEST PASSED\n");
	    else
	      printf("TEST FAILED\n");
  	}
	printf("--- Opponent deckcount unchanged? ---\n");
	  if(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer])
	    printf("TEST PASSED\n");
	  else
	    printf("TEST FAILED\n");

	printf("--- Opponent deck unchanged? ---\n");
	for (j = 0; j < G.deckCount[thisPlayer]; j++)
	{
	   	if(testG.deck[thisPlayer][j] == G.deck[thisPlayer][j])
		   printf("TEST PASSED\n");
		else
		   printf("TEST FAILED\n");
	}
		
	printf("--- Opponent discardcount unchanged? ---\n");
	  if(testG.discardCount[thisPlayer] == G.discardCount[thisPlayer])
	    printf("TEST PASSED\n");
	  else
	    printf("TEST FAILED\n");

	printf("--- Opponent discard unchanged? ---\n");
	for (j = 0; j < G.discardCount[thisPlayer]; j++)
	{
	    if(testG.discard[thisPlayer][j] == G.discard[thisPlayer][j])
	      printf("TEST PASSED\n");
	    else
	      printf("TEST FAILED\n");
	}

	printf("---------- adventurerCard testing completed. ----------\n\n");

 return 0;
}
Ejemplo n.º 9
0
int main()
{
	int x, rcard, n, p, draw;
	int t;
	int treas1 = 0;
	int treas2 = 0;
	int i = 0;
	int pass = 0;
	int treas = 0;
	int temp[MAX_HAND];
	struct gameState G, testG;
	int k[20] = {adventurer, council_room, feast, gardens, mine,
	       remodel, smithy, village, baron, great_hall, copper, copper, copper, 
		   copper, silver, silver, silver, gold, gold, gold};
	
	SelectStream(8);
	PutSeed(2);

	printf("Testing adventurer card\n");
	
	for (n = 0; n < 50; n++) {
		for (i = 0; i < sizeof(struct gameState); i++) {
			((char*)&G)[i] = floor(Random() * 256);
    }
		p = floor(Random() * 2);
		G.whoseTurn = p;
		G.deckCount[p] = floor(Random() * MAX_HAND);
		G.discardCount[p] = 5;
		G.handCount[p] = floor(Random() * MAX_HAND);
		for(i = 0; i < G.deckCount[p]; i++){
			rcard = floor(Random() * 19);
			G.deck[p][i] = k[rcard];
		}
		for(i = 0; i < G.handCount[p]; i++){
			rcard = floor(Random() * 19);
			G.hand[p][i] = k[rcard];
		}
		for(i = 0; i < G.discardCount[p]; i++){
			rcard = floor(Random() * 19);
			G.discard[p][i] = k[rcard];
		}
		
		memcpy(&testG, &G, sizeof(struct gameState));
		
	t = adventurerCard(&testG, 0);
	assert(t == 0);
	
	if(G.handCount[G.whoseTurn] + 2 != testG.handCount[testG.whoseTurn]){
		printf("Failed card number, Expected: %d, Result: %d\n", G.handCount[G.whoseTurn] + 2, testG.handCount[testG.whoseTurn]);
		pass = 1;
	}
	
	while(treas<2){
	drawCard(G.whoseTurn, &G);
	draw = G.hand[G.whoseTurn][G.handCount[G.whoseTurn]-1];
	if (draw == copper || draw == silver || draw == gold){
	  treas++;
	}
	else{
	  temp[i]=draw;
	  G.handCount[G.whoseTurn]--; 
	  i++;
	}
    }
	
	if(G.discardCount[G.whoseTurn] + i != testG.discardCount[testG.whoseTurn]){
		printf("Failed discard count, expected: %d, Result: %d\n", G.discardCount[G.whoseTurn] + i, testG.discardCount[testG.whoseTurn]);
		pass = 1;
	}
	
	for(x = 0; x < G.handCount[G.whoseTurn]; x++){
		if (G.hand[G.whoseTurn][x] == copper || G.hand[G.whoseTurn][x] == silver || G.hand[G.whoseTurn][x] == gold){
			treas1++;
		}
			
	}
	
	for(x = 0; x < testG.handCount[testG.whoseTurn]; x++){
		if (testG.hand[testG.whoseTurn][x] == copper || testG.hand[testG.whoseTurn][x] == silver || testG.hand[testG.whoseTurn][x] == gold){
			treas2++;
		}
			
	}
	
	if(treas1 != treas2){
		printf("Failed treasure count, Expected: %d, Result: %d\n", treas1, treas2);
		pass = 1;
	}
	
	if(pass == 0){
		printf("Passed all tests\n");
	}

	}
	printf("Hand count: %d, MAX_HAND: %d\n", G.handCount[p], MAX_HAND);
	
	return 0;
}
Ejemplo n.º 10
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 an adventurer card to be played
		G.hand[randomPlayer][G.handCount[randomPlayer]] = adventurer;
		G.handCount[randomPlayer]++;

		//Set defaults for card/coin counts
		int cardCount = G.handCount[randomPlayer];
		int pCardCount = G.playedCardCount;
		int treasureCount = 0;
		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 deck count to count how many cards need to be discarded
		for(j = G.deckCount[randomPlayer] - 1; j >= 0; j--){
			if(treasureCount < 2){
				if(G.deck[randomPlayer][j] == copper){
					treasureCount++;
					coinCount++;
				}
				else if(G.deck[randomPlayer][j] == silver){
					treasureCount++;
					coinCount+=2;
				}
				else if(G.deck[randomPlayer][j] == gold){
					treasureCount++;
					coinCount+=3;
				}
				else
					dCardCount++;
			}
		}
		//Add the old discardcount to deck card count to calculate how many cards are discarded
		deCardCount+=G.discardCount[randomPlayer];

		//Play adventurerCard, add one to played pile, add (2-1) cards to hand count
		adventurerCard(randomPlayer, &G);
		pCardCount++;
		cardCount++;

		//Remove 2+discardCount from deck card count, and the new discard count
		deCardCount = deCardCount - 2 - G.discardCount[randomPlayer];

		//Update coin count
		updateCoins(randomPlayer, &G, 0);
		if(G.handCount[randomPlayer] != cardCount)
			printf("randomtestadventurer.c: FAIL\r\nG.handCount[randomPlayer] == %d\r\nExpected:G.handCount[randomPlayer] == %d\r\n", G.handCount[randomPlayer], cardCount);
		if(G.playedCardCount != pCardCount)
			printf("randomtestadventurer.c: FAIL\r\nG.playedCardCount == %d\r\nExpected:G.playedCardCount == %d\r\n", G.playedCardCount, pCardCount);
		if(G.discardCount[randomPlayer] != dCardCount)
			printf("randomtestadventurer.c: FAIL\r\nG.discardCount == %d\r\nExpected:G.discardCount == %d\r\n", G.discardCount[randomPlayer], dCardCount);
		if(G.deckCount[randomPlayer] != deCardCount)
			printf("randomtestadventurer.c: FAIL\r\nG.deckCount == %d\r\nExpected:G.deckCount == %d\r\n", G.deckCount[randomPlayer], deCardCount);
		if(G.coins != coinCount)
			printf("randomtestadventurer.c: FAIL\r\nG.coins == %d\r\nExpected:G.coins == %d\r\n", G.coins, coinCount);

		//printf("All test passed for adventurer card, cardtest1.c\n");
		printf("All other test passed for adventurer card, randomtestadventurer.c, iteration %d\r\n\r\n", i+1);
		printf("--------------------\r\n\r\n");
	}
	return 0;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
0
void testAdventurer(struct gameState *post,int p ) {

	struct gameState pre;
	memcpy (&pre, post, sizeof(struct gameState));
	
	adventurerCard(p,post);
	drawCard(p,&pre);
#if (NOISY_TEST == 1)
	printf("Testing when player %d plays Adventurer card\n",p);
	if(p==1)
	{
		printf("Initial values for player 1 are handCount:%d, discardCount:%d, deckCount:%d\n",pre.handCount[1], pre.discardCount[1], pre.deckCount[1]);
		printf("Initial values for player 2 are handCount:%d, discardCount:%d, deckCount:%d\n",pre.handCount[2], pre.discardCount[2], pre.deckCount[2]);
	}
	else{
		printf("Initial values for player 2 are handCount:%d, discardCount:%d, deckCount:%d\n",pre.handCount[2], pre.discardCount[2], pre.deckCount[2]);
		printf("Initial values for player 1 are handCount:%d, discardCount:%d, deckCount:%d\n",pre.handCount[1], pre.discardCount[1], pre.deckCount[1]);
	}
	if (p==1)
	{
		printf("Testing if player 1 handCount increased");
		if (pre.handCount[1]<post->handCount[1])
		{
			printf("....PASSED\n");
			printf("pre: %d, post:%d\n", pre.handCount[1],post->handCount[1]);
		}
		else{
			printf("....FAILED\n");
			printf("pre: %d, post:%d\n", pre.handCount[1],post->handCount[1]);
		}
		
		printf("Testing player 2 handCount remains unchanged");		
		if (pre.handCount[2]==post->handCount[2])
		{
			printf("....PASSED\n");
			printf("pre: %d, post:%d\n", pre.handCount[2],post->handCount[2]);
		}
		else{
			printf("....FAILED\n");
			printf("pre: %d, post:%d\n", pre.handCount[2],post->handCount[2]);
		}
		
		printf("Testing if player 1 discardCount remains unchanged");
		if (pre.discardCount[1]==post->discardCount[1])
		{
			printf("....PASSED\n");
			printf("pre: %d, post:%d\n", pre.discardCount[1],post->discardCount[1]);
		}
		else{
			printf("....FAILED\n");
			printf("pre: %d, post:%d\n", pre.discardCount[1],post->discardCount[1]);
		}
		
		printf("Testing player 2 discardCount remains unchanged");		
		if (pre.discardCount[2]==post->discardCount[2])
		{
			printf("....PASSED\n");
			printf("pre: %d, post:%d\n", pre.discardCount[2],post->discardCount[2]);
		}
		else{
			printf("....FAILED\n");
			printf("pre: %d, post:%d\n", pre.discardCount[2],post->discardCount[2]);
		}
		
		
		printf("Testing if player 1 deckCount remains unchanged");
		if (pre.deckCount[1]==post->deckCount[1])
		{
			printf("....PASSED\n");
			printf("pre: %d, post:%d\n", pre.deckCount[1],post->deckCount[1]);
		}
		else{
			printf("....FAILED\n");
			printf("pre: %d, post:%d\n", pre.deckCount[1],post->deckCount[1]);
		}
		
		printf("Testing player 2 deckCount remains unchanged");		
		if (pre.deckCount[2]==post->deckCount[2])
		{
			printf("....PASSED\n");
			printf("pre: %d, post:%d\n", pre.deckCount[2],post->deckCount[2]);
		}
		else{
			printf("....FAILED\n");
			printf("pre: %d, post:%d\n", pre.deckCount[2],post->deckCount[2]);
		}
		
	}
	if (p==2)
	{
		printf("Testing player 2 handCount increased");
		if (pre.handCount[2]<post->handCount[2])
		{
			printf("....PASSED\n");
			printf("pre: %d, post:%d\n", pre.handCount[2],post->handCount[2]);
		}
		else{
			printf("....FAILED\n");
			printf("pre: %d, post:%d\n", pre.handCount[2],post->handCount[2]);
		}
		
		printf("Testing player 1 handCount remains unchanged");
		if (pre.handCount[1]==post->handCount[1])
		{
			printf("....PASSED\n");
			printf("pre: %d, post:%d\n", pre.handCount[1],post->handCount[1]);
		}
		else{
			printf("....FAILED\n");
			printf("pre: %d, post:%d\n", pre.handCount[1],post->handCount[1]);
		}
		
		
		printf("Testing if player 2 discardCount remains unchanged");
		if (pre.discardCount[2]==post->discardCount[2])
		{
			printf("....PASSED\n");
			printf("pre: %d, post:%d\n", pre.discardCount[2],post->discardCount[2]);
		}
		else{
			printf("....FAILED\n");
			printf("pre: %d, post:%d\n", pre.discardCount[2],post->discardCount[2]);
		}
		
		printf("Testing player 1 discardCount remains unchanged");		
		if (pre.discardCount[1]==post->discardCount[1])
		{
			printf("....PASSED\n");
			printf("pre: %d, post:%d\n", pre.discardCount[1],post->discardCount[1]);
		}
		else{
			printf("....FAILED\n");
			printf("pre: %d, post:%d\n", pre.discardCount[1],post->discardCount[1]);
		}
		
		
		printf("Testing if player 2 deckCount remains unchanged");
		if (pre.deckCount[2]==post->deckCount[2])
		{
			printf("....PASSED\n");
			printf("pre: %d, post:%d\n", pre.deckCount[2],post->deckCount[2]);
		}
		else{
			printf("....FAILED\n");
			printf("pre: %d, post:%d\n", pre.deckCount[2],post->deckCount[2]);
		}
		
		printf("Testing player 2 deckCount remains unchanged");		
		if (pre.deckCount[1]==post->deckCount[1])
		{
			printf("....PASSED\n");
			printf("pre: %d, post:%d\n", pre.deckCount[1],post->deckCount[1]);
		}
		else{
			printf("....FAILED\n");
			printf("pre: %d, post:%d\n", pre.deckCount[1],post->deckCount[1]);
		}
	}
	printf("Testing adventurer card supply Count");
	if (pre.supplyCount[adventurer]==post->supplyCount[adventurer])
	{
		printf("....PASSED\n");
		printf("pre: %d, post:%d\n", pre.supplyCount[adventurer],post->supplyCount[adventurer]);
	}
	else{
		printf("....FAILED\n");
		printf("pre: %d, post:%d\n", pre.supplyCount[adventurer],post->supplyCount[adventurer]);
	}
	printf("Testing outpost count");
	if (pre.outpostPlayed==post->outpostPlayed)
	{
		printf("....PASSED\n");
		printf("pre: %d, post:%d\n", pre.outpostPlayed,post->outpostPlayed);
	}
	else{
		printf("....FAILED\n");
		printf("pre: %d, post:%d\n", pre.outpostPlayed,post->outpostPlayed);
	}
	printf("Testing if numActions is unchanged");
	if (pre.numActions==post->numActions)
	{
		printf("....PASSED\n");
		printf("pre: %d, post:%d\n", pre.numActions,post->numActions);
	}
	else{
		printf("....FAILED\n");
		printf("pre: %d, post:%d\n", pre.numActions,post->numActions);
	}
	printf("Testing if Coin count is unchanged");
	if (pre.coins==post->coins)
	{
		printf("....PASSED\n");
		printf("pre: %d, post:%d\n", pre.coins,post->coins);
	}
	else{
		printf("....FAILED\n");
		printf("pre: %d, post:%d\n", pre.coins,post->coins);
	}
	printf("Testing if numBuys is unchanged");
	if (pre.numBuys==post->numBuys)
	{
		printf("....PASSED\n");
		printf("pre: %d, post:%d\n", pre.numBuys,post->numBuys);
	}
	else{
		printf("....FAILED\n");
		printf("pre: %d, post:%d\n", pre.numBuys,post->numBuys);
	}
#endif
	endTurn(&post);
#if (NOISY_TEST == 1)
	printf("Testing adventurer card supply Count");
	if (pre.supplyCount[adventurer]==post->supplyCount[adventurer])
	{
		printf("....PASSED\n");
		printf("pre: %d, post:%d\n", pre.supplyCount[adventurer],post->supplyCount[adventurer]);
	}
	else{
		printf("....FAILED\n");
		printf("pre: %d, post:%d\n", pre.supplyCount[adventurer],post->supplyCount[adventurer]);
	}
	printf("Testing outpost count");
	if (pre.outpostPlayed==post->outpostPlayed)
	{
		printf("....PASSED\n");
		printf("pre: %d, post:%d\n", pre.outpostPlayed,post->outpostPlayed);
	}
	else{
		printf("....FAILED\n");
		printf("pre: %d, post:%d\n", pre.outpostPlayed,post->outpostPlayed);
	}
	printf("Testing if numActions is unchanged");
	if (pre.numActions==post->numActions)
	{
		printf("....PASSED\n");
		printf("pre: %d, post:%d\n", pre.numActions,post->numActions);
	}
	else{
		printf("....FAILED\n");
		printf("pre: %d, post:%d\n", pre.numActions,post->numActions);
	}
	printf("Testing if Coin count is unchanged");
	if (pre.coins==post->coins)
	{
		printf("....PASSED\n");
		printf("pre: %d, post:%d\n", pre.coins,post->coins);
	}
	else{
		printf("....FAILED\n");
		printf("pre: %d, post:%d\n", pre.coins,post->coins);
	}
	printf("Testing if numBuys is unchanged");
	if (pre.numBuys==post->numBuys)
	{
		printf("....PASSED\n");
		printf("pre: %d, post:%d\n", pre.numBuys,post->numBuys);
	}
	else{
		printf("....FAILED\n");
		printf("pre: %d, post:%d\n", pre.numBuys,post->numBuys);
	}	
	printf("\n\n");
	#endif
}
Ejemplo n.º 13
0
 int main () {

  int n, p, i;
  struct gameState G;
  time_t t;
  srand((unsigned)time(&t));
  printf ("Testing Adventurer.\n");

  printf ("RANDOM TESTS.\n");

  SelectStream(2);
  PutSeed(3);

  for (n = 0; n < 2000; n++) {
	int* k=kingdomCards(1,2,3,4,5,6,7,8,9,10);
	G.numPlayers=rand() % 3+1;
	initializeGame(G.numPlayers,k,1000,&G);
	p = rand() % 2+1;
	G.numPlayers=rand() % 3+1;
    G.deckCount[p] = rand() % MAX_DECK;
    G.discardCount[p] = rand() % MAX_DECK;
    G.handCount[p] = rand() % MAX_HAND;
	G.supplyCount[adventurer]=rand()%10;
    testAdventurer(&G,p);
  }
	
    printf ("Fixed tests for adventurer():\n");
	for (i=0;i<50;i++)
	{
		int* k=kingdomCards(1,2,3,4,5,6,7,8,9,10);
		memset(&G, 23, sizeof(struct gameState));   // clear the game state
		initializeGame(2, k, 1000, &G); // initialize a new game
		G.handCount[0]=0;
	#if (NOISY_TEST == 1)
		printf ("Playing adventurer card 1 time\n");
	#endif	
		adventurerCard(1,&G); 
	#if (NOISY_TEST == 1)
		printf("Handcount: %d\n", G.handCount[0]);
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf ("Playing adventurer card another time\n");
	#endif	 
		adventurerCard(1,&G); 
	#if (NOISY_TEST == 1)
		printf("Handcount: %d\n", G.handCount[0]);
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf ("Playing adventurer card another time\n");
	#endif	
		adventurerCard(1,&G); 
	#if (NOISY_TEST == 1)
		printf("Handcount: %d\n", G.handCount[0]);
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf ("Playing adventurer card another time\n");
	#endif	
		adventurerCard(1,&G); 
	#if (NOISY_TEST == 1)
		printf("Handcount: %d\n", G.handCount[0]);
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf ("Playing adventurer card another time\n");
	#endif	
		adventurerCard(1,&G);
	#if (NOISY_TEST == 1)
		printf("Handcount: %d\n", G.handCount[0]);
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf ("Playing adventurer card another time\n");
	#endif	 
		adventurerCard(1,&G); 
	#if (NOISY_TEST == 1)
		printf("Handcount: %d\n", G.handCount[0]);
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n");
		}
		else{
			printf("....FAIL\n");
		}
		printf ("Playing adventurer card another time*\n");
	#endif	
		adventurerCard(1,&G);
	#if (NOISY_TEST == 1)
		printf("Handcount: %d\n", G.handCount[0]);
		printf("Number of Cards Played = %d, expected = 0", G.playedCardCount);	
		if (G.playedCardCount==0)
		{
			printf("....PASS\n\n");
		}
		else{
			printf("....FAIL\n\n");
		}
	#endif	
		endTurn(&G);
	#if (NOISY_TEST == 1)
		printf("Testing other player's hand\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 ("ALL TESTS COMPLETE\n");
  return 0;
}