Example #1
0
int runTest(struct gameState *state, int handPos, int currentPlayer){
		//precondition, game state, card position and current player is passed to the function
		// post condition, one additional card is added to the hand, two additional actions added

	// toFlag = 0 : add to discard
  // toFlag = 1 : add to deck
  // toFlag = 2 : add to hand
	int startingHand;
	int endingHand;
	int startingBuy;
	int endingBuy;

	startingBuy = state->numBuys;
	startingHand = state->handCount[currentPlayer];
	playCouncil_Room(state, handPos, currentPlayer);
	endingBuy = state->numBuys;
	endingHand = state->handCount[currentPlayer];
	testVals(startingBuy + 1, endingBuy, "Number of Buys"); // minus one from expected values for council room card discarded
	testVals(startingHand + 3, endingHand, "Number in Hand");


	//testVals(1, 2, "badstuff");
	//testVals(1, 1, "goodstuff");

	return 0;

}
Example #2
0
int main ()
{
	int seed = 1000;
	int numPlayer = 2;
	struct gameState* testGame = newGame();
	
	
 	
 	int k[10] = {adventurer, council_room, feast, gardens, mine,
 				remodel, smithy, village, baron, great_hall}; 

	initializeGame(numPlayer, k, seed, testGame);
	
	int currentPlayer = 0;	
	int handCount = testGame->handCount[currentPlayer];
	int handPosition = handCount - 1;
	int deckSize = testGame->deckCount[currentPlayer];
	testGame->hand[currentPlayer][handPosition] = council_room; //replace
	
	int test = playCouncil_Room (testGame, handPosition);
	if (test == 0)
		printf("Testing Council Room\n");
	else
		printf("Testing Council Room - Fail \n");
///////////////////////Draw Section////////////////////
	if (testGame->handCount[currentPlayer] != handCount - 1 + 4)
		printf("Council Room Card Effect1 - Fail \n");
	else
		printf("Council Room Effect -  check \n");
	
	if (testGame->hand[currentPlayer][handPosition] != smithy)
		printf("Council Room  Not In Hand - check \n");
	else
		printf("Council Room  Not In Hand  - check \n");
	
	if (testGame->playedCards[testGame->playedCardCount] != council_room)
		printf("Council Room  Placed in Played - check \n");
	else
		printf("Council Room  Placed in Played - fail \n");
	
	if (testGame->deckCount[currentPlayer] != deckSize - 4)
		printf("Council Room  Card Draw - Fail \n");
	else
		printf("Council Room  Card Draw - check \n");
	
/////////////////////Buy Section///////////////////////////
	if (testGame->numBuys != 2)
		printf("Council Room  Card Buy Increase - Fail \n");
	else
		printf("Council Room  Card Buy Increase - check \n");
	
	return 0;
	
}
Example #3
0
void testPlayCouncil_Room(int handpos, struct gameState *post){
	struct gameState pre;
	memcpy (&pre, post, sizeof(struct gameState));
	int currentPlayer = whoseTurn(post);
	int i, r;  
	r = playCouncil_Room(post, handpos);

	if (r != 0)
		printf("r != 0\n");
	
	//Check number of actions decreases by 1
	if  (pre.numActions - 1 != post->numActions) 
		printf ("pre.numActions - 1 != post->numActions\n");
	
	//Check number of buys increases by 1
	if (pre.numBuys + 1 != post->numBuys)
		printf ("pre.numBuys + 1 != post->numBuys\n");
	
	if (pre.handCount[currentPlayer] + 3 != post->handCount[currentPlayer]) 
		printf("pre.handCount[currentPlayer] + 3 != post->handCount[currentPlayer]\n");
	if (pre.playedCardCount + 1 != post->playedCardCount)
		printf("pre.playedCardCount + 1 != post->playedCardCount\n");
	if (post->playedCards[post->playedCardCount - 1] != council_room)
		printf("post->playedCards[post->playedCardCount - 1] != council_room\n");
	
	//Check that the player's deck count decreases by 4
	if (pre.deckCount[currentPlayer] >= 4){
		if (pre.deckCount[currentPlayer] - 4 != post->deckCount[currentPlayer])
			printf("pre.deckCount[currentPlayer] - 4 != post->deckCount[currentPlayer]\n");
	} else {
		if (pre.deckCount[currentPlayer] + pre.discardCount[currentPlayer] - 4 != post->deckCount[currentPlayer])
			printf("pre.deckCount[currentPlayer] + pre.discardCount[currentPlayer] - 4 != post->deckCount[currentPlayer]\n");
	}
	
	// Check that handsize of every other player increases by 1 and deck size decreases by 1.
	for (i = 0; i < pre.numPlayers; i++){
		if (i != currentPlayer) {
			if (pre.handCount[i] + 1 != post->handCount[i])
				printf("pre.handCount[i] + 1 != post->handCount[i]");
			if (pre.deckCount[i] >= 1){
				if (pre.deckCount[i] - 1 != post->deckCount[i])
					printf("pre.deckCount[i] - 1 != post->deckCount[i]\n");
			}
				
			else {
				if (pre.deckCount[i] + pre.discardCount[i] - 1 != post->deckCount[i])
					printf("pre.deckCount[i] + pre.discardCount[i] - 1 != post->deckCount[i]\n");
			}
		}
			
	}
	
}
Example #4
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 index;
  int currentPlayer = whoseTurn(state);
  int nextPlayer = currentPlayer + 1;

  int tributeRevealedCards[2] = {-1, -1};
  if (nextPlayer > (state->numPlayers - 1)){
    nextPlayer = 0;
  }
  
	
  //uses switch to select card and perform actions
  switch( card ) 
    {
    case adventurer:
      return playAdventurer(state, currentPlayer);
	  break;
    case council_room:
      return playCouncil_Room(state, handPos, currentPlayer);
	  break;
			
    case feast:
      return playFeast(state, choice1, currentPlayer);
	  break;
			
    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:
      return playSmithy(state, handPos, currentPlayer);
		break;
    case village:
      return playVillage(state, currentPlayer, handPos);
	  break;
    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:
      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;
}
Example #5
0
int main() {
	//intialization steps below borrowed from unittest2
    //seed for initialize game
    int seed = 12345;
    int i = 0;
    int crFlag = 0;
    //here you can choose number of players, between 2 and 4
    int numPlayers = 2;
    //here you can choose player number, starting at 0, up to # of players -1
    int player = 0;
    //players start with 5 cards
    int handNum = 5;
    //this one should pass
    //array to hold current cards
	int currHand[handNum];
	int handPos=0;
    //kingdom cards uses for tets
    int k[10] = {adventurer, ambassador, embargo, smithy, village, feast, mine, gardens, baron, council_room};

	while (player <= numPlayers){
		crFlag = 0;
		i = 0;
		handNum = 5;
		currHand[0] = copper;  //worth 1
    	currHand[1] = silver;  //worth 3
   		currHand[2] = estate;    //
    	currHand[3] = remodel; //can trash a card
    	currHand[4] = council_room; 

    	struct gameState newGame;
    	memcpy(newGame.hand[player], currHand, sizeof(int)*handNum);
    	//itnialzieGame supplies all the supplyCounts of cards
    	printf("Testing playCouncil_Room Fuction for player %d...\n", player);
   		printf("Intializing Game...\n");
    	initializeGame(numPlayers, k, seed, &newGame);

    	printf("Check council room card is in hand of player %d...\n", player);
    	for(i = 0; i < handNum; i++) {
    		if (currHand[i] == council_room) {
    			printf("council room is in hand...\n");
    			crFlag = 1;
    			handPos = i;
    			break;
    		} else {
    			continue;
    		}
    	}


    	int deckCountBefore = newGame.deckCount[player]; //should be -3
    	int discardCountBefore = newGame.discardCount[player]; //shoudl be +1
    	int handCounts[numPlayers];
    	int numOfBuysBefore = 0;
    	int j = 0;
    	for(j=0; j<=numPlayers; j++) {
    		//curr player +3, others plus+1
    		handCounts[i]=newGame.handCount[i];
    	}
    	numOfBuysBefore = newGame.numBuys;
    	playCouncil_Room(&newGame, handPos);

    	if (!crFlag) {
    		printf("No Council Room Card In Hand!\n");
    	} else {
		//plus 4 cards, -1 for discard
    		if((handCounts[player]+3) == newGame.handCount[player]) {
    			printf("Passed! current player handcount is correct\n");
    		} else {
    			printf("Failed! current player handcount is wrong\n");
    		}
		//plus 1 buy
    		if (numOfBuysBefore++ == newGame.numBuys){
    			printf("Passed! Number of buys is correct!\n");
    		} else {
    			printf("Failed! Number of buys is wrong!\n");
    		}
    	//deck count - 3
    		if((deckCountBefore-3) == newGame.deckCount[player]){
    			printf("Passed! Deck count is correct!\n");
    		} else {
    			printf("Failed! Deck count is wrong!\n");
    			printf("Should be %d but it is %d \n",(deckCountBefore-3), newGame.deckCount[player]);
    		}
    	//discard count +1
    		if((discardCountBefore++)==newGame.discardCount[player]){
    			printf("Passed! Discard count is correct\n");
    		} else {
    			printf("Failed! Discard count is wrong!\n");
    		}
		//all other players hand +1
			for(j = 0; j<numPlayers; j++){
				if (j == player) {
					continue;
				} else {
					if ((handCounts[i]++) == newGame.handCount[i]){
						printf("Player %d handcount is correct\n",i);
					} else {
						printf("Player %d handcount is incorrect\n",i);
					}
				}
			}    	
    	}
    	player++;
    }
	return 0;
}
Example #6
0
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
{
   //uses switch to select card and perform actions
  switch( card ) 
    {
    case adventurer:
       return (playAdventurer(state));
	
    case council_room:
       return (playCouncil_Room(state, handPos));
			
    case feast:
       return(playFeast(state, choice1)); 
	
    case gardens:
       return -1;

    case smithy:
      return (playSmithy(state, handPos));
		
    case village:
      return (playVillage(state, handPos));
			
    case mine:
      return(playMine(state, choice1, choice2, handPos));
			
    case remodel:
      return(playRemodel(state, choice1, choice2, handPos));
 
    case baron:
      return(playBaron(state, choice1, choice2, handPos));
   
    case great_hall:
      return(playGreat_hall(state, handPos));
 
    case minion:
      return(playMinion(state, choice1, choice2, handPos));

    case steward:
      return(playSteward(state, choice1, choice2, choice3, handPos));
		
    case tribute:
      return(playTribute(state));

    case ambassador:
      return(playAmbassador(state,choice1, choice2, handPos));
		
    case cutpurse:
      return(playCutpurse(state, handPos));
		
    case embargo:
      return(playEmbargo(state, choice1, handPos));
		
    case outpost:
      return(playOutpost(state, handPos));
		
    case salvager:
      return(playSalvager(state, choice1, handPos));
		
    case sea_hag:
      return(playSea_hag(state));
		
    case treasure_map:
      return(playTreasure_map(state, handPos));
 
    }
  return -1;
}