コード例 #1
0
ファイル: cardtest1.c プロジェクト: welborau/CS362Su2015
int testAdventureCard() {
  struct gameState state = setUp("Unit Test/ Card 1: Adventure Card");
  int player = 0;

  puts("]] Test starting with empty hand");
  int deckCount = state.deckCount[player];
  state.handCount[player] = 0;
  updateCoins(player, &state, 0);
  assert(state.coins == 0);
  adventureCard(player, &state);
  updateCoins(player, &state, 0);
  assert(state.coins > 0);
  puts("   can't possibly discard more than what your deck it");
  puts("   (since we are starting fresh with full deck)");
  assert(state.discardCount[player] < deckCount);

  return 0;
}
コード例 #2
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};
  /*
   * Unused variables after refactorring
  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 adventureCard(currentPlayer,state);
    case council_room:
    	return council_roomCard(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{
	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;
}
コード例 #3
0
ファイル: cardtest2.c プロジェクト: Jmmyr41/cs362f15
int checkAdventure(struct gameState *pre, int currentPlayer, int tempHand[MAX_HAND], int z, int cardDrawn, int n){	
	struct gameState post;
	memcpy (&post, pre, sizeof(struct gameState));
	int i;
	int postCount;
	int t;
	int q;
	int funErrors = 0;
	int treasure = 0;
	int postTreasure = 0;
	int deckPreTreasure = 0;
	adventureCard(0, &post, currentPlayer, tempHand, z, cardDrawn);	

	for(i = 0; i < pre->handCount[currentPlayer]; i++){
		if(pre->hand[currentPlayer][i]==copper || pre->hand[currentPlayer][i]==gold || pre->hand[currentPlayer][i]==silver){
			treasure++;//get orriginal amount of treasure in hand
		}
	}

	for(i = 0; i < post.handCount[currentPlayer]; i++){
		if(post.hand[currentPlayer][i]==copper || post.hand[currentPlayer][i]==gold || post.hand[currentPlayer][i]==silver){
			postTreasure++;//get amount of treasure after adventure card has been played
		}
	}
	
	for (t=0; t < pre->numPlayers; t++){//check other players' stats to make sure they haven't changed
		if(pre->handCount[t] != post.handCount[t]){
			if(t != currentPlayer){//if it's current player their stuff is probably different
				#if(NOISY_TEST == 1)
				printf("Test #: %d failed\n", n);
				printf("Expected: Player %d handCount = %d	Actual: Player %d handCount = %d\n", t, pre->handCount[t], t, post.handCount[t]);
				#endif
				funErrors++;
			}
		}
		if(pre->discardCount[t] != post.discardCount[t]){
			if(t != currentPlayer){
				#if(NOISY_TEST == 1)
				printf("Test #: %d failed\n", n);
				printf("Expected: Player %d discardCount = %d	Actual: Player %d discardCount = %d\n", t, pre->discardCount[t], t, post.discardCount[t]);
				#endif
				funErrors++;
			}
		}
		if(pre->deckCount[t] != post.deckCount[t]){
			if(t != currentPlayer){
				#if(NOISY_TEST == 1)
				printf("Test #: %d failed\n", n);
				printf("Expected: Player %d deckCount = %d	Actual: Player %d deckCount = %d\n", t, pre->deckCount[t], t, post.deckCount[t]);
				#endif
				funErrors++;
			}
		}
		postCount = 0;
		for(q = 0; q < post.deckCount[t]; q++){
			if(post.deck[t][q] == treasure_map){
				postCount++;
			}
		}
		if(1 != postCount){
			if(t != currentPlayer){
				#if(NOISY_TEST == 1)
				printf("Test #: %d failed\n", n);
				printf("Expected: Player %d treasure_map = 1	Actual: Player %d treasure_map = %d\n", t, t, postCount);
				#endif
				funErrors++;
			}
		}
	}
	if(treasure+2 != postTreasure){//possibly not 2 treasure cards in player's deck or discard
		for(i=0; i < pre->deckCount[currentPlayer]; i++){
			if(pre->deck[currentPlayer][i]==copper || pre->deck[currentPlayer][i]==silver || pre->deck[currentPlayer][i]==gold){
				deckPreTreasure++;//check to see how many treasure cards are in deck
			}
		}
		for(i=0; i < pre->discardCount[currentPlayer]; i++){
			if(pre->discard[currentPlayer][i]==copper || pre->discard[currentPlayer][i]==silver || pre->discard[currentPlayer][i]==gold){
				deckPreTreasure++;//check to see how many treasure cards are in discard
			}
		}
		if(deckPreTreasure >= 2){//if we found more than two treasure then we have an error
			if(post.handCount[currentPlayer] != pre->handCount[currentPlayer]+2){
				#if(NOISY_TEST == 1)
				printf("Test #: %d failed\n", n);
				printf("Expected: handCount = %d	Actual: handCount = %d\n", pre->handCount[currentPlayer]+2, post.handCount[currentPlayer]);
				#endif
				funErrors++;
			}
		}
		else if(deckPreTreasure == 1){//if only one treasure is found then player hand count should go up by one
			if(post.handCount[currentPlayer] != pre->handCount[currentPlayer]+1){
				#if(NOISY_TEST == 1)
				printf("Test #: %d failed\n", n);
				printf("Expected: handCount = %d	Actual: handCount = %d\n", pre->handCount[currentPlayer]+1, post.handCount[currentPlayer]);
				#endif
				funErrors++;
			}
		}
		else if(deckPreTreasure !=0){//else something went wrong
			#if(NOISY_TEST == 1)
			printf("Test #: %d failed\n", n);
			printf("Expected: Post treasure = %d	Actual: Post treasure = %d\n", treasure+2, postTreasure);
			#endif
			funErrors++;
		}
	}
	return funErrors;
}