Exemplo n.º 1
0
void testPlayAdventurer()
{
	int seed = 100;
	int k[10] = {adventurer, council_room, feast, gardens, mine,
                remodel, smithy, village, baron, great_hall};
	struct gameState state;
	int r;
	int i;
	int numPlayer = 2;
	int player;
	
	/*Tests two cards in the players hand*/
	memset(&state, 0, sizeof(struct gameState));  
    initializeGame(numPlayer, k, seed, &state);
	player = 1;	
	state.handCount[player] = 3;
	r = playAdventurer(player, &state);
	if(state.handCount[player] == 5)
		printf("playAdventurer: PASS two cards added to player hand.\n");
	else
		printf("playAdventurer: FAIL two cards added to player hand.\n");
	if(r == 0)
		printf("playAdventurer: PASS exit code 0.\n");
	else
		printf("playAdventurer: FAIL exit code 0.\n");
	
	/*Check if treasure is added to hand*/
	memset(&state, 0, sizeof(struct gameState));   
    initializeGame(numPlayer, k, seed, &state);
	int treasureAdded = 0;
	player = 1;	
	state.handCount[player] = 3;  
	for(i = 0; i < 3; i++)
	{
		state.hand[player][i] = 1;
	}
	r = playAdventurer(player, &state);
	for(i = 0; i < 3; i++)
	{
		if(state.hand[player][i] == copper || state.hand[player][i] == silver || state.hand[player][i] == gold)
		{
			treasureAdded++;
		}
	}
	if(treasureAdded == 2)
		printf("playAdventurer: PASS draw two treasure cards.\n");
	else
		printf("playAdventurer: FAIL draw two treasure cards.\n");
}
Exemplo n.º 2
0
int checkRandomAdventurer(int p, struct gameState *postTest)
{
  int fail = 0;
  int emptyHand[MAX_HAND];
  struct gameState preTest;
  
  //clear out preTest and copy over postTest
  memset(&preTest, 23, sizeof(struct gameState)); 
  memcpy(&preTest, postTest, sizeof(struct gameState));
  
  playAdventurer(emptyHand, postTest, p);

  //ensure correct number of cards are added
  if (postTest->handCount[p] != preTest.handCount[p] + 2)
  {
    printFailure(p, preTest.handCount[p], __LINE__);
    fail++;
  }
  
  //ensure cards added are treasure cards
  if (postTest->hand[p][postTest->handCount[p] - 2] != copper )
  {
    if (postTest->hand[p][postTest->handCount[p] - 2] != silver )
    {
      if (postTest->hand[p][postTest->handCount[p] - 2] != gold )
      {
        printFailure(p, preTest.handCount[p], __LINE__);
        fail++;
      }
    }
  }

  //ensure cards added are treasure cards
  if (postTest->hand[p][postTest->handCount[p] - 1] != copper )
  {
    if (postTest->hand[p][postTest->handCount[p] - 1] != silver )
    {
      if (postTest->hand[p][postTest->handCount[p] - 1] != gold )
      {
        printFailure(p, preTest.handCount[p], __LINE__);
        fail++;
      }
    }
  }

  return fail;
}
Exemplo n.º 3
0
int main(void) {
	int k[10] = {adventurer, ambassador, village, remodel, baron, mine, 
		gardens, feast, minion, steward};
	struct gameState G;
	int count = 0;
	int i = 0;
	int temphand[MAX_HAND];

	printf("Beginning unit testing of Adventurer...\n\n");

	//Initialize game for testing
	initializeGame(2, k, 1111, &G);

	for(i = 0; i < G.handCount[0]; i++) {
		if(G.hand[0][i] == copper || G.hand[0][i] == silver || G.hand[0][i] == gold) {
			count++;
		}
	}
	printf("Printing initial state of player 0...\n");
	printf("Hand count player 0: %d\n", G.handCount[0]);
	printf("Treasure count player 0: %d\n\n", count);
	count = 0; //reset count

	//Case: base case, does it work
	//BUG - treasurecount is 1 too large after playing adventurer - BUG
	printf("Testing case: base case.\n");
	playAdventurer(0, 0, &G, 0, temphand);

	for(i = 0; i < G.handCount[0]; i++) {
		if(G.hand[0][i] == copper || G.hand[0][i] == silver || G.hand[0][i] == gold) {
			count++;
		}
	}
	check(count == 6);
	printf("\nPrinting final state of player 0...\n");
	printf("Hand count player 0: %d\n", G.handCount[0]);
	printf("Treasure count player 0: %d\n", count);

	return 0;
}
Exemplo n.º 4
0
int main() {
    int player;
    int i, initialHand, finalHand, initialDeck, finalDeck;
    struct gameState Game;

    int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse,
                 sea_hag, tribute, smithy};

    //testing adventurer card
    printf("Testing adventurer card\n");

    srand(time(NULL));

    int seed = rand() % 10;

    initializeGame(2, k, seed, &Game);

    player = Game.whoseTurn;
    initialDeck = Game.deckCount[player];
    initialHand = Game.handCount[player];

    playAdventurer(&Game);

    finalDeck = Game.deckCount[player];
    finalHand = Game.handCount[player];

    if (initialDeck - finalDeck != 2) {
        printf("Two cards were not drawn from the deck\n");
    }

    if (finalHand - initialHand != 1) {
        printf("Two cards were not added to the players hand!\n");
    }

    return 0;

}
Exemplo n.º 5
0
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
{
  int i;
  int j;
  int k;
  int x;
  int index;
  int currentPlayer = whoseTurn(state);
  int nextPlayer = currentPlayer + 1;

  int tributeRevealedCards[2] = {-1, -1};
  int temphand[MAX_HAND];// moved above the if statement
  int drawntreasure=0;
  int cardDrawn;
  int z = 0;// this is the counter for the temp hand
  if (nextPlayer > (state->numPlayers - 1)){
    nextPlayer = 0;
  }
  
	
  //uses switch to select card and perform actions
  switch( card ) 
    {
    case adventurer:
      return playAdventurer(state);
			
    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:
      //+3 Cards
      return playSmithy(state, handPos);
	
	case village:
			return playVillage(state, handPos);
			
    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:
      return playSteward(state, choice1, choice2, choice3, handPos);
		
    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:
      return playSalvager(state, handPos, choice1);
		
    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;
}
Exemplo n.º 6
0
int main() {
    int i;
    int seed = 1000;

    int numPlayer = 2;
    int p, r;
    int k[10] = {adventurer, great_hall, cutpurse, gardens, mine
               , remodel, smithy, village, sea_hag, embargo};

    struct gameState G, testG;
    int count;

    // Default
    int estateDefault = 8;
    // Check pile counts
    int copperCount = 0;
    int estateCount = 0;
    bool pass = true;

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

    printf("----------------- Testing adventurer\n");

    // Copy the game state to a test case
    memcpy(&testG, &G, sizeof(struct gameState));

    // Player 1
    p = 0;
    printf("----------------- Player %d:\n", p);

    printf("----------------- Test 1: coppers at top of deck\n");
    printf("----------------- Initial counts\n");

    // 1, 1, 4, 4, 4
    printf("DECK COUNT\n");
    for (i = 0; i < testG.deckCount[p]; i++) {
        printf("%d\n", testG.deck[p][i]);
    }

    // Empty
    printf("DISCARD COUNT\n");
    for (i = 0; i < testG.discardCount[p]; i++) {
        printf("%d\n", testG.discard[p][i]);
    }

    // 4, 4, 1, 4, 4
    printf("HAND COUNT\n");
    for (i = 0; i < testG.handCount[p]; i++) {
        printf("%d\n", testG.hand[p][i]);
    }

    printf("----------------- After playAdventurer\n");

    // int playAdventurer (struct gameState *state, int currentPlayer, int drawntreasure, int cardDrawn, int temphand[], int z);
    playAdventurer(&testG);

    // 1, 1, 4,
    printf("DECK COUNT\n");
    for (i = 0; i < testG.deckCount[p]; i++) {
        printf("%d\n", testG.deck[p][i]);
    }

    // Should have taken 2 coppers from top
    int expected1[] = {1, 1, 4};
    count = sizeof(expected1)/sizeof(expected1[0]);

    // Check that count of cards is correct
    printf("Card count: %d, Expected: %d\n", testG.deckCount[p], count);
    assert(testG.deckCount[p] == count);

    // Check that names of cards are correct
    printf("Expected:\n");
    for (i = 0; i < count; i++) {
        printf("%d\n", expected1[i]);
        assert(testG.deck[p][i] == expected1[i]);
    }

    // Empty
    printf("DISCARD COUNT\n");
    for (i = 0; i < testG.discardCount[p]; i++) {
        printf("%d\n", testG.discard[p][i]);
    }

    // No non-treasure cards revealed so no discards
    int expected2[] = {};
    count = sizeof(expected2)/sizeof(expected2[0]);

    // Check that count of cards is correct
    printf("Card count: %d, Expected: %d\n", testG.discardCount[p], count);
    assert(testG.discardCount[p] == count);

    // 4, 4, 1, 4, 4, 4, 4
    printf("HAND COUNT\n");
    for (i = 0; i < testG.handCount[p]; i++) {
        printf("%d\n", testG.hand[p][i]);
    }

    // 2 coppers added to hand
    int expected3[] = {4, 4, 1, 4, 4, 4, 4};
    count = sizeof(expected3)/sizeof(expected3[0]);

    // Check that count of cards is correct
    printf("Card count: %d, Expected: %d\n", testG.handCount[p], count);
    assert(testG.handCount[p] == count);

    // Check that names of cards are correct
    printf("Expected:\n");
    for (i = 0; i < count; i++) {
        printf("%d\n", expected3[i]);
        assert(testG.hand[p][i] == expected3[i]);
    }

    printf("----------------- Test 2: coppers at bottom of deck\n");
    printf("----------------- Initial counts\n");

    // Copy the game state to a test case
    memcpy(&testG, &G, sizeof(struct gameState));

    // 4, 4, 4, 1, 1
    for (i = 0; i < 3; i++) {
        testG.deck[p][i] = copper;
    }

    for (i = 3; i < 5; i++) {
        testG.deck[p][i] = estate;
    }

    printf("DECK COUNT\n");
    for (i = 0; i < testG.deckCount[p]; i++) {
        printf("%d\n", testG.deck[p][i]);
    }

    // Empty
    printf("DISCARD COUNT\n");
    for (i = 0; i < testG.discardCount[p]; i++) {
        printf("%d\n", testG.discard[p][i]);
    }

    // 4, 4, 1, 4, 4
    printf("HAND COUNT\n");
    for (i = 0; i < testG.handCount[p]; i++) {
        printf("%d\n", testG.hand[p][i]);
    }

    printf("----------------- After playAdventurer\n");

    playAdventurer(&testG);

    // 4
    printf("DECK COUNT\n");
    for (i = 0; i < testG.deckCount[p]; i++) {
        printf("%d\n", testG.deck[p][i]);
    }

    // Should have discarded 2 estates and taken 2 coppers
    int expected4[] = {4};
    count = sizeof(expected4)/sizeof(expected4[0]);

    // Check that count of cards is correct
    printf("Card count: %d, Expected: %d\n", testG.deckCount[p], count);
    assert(testG.deckCount[p] == count);

    // Check that names of cards are correct
    printf("Expected:\n");
    for (i = 0; i < count; i++) {
        printf("%d\n", expected4[i]);
        assert(testG.deck[p][i] == expected4[i]);
    }

    // 1, 1
    printf("DISCARD COUNT\n");
    for (i = 0; i < testG.discardCount[p]; i++) {
        printf("%d\n", testG.discard[p][i]);
    }

    // Should have discarded 2 estates
    int expected5[] = {1, 1};
    count = sizeof(expected5)/sizeof(expected5[0]);

    // Check that count of cards is correct
    printf("Card count: %d, Expected: %d\n", testG.discardCount[p], count);
    if (testG.discardCount[p] != count) {
        printf("----------------- TEST FAILED!\n");
        pass = false;
    }

    // Check that names of cards are correct
    printf("Expected:\n");
    for (i = 0; i < count; i++) {
        printf("%d\n", expected5[i]);
        if (testG.discard[p][i] != expected5[i]) {
            printf("----------------- TEST FAILED!\n");
            pass = false;
        }
    }

    // 4, 4, 1, 4, 4, 4, 4
    printf("HAND COUNT\n");
    for (i = 0; i < testG.handCount[p]; i++) {
        printf("%d\n", testG.hand[p][i]);
    }

    // 2 coppers added to hand
    int expected6[] = {4, 4, 1, 4, 4, 4, 4};
    count = sizeof(expected6)/sizeof(expected6[0]);

    // Check that count of cards is correct
    printf("Card count: %d, Expected: %d\n", testG.handCount[p], count);
    assert(testG.handCount[p] == count);

    // Check that names of cards are correct
    printf("Expected:\n");
    for (i = 0; i < count; i++) {
        printf("%d\n", expected6[i]);
        assert(testG.hand[p][i] == expected6[i]);
    }

    printf("----------------- Test 3: coppers interspersed through deck\n");
    printf("----------------- Initial counts\n");

    memcpy(&testG, &G, sizeof(struct gameState));

    // 4, 1, 4, 1, 4
    for (i = 0; i < 5; i = i + 2) {
        testG.deck[p][i] = copper;
    }

    for (i = 1; i < 5; i = i + 2) {
        testG.deck[p][i] = estate;
    }

    printf("DECK COUNT\n");
    for (i = 0; i < testG.deckCount[p]; i++) {
        printf("%d\n", testG.deck[p][i]);
    }

    // Empty
    printf("DISCARD COUNT\n");
    for (i = 0; i < testG.discardCount[p]; i++) {
        printf("%d\n", testG.discard[p][i]);
    }

    // 4, 4, 1, 4, 4
    printf("HAND COUNT\n");
    for (i = 0; i < testG.handCount[p]; i++) {
        printf("%d\n", testG.hand[p][i]);
    }

    printf("----------------- After playAdventurer\n");

    playAdventurer(&testG);

    // 4, 1
    printf("DECK COUNT\n");
    for (i = 0; i < testG.deckCount[p]; i++) {
        printf("%d\n", testG.deck[p][i]);
    }

    // Should have discarded 1 estate and taken 2 coppers
    int expected7[] = {4, 1};
    count = sizeof(expected7)/sizeof(expected7[0]);

    // Check that count of cards is correct
    printf("Card count: %d, Expected: %d\n", testG.deckCount[p], count);
    assert(testG.deckCount[p] == count);

    // Check that names of cards are correct
    printf("Expected:\n");
    for (i = 0; i < count; i++) {
        printf("%d\n", expected7[i]);
        assert(testG.deck[p][i] == expected7[i]);
    }

    // 1
    printf("DISCARD COUNT\n");
    for (i = 0; i < testG.discardCount[p]; i++) {
        printf("%d\n", testG.discard[p][i]);
    }

    // Should have discarded 1 estate
    int expected8[] = {1};
    count = sizeof(expected8)/sizeof(expected8[0]);

    // Check that count of cards is correct
    printf("Card count: %d, Expected: %d\n", testG.discardCount[p], count);
    if (testG.discardCount[p] != count) {
        printf("----------------- TEST FAILED!\n");
        pass = false;
    }

    // Check that names of cards are correct
    printf("Expected:\n");
    for (i = 0; i < count; i++) {
        printf("%d\n", expected8[i]);
        if (testG.discard[p][i] != expected8[i]) {
            printf("----------------- TEST FAILED!\n");
            pass = false;
        }
    }

    // 4, 4, 1, 4, 4, 4, 4
    printf("HAND COUNT\n");
    for (i = 0; i < testG.handCount[p]; i++) {
        printf("%d\n", testG.hand[p][i]);
    }

    // 2 coppers added to hand
    int expected9[] = {4, 4, 1, 4, 4, 4, 4};
    count = sizeof(expected9)/sizeof(expected9[0]);

    // Check that count of cards is correct
    printf("Card count: %d, Expected: %d\n", testG.handCount[p], count);
    assert(testG.handCount[p] == count);

    // Check that names of cards are correct
    printf("Expected:\n");
    for (i = 0; i < count; i++) {
        printf("%d\n", expected9[i]);
        assert(testG.hand[p][i] == expected9[i]);
    }

    // Should be NO state changes made to next player's decks
    p = 1;
    printf("----------------- Player %d:\n", p);
    printf("----------------- Test 4: Check that no state changes were made to other player's deck\n");

    printf("DECK COUNT\n");
    for (i = 0; i < G.deckCount[p]; i++)
    {
        printf("Position %d, Card: %d\n", i, G.deck[p][i]);
        if (G.deck[p][i] == copper) {
            copperCount++;
        }
        if (G.deck[p][i] == estate) {
            estateCount++;
        }
    }

    // Verify
    printf("Copper count: %d, Expected: 7\n", copperCount);
    printf("Estate count: %d, Expected: 3\n", estateCount);
    assert(copperCount == 7);
    assert(estateCount == 3);

    printf("Deck count: %d, Expected: 10\n", G.deckCount[p]);
    assert(G.deckCount[p] == 10);

    printf("DISCARD COUNT\n");
    for (i = 0; i < G.discardCount[p]; i++)
    {
        printf("Position %d, Card: %d\n", i, G.discard[p][i]);
    }

    // Verify
    printf("Discard count: %d, Expected: 0\n", G.discardCount[p]);
    assert(G.discardCount[p] == 0);

    printf("HAND COUNT\n");
    for (i = 0; i < G.handCount[p]; i++)
    {
        printf("Position %d, Card: %d\n", i, G.hand[p][i]);
    }

    // Verify
    printf("Hand count: %d, Expected: 0\n", G.handCount[p]);
    assert(G.handCount[p] == 0);

    printf("----------------- Test 5: Check that no state changes were made to estate pile\n");
    printf("Estate count: %d, Expected: %d\n", G.supplyCount[estate], estateDefault);
    assert(G.supplyCount[estate] == estateDefault);

    if (pass) {
        printf("\nAll tests passed!\n");
    }
    else {
        printf("\nSome test(s) failed!\n");
    }
    
    return 0;
}
Exemplo n.º 7
0
int main() {
	struct gameState G;
    int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse,
           sea_hag, tribute, smithy};
    int i;
	int j;
	int flag;

    printf("\n");
    initializeGame(2, k, 4, &G);
	printf("Beginning -- 3 Cards Drawn -- Test for playAdventurer \n");
	for (i = 0; i < MAX_PLAYERS; i++){
        flag = 0;
        G.whoseTurn = i;
        G.handCount[i] = 1; //adventurer card is only card in hand
        printf("Beginning Test for player %d \n", i + 1);
        playAdventurer(0,i,&G);
        if (G.handCount[i] != 3){
            printf("Test Failed for player %d Adventurer drew %d card(s)! \n", i + 1, G.handCount[i]);
            flag = 1;
        }
        if (flag == 0){
            printf("Test Passed for player %d \n", i + 1);
        }
	}
	initializeGame(2, k, 4, &G);
	printf("\n\n");
	printf("Beginning -- Drawn Cards are Treasure Cards -- Test for playAdventurer \n");
	for (i = 0; i < MAX_PLAYERS; i++){
        flag = 0;
        G.whoseTurn = i;
        G.handCount[i] = 1;
        printf("Beginning Test for player %d \n", i + 1);
        playAdventurer(0,i,&G);
        for (j=0; j<G.handCount[i];j++){
            if (G.hand[i][j] != copper && G.hand[i][j] != silver && G.hand[i][j] != gold){
            printf("Test Failed for player %d \n", i + 1);
            printf("Card %d is: %d \n",j, G.hand[i][j]);
            flag = 1;
            }
        }

        if (flag == 0){
            printf("Test Passed for player %d \n", i + 1);
        }
	}
    initializeGame(2, k, 4, &G);
	printf("\n\n");
	printf("Beginning --Card Played--- test for playAdventurer \n");
	for (i = 0; i < MAX_PLAYERS; i++){
        flag = 0;
        G.whoseTurn = i;
        G.playedCardCount = 0;
        printf("Beginning Test for player %d \n", i + 1);
        for(j=0; j<=MAX_HAND; j++) {
            G.deckCount[i] = MAX_DECK; //deck is full
            G.handCount[i] = 1; //adventurer card is only card in hand
            playAdventurer(j,i,&G);
            if (G.playedCards[0] != adventurer){
                printf("Test Failed for player %d Adventurer is not in the played card pile! \n", i + 1);
                flag = 1;
                break;
            }
        }
        if (flag == 0){
            printf("Test Passed for player %d \n", i + 1);
        }
	}
	return 0;
}
Exemplo n.º 8
0
int main()
{
	srand(time(NULL));

	int i, j, a;

	struct gameState state;
	struct gameState testState;

	int k[10] = { adventurer, salvager, smithy, village, minion, mine, gardens, council_room, great_hall, sea_hag };

	int newCards = 0, discarded = 1, numTests = 1000;
	int handPos = 0, shuffledCards = 0, z = 0, temphand[MAX_HAND];
	int thisPlayer = 0, numPlayers = 2, seed = 29365;
	int drawnTreasure;
	int totalSuccesses, totalFailures;
	int successBool;

	const char* cardNames[] = {"curse", "estate", "duchy", "province", "copper", "silver", "gold", "adventurer",
							    "council_room", "feast", "gardens", "mine", "remodel", "smithy", "village", "baron", "great_hall", "minion",
								"steward", "tribute", "ambassador", "cutpurse", "embargo", "outpost", "salvager", "sea_hag", "treasure_map"};


	initializeGame(numPlayers, k, seed, &state);

	// Make sure we are at least close to the base game:

	assert(state.supplyCount[estate] == 8);
	assert(state.supplyCount[duchy] == 8);
	assert(state.supplyCount[province] == 8);

	assert(state.supplyCount[copper] == 46);
	assert(state.supplyCount[silver] == 40);
	assert(state.supplyCount[gold] == 30);


	printf("\nGENERATING CARD TESTS FOR %s\n", TESTCARD);

	totalSuccesses = totalFailures = 0;

	for(i = 0; i < numTests; i++)
	{
		drawnTreasure = 0;

		for(j=0; j < temphand[MAX_HAND]; j++)
		{
			temphand[j] = random() % 27;
			if(temphand[j] == 4 || temphand[j] == 5 || temphand[j] == 6)
				drawnTreasure++;
		}

		for(j=0; j < temphand[MAX_HAND]; j++)
		{
			state.hand[thisPlayer][j] = temphand[j];
		}

		successBool = 1;
		printf("\nITERATION %d\n", i + 1);
		printf("Drawn Treasure: %d\n", drawnTreasure);

		// Starting Hands...
//		state.hand[thisPlayer][0] = adventurer;
//		state.hand[thisPlayer][1] = smithy;
//		state.hand[thisPlayer][2] = silver;
//		state.hand[thisPlayer][3] = ambassador;
//		state.hand[thisPlayer][4] = mine;

		memcpy(&testState, &state, sizeof(struct gameState));


		if(testState.supplyCount[estate] != 8 || testState.supplyCount[duchy] != 8 || testState.supplyCount[province] != 8)
		{
			printf("\nFailed Test, victory cards are incorrect.\n");
			successBool = 0;
		}

		if((testState.supplyCount[copper] + testState.supplyCount[silver] + testState.supplyCount[gold]) != 116)
		{
			printf("\nTest failed, total coins is NOT 116\n");
			successBool = 0;
		}

		if(testState.supplyCount[copper] != 46 || testState.supplyCount[silver] != 40 || testState.supplyCount[gold] != 30)
		{
			printf("\nTest failed, treasure card totals are incorrect. \n");
			successBool = 0;
		}

		newCards = 0;
		discarded = 0;

		if(testState.deckCount[thisPlayer] != state.deckCount[thisPlayer] - newCards + shuffledCards)
		{
			printf("\nTest failed, card changes are incorrect. Player 1 Deck count is incorrect.\n");
			successBool = 0;
		}

		if(testState.deckCount[thisPlayer + 1] != state.deckCount[thisPlayer + 1] - newCards + shuffledCards)
		{
			printf("\nTest failed, card changes are incorrect. Player 2 Deck Count is incorrect\n");
			successBool = 0;
		}

		playAdventurer(&testState, thisPlayer, 0, drawnTreasure, temphand, z);

		printf("\nCards in hand for player 1 are: ");
		for(j=0; j<testState.handCount[thisPlayer]; j++)
		{
			printf("Card: %s\n", cardNames[testState.hand[thisPlayer][j]]);

		}

		printf("\nCards in the deck for player 1: ");
		for(j=0; j<testState.deckCount[thisPlayer]; j++)
		{
			printf("Card in Deck: %s\n", cardNames[testState.deck[thisPlayer][j]]);
		}


	//	playAdventurer(&testState, thisPlayer, 0, drawnTreasure, temphand, z);

		printf("\nEnd Turn Cards for Player 1: ");

		for(j=0; j<testState.handCount[thisPlayer]; j++)
		{
			printf("Card: %s\n", cardNames[testState.hand[thisPlayer][j]]);
		}

		printf("\nEnd Turn Deck Cards for Player 1: ");

		for(j=0; j<testState.deckCount[thisPlayer]; j++)
		{
			printf("Cards in Deck: %s\n", cardNames[testState.hand[thisPlayer][j]]);
		}

		newCards = testState.handCount[thisPlayer] - state.handCount[thisPlayer];

		if(testState.handCount[thisPlayer] != state.handCount[thisPlayer] + newCards)
		{
			printf("\nTest failed, player 1 cards are incorrect. \n");
			successBool = 0;
		}

		// 46 + 40 + 30 = 116

		if((testState.supplyCount[copper] + testState.supplyCount[silver] + testState.supplyCount[gold]) != 116)
		{
			printf("\nTest failed, total coins is NOT 116\n");
			successBool = 0;
		}

/*		if(testState.supplyCount[estate] != 8 || testState.supplyCount[duchy] != 8 || testState.supplyCount[province] != 8)
		{
			printf("\nFailed Test, victory cards are incorrect.\n");
			successBool = 0;
		}*/

/*		if(testState.supplyCount[copper] != 46 || testState.supplyCount[silver] != 40 || testState.supplyCount[silver] != 30)
		{
			printf("\nTest failed, treasure card totals are incorrect. \n");
			successBool = 0;
		}*/

		newCards = testState.handCount[thisPlayer] - state.handCount[thisPlayer];;
		discarded = testState.discardCount[thisPlayer] - state.discardCount[thisPlayer];;

		printf("New Cards: %d\n", newCards);
		printf("Discarded: %d\n", discarded);

		if(testState.handCount[thisPlayer] != state.handCount[thisPlayer] + newCards - discarded)
		{
			printf("\nFailed test, Player 1 hand count is incorrect.\n");
			successBool = 0;
		}

		a = 0;

		for(j = 0; j < testState.discardCount[thisPlayer]; j++)
		{
			if(testState.discard[thisPlayer][j] == copper || testState.discard[thisPlayer][j] == silver || testState.discard[thisPlayer][j] == gold)
			{
				a++;
			}
		}

		if(a > 0)
		{
			printf("\nTest failed, the discard piles have treasure cards in them. %d total treasure discarded:", a);
			successBool = 0;
		}


		newCards = 0;
		discarded = 0;

		if(testState.deckCount[thisPlayer + 1] != state.deckCount[thisPlayer + 1] - newCards + shuffledCards)
		{
			printf("\nTest failed, player 2 deck is incorrect.");
			successBool = 0;
		}

		if(successBool == 1)
		{
			totalSuccesses++;
		}
		else
		{
			totalFailures++;
		}

	}

	//printf("Testing seed: %d", seed); // 29365 for debugging purposes. Had to find one that had consistent test failures.
	printf("Testing complete for %s.\n", TESTCARD);
	printf("Total Tests: %d\n", numTests);
	printf("Total Successful: %d\n", totalSuccesses);
	printf("Total Unsuccessful: %d\n", totalFailures);

	return 0;
}
Exemplo n.º 9
0
int cardtest2() {
	int num_players = 2;
	int random_seed = 1000;
	struct gameState state;
  struct gameState pre;
  struct gameState tmp;
	int max_hand = 5;
	int k[10] = {adventurer, great_hall, embargo, village, minion, mine, cutpurse,
         sea_hag, tribute, smithy};

  int g = initializeGame(num_players, k, random_seed, &state);
  memcpy(&pre, &state, sizeof(struct gameState));
  memcpy(&tmp, &state, sizeof(struct gameState));

  printf("---------------- Testing %s Card ----------------\n", TEST_CARD);

  int player = 0;
  int drawntreasure = 0;
  int temphand[MAX_HAND];
  int cardDrawn;
  int i;
  int j;
  int ret;

  int state_total;
  int pre_total;
  int failed = 0;

  // For each player
  for (player = 0; player < num_players; player++)
  {
    // We must do brute force iteration and add more cards to the player's deck
    // in order to achieve a more thorough test.
  	for (i = 0; i < 10; i++)
  	{ 
  		playAdventurer(player, &state, drawntreasure, temphand, cardDrawn); 
  		assert(state.handCount[player] == pre.handCount[player] + 2);

  		state_total = state.deckCount[player];
  		state_total += state.handCount[player];
  		state_total += state.discardCount[player];
  		
  		pre_total = pre.deckCount[player];
  		pre_total += pre.handCount[player];
  		pre_total += pre.discardCount[player];

  		// This is where I introduced a bug into this program.
  		// We must count all of the cards in the deck, hand, and discard
  		// pile in order to find it.
      // I purposefully do not use the assert statement so that I can check
      // further game conditions and print the errors that are occurring.
  		if (state_total < pre_total)
  		{
  			printf("Player has %d cards in total, expected %d\n", state_total, pre_total);
  			failed = 1;
  		}
      // This assert function is where this card function fails.
  		// assert(state_total == pre_total);

  		// Try to buy gold and then try to buy silver in order to diversify the
      // test deck for the cards drawn by the adventurer.
  		ret = gainCard(7, &tmp, 1, player);
  		ret = gainCard(6, &tmp, 1, player);
  		memcpy(&state, &tmp, sizeof(struct gameState));
  		memcpy(&pre, &tmp, sizeof(struct gameState)); 

  	}
  }

  if (failed == 0) 
  {
  	printf("\nCARD TEST 2 PASSED.\n\n");
  } else
  {
  	printf("\nCARD TEST 2 FAILED.\n\n");
  }

  return 0;

}
Exemplo n.º 10
0
int main()
{
  int totalFail = 0;
  int totalPass = 0;
  int seed = -1;

  struct gameState G;
  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
           sea_hag, tribute, smithy};

  int priorHand, postHand;
  int priorCard, postCard1, postCard2;
  int priorDiscard, postDiscard;
  int priorDeck;
  int i;

  initializeGame(2, k, seed, &G);

  //Begin testing--------------------------------------------------------------
  printf("------------------------------------------------------------\n");
  printf("--------------BEGIN TESTING FOR ADVENTURER CARD-------------\n");
  printf("------------------------------------------------------------\n");

  //test play of adventure card with adventure card as last card and full deck
  //there will be no shuffle here
  //tests if last 2 cards are now treasure cards
  //tests if cards were added to discard pile
  //tests if post play hand count is correct
  //tests if adventure card was discarded after play
  addAdventurer(&G, G.handCount[0]);
  priorHand = G.handCount[0];
  priorDiscard = G.discardCount[0];
  priorCard = G.handCount[0] - 1;
  playAdventurer(&G, 0);
  postCard1 = G.hand[0][G.handCount[0] - 1];    //last card in hand
  postCard2 = G.hand[0][G.handCount[0] - 2];    //2nd to last card
  postDiscard = G.discardCount[0];
  postHand = G.handCount[0];

  if ( postCard1 == copper || postCard1 == silver || postCard1 == gold ) {
    printf("Adventurer: PASS -> Test adventurer last card in hand: last card is now a treasure card.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer last card in hand: last card is not a treasure card.\n\n");
    totalFail++;
  }  

  if ( postCard2 == copper || postCard2 == silver || postCard2 == gold ) {
    printf("Adventurer: PASS -> Test adventurer last card in hand: 2nd to last card is now a treasure card.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer last card in hand: 2nd to last card is not a treasure card.\n\n");
    totalFail++;
  }  

  if ( postDiscard > priorDiscard ) {
    printf("Adventurer: PASS -> Test adventurer last card in hand: cards were discarded.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer last card in hand: no cards were discarded.\n\n");
    totalFail++;
  }    

  if ( postHand == (priorHand + 1) ) {
    printf("Adventurer: PASS -> Test adventurer last card in hand: hand count went up 1.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer last card in hand: hand count did not increase correctly.\n\n");
    totalFail++;
  }    

  if ( G.hand[0][priorCard] != adventurer ) {
    printf("Adventurer: PASS -> Test adventurer last card in hand: adventurer was discarded from hand.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer last card in hand: adventurer was not discarded from hand.\n\n");
    totalFail++;
  }    

  //test play of adventure card with adventure card as only card in hand
  //there will be no shuffle here
  //tests if last 2 cards are now treasure cards
  //tests if cards were added to discard pile
  //tests if post play hand count is correct
  //tests if adventure card was discarded after play
  initializeGame(2, k, seed, &G);
  addAdventurer(&G, G.handCount[0]);
  G.handCount[0] = 1;
  priorDiscard = G.discardCount[0];
  playAdventurer(&G, 0);
  postCard1 = G.hand[0][G.handCount[0] - 1];    //last card in hand
  postCard2 = G.hand[0][G.handCount[0] - 2];    //2nd to last card
  postDiscard = G.discardCount[0];
  postHand = G.handCount[0];
  
  if ( postCard1 == copper || postCard1 == silver || postCard1 == gold ) {
    printf("Adventurer: PASS -> Test adventurer only card in hand: last card is now a treasure card.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer only card in hand: last card is not a treasure card.\n\n");
    totalFail++;
  }  

  if ( postCard2 == copper || postCard2 == silver || postCard2 == gold ) {
    printf("Adventurer: PASS -> Test adventurer only card in hand: 2nd to last card is now a treasure card.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer only card in hand: 2nd to last card is not a treasure card.\n\n");
    totalFail++;
  }  

  if ( postDiscard > priorDiscard ) {
    printf("Adventurer: PASS -> Test adventurer only card in hand: cards were discarded.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer only card in hand: no cards were discarded.\n\n");
    totalFail++;
  }    

  if ( postHand == (priorHand + 1) ) {
    printf("Adventurer: PASS -> Test adventurer only card in hand: hand count went up 1.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer only card in hand: hand count did not increase correctly.\n\n");
    totalFail++;
  }    

  if ( G.hand[0][0] != adventurer ) {
    printf("Adventurer: PASS -> Test adventurer only card in hand: adventurer was discarded from hand.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer only card in hand: adventurer was not discarded from hand.\n\n");
    totalFail++;
  }    

  //test when deck is empty
  //shuffle has to happen here
  initializeGame(2, k, seed, &G);
  //add deck to discard pile
  priorDeck = G.deckCount[0];
  for (i = 0; i < priorDeck; i++) {
    G.discard[0][G.discardCount[0]] = G.deck[0][i];
    G.deckCount[0]--;
    G.discardCount[0]++;
  }
  addAdventurer(&G, G.handCount[0]);
  //deck is now 0 and addventurer is in hand
  priorHand = G.handCount[0];
  priorDiscard = G.discardCount[0];
  priorCard = G.handCount[0] - 1;
  playAdventurer(&G, 0);
  postCard1 = G.hand[0][G.handCount[0] - 1];    //last card in hand
  postCard2 = G.hand[0][G.handCount[0] - 2];    //2nd to last card
  postDiscard = G.discardCount[0];
  postHand = G.handCount[0];
  
  if ( postCard1 == copper || postCard1 == silver || postCard1 == gold ) {
    printf("Adventurer: PASS -> Test adventurer deck empty: last card is now a treasure card.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer deck empty: last card is not a treasure card.\n\n");
    totalFail++;
  }  

  if ( postCard2 == copper || postCard2 == silver || postCard2 == gold ) {
    printf("Adventurer: PASS -> Test adventurer deck empty: 2nd to last card is now a treasure card.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer deck empty: 2nd to last card is not a treasure card.\n\n");
    totalFail++;
  }  

  if ( postDiscard > priorDiscard ) {
    printf("Adventurer: PASS -> Test adventurer deck empty: cards were discarded.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer deck empty: no cards were discarded.\n\n");
    totalFail++;
  }    

  if ( postHand == (priorHand + 1) ) {
    printf("Adventurer: PASS -> Test adventurer deck empty: hand count went up 1.\n\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer deck empty: hand count did not increase correctly.\n\n");
    totalFail++;
  }    

  if ( G.hand[0][priorCard] != adventurer ) {
    printf("Adventurer: PASS -> Test adventurer deck empty: adventurer was discarded from hand.\n");
    totalPass++;
  }
  else {
    printf("Adventurer: FAIL -> Test adventurer deck empty: adventurer was not discarded from hand.\n");
    totalFail++;
  }    

  printf("------------------------------------------------------------\n");
  printf("-------------RESULTS of Adventurer card testing-------------\n");
  printf("Tests Passed: %d\tTests Failed: %d\n", totalPass, totalFail);
  printf("------------------------------------------------------------\n");

  return 0;
}
Exemplo n.º 11
0
int main() {
    int i, j;
    int seed = 1000;

    int numPlayer = 2;
    int p, r;
    int k[10] = {adventurer, great_hall, cutpurse, gardens, mine
               , remodel, smithy, village, sea_hag, embargo};

    int cards[10] = {copper, smithy, village, silver, mine, gold,
                gardens, remodel, embargo, cutpurse};

    struct gameState G, testG;
    int index, count;
    int treasureCount;
    int treasureDrawn, otherRevealed;
    int preDeck, preDiscard, preHand;
    bool pass = true;

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

    printf("----------------- Testing adventurer\n");

    // Number of runs
    for (j = 1; j < 1001; j++) {
        // Copy the game state to a test case
        memcpy(&testG, &G, sizeof(struct gameState));

        // Player 0
        p = 0;
        printf("----------------- Random Deck Test %d\n", j);
        printf("----------------- Initial counts\n");

        // Initialize deckCount and treasureCount
        testG.deckCount[p] = 0;
        treasureCount = 0;

        // Create deck of 10 random cards
        for (i = 0; i < 10; i++) {
            index = floor(Random() * 10);
            testG.deck[p][i] = cards[index];
            testG.deckCount[p]++;
        }

        // Check deck for number of treasures
        for (i = 0; i < testG.deckCount[p]; i++) {
            if (testG.deck[p][i] == copper || testG.deck[p][i] == silver || testG.deck[p][i] == gold) {
                treasureCount++;
            }
        }

        // Discard should be empty
        testG.discardCount[p] = 0;

        // Create fixed hand of 5 cards
        testG.handCount[p] = 0;
        for (i = 0; i < 5; i++) {
            testG.hand[p][i] = estate;
            testG.handCount[p]++;
        }

        // Save pre-test values
        preDeck = testG.deckCount[p];
        preDiscard = testG.discardCount[p];
        preHand = testG.handCount[p];

        // Calculate expected values
        // If no treasures in deck, then reveal all cards in deck
        if (treasureCount == 0) {
            treasureDrawn = 0;
            otherRevealed = testG.deckCount[p];
        }
        // If 1 treasure in deck,
        // then reveal all cards in deck in an attempt to get 2 treasures
        else if (treasureCount == 1) {
            treasureDrawn = 1;
            otherRevealed = testG.deckCount[p] - treasureDrawn;
        }
        // If at least 2 treasures in deck
        else {
            treasureDrawn = 0;
            otherRevealed = 0;
            i = testG.deckCount[p] - 1;
            while (treasureDrawn < 2) {
                if (testG.deck[p][i] == copper || testG.deck[p][i] == silver || testG.deck[p][i] == gold) {
                    treasureDrawn++;
                    i--;
                }
                else {
                    otherRevealed++;
                    i--;
                }
            }
        }

        displayAll(&testG, p);
    
        printf("----------------- After playAdventurer\n");

        playAdventurer(&testG, p);

        displayDeck(&testG, p);

        // Check that deck is correct
        count = preDeck - otherRevealed - treasureDrawn;
        printf("Deck count: %d, Expected: %d\n", testG.deckCount[p], count);
        if (testG.deckCount[p] != count) {
            printf("----------------- TEST FAILED!\n");
            pass = false;
        }

        displayDiscard(&testG, p);

        // Check that discard is correct
        count = preDiscard + otherRevealed;
        printf("Discard count: %d, Expected: %d\n", testG.discardCount[p], count);
        if (testG.discardCount[p] != count) {
            printf("----------------- TEST FAILED!\n");
            pass = false;
        }

        displayHand(&testG, p);

        // Check that count of cards is correct
        count = preHand + treasureDrawn;
        printf("Hand count: %d, Expected: %d\n", testG.handCount[p], count);
        if (testG.handCount[p] != count) {
            printf("----------------- TEST FAILED!\n");
            pass = false;
        }
    }

    if (pass) {
        printf("\nAll tests passed!\n");
    }
    else {
        printf("\nSome test(s) failed!\n");
    }
    
    return 0;
}
Exemplo n.º 12
0
int main(){
    printf("*********************BEGIN UNIT TESTS OF ADVENTURER*********************\n\n");
//compare returned value to correct value for each card type
    struct gameState T;
    int i, total_cards;
    int playerCount = T.handCount[0];
    int opponentCount = T.handCount[1];
    int playerDiscard = T.discardCount[0];
    int opponentDiscard = T.discardCount[1];
    int beg_count, end_count = 0;
    int k[10] = {gardens, adventurer, embargo, village, minion, mine, cutpurse,
            sea_hag, tribute, smithy};

    initializeGame(2, k, 5, &T);
    T.hand[0][0] = adventurer;
    total_cards = T.handCount[0] + T.deckCount[0] + T.discardCount[0];

    //count current treasure cards in hand
    for(i = 0; i < T.handCount[0]; i++){
        if(T.hand[0][i] == copper ||
            T.hand[0][i] == silver ||
            T.hand[0][i] == gold){
                beg_count ++;
        }
    }
    //Play the adventurer card for the Test state player 0, position 0
    playAdventurer(&T, 0, 0);
   
    //check that two cards have added and one discarded
    if(T.handCount[0] != playerCount + 1){
        printf("FAIL incorrect number of cards in player hand\n");
    }

    //check that the treasure count has increased by 2
    for(i = 0; i < T.handCount[0]; i++){
        if(T.hand[0][i] == copper ||
            T.hand[0][i] == silver ||
            T.hand[0][i] == gold){
                end_count ++;
        }
    }
    if(end_count != beg_count + 2){
        printf("FAIL two treasure cards were not added to hand\n");
    }
    
    //check that the card was added to discard pile
    if(T.discardCount[0] != playerDiscard + 1){
        printf("FAIL incorrect number of cards in player discard pile\n");
    }
    
    //check that no cards were thrown away
    if(total_cards != T.handCount[0] + T.deckCount[0] + T.discardCount[0]){
        printf("FAIL total player cards is incorrect\n");
    }
    
    //check that nothing else has changed
    if(T.handCount[1] != opponentCount){
        printf("FAIL incorrect number of cards in player hand\n");
    }
    
    if(T.discardCount[1] != opponentDiscard){
        printf("FAIL incorrect number of cards in player discard pile\n");
    }
   

    printf("**********************TESTS COMPLETE*************************\n\n");
    return 0;

}
Exemplo n.º 13
0
int testAdventurer(struct gameState *after)
{
	int beforeTreasure, afterTreasure;
	int drawnCard;
	int p = after->whoseTurn;//initialize whoseTurn stored as p 
	
	struct gameState before;//before card played 
	memcpy(&before, after, sizeof(struct gameState));
	
	playAdventurer(after, p);
	
	//first checking for state changes
	int beforeTotal = before.deckCount[p] + before.discardCount[p] - 2;//because 2 cards in the hand of player 
	int afterTotal = after->deckCount[p] + after->discardCount[p];
	
	//if deck counts not different by 2 then error msg 
	if(afterTotal != beforeTotal) 
	{
		printf("ERROR 1: Total card count difference! Should be 2 less than before total. Before: %d After: %d\n", beforeTotal, afterTotal);
	}
	//checking hand state
	 before.handCount[p] =  before.handCount[p]+2;//hand count should be different by 2
	if(after->handCount[p] != before.handCount[p])//before + 2 should equal after 
	{
		printf("ERROR 2: Hand count difference! Before: %d After: %d\n", before.handCount[p], after->handCount[p]);
	}
	
	//checking all treasure card types in hand are higher than before adventurer was played
	int i;
	for(i = 0; i < before.handCount[p]; i++) //ensuring there are more treasure cards in hand after adventurer is played
	{
		//before
		drawnCard = before.hand[p][i];//checking players hand with all 3 treasure card types
		if (drawnCard == copper || drawnCard == silver || drawnCard == gold)
			beforeTreasure++;
	}
	int j;
	for(j = 0; j < after->handCount[p]; j++)
	{
		//after
		drawnCard = after->hand[p][j];//checking after hand with all 3 treasure card types
		if (drawnCard == copper || drawnCard == silver || drawnCard == gold)
			afterTreasure++;
	}
	//testing if after treasure count is greater after 
	if(!(afterTreasure > beforeTreasure))
		printf("ERROR 3: Not enough treasure cards added to hand. Before: %d After: %d\n", beforeTreasure, afterTreasure);
	//Testing State Changes:
		//checking that buys didn't change
	if(before.numBuys != after->numBuys)
		printf("ERROR 4: Buys has changed from %i, to %i", before.numBuys, after->numBuys);
	//Ensuring that before and after player is the same using whoseTurn
	if(before.whoseTurn != after->whoseTurn)
		printf("ERROR 5: Player has changed from %i to %i", before.whoseTurn, after->whoseTurn);
		//checking the number of actions stayed the same
	if(before.numActions != after->numActions)
		printf("ERROR: Actions has changed from %i to %i", before.numActions, after->numActions);
	//checking that number of coins didn't change 
	if(before.coins != after->coins)
		printf("ERROR 6: Coins changed from %i to %i", before.coins, after->coins);
	
	return 0;
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
0
int main(){
   int seed = 1234;
   int numPlayers = 2;
   int i, r;
   int k[10] = {adventurer, council_room, feast, gardens, mine,
   		remodel, smithy, village, baron, great_hall};
   struct gameState G;

   int handCount, discardCount, treasureCount, newCount;
   int drawnTreasure = 0;

   printf("Testing playAdventurer():\n\n");

   //Test from initial state
   r = initializeGame(numPlayers, k, seed, &G);

   handCount = G.handCount[0];
   discardCount = G.discardCount[0];

   for(i = 0; i < handCount + discardCount + G.deckCount[0]; i++){
      if (G.hand[0][i] == copper ||
	  G.hand[0][i] == silver ||
	  G.hand[0][i] == gold){
	 treasureCount++;
      } 
   }

   playAdventurer(drawnTreasure, 0, &G);

   //two cards added to hand
   if (G.handCount[0] == handCount + 2){
      printf("PASSED: Two cards added to hand\n");
   } else {
      printf("FAILED: Two cards added to hand\n");
   }
   
   //other drawn cards are added to discard pile
   if (G.discardCount[0] >= discardCount){
      printf("PASSED: Other cards discarded\n");
   } else {
      printf("Failed: Other cards discaured\n");
   }
   
   //added cards are treasure cards
   for(i = 0; i < handCount + discardCount + G.deckCount[0]; i++){
      if (G.hand[0][i] == copper ||
	  G.hand[0][i] == silver ||
	  G.hand[0][i] == gold){
	 newCount++;
      } 
   }

   if (newCount == treasureCount + 2){
      printf("PASSED: Added cards were treasure cards\n");
   } else {
      printf("FAILED: Added cards were treasure cards\n");
   }

   printf("Tests completed\n\n");

   return 0;
}
Exemplo n.º 16
0
int testAdventurer(struct gameState *state, int curTest) {
  int curPlayer = state->whoseTurn;
  int tempHand[MAX_HAND];
  int tempHandCount;
  int tempDeck[MAX_DECK];
  int tempDeckCount;
  int tempDiscard[MAX_DECK];
  int tempDiscardCount;

  int i;
  //generate random treasure placement x 2
  int treasure1 = floor(Random() * state->deckCount[curPlayer]);
  int treasure2 = floor(Random() * state->deckCount[curPlayer]);
  while(treasure1 == treasure2) {
    treasure2 = floor(Random() * state->deckCount[curPlayer]);
  }
  //generate random treasure type (4-5)
  int type1 = floor(Random() * 3) + 4;
  int type2 = floor(Random() * 3) + 4;

  state->deck[curPlayer][treasure1] = type1;
  state->deck[curPlayer][treasure2] = type2;

  memcpy(&tempHand, &state->hand[curPlayer], MAX_HAND * sizeof(int));

  memcpy(&tempDeck, &state->deck[curPlayer], MAX_DECK * sizeof(int));
  memcpy(&tempDiscard, &state->discard[curPlayer], MAX_DECK * sizeof(int));  

  tempHandCount = state->handCount[curPlayer];
  tempDeckCount = state->deckCount[curPlayer];
  tempDiscardCount = state->discardCount[curPlayer];

  //  displayArr(tempDiscard, tempDiscardCount);
  //splayArr(state->discard[curPlayer], state->discardCount[curPlayer]);
  //test with empty deck
  //test with non-empty deck
  int found = 0;
  int discard[MAX_HAND];
  int z = 0;
  for(i = tempDeckCount - 1; i >= 0 && found < 2; i--) {
    if(tempDeck[i] == type1 || tempDeck[i] == type2) {
      tempHand[tempHandCount] = tempDeck[i];
      tempHandCount++;
      found++;
    } else {
      discard[z] = tempDeck[i];
      z++;
    }
    tempDeckCount--;
  }

  for(i = 0; i < z; i++) {
    tempDiscard[z-i-1] = discard[i];
    tempDiscardCount++;
  }

  playAdventurer(state, 0);
  int handCheck = memcmp(&tempHand, &state->hand[curPlayer], MAX_HAND*sizeof(int));
  //  printf("handCheck: %d ", handCheck);
  int deckCheck = memcmp(&tempDeck, &state->deck[curPlayer], MAX_DECK*sizeof(int));
  //  printf("deckCheck: %d ", deckCheck);
  int discardCheck = memcmp(&tempDiscard, &state->discard[curPlayer], MAX_DECK*sizeof(int));
  //  printf("discardCheck: %d\n", discardCheck);

// printf("discardCount State: %d\n", state->discardCount[curPlayer]);
// printf("tempDiscardCount: %d\n", tempDiscardCount);
// displayArr(tempDiscard, tempDiscardCount);
// displayArr(state->discard[curPlayer], state->discardCount[curPlayer]);
  if(handCheck != 0 ||deckCheck != 0 || discardCheck != 0) {
    printf("Test: %d FAIL\n", curTest);
    return 1;
  }
  return 0;
}