Beispiel #1
0
int checkCutpurseCard(int p, struct gameState *post) {
  
  struct gameState pre;
  post->whoseTurn = p;
  memcpy (&pre, post, sizeof(struct gameState));

  int i, j, r;
  
  int handPos = rand() % pre.handCount[p];
  r = cutpurseCard(post, handPos);

  updateCoins(p, &pre, 2);
   printf("After gaining 2 coins, tester coinCount: %d\n", pre.coins);
   printf("After gaining 2 coins, testee coinCount: %d\n", post->coins);
  for (i = 0; i < pre.numPlayers; i++)
     {
       if (i != p)
       {
         for (j = 0; j < pre.handCount[i]; j++)
          {
            if (pre.hand[i][j] == copper)
            {
              discardCard(j, i, &pre, 0);
              break;
            }
            if (j == pre.handCount[i])
            {
              int revealedCard = rand () % pre.handCount[i];
              printf("Player %d reveals card number %d\n", i, pre.hand[i][revealedCard]);          
              break;
            }   
          }          
        }        
       }        
    
  assert (r == 0);
  discardCard(handPos, p, &pre, 0);
  if (memcmp(&pre, post, sizeof(struct gameState)) == 0) {
    printf("cutpurseCard() function unit test passed for player %d!\n", p);
  } else {
    printf("cutpurseCard() function unit test failed for player %d\n", p);
  }
  return 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;
}