int main3(int argc, char* argv[]) {
	char *add  = "add";
	char *buyC = "buy";
	char *endT = "end";
	char *exit = "exit";
	char *help = "help";
	char *init = "init";
	char *numH = "num";
	char *play = "play";
	char *resign  = "resi";
	char *show = "show";
	char *stat = "stat";
	char *supply = "supp";
	char *whos = "whos";
		
	char command[MAX_STRING_LENGTH];
	char line[MAX_STRING_LENGTH];
	char cardName[MAX_STRING_LENGTH];

	//Array to hold bot presence 
	int isBot[MAX_PLAYERS] = { 0, 0, 0, 0};

	int players[MAX_PLAYERS];
	int playerNum;
	int outcome;
	int currentPlayer;
	int gameOver = FALSE;
	int gameStarted = FALSE;
	int turnNum = 0;

	int randomSeed = atoi(argv[1]);

	//Default cards, as defined in playDom
	int kCards[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};

	struct gameState g;
	struct gameState * game = &g;

	memset(game,0,sizeof(struct gameState));
		
	if(argc != 2){
		printf("Usage: player [integer random number seed]\n");
		return EXIT_SUCCESS;
	}

	if(randomSeed <= 0){
		printf("Usage: player [integer random number seed]\n");
		return EXIT_SUCCESS;
	}	
	
	initializeGame(2,kCards,randomSeed,game);

	printf("Please enter a command or \"help\" for commands\n");
	

	while(TRUE) {
		int arg0 = UNUSED;
		int arg1 = UNUSED;
		int arg2 = UNUSED;
		int arg3 = UNUSED;

		outcome = FAILURE;
		strcpy(line,"");
		strcpy(command,"");
		strcpy(cardName,"");
		
		currentPlayer = whoseTurn(game);
		
		//If you are getting a seg fault comment this if block out
		gameOver = isGameOver(game); 		
		if(gameStarted == TRUE && gameOver == TRUE){
			printScores(game);
			getWinners(players, game);
			printf("After %d turns, the winner(s) are:\n", turnNum);
			for(playerNum = 0; playerNum < game->numPlayers; playerNum++){
				if(players[playerNum] == WINNER) printf("Player %d\n", playerNum);
			}
		for(playerNum = 0; playerNum < game->numPlayers; playerNum++){
				printHand(playerNum, game);
				printPlayed(playerNum, game);
				printDiscard(playerNum, game);
				printDeck(playerNum, game);
			}
			
			break; //Exit out of the game/while loop
		}         
		

		if(isBot[currentPlayer] == TRUE) {
				executeBotTurn(currentPlayer, &turnNum, game);
				continue;
		}
		
		printf("$ ");
		fgets(line, MAX_STRING_LENGTH, stdin);
		sscanf(line, "%s %d %d %d %d", command, &arg0, &arg1, &arg2, &arg3);


		if(COMPARE(command, add) == 0) {
			outcome = addCardToHand(currentPlayer, arg0, game);
			cardNumToName(arg0, cardName);
			printf("Player %d adds %s to their hand\n\n", currentPlayer, cardName);
		} else
		if(COMPARE(command, buyC) == 0) {
			outcome = buyCard(arg0, game);
			cardNumToName(arg0, cardName);
			if(outcome == SUCCESS){
				printf("Player %d buys card %d, %s\n\n", currentPlayer, arg0, cardName);
			} else {
				printf("Player %d cannot buy card %d, %s\n\n", currentPlayer, arg0, cardName);
			}
		} else
		if(COMPARE(command, endT) == 0) {
			if(gameStarted == TRUE) {
				if(currentPlayer == (game->numPlayers -1)) turnNum++;
				endTurn(game);
				currentPlayer = whoseTurn(game);
				printf("Player %d's turn number %d\n\n", currentPlayer, turnNum);
			}

		} else			
		if(COMPARE(command, exit) == 0) {
			break;
		} else
		if(COMPARE(command, help) == 0) {
			printHelp();
		} else
		if(COMPARE(command, init) == 0) {
			int numHuman = arg0 - arg1;
			for(playerNum = numHuman; playerNum < arg0; playerNum++) {
				isBot[playerNum] = TRUE;
			}			
	//		selectKingdomCards(randomSeed, kCards);  //Comment this out to use the default card set defined in playDom.
			outcome = initializeGame(arg0, kCards, randomSeed, game);
			printf("\n");
			if(outcome == SUCCESS){
				gameStarted = TRUE;
				currentPlayer = whoseTurn(game);
				printf("Player %d's turn number %d\n\n", currentPlayer, turnNum);
			}

		} else
		if(COMPARE(command, numH) == 0) {
			int numCards = numHandCards(game);
			printf("There are %d cards in your hand.\n", numCards);
		} else
		if(COMPARE(command, play) == 0) {
			int card = handCard(arg0,game);
			outcome = playCard(arg0, arg1, arg2, arg3, game);
			cardNumToName(card, cardName);
			if(outcome == SUCCESS){
				printf("Player %d plays %s\n\n", currentPlayer, cardName);
			} else {
				printf("Player %d cannot play card %d\n\n", currentPlayer, arg0);
			}

		} else
		if(COMPARE(command, resign) == 0) {
			endTurn(game);
			printScores(game);
			break;
		} else
		if(COMPARE(command, show) == 0) {
			if(gameStarted == FALSE) continue;
			printHand(currentPlayer, game);
			printPlayed(currentPlayer, game);
			//printDiscard(currentPlayer, game);
			//printDeck(currentPlayer, game);
		} else
		if(COMPARE(command, stat) == 0) {
			if(gameStarted == FALSE) continue;
			printState(game);
		} else
		if(COMPARE(command, supply) == 0) {
			printSupply(game);
		} else
		if(COMPARE(command, whos) == 0) {
			int playerNum =	whoseTurn(game);
			printf("Player %d's turn\n", playerNum);
		} 
    	}
	
    	return EXIT_SUCCESS;

}
Example #2
0
// Tests the smithy card in dominion.c
int main (int argc, char** argv) {
    printf("TESTING smithy card\n");

    srand(time(NULL));

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

    printf("RANDOM TESTS\n");

    int numtests = 100;
    for(int i = 0; i < numtests; i++){
        initializeGame(numplayers, k, rand(), &G);

          int money = 0;
          int smithyPos = -1;
          int adventurerPos = -1;
          int i=0;

          int numSmithies = 0;
          int numAdventurers = 0;

          while (!isGameOver(&G)) {
            money = 0;
            smithyPos = -1;
            adventurerPos = -1;
            for (i = 0; i < numHandCards(&G); i++) {
              if (handCard(i, &G) == copper)
            money++;
              else if (handCard(i, &G) == silver)
            money += 2;
              else if (handCard(i, &G) == gold)
            money += 3;
              else if (handCard(i, &G) == smithy)
            smithyPos = i;
              else if (handCard(i, &G) == adventurer)
            adventurerPos = i;
            }

            if (whoseTurn(&G) == 0) {
              if (smithyPos != -1) {
                struct gameState orig;
                memcpy(&orig, &G, sizeof(struct gameState));

                playCard(smithyPos, -1, -1, -1, &G); 
                
               // assert(G.handCount[0] == orig.handCount[0] + 2);
                money = 0;
                i=0;
            while(i<numHandCards(&G)){
              if (handCard(i, &G) == copper){
                playCard(i, -1, -1, -1, &G);
                money++;
              }
              else if (handCard(i, &G) == silver){
                playCard(i, -1, -1, -1, &G);
                money += 2;
              }
              else if (handCard(i, &G) == gold){
                playCard(i, -1, -1, -1, &G);
                money += 3;
              }
              i++;
            }
              }

              if (money >= 8) {
                buyCard(province, &G);
              }
              else if (money >= 6) {
                buyCard(gold, &G);
              }
              else if ((money >= 4) && (numSmithies < 2)) {
                buyCard(smithy, &G);
                numSmithies++;
              }
              else if (money >= 3) {
                buyCard(silver, &G);
              }

              endTurn(&G);
            }
            else {
              if (adventurerPos != -1) {
            playCard(adventurerPos, -1, -1, -1, &G); 
            money = 0;
            i=0;
            while(i<numHandCards(&G)){
              if (handCard(i, &G) == copper){
                playCard(i, -1, -1, -1, &G);
                money++;         
              }
              else if (handCard(i, &G) == silver){
                playCard(i, -1, -1, -1, &G);
                money += 2;
              }
              else if (handCard(i, &G) == gold){
                playCard(i, -1, -1, -1, &G);
                money += 3;
              }
              i++;
            }
              }

              if (money >= 8) {
                buyCard(province, &G);
              }
              else if ((money >= 6) && (numAdventurers < 2)) {
            buyCard(adventurer, &G);
            numAdventurers++;
              }else if (money >= 6){
                buyCard(gold, &G);
                }
              else if (money >= 3){
                buyCard(silver, &G);
              }
              
              endTurn(&G);      
            }
          } // end of While
    }

    printf("ALL TESTS OK\n");
}
Example #3
0
int main(int argc, char** argv)
{
  int testcounter = 0;
  int numTests = 20;
  //The random card values are between 0 and 26, so mod by 27, you should be
  //pretty jevo about it. As for initiating games, super easy to randomize
  //number of players playing, however, playing games is still intersting,
  //ask about in class on Tuesday (May 19th, 2015)
  struct gameState G;
  struct gameState *p = &G;
  while(testcounter != numTests){

    srand(time(NULL));
  
  int k[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  int r; //Store our random card values;
  int i, j;
  int numPlayers = rand() % 5; 
  int money = 0;

  //Make sure I have more than 2 players
  if (numPlayers < 2){
    while(1){
      numPlayers = rand() % 5;
      if (numPlayers < 2)
	continue;
      else
	break;
    }
  }
  int players[numPlayers];
  //intialize deck with cards ( have to be greater than or equal to 7)
  for (i = 0; i < 10; i++){
    r = rand() % 27;
    while (r < 7){
      r = rand() % 27;
    }
    k[i] = r;
  }
  
  //Make sure kingdom cards are random
  for (i = 0; i < 10; i++){
    r = rand() % 27;
    while (r < 7){
      r = rand() % 27;
    }
    if (k[i] == 0)
      k[i] = r;
    for (j = i+1; j < 10; j++){
      if (k[i] == k[j]){
	k[i] = r;
	i = -1;
	break;
      }     
    }
  }
  

 
  printf("***STARTING GAME***\n");
  initializeGame(numPlayers, k, atoi(argv[1])+ rand(), p);
  
  while (!isGameOver(p)){
    
    printf("\nCards in player %d's hand:  ", whoseTurn(p));
    for (i = 0; i < numHandCards(p); i++){
      if (i < 4){
	printCard(handCard(i, p));
	printf(", ");
      }
      else{
	printCard(handCard(i, p));
      }
    }
    printf("\n");

    //Not entirely sure what this phase does, 
    for (i = 0; i < numHandCards(p); i++){
      if (handCard(i, p) == copper)
	money++;
      else if (handCard(i, p) == silver)
	money += 2;
      else if (handCard(i, p) == gold)
	money += 3;
    }
    
    //How much money does the player have
    for (i = 0; i < numPlayers; i++){
      money = 0;
      j = 0;     
      while (j < numHandCards(p)){
        r = rand() % 2;

	if (handCard(j, p) == copper){
	  playCard(j, -1, -1, -1, p);
	  money++;
	}
	else if (handCard(j, p) == silver){
	  playCard(j, -1, -1, -1, p);
	  money += 2;
	}
	else if (handCard(j, p) == gold){
	  playCard(j, -1, -1, -1, p);
	  money += 3;
	}
	
	// 1/3 chance of being able to play another card besides money:

	if (r == 0){
	  if (handCard(j,p) == adventurer){
	    playCard(j, -1, -1, -1, p);
	    printf("Player %d: ***Played Adventurer***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == feast){
	    playCard(j, copper, -1, -1, p);
	    printf("Player %d: ***Played Feast***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == council_room){
	    playCard(j, -1, -1, -1, p);
	    printf("Player %d: ***Played Council Room***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == mine){
	    playCard(j, copper, gardens, -1, p);	    
	    printf("Player %d: ***Played Mine***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == smithy){
	    playCard(j, -1, -1, -1, p);
	    printf("Player %d: ***Played Smithy***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == remodel){
	    playCard(j, embargo, duchy, -1, p);	    
	    printf("Player %d: ***Played Remodel***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == village){
	    playCard(j, -1, -1, -1, p);
	    printf("Player %d: ***Played Village***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == baron){
	    playCard(j, -1, -1, -1, p);
	    printf("Player %d: ***Played Baron***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == great_hall){
	    playCard(j, -1, -1, -1, p);	    
	    printf("Player %d: ***Played Great Hall***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == minion){
	    playCard(j, adventurer, copper, -1, p);
	    printf("Player %d: ***Played Minion***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == steward){
	    playCard(j, 1, -1, -1, p);	    
	    printf("Player %d: ***Played Steward***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == tribute){
	    playCard(j, -1, -1, -1, p);
	    printf("Player %d: ***Played Tribute***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == ambassador){
	    playCard(j, 1, 1, -1, p);
	    printf("Player %d: ***Played Ambassador***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == cutpurse){
	    playCard(j, -1, -1, -1, p);
	    printf("Player %d: ***Played Cutpurse***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == embargo){
	    playCard(j, copper, -1, -1, p);
	    printf("Player %d: ***Played Embargo***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == outpost){
	    playCard(j, -1, -1, -1, p);	    
	    printf("Player %d: ***Played Outpost***\n", whoseTurn(p));
	  }	  
	  else if (handCard(j,p) == salvager){
	    playCard(j, copper, -1, -1, p);
	    printf("Player %d: ***Played Salvager***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == sea_hag){
	    playCard(j, -1, -1, -1, p);	    
	    printf("Player %d: ***Played Sea Hag***\n", whoseTurn(p));
	  }
	  else if (handCard(j,p) == treasure_map){
	    playCard(j, -1, -1, -1, p);	    
	    printf("Player %d: ***Played Treasure Map***\n", whoseTurn(p));
	  }
	}
	j++;
      }
      
      int check = 0, count = 0;
      //***Buying Phase***
      if (money >= 8){
	printf("Player %d: Bought Province\n\n", whoseTurn(p));
	buyCard(province, p);
	}
      else if (money >= 6){
	// adventurer
	for (count = 0; count < 10; count++){
	  if (k[count] == adventurer){
	    check = 1;
	  }
	}
	if (check == 1 && (rand() % 3 == 0)){ // 1/3 to buy adventurer
	  printf("Player %d: Bought Adventurer\n\n", whoseTurn(p));
	  buyCard(adventurer, p);
	}
	else {
	  printf("Player %d: Bought Gold\n\n", whoseTurn(p));
	  buyCard(gold, p);
	}
      }
      else if (money >= 5){
	//council_room, mine, minion, tribute, outpost
	for (count = 0; count < 10; count++){
	  if (k[count] == council_room || k[count] == mine ||
	      k[count] == minion || k[count] == tribute ||
	      k[count] == outpost){
	    
	    check += 1;
	  }
	}
	if (rand() % 5 == 0){
	  for (count = 0; count < 10; count++){
	    if(check > 0 && k[count] == council_room && rand()% 5 == 0){
	      printf("Player %d: Bought Council Room\n\n", whoseTurn(p));
	      buyCard(council_room, p);
	      break;
	    }
	    else if(check > 0 && k[count] == mine && rand()% 5 == 0){
	      printf("Player %d: Bought Mine\n\n", whoseTurn(p));
	      buyCard(mine, p);
	      break;
	    }
	    else if(check > 0 && k[count] == minion && rand()% 5 == 0){
	      printf("Player %d: Bought Minion\n\n", whoseTurn(p));
	      buyCard(minion, p);
	      break;
	    }
	    else if(check > 0 && k[count] == tribute && rand()% 5 == 0){
	      printf("Player %d: Bought Tribute\n\n", whoseTurn(p));
	      buyCard(tribute, p);
	      break;
	    }
	    else if(check > 0 && k[count] == outpost && rand()% 5 == 0){
	      printf("Player %d: Bought Outpost\n\n", whoseTurn(p));
	      buyCard(outpost, p);
	      break;
	    }
	  }
	}
	else {		      
	  printf("Player %d: Bought Duchy\n\n", whoseTurn(p));
	  buyCard(duchy, p);
	}
      }
      else if (money >= 4){
	//feast, gardens, remodel, smithy, baron, cutpurse, salvager, sea_hag
	// treasure_map
	for (count = 0; count < 10; count++){
	  if (k[count] == feast || k[count] == gardens || k[count] == remodel
	      || k[count] == smithy || k[count] == baron || 
	      k[count] == cutpurse || k[count] == salvager ||
	      k[count] == sea_hag || k[count] == treasure_map) {	   
	    
	      check += 1;
	  }
	}
	// 1/5 chance of buying a card in deck
	if (rand() % 5 == 0){
	  for (count = 0; count < 10; count++){
	    if(check > 0 && k[count] == feast && rand()% 5 == 0){
	      printf("Player %d: Bought Feast\n\n", whoseTurn(p));
	      buyCard(feast, p);
	      break;
	    }
	    else if(check > 0 && k[count] == gardens && rand()% 5 == 0){
	      printf("Player %d: Bought Gardens\n\n", whoseTurn(p));
	      buyCard(gardens, p);
	      break;
	    }
	    else if(check > 0 && k[count] == smithy && rand()% 5 == 0){
	      printf("Player %d: Bought Smithy\n\n", whoseTurn(p));
	      buyCard(smithy, p);
	      break;
	    }
	    else if(check > 0 && k[count] == baron && rand()% 5 == 0){
	      printf("Player %d: Bought Baron\n\n", whoseTurn(p));
	      buyCard(baron, p);
	      break;
	    }
	    else if(check > 0 && k[count] == cutpurse && rand()% 5 == 0){
	      printf("Player %d: Bought Cutpurse\n\n", whoseTurn(p));
	      buyCard(cutpurse, p);
	      break;
	    }
	    else if(check > 0 && k[count] == salvager && rand()% 5 == 0){
	      printf("Player %d: Bought Salvager\n\n", whoseTurn(p));
	      buyCard(salvager, p);
	      break;
	    }
	    else if(check > 0 && k[count] == sea_hag && rand()% 5 == 0){
	      printf("Player %d: Bought Sea Hag\n\n", whoseTurn(p));
	      buyCard(sea_hag, p);
	      break;
	    }
	    else if(check > 0 && k[count] == treasure_map && rand()% 5 == 0){
	      printf("Player %d: Bought Treasure Map\n\n", whoseTurn(p));
	      buyCard(treasure_map, p);
	      break;
	    }
	  }
	}
      }
      else if (money >= 3){
	//embargo, ambassador, steward, great_hall,village
	for (count = 0; count < 10; count++){
	  if (k[count] == embargo || k[count] == ambassador || 
	      k[count] == steward || k[count] == great_hall || 
	      k[count] == village){
	    
	    check += 1;
	  }	  
	}
	if (rand() % 5 == 0) {
	  for (count = 0; count < 10; count++){
	    if(check > 0 && k[count] == embargo && rand()% 5 == 0){
	      printf("Player %d: Bought Embargo\n\n", whoseTurn(p));
	      buyCard(embargo, p);
	      break;
	    }
	    else if(check > 0 && k[count] == ambassador && rand()% 5 == 0){
	      printf("Player %d: Bought Ambassador\n\n", whoseTurn(p));
	      buyCard(ambassador, p);
	      break;
	    }
	    else if(check > 0 && k[count] == steward && rand()% 5 == 0){
	      printf("Player %d: Bought Steward\n\n", whoseTurn(p));
	      buyCard(steward, p);
	      break;
	    }
	    else if(check > 0 && k[count] == great_hall && rand()% 5 == 0){
	      printf("Player %d: Bought Great Hall\n\n", whoseTurn(p));
	      buyCard(great_hall, p);
	      break;
	    }
	    else if(check > 0 && k[count] == village && rand()% 5 == 0){
	      printf("Player %d: Bought Village\n\n", whoseTurn(p));
	      buyCard(village, p);
	      break;
	    }
	  }
	}
	else {
	  printf("Player %d: Bought Silver\n\n", whoseTurn(p));
	  buyCard(silver, p);
	}
      }
      endTurn(p);
      
      for (i = 0; i < numPlayers; i++){
	printf("Player %d: %d\n", i, scoreFor(i, p));  
      }
    }
  }
    //***End of Game***
    printf("***GAME FINISHED***\n");
    
    for (i = 0; i < numPlayers; i++){
      printf("Player %d: %d\n", i, scoreFor(i, p));
    }
    getWinners(players, p);
    testcounter++;
  }    
    return 0;
}
int main (int argc, char** argv) {
  struct gameState G;
  struct gameState *p = &G;
  int *k,i, players, money = 0, chosenCard=0, playedCard=0, flag=0, buyc=0;
  

  printf ("Starting game.\n");
  k=randomKingdom();
 /* for(i=0; i<10; i++){
    printf("%d\n",k[i]);
  }*/
  players = rand() % 2 + 2;

  initializeGame(players, k, rand(), p);
  

  while (!isGameOver(p)) { //loop for every turn
    printf("#Player%d's turn ###################################\n", whoseTurn(p)+1);
    money = 0;

    printf("-Check hand for treaure.\n");
    for (i = 0; i < numHandCards(p); i++) { //check if the current player has any treasures
      if (handCard(i, p) == copper){
        money++;
        printf("get 1 coin with copper\n");
      }
      else if (handCard(i, p) == silver){
        money += 2;
        printf("get 2 coins with silver\n");
      }
      else if (handCard(i, p) == gold){
        money += 3;
        printf("get 3 coins with gold\n");

      }
    }
    printf("Current coins: %d\n", money);
    printf("Current num of cards (before) %d\n", p->handCount[whoseTurn(p));
      flag=1;
      for(i=0; i< p->handCount[whoseTurn(p)]; i++){
        if (p->hand[whoseTurn(p)][i]!=copper && p->hand[whoseTurn(p)][i] != silver && p->hand[whoseTurn(p)][i] != gold)
          flag=0;
      }
      if(flag==0){ //play a card
        while (flag==0){
          chosenCard=rand() % p->handCount[whoseTurn(p)];
          if (chosenCard!=copper && chosenCard != silver && chosenCard != gold)
            flag=1;
        }
        flag=0;

        playedCard=p->hand[whoseTurn(p)][chosenCard];
          printf("%s played from position %d\n", whichCard(playedCard), chosenCard); 
  	      playCard(chosenCard, 1, 1, 1, p); 
  	      printf("%s played.\n", whichCard(playedCard));
          printf("Current num of cards (after) %d\n", p->handCount[whoseTurn(p));
          if(playedCard==22){
            //printf("\n\n\nembargo\n\n\n\n\n");
            embargoTest(G, whoseTurn(p));
          }
  	      money = 0;
  	      i=0;
  	      while(i<numHandCards(p)){
  	       if (handCard(i, p) == copper){
  	         playCard(i, -1, -1, -1, p);
  	         money++;
  	       }
  	       else if (handCard(i, p) == silver){
  	         playCard(i, -1, -1, -1, p);
  	         money += 2;
  	       }
  	       else if (handCard(i, p) == gold){
  	         playCard(i, -1, -1, -1, p);
  	         money += 3;
  	       }
  	       i++;
  	     }
        }
      

      buyc=random()%2-2;
      if(buyc==-1){
        int x=0;
        x=random()%3;
        if(x==0)
          buyc=copper;
        else if(x==1)
          buyc=silver;
        else
          buyc=gold;
      }
      else{
        buyc = k[random()%10];
      }
      printf("attempting to buy %s\n", whichCard(buyc)); 
      buyCard(buyc, p);
      


      printf ("Player %d's current score: %d\n", whoseTurn(p)+1, scoreFor(whoseTurn(p), p));
      printf("Player %d's turn ends.\n", whoseTurn(p)+1);
	    endTurn(p);

  } // end of While

  printf ("Finished game.\n");
  printf(":FINAL RESULT:::::::::::::::::::::::::::::::\n");
  for (i=0; i<players; i++){
    printf ("Player %d's final score: %d\n", i+1, scoreFor(i, p));
  }

  return 0;
}
Example #5
0
int main (int argc, char** argv) {
  struct gameState G;
  struct gameState *p = &G;

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

  printf ("Starting game.\n");
  
  initializeGame(2, k, atoi(argv[1]), p);
  
  int money = 0;
  int smithyPos = -1;
  int adventurerPos = -1;
  int i=0;

  int numSmithies = 0;
  int numAdventurers = 0;

  while (!isGameOver(p)) 
  {
    money = 0;
    smithyPos = -1;
    adventurerPos = -1;
    for (i = 0; i < numHandCards(p); i++) {
      if (handCard(i, p) == copper)
       money++;
      else if (handCard(i, p) == silver)
       money += 2;
      else if (handCard(i, p) == gold)
       money += 3;
      else if (handCard(i, p) == smithy)
       smithyPos = i;
       else if (handCard(i, p) == adventurer)
    adventurerPos = i;
    }

    if (whoseTurn(p) == 0) 
    {
      if (smithyPos != -1) 
      {
        printf("0: smithy played from position %d\n", smithyPos); 
	      playCard(smithyPos, -1, -1, -1, p); 
	      printf("smithy played.\n");
	      money = 0;
	      i=0;
	      while(i<numHandCards(p))
        {
	         if (handCard(i, p) == copper){
	           playCard(i, -1, -1, -1, p);
	           money++;
	         }
	         else if (handCard(i, p) == silver){
	           playCard(i, -1, -1, -1, p);
	           money += 2;
	         }
	         else if (handCard(i, p) == gold){
	           playCard(i, -1, -1, -1, p);
	           money += 3;
	         }
	         i++;
	      }
      }

      if (money >= 8) {
        printf("0: bought province\n"); 
        buyCard(province, p);
      }
      else if (money >= 6) {
        printf("0: bought gold\n"); 
        buyCard(gold, p);
      }
      else if ((money >= 4) && (numSmithies < 2)) {
        printf("0: bought smithy\n"); 
        buyCard(smithy, p);
        numSmithies++;
      }
      else if (money >= 3) {
        printf("0: bought silver\n"); 
        buyCard(silver, p);
      }

      printf("0: end turn\n");
      endTurn(p);
    }

    else 
    {
      if (adventurerPos != -1) 
      {
        printf("1: adventurer played from position %d\n", adventurerPos);
	      playCard(adventurerPos, -1, -1, -1, p); 
	      money = 0;
	      i=0;
	      while(i<numHandCards(p))
        {
	        if (handCard(i, p) == copper)
          {
	          playCard(i, -1, -1, -1, p);
	          money++;         
	        }

	        else if (handCard(i, p) == silver)
          {
	        playCard(i, -1, -1, -1, p);
	        money += 2;
	        }

	        else if (handCard(i, p) == gold)
          {
	        playCard(i, -1, -1, -1, p);
	        money += 3;
	        }

	        i++;
	      }
      }

      if (money >= 8) 
      {
         printf("1: bought province\n");
         buyCard(province, p);
     }
     
     else if ((money >= 6) && (numAdventurers < 2)) 
     {
         printf("1: bought adventurer\n");
	       buyCard(adventurer, p);
	       numAdventurers++;
      }

      else if (money >= 6)
      {
         printf("1: bought gold\n");
	        buyCard(gold, p);
      }
    
     else if (money >= 3)
     {
          printf("1: bought silver\n");
	        buyCard(silver, p);
     }
    
     printf("1: endTurn\n");
      
     endTurn(p);      
    }

      printf ("Player 0: %d\nPlayer 1: %d\n", scoreFor(0, p), scoreFor(1, p));
	    
  } // end of While

  printf ("Finished game.\n");
  printf ("Player 0: %d\nPlayer 1: %d\n", scoreFor(0, p), scoreFor(1, p));

  return 0;
}
int main (int argc, char** argv) {
  //testing steward
  struct gameState G;

  int i, j, players, player, handCount, deckCount, discardCount, handPos, difference, numActions, seed, coinBefore, coinAfter, testPass, testFail;

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

  printf ("\n*** Starting %i Random Adventurer Unit Test. ***\n", MAX_TESTS);
  for (i = 0; i < MAX_TESTS; i++)
  {
    int timeseed = time(NULL);
    srand(timeseed);
    //printf("-------------------------------------\n");
    players = (rand() % 4) + 1;
		player = rand() % players;
		seed = rand();
		initializeGame(players, k, seed, &G);

    G.deckCount[player] = rand() % MAX_DECK; //Pick random deck size out of MAX DECK size
		G.discardCount[player] = rand() % MAX_DECK;
		G.handCount[player] = rand() % MAX_HAND;

    for (j = 0; j < G.deckCount[player]; j++) {
      G.deck[player][j] = rand() % (treasure_map + 1);
    }
    for (j = 0; j < G.handCount[player]; j++) {
      G.hand[player][j] = rand() % (treasure_map + 1);
    }
    for (j = 0; j < G.discardCount[player]; j++) {
      G.discard[player][j] = rand() % (treasure_map + 1);
    }

    G.hand[player][0] = adventurer;

		//Copy state variables
		handCount = G.handCount[player];
		deckCount = G.deckCount[player];

    if (seed % 3 == 0) {
      G.deckCount[player] = 0;
    }

    int numCards = numHandCards(&G);
    //printf("numCards before: %i\n", numCards);
    cardEffect(adventurer, 0,0,0, &G ,0,0);
    int numCardsAfter = numHandCards(&G);
    //printf("numCards after: %i\n", numCardsAfter);

    if(numCardsAfter - numCards == 2){
      testPass++;
    } else {
      printf("** Failed Test **\n");
      printf("timeseed: %i\n", timeseed);
      printf("numCards before: %i\n", numCards);
      printf("numCards after: %i\n", numCardsAfter);
      printf("*****************\n");
      testFail++;
    }
  }
  //printf("-------------------------------------\n");
  printf("Tests passed: %i\n", testPass);
  printf("Tests fails: %i\n", testFail);
  return 0;
}
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
{
	int i;
	int j;
	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:
		playedCard(handPos, NULL, NULL, state);
		while (drawntreasure < 2) {
			if (drawCard(currentPlayer, state) == -1)
				break;
			cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer] - 1];//top card of hand is most recently drawn card.
			if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold)
				drawntreasure++;
			else {
				temphand[z] = cardDrawn;
				state->hand[currentPlayer][state->handCount[currentPlayer] - 1] = -1;
				state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one).
				z++;
			}
		}
		while (z > 0) {
			state->discard[currentPlayer][state->discardCount[currentPlayer]++] = temphand[z - 1]; // discard all cards in play that have been drawn
			z--;
		}
		endPlayed(state, 0);
		return 0;

	case council_room:
		return councilRoomEffect(currentPlayer, handPos, state);

	case feast:
		if (choice1 < curse || choice1 > treasure_map)
			return -1;

		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));
			}
			return -1;
		}
		else if (5 < getCost(choice1)) {
			if (DEBUG) {
				printf("That card is too expensive!\n");
				printf("Coins: %d < %d\n", state->coins, getCost(choice1));
			}
			return -1;
		}	

		playedCard(handPos, NULL, NULL, state);

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

		gainCard(choice1, state, 0, currentPlayer);//Gain the card

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

		//trash feast
		endPlayed(state, 1);

		return 0;

	case gardens:
		return -1;

	case mine:
		if (choice1 >= state->handCount[currentPlayer] || choice1 < 0 || choice1 == handPos)
			return -1;

		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 > gold || choice2 < copper)
		{
			return -1;
		}

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

		playedCard(handPos, &choice1, NULL, state);

		//trash old treasure
		discardCard(choice1, currentPlayer, state, 1);

		//gain new treasure
		gainCard(choice2, state, 2, currentPlayer);

		endPlayed(state, 0);

		return 0;

	case remodel:
		if (choice1 >= state->handCount[currentPlayer] || choice1 < 0 || choice1 == handPos)
			return -1;

		if (choice2 < curse || choice2 > treasure_map)
			return -1;

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

		playedCard(handPos, &choice1, NULL, state);

		//trash choice
		discardCard(choice1, currentPlayer, state, 1);

		//gain new card
		gainCard(choice2, state, 0, currentPlayer);

		endPlayed(state, 0);
		return 0;

	case smithy:
		return smithyEffect(currentPlayer, handPos, state);

	case village:
		return villageEffect(currentPlayer, handPos, state);

	case baron:
		if (!(choice1 == 1 || choice1 == 2))
			return -1;

		if (choice1 == 1) {//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 (p >= state->handCount[currentPlayer]) {
					if (DEBUG) {
						printf("No estate cards in your hand, invalid choice\n");						
					}
					return -1;
				}
				else if (state->hand[currentPlayer][p] == estate) {//Found an estate card!
					playedCard(handPos, &p, NULL, state);
					*bonus += 4;//Add 4 coins to the amount of coins
					discardCard(p, currentPlayer, state, 0);
					card_not_discarded = 0;//Exit the loop
				}
				else {
					p++;//Next card
				}
			}
		}

		else {
			playedCard(handPos, NULL, NULL, state);
			gainCard(estate, state, 0, currentPlayer);//Gain an estate	
		}
		state->numBuys++;//Increase buys by 1!
		endPlayed(state, 0);
		return 0;

	case great_hall:
		return greatHallEffect(currentPlayer, handPos, state);

	case minion:
		if (!(choice1 == 1 || choice1 == 2))
			return -1;

		playedCard(handPos, NULL, NULL, state);

		//+1 action
		state->numActions++;

		if (choice1 == 1)      //+2 coins
		{
			*bonus += 2;
		}

		else if (choice1 == 2)     //discard hand, redraw 4, other players with 5+ cards discard hand and draw 4
		{
			//discard hand
			while (numHandCards(state) > 0)
			{
				discardCard(0, 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(0, i, state, 0);
						}

						//draw 4
						for (j = 0; j < 4; j++)
						{
							drawCard(i, state);
						}
					}
				}
			}

		}
		endPlayed(state, 0);
		return 0;

	case steward:
		if (!(choice1 == 1 || choice1 == 2 || choice1 == 3))
			return -1;
		if (choice1 == 3 && ((choice2 >= state->handCount[currentPlayer] || choice2 < 0) || (choice3 >= state->handCount[currentPlayer] || choice3 < 0) || choice2 == choice3 || (choice2 == handPos || choice3 == handPos)))
			return -1;

		if (choice1 == 1)
		{
			playedCard(handPos, NULL, NULL, state);
			//+2 cards
			drawCard(currentPlayer, state);
			drawCard(currentPlayer, state);
		}
		else if (choice1 == 2)
		{
			//+2 coins
			playedCard(handPos, NULL, NULL, state);
			*bonus += 2;
		}
		else
		{
			playedCard(handPos, &choice2, &choice3, state);
			//trash 2 cards in hand
			if (choice2 < choice3) {
				int tmp = choice2;
				choice2 = choice3;
				choice3 = tmp;
			}

			//discard order matters, must discard max to min for correct effect
			discardCard(choice2, currentPlayer, state, 1);
			discardCard(choice3, currentPlayer, state, 1);			
		}
		endPlayed(state, 0);
		return 0;

	case tribute:
		playedCard(handPos, NULL, NULL, state);
		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]--;
				state->discard[nextPlayer][state->discardCount[nextPlayer]] = tributeRevealedCards[0];
				state->discardCount[nextPlayer]++;
			}
			else if (state->discardCount[nextPlayer] > 0) {
				tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer] - 1];
			}
			else {
				//No Card to Reveal
				if (DEBUG) {
					printf("No cards to reveal\n");
				}
				endPlayed(state, 0);
				return 0;
			}
		}

		else {
			if (state->deckCount[nextPlayer] == 0) {
				j = state->discardCount[nextPlayer];
				for (i = 0; i < j; 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] = -1;
			state->deckCount[nextPlayer]--;

			if (state->deckCount[nextPlayer] == 0) {
				j = state->discardCount[nextPlayer];
				for (i = 0; i < j; 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
			}

			state->discard[nextPlayer][state->discardCount[nextPlayer]] = tributeRevealedCards[0];
			state->discardCount[nextPlayer]++;

			tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer] - 1];
			state->deck[nextPlayer][state->deckCount[nextPlayer] - 1] = -1;
			state->deckCount[nextPlayer]--;
			state->discard[nextPlayer][state->discardCount[nextPlayer]] = tributeRevealedCards[1];
			state->discardCount[nextPlayer]++;
		}

		if (tributeRevealedCards[0] == tributeRevealedCards[1]) {//If we have a duplicate card, just drop one 
			tributeRevealedCards[1] = -1;
		}

		for (i = 0; i < 2; i++) {
			if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold) {//Treasure cards
				*bonus += 2;
			}

			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);
			}
			if (tributeRevealedCards[i] >= adventurer && tributeRevealedCards[i] <= treasure_map){//Action Card
				state->numActions = state->numActions + 2;
			}
		}

		endPlayed(state, 0);

		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 || choice1 >= numHandCards(state) || choice1 < 0)
		{
			return -1;
		}

		for (i = 0; i < state->handCount[currentPlayer]; i++)
		{
			if (i != handPos && i == state->hand[currentPlayer][choice1])
			{
				j++;
			}
		}
		if (j < choice2)
		{
			return -1;
		}

		playedCard(handPos, &choice1, NULL, state);

		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);
			}
		}

		//trash copies of cards returned to supply
		for (j = 0; j < choice2; j++)
		{
			for (i = state->handCount[currentPlayer] - 1; i >= 0; i--)
			{
				if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1])
				{
					discardCard(i, currentPlayer, state, 1);
					break;
				}
			}
		}

		endPlayed(state, 0);

		return 0;

	case cutpurse:
		return cutpurseEffect(currentPlayer, handPos, state, bonus);

	case embargo:
		if (choice1 < curse || choice1 > treasure_map)
			return -1;
		//see if selected pile is in play
		if (state->supplyCount[choice1] == -1)
		{
			return -1;
		}

		playedCard(handPos, NULL, NULL, state);

		//+2 Coins
		*bonus += 2;

		//add embargo token to selected supply pile
		state->embargoTokens[choice1]++;

		//trash card
		endPlayed(state, 1);
		return 0;

	case outpost:
		if (state->outpostTurn == 1)
			return -1;
		
		playedCard(handPos, NULL, NULL, state);
		//set outpost flag
		state->outpostPlayed = 1;

		//we actually don't call endPlayed() here on purpose
		return 0;

	case salvager:
		if (choice1 >= state->handCount[currentPlayer] || choice1 < 0 || choice1 == handPos)
			return -1;

		playedCard(handPos, &choice1, NULL, state);

		//+1 buy
		state->numBuys++;
		
		//gain coins equal to trashed card
		*bonus += getCost(handCard(choice1, state));
		
		//trash card
		discardCard(choice1, currentPlayer, state, 1);
		
		endPlayed(state, 0);
		return 0;

	case sea_hag:
		playedCard(handPos, NULL, NULL, state);
		for (i = 0; i < state->numPlayers; i++) {
			if (i != currentPlayer) {
				if (state->deckCount[i] + state->discardCount[i] > 0) {
					if (state->deckCount[i] == 0) {
						j = state->discardCount[i];
						for (index = 0; index < j; index++) {
							state->deck[i][index] = state->discard[i][index];//Move to deck
							state->deckCount[i]++;
							state->discard[i][index] = -1;
							state->discardCount[i]--;
						}

						shuffle(i, state);//Shuffle the deck
					}
					state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i] - 1];
					state->discardCount[i]++;
					//conveniently, this happens to add it to the top of the deck
					gainCard(curse, state, 1, i);
				}
				else { //literally no cards in their deck or discard, so they just get a curse in their deck
					gainCard(curse, state, 1, i);
				}				
			}
		}
		endPlayed(state, 0);
		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){
			playedCard(handPos, &index, NULL, state);
			//trash other treasure_map
			discardCard(index, currentPlayer, state, 1);

			//gain 4 Gold cards
			for (i = 0; i < 4; i++)
			{
				gainCard(gold, state, 1, currentPlayer);
			}
		}
		else {
			return -1;
		}
		endPlayed(state, 1);
		return 0;
		
	}

	return -1;
}
//baron
int main(int argc, char* args[])
{
	int kCards[10] = {adventurer, gardens, embargo, village, minion, baron, cutpurse, sea_hag, tribute, smithy};
	struct gameState g, orig;
	int r;

	if(argc != 3)
	{
		printf("Usage: randomtestcard1 seed secondsToRun\n");
		return -1;
	}
	int seed = atoi(args[1]);
	int secondsLeft = atoi(args[2]);

	srand(seed);
	initializeGame(2, kCards, seed, &orig);

	printf("Running randomtestcard1 for %d seconds\n", secondsLeft);
	clock_t start = clock();
	while(1)
	{
		clock_t totalTime = (clock() - start) / CLOCKS_PER_SEC;
		if(totalTime >= secondsLeft)
			break;


		memcpy(&g, &orig, sizeof(struct gameState));

		int numHand = rand() % 10;
		for(int i = 0; i < numHand; ++i)
		{
			int randCard = rand() % (treasure_map+1);
			g.hand[0][i] = randCard;
		}
		g.handCount[0] = numHand;
		gainCard(baron, &g, 2, 0);

		int numEstates = 0;
		for(int i = 0; i < numHandCards(&g); ++i)
			if(handCard(i, &g) == estate)
				numEstates++;

		
		int oldTotalCards = fullDeckCount(0, &g);
		int totalCoins = updateCoins(0, &g);
		int estateSupp = supplyCount(estate, &g);
		int randOption = rand() % 2;
		r = playCard(numHandCards(&g)-1, randOption, 0, 0, &g);
		int newCoins = updateCoins(0, &g);
		myAssert(r == 0, "Played card failed", __LINE__);
		myAssert(g.numBuys == 2, "Did not get a buy", __LINE__);

		int newEstates = 0;
		for(int i = 0; i < numHandCards(&g); ++i)
			if(handCard(i, &g) == estate)
				newEstates++;

		//move playedCards into discard
		endTurn(&g);

		//wants to discard and has estates
		if(randOption && numEstates)
		{
			myAssert(newEstates == numEstates-1, "Did not discard estate when had/wanted to", __LINE__);
			myAssert(newCoins == totalCoins+4, "Did not get 4 coins for discarding estate", __LINE__);
			r = myAssert(oldTotalCards == fullDeckCount(0, &g), "Lost cards", __LINE__);
		}
		//wants to discard but has no estates
		else if(randOption && !numEstates)
		{
			myAssert(estateSupp-1 == supplyCount(estate, &g), "Did not gain estate when had none to discard", __LINE__);
			myAssert(newCoins == totalCoins, "Coins are not the same after forced to gain an estate", __LINE__);
			r = myAssert(oldTotalCards+1 == fullDeckCount(0, &g), "Incorrect total card count", __LINE__);
		}
		//did not want to discard
		else
		{
			myAssert(estateSupp-1 == supplyCount(estate, &g), "Did not gain estate", __LINE__);
			myAssert(newCoins == totalCoins, "Coins are not the same after gaining estate", __LINE__);
			r = myAssert(oldTotalCards+1 == fullDeckCount(0, &g), "Incorrect total card count", __LINE__);
		}
		
		if(r != 0)
			break;
	}

	r = myAssert(1, "", __LINE__);
	if(r == 0)
		printf("Tests completed successfully\n");

	return 0;
}
Example #9
0
int main (int argc, char** argv) {
	int y = 0;
	int l = 0;
	int moneyError = 0; 
	srand (SEED_VALUE);
	struct gameState G;
	struct gameState *p = &G;
	struct posTrack o;
	struct posTrack *pt = &o;
	int z;
	int breakNum = 0;
	int * k = malloc(sizeof(int)*10);
	for(;y<NUM_GAMES;y++){
		p = newGame();
		k = getCard(); //get random kingdom cards; 
		//ger Random Number of Players
		int numPlayers = (rand() % 2) + 2;
		printf("-------------------------------------\n");
		printf ("Starting game with %d players.\n", numPlayers);
		printf("-------------------------------------\n");
		int countTurn = 0;
		initializeGame(numPlayers, k,5, p);
		int money = 0;
		int i=0;


		while (!isGameOver(p)) {
		if(countTurn >= 100){
			break;
			moneyError++;}
			
		printf("Start player %d's turn\n", p->whoseTurn);
		
		if(countTurn % numPlayers != p->whoseTurn){
			breakNum++;
			break;	
			}			//If a player gets skipped. end the game 
		structInitializer(pt);
		money = 0;
		money = setPos(pt,p); //gets card positions and money amount
		int hold = countPlayable(p); //counts action cards in hand
		int track = 0; //tracker that makes sure we don't check for another action card when all have been played
		int * playableCards = malloc(sizeof(int)*hold);
		int * cardPos = malloc(sizeof(int)*hold);
		makePlayable(p, playableCards);
		storePlayable(p,cardPos);
		if(hold != 0){ // if there is 1 or more action cards
			printf("Cards Played:");
			while(p->numActions != 0 && track < hold){ // while there are still actions left and not all the actions cards have been played
				playCard(playableCards[track], -1,-1,-1,p);
				if(printCard(cardPos[track]) != "Nothing")
					printf(" %s, ", printCard(playableCards[track]));
				track++;
			}
			printf("\n");
		}
		else
			printf("Nothing played.\n");
			money = 0;
			i=0;
			while(i<numHandCards(p)){
			  if (handCard(i, p) == copper){
				playCard(i, -1, -1, -1, p);
				money++;
			  }
			  else if (handCard(i, p) == silver){
				playCard(i, -1, -1, -1, p);
				money += 2;
			  }
			  else if (handCard(i, p) == gold){
				playCard(i, -1, -1, -1, p);
				money += 3;
			  }
			  i++;
			} 
		  printf("Total money: %d\n", money);
		  if (money >= 8) {
			buyCard(province, p);
			printf("%s bought\n",printCard(province));
		  }
		  else if (money >= 6) {
			z = rand() % 3;
			if(z == 0){
				buyCard(gold, p);
				printf("%s bought\n",printCard(gold));
				}
			else if(z == 1)
				buyCost5(p,k); //buys random kingdom card that is 5
		  }
		  else if ((money >= 4)) 
				buyCost4(p,k); //buys random card that costs 4
		  else if ((money >= 3)){
			z = rand() %2;
			if( z==0){
				buyCard(silver,p);
				printf("%s bought\n",printCard(silver));
				}
			else
				buyCost3(p,k); //buys random card that costs 3
		  
		  }
		  else if ((money >= 2)){
			z = rand() %2;
			if ( z == 0){
				buyCard(estate,p);
				printf("%s bought\n",printCard(estate));
				}
			else
				buyCost2(p,k);
			}
		  printf("%d: end turn\n", p->whoseTurn);
		  endTurn(p);
		for(l=0;l<numPlayers;l++)
			printf ("Player %d: %d\n", l, scoreFor(l, p));
		 // End of Game
		 countTurn++;
		}
		int * players;
		players = malloc(sizeof(int)*4);
		getWinners(players,p);
		printf ("Finished game.\n");
		for(l=0;l<numPlayers;l++)
			printf ("Score for Player %d: %d\n", l, scoreFor(l, p));
		for(l=0; l<4;l++){
			if(players[l] == 1)
				printf("Player %d wins!\n", l);
		}
		
	}
	printf("Of %d Games: Break was ran %d times.\n", NUM_GAMES, breakNum);
	printf("Number of money count loss: %d\n", moneyError);
	return 0;
}
Example #10
0
int main()
{
	/*initialize variables needed*/
	int	i;
	int k[10] = { adventurer, council_room, feast, gardens, mine,
		remodel, smithy, village, baron, great_hall };
	int gameSeed;
	int numPlayer = 2;
	struct gameState Game;
	int currentActions, expectedActions, currentBuys, expectedBuys;
	int result, currentNumCards, numCardsAfter, cardType;
	const char* cardNames[] = { "curse", "estate", "duchy", "province", "copper", "silver", "gold", "adventurer", "council_room", "feast", "gardens", "mine", "remodel", "Adventurer", "village", "baron", "great_hall", "minion", "steward", "tribute", "ambassador", "cutpurse", "embargo", "outpost", "salvager", "sea_hag", "treasure_map" };

	/*Keep track of P0s deck & hand before & after*/
	int p_0_deckBeforeAdventurer[MAX_DECK];
	//int p_0_deckAfterAdventurer[MAX_DECK];
	//int p_0_handBeforeAdventurer[MAX_HAND];
	int p_0_handAfterAdventurer[MAX_HAND];

	/*Keep track of P1s deck before & after*/
	int p_1_deckBeforeAdventurer[MAX_DECK];
	int p_1_deckAfterAdventurer[MAX_DECK];
	int p_1_handBeforeAdventurer[MAX_HAND];
	int p_1_handAfterAdventurer[MAX_HAND];

	/*initialize array of silver filled hands, starting with Adventurer*/
	int silverHand[MAX_HAND];
	for (i = 0; i < MAX_HAND; i++)
	{
		if (i == 0)
			silverHand[i] = adventurer;
		else
			silverHand[i] = silver;
	}

	/*initialize array of copper filled hands*/
	int copperHand[MAX_HAND];
	for (i = 0; i < MAX_HAND; i++)
	{
		if (i == 0)
			copperHand[i] = adventurer;
		else
			copperHand[i] = copper;
	}


	/*Starting Test #1*/
#if (NOISY_TEST==1)
	printf("Starting cardtest1.c which checks adventureCard() \n");
	printf("\n Starting Test #1 - player receives first 2 treasure cards \n");
#endif
	/*initialize gameSeed*/
	gameSeed = rand() % 1000 + 1;

	/*clear the game state*/
	memset(&Game, 23, sizeof(struct gameState));

	/*initialize game*/
	initializeGame(numPlayer, k, gameSeed, &Game);

	/*load player 0 hands with silverHand array & player 1 with copper*/
	memcpy(Game.hand[0], silverHand, sizeof(int) * MAX_HAND);
	memcpy(Game.hand[1], copperHand, sizeof(int) * MAX_HAND);

	/*load silver in the p0's deck*/
	Game.deck[0][0] = silver;
	Game.deck[0][1] = copper;
	Game.deck[0][2] = copper;
	Game.deck[0][3] = silver;
	Game.deck[0][4] = silver;
	Game.deck[0][5] = gold;

	/*Save player 0's deck*/
	for (i = 0; i < 10; i++)
	{
		p_0_deckBeforeAdventurer[i] = Game.deck[0][i];
	}

	updateCoins(0, &Game, 0);

	currentNumCards = (numHandCards(&Game));

	cardType = handCard(0, &Game);

	/*play the adventurer card*/
	result = playCard(0, 1, 2, 3, &Game);

	numCardsAfter = (numHandCards(&Game));

	/*Copy the hand after the Adventure was played*/
	for (i = 0; i < numCardsAfter; i++)
	{
		p_0_handAfterAdventurer[i] = Game.hand[0][i];
	}


#if (NOISY_TEST==1)
	if (p_0_handAfterAdventurer[currentNumCards] == p_0_deckBeforeAdventurer[currentNumCards - 1] && p_0_handAfterAdventurer[currentNumCards + 1] == p_0_deckBeforeAdventurer[currentNumCards - 2])
	{
		printf("\t Current card = %s, Expected card = %s\n", cardNames[p_0_handAfterAdventurer[currentNumCards]], cardNames[p_0_deckBeforeAdventurer[currentNumCards - 1]]);
		printf("\t Current card = %s, Expected card = %s\n", cardNames[p_0_handAfterAdventurer[currentNumCards + 1]], cardNames[p_0_deckBeforeAdventurer[currentNumCards - 2]]);
		printf(" Test #1 passed. Player received the expected cards\n");
	}
	else
	{
		printf("\t Current card = %s, Expected card = %s\n", cardNames[p_0_handAfterAdventurer[currentNumCards]], cardNames[p_0_deckBeforeAdventurer[currentNumCards - 1]]);
		printf("\t Current card = %s, Expected card = %s\n", cardNames[p_0_handAfterAdventurer[currentNumCards + 1]], cardNames[p_0_deckBeforeAdventurer[currentNumCards - 2]]);
		printf(" Test #1 FAILED! Player did not receive expected cards. \n");
	}

#endif



	/*Starting Test #2*/
#if (NOISY_TEST==1)
	printf("\n Starting Test #2 - player receives treasures from own deck \n");
#endif
	/*initialize gameSeed*/
	gameSeed = rand() % 1000 + 1;

	/*clear the game state*/
	memset(&Game, 23, sizeof(struct gameState));

	/*initialize game*/
	initializeGame(numPlayer, k, gameSeed, &Game);

	/*load player 0 hands with silverHand array & player 1 with copper*/
	memcpy(Game.hand[0], silverHand, sizeof(int) * MAX_HAND);
	memcpy(Game.hand[1], copperHand, sizeof(int) * MAX_HAND);


	/*Save player 0's deck*/
	for (i = 0; i < 10; i++)
	{
		p_0_deckBeforeAdventurer[i] = Game.deck[0][i];
	}

	updateCoins(0, &Game, 0);

	currentNumCards = (numHandCards(&Game));

	cardType = handCard(0, &Game);

	/*play the adventurer card*/
	result = playCard(0, 1, 2, 3, &Game);

	numCardsAfter = (numHandCards(&Game));

	/*Copy the hand after the Adventure was played*/
	for (i = 0; i < numCardsAfter + 2; i++)
	{
		p_0_handAfterAdventurer[i] = Game.hand[0][i];
	}


#if (NOISY_TEST==1)
	if (p_0_handAfterAdventurer[currentNumCards] == p_0_deckBeforeAdventurer[currentNumCards - 3] && p_0_handAfterAdventurer[currentNumCards + 1] == p_0_deckBeforeAdventurer[currentNumCards - 4])
	{
		printf("\t Current card = %d, Expected card = %d\n", p_0_handAfterAdventurer[currentNumCards], p_0_deckBeforeAdventurer[currentNumCards - 3]);
		printf("\t Current card = %d, Expected card = %d\n", p_0_handAfterAdventurer[currentNumCards + 1], p_0_deckBeforeAdventurer[currentNumCards - 4]);
		printf(" Test #2 passed. Player received treasure cards from deck \n");
	}
	else
	{
		printf("\t Current card = %d, Expected card = %d\n", p_0_handAfterAdventurer[currentNumCards], p_0_deckBeforeAdventurer[currentNumCards - 3]);
		printf("\t Current card = %d, Expected card = %d\n", p_0_handAfterAdventurer[currentNumCards + 1], p_0_deckBeforeAdventurer[currentNumCards - 4]);
		printf(" Test #2 FAILED! Player did not receive treasure cards from own deck. \n");
	}

#endif

	/*Starting Test #3*/
#if (NOISY_TEST==1)
	printf("\n Starting Test #3 - Adventurer doesn't affect other player's deck \n");
#endif

	/*initialize gameSeed*/
	gameSeed = rand() % 1000 + 1;

	/*clear the game state*/
	memset(&Game, 23, sizeof(struct gameState));

	/*initialize game*/
	initializeGame(numPlayer, k, gameSeed, &Game);

	/*load player 0 hands with silverHand array & player's 1 deck with copper*/
	memcpy(Game.hand[0], silverHand, sizeof(int) * MAX_HAND);
	memcpy(Game.deck[1], copperHand, sizeof(int) * MAX_HAND);


	/*save player 1's deck*/
	for (i = 0; i < 10; i++)
	{
		p_1_deckBeforeAdventurer[i] = Game.deck[1][i];
	}

	/* P0 plays the Adventurer card*/
	result = playCard(0, 1, 2, 3, &Game);

	numCardsAfter = (numHandCards(&Game));

	/*Copy p1's deck after the Adventurer was played*/
	for (i = 0; i < 10; i++)
	{
		p_1_deckAfterAdventurer[i] = Game.deck[1][i];
	}

#if (NOISY_TEST==1)
	if (memcmp(p_1_deckBeforeAdventurer, p_1_deckAfterAdventurer, 10) == 0)
	{
		printf("Test #3 passed and other player's deck was not affected! \n");
	}
	else
	{
		printf("Test #3 FAILED! Other player's deck was affected by Adventurer! \n");
	}
#endif

	/*Starting Test #4*/
#if (NOISY_TEST==1)
	printf("\n Starting Test #4 - adventurer doesn't affect other player's hand \n");
#endif

	/*initialize gameSeed*/
	gameSeed = rand() % 1000 + 1;

	/*clear the game state*/
	memset(&Game, 23, sizeof(struct gameState));

	/*initialize game*/
	initializeGame(numPlayer, k, gameSeed, &Game);

	/*load player 0 hands with silverHand array & player's 1 deck with copper*/
	memcpy(Game.hand[0], silverHand, sizeof(int) * MAX_HAND);
	memcpy(Game.deck[1], copperHand, sizeof(int) * MAX_HAND);

	/*save player 1's hand*/
	for (i = 0; i < 10; i++)
	{
		p_1_handBeforeAdventurer[i] = Game.hand[1][i];
	}

	/*P0 plays the Adventurer card*/
	result = playCard(0, 1, 2, 3, &Game);

	numCardsAfter = (numHandCards(&Game));

	/*Copy p1's hand after the Adventurer was played*/
	for (i = 0; i < 10; i++)
	{
		p_1_handAfterAdventurer[i] = Game.hand[1][i];
	}

#if (NOISY_TEST==1)
	if (memcmp(p_1_handBeforeAdventurer, p_1_handAfterAdventurer, 10) == 0)
	{
		printf("Test #4 passed and other player's hand was not affected! \n");
	}
	else
	{
		printf("Test #4 FAILED! Other player's hand was affected by Adventurer! \n");
	}
#endif

	/*Starting Test #5*/
#if (NOISY_TEST==1)
	printf("\n Starting Test #5 - ensure player doesn't receive additional actions \n");
#endif
	/*initialize gameSeed*/
	gameSeed = rand() % 1000 + 1;

	/*clear the game state*/
	memset(&Game, 23, sizeof(struct gameState));

	/*initialize game*/
	initializeGame(numPlayer, k, gameSeed, &Game);

	/*load player 0 hands with silverHand array & player 1 with copper*/
	memcpy(Game.hand[0], silverHand, sizeof(int) * MAX_HAND);
	memcpy(Game.hand[1], copperHand, sizeof(int) * MAX_HAND);

	/*load player's deck with gold*/
	memcpy(Game.deck[0], silverHand, sizeof(int) * MAX_DECK);

	updateCoins(0, &Game, 0);

	currentNumCards = (numHandCards(&Game));

	cardType = handCard(0, &Game);

	/*play the Adventurer card*/
	result = playCard(0, 1, 2, 3, &Game);

	expectedActions = 0;
	currentActions = Game.numActions;

#if (NOISY_TEST==1)
	if (expectedActions == currentActions)
	{
		printf("\t Current actions = %d, Expected actions = %d\n", currentActions, expectedActions);
		printf("Test #5 passed. \n");
	}
	else
	{
		printf("\t Current actions = %d, Expected actions = %d\n", currentActions, expectedActions);
		printf("Test #5 FAILED! Player had additional actions. \n");
	}

#endif

	/*Starting Test #7*/
#if (NOISY_TEST==1)
	printf("\n Starting Test #6 - ensure player doesn't receive additional buys \n");
#endif
	/*initialize gameSeed*/
	gameSeed = rand() % 1000 + 1;

	/*clear the game state*/
	memset(&Game, 23, sizeof(struct gameState));

	/*initialize game*/
	initializeGame(numPlayer, k, gameSeed, &Game);

	/*load player 0 hands with silverHand array & player 1 with copper*/
	memcpy(Game.hand[0], silverHand, sizeof(int) * MAX_HAND);
	memcpy(Game.hand[1], copperHand, sizeof(int) * MAX_HAND);

	/*load player's deck with gold*/
	memcpy(Game.deck[0], silverHand, sizeof(int) * MAX_DECK);

	updateCoins(0, &Game, 0);

	currentNumCards = (numHandCards(&Game));

	cardType = handCard(0, &Game);

	/*play the Adventurer card*/
	result = playCard(0, 1, 2, 3, &Game);

	expectedBuys = 1;
	currentBuys = Game.numBuys;

#if (NOISY_TEST==1)
	if (expectedBuys == currentBuys)
	{
		printf("\t Current buys = %d, Expected buys = %d\n", currentBuys, expectedBuys);
		printf("Test #6 passed.  Player did not have additional buys.\n");
	}
	else
	{
		printf("\t Current buys = %d, Expected buys = %d\n", currentBuys, expectedBuys);
		printf("Test #6 FAILED! Player had additional buys. \n");
	}

#endif


	return 0;

}
int main() {
	
	int i, test1=0, scoreTrack=10;
	int currentPlayer, money;
	struct gameState G;
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, sea_hag, great_hall, tribute, outpost};
	int r = initializeGame(2, k, 2, &G);
	assert (r ==0);
	
	///// ----------------------- game -----------------------
	while (!isGameOver(&G)) 
	{
		money=0;
		for (i = 0; i < numHandCards(&G); i++) 
		{
			/*
			if (handCard(i, &G) == outpost)
				{
				test1=numHandCards(&G);
				playCard(i, -1, -1, -1, &G);
				//assert(test1==numHandCards(&G)+2);
				}*/
			if (handCard(i, &G) == copper)
				{
				playCard(i, -1, -1, -1, &G);
				money++;
				}
			else if (handCard(i, &G) == silver)
				{
				playCard(i, -1, -1, -1, &G);
				money += 2;
				}
			else if (handCard(i, &G) == gold)
				{
				playCard(i, -1, -1, -1, &G);
				money += 3;
				}
		}	
		
		if ((supplyCount(gold, &G)==0) && (supplyCount(silver, &G)==0))
		{
			if (money >= 8) 
			{
				buyCard(province, &G);
				scoreTrack=scoreTrack+6;
			}
		}
		else if (money >= 6) 
		{
			buyCard(gold, &G);
		}
		/*
		else if (money >= 5)
		{ 
			buyCard(outpost, &G);
		}*/
		else if (money >= 3) 
		{ 
			buyCard(silver, &G);
		}
		endTurn(&G);
	}

	
}
Example #12
0
int main() {

    int i, n, deckCount = 0, error1 = 0, error2 = 0, error3 = 0, error4 = 0, error5 = 0;
    int handPos = 0;
    int seed = 2000;
    int numPlayers = floor(Random() * MAX_PLAYERS);
    int player;
    int numBefore;
    int numAfter;
    int coinsBefore;
    int coinsAfter;

    int card = 0;
    int bonus = 0;

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

	printf("----------------- Random Testing for %s Begin----------------\n", TESTCARD);
for(n = 0; n < seed; n++){
	player = floor(Random() * 2);
	G.deckCount[player] = floor(Random() * MAX_DECK);
	G.discardCount[player] = floor(Random() * MAX_DECK);
	G.handCount[player] = floor(Random() * MAX_HAND);	
	numPlayers = floor(Random() * MAX_PLAYERS);

	// initialize a game state and player cards
	initTestGame(numPlayers, k, seed, &G);



	

	/*************** TEST 1: Two treasure cards are revealed ***********/
	

	// copy the game state to a test case
	memcpy(&testG, &G, sizeof(struct gameState));
	player = testG.whoseTurn;

	// make sure the player has treasure cards
	gainCard(copper,&testG,1,player);
	gainCard(silver,&testG,1,player);
	gainCard(gold,&testG,1,player);

	// record coin amount before card is played
	updateCoins(player, &testG, 0);
	coinsBefore = testG.coins;


	// fill players deck with gardens cards
	for (i = deckCount; i < (deckCount + 5); i++)
	{
        	gainCard(k[rand() % 9 + 1],&testG,1,player);
      	}

	// give player an adventurer card and play it
	gainCard(adventurer,&testG,2,player);
	cardEffect(card, 0, 0, 0, &testG, handPos, &bonus);

	// get coin amounts after card is played
	updateCoins(player, &testG, 0);
	coinsAfter = testG.coins;

	endTurn(&testG);


	// this will fail due to the altered dominion.c code
	if(coinsAfter != 5)
	{	printf("Error 1 'Two treasure cards in deck' Expected: 5, Actual: %d\n", coinsAfter);
		error1++;
	}
	if(numHandCards(&testG) != (numHandCards(&G) + 1))
	{ 	printf("Error 5 'Number of cards in hand updated' Expected: %d, Actual: %d\n", (numHandCards(&G) + 1), numHandCards(&testG));
		error5++; 
	}




	/*************** TEST 2: No treasure cards in deck ***********/
	

	// copy the game state to a test case
	memcpy(&testG, &G, sizeof(struct gameState));
	player = testG.whoseTurn;

	// record coin amount before card is played
	updateCoins(player, &testG, 0);
	coinsBefore = testG.coins;

	// fill players deck with gardens cards
	for (i = deckCount; i < (deckCount + 5); i++)
	{
        	gainCard(k[rand() % 9 + 1],&testG,1,player);
      	}

	// give player an adventurer card and play it
	gainCard(adventurer,&testG,2,player);
	cardEffect(card, 0, 0, 0, &testG, handPos, &bonus);

	// get coin amounts after card is played
	updateCoins(player, &testG, 0);
	coinsAfter = testG.coins;

	endTurn(&testG);

	// test fails if player gains coins from playing the adventurer card	
	if(coinsAfter != 0)
	{	printf("Error 2 'No treasure cards in deck' Expected: 0, Actual: %d\n", coinsAfter);
		error2++;//printf("PASS: No treasure cards in deck\n\n\n");
		
	}
	if(numHandCards(&testG) != numHandCards(&G))
	{	printf("Error 5 'Number of cards in hand updated' Expected: %d, Actual: %d\n", numHandCards(&G), numHandCards(&testG));
		 error5++; 
	}



	/*************** TEST 3: One treasure card in deck ***********/
	

	// copy the game state to a test case
	memcpy(&testG, &G, sizeof(struct gameState));
	player = testG.whoseTurn;

	// record coin amount before card is played
	gainCard(copper,&testG,1,player);
	
	updateCoins(player, &testG, 0);
	coinsBefore = testG.coins;

	// fill players deck with gardens cards
	for (i = deckCount; i < (deckCount + 5); i++)
	{
        	gainCard(k[rand() % 9 + 1],&testG,1,player);
      	}

	// give player an adventurer card and play it
	gainCard(adventurer,&testG,2,player);
	cardEffect(card, 0, 0, 0, &testG, handPos, &bonus);

	// get coin amounts after card is played
	updateCoins(player, &testG, 0);
	coinsAfter = testG.coins;

	endTurn(&testG);

	// test fails if player gains no coins from playing the adventurer card
	// will fail due to altered dominion.c code
	if(coinsAfter == 0)
	{	printf("Error 3 'One treasure card in deck' Expected: 1, Actual: %d\n", coinsAfter);
		error3++;//printf("PASS: One treasure card in deck\n\n\n");
		
	}
	if(numHandCards(&testG) != numHandCards(&G))
	{ 	printf("Error 5 'Number of cards in hand updated' Expected: %d, Actual: %d\n", numHandCards(&G), numHandCards(&testG));
		error5++; 
	}



	/*************** TEST 4: All revealed non-treasure cards are discarded ***********/
	

	// copy the game state to a test case
	memcpy(&testG, &G, sizeof(struct gameState));
	player = testG.whoseTurn;

	// give player treasure cards and record card amounts before card is played
	gainCard(silver,&testG,1,player);
	gainCard(silver,&testG,1,player);
	gainCard(silver,&testG,1,player);
	numBefore = numHandCards(&testG);

	// fill players deck with gardens cards
	for (i = deckCount; i < (deckCount + 5); i++)
	{
        	gainCard(k[rand() % 9 + 1],&testG,1,player);
      	}

	// give player an adventurer card and play it
	gainCard(adventurer,&testG,2,player);
	cardEffect(card, 0, 0, 0, &testG, handPos, &bonus);

	// get card amounts after card is played
	oldG = testG;	
	endTurn(&testG);
	numAfter = numHandCards(&oldG);


	// test passes if player's hand cointains only the adventurer card 
	if(numAfter != (numBefore + 1))
	{	printf("Error 4 'All revealed non-treasure cards discarded' failed. Expected: %d, actual: %d\n", (numBefore+1), numAfter);
		error4++;	
	}
	

    }

	


	printf("\n >>>>> SUCCESS: Random Testing Complete for %s <<<<<\n\n", TESTCARD);
	printf("Error 1 'Two treasure cards in deck' failed %d of %d times\n", error1, seed);
	printf("Error 2 'No treasure cards in deck' failed %d of %d times\n", error2, seed);
	printf("Error 3 'One treasure card in deck' failed %d of %d times\n", error3, seed);
	printf("Error 4 'All revealed non-treasure cards discarded' failed %d of %d times\n", error4, seed);
	printf("Error 5 'Number of cards in hand updated' failed %d of %d times\n\n\n\n", error5, (seed * 3));

	return 0;
}
int main(int argc, char**argv){

   struct gameState Game;
   struct gameState *Ga = &Game;
   int players, ranCard, i;
   int money, cardPos, curPlayer, useCard, returnCard, buyCa;
   int k[10];
   int pool[20] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall, minion, steward, tribute, ambassador, cutpurse, embargo, outpost, salvager, sea_hag, treasure_map};

   srand(atoi(argv[1]));
   players = rand()% 3 + 2;
   ranCard = rand() % 20;

   for(i=0;i<10;i++){
      k[i] = pool[(ranCard+i)%20];
   }

   printf("Starting Game\n");
   initializeGame(players,k,atoi(argv[1]),Ga);
   printf("Number of player %d\n",players);

   while(!isGameOver(Ga)){
      money = 0;
      cardPos = -1;
      curPlayer = whoseTurn(Ga);
      for(i=0;i<numHandCards(Ga);i++){
	 if (handCard(i,Ga) == copper)
	    money++;
	 else if(handCard(i,Ga) == silver)
	    money += 2;
	 else if(handCard(i,Ga) == gold)
	    money += 3;
	 else if(handCard(i,Ga) > 6)
	    cardPos = i;
      }
      if(cardPos != -1){
     	useCard = handCard(cardPos,Ga);
      	printf("Player %d: is playing card %d\n",curPlayer,useCard);
      	returnCard = playCard(cardPos,1,1,1,Ga);
      	if(returnCard== -1)
		 printf("Playing card Failed\n",useCard);
      	else
		 printf("Playing card %d Succeded\n",useCard);
      }
      buyCa = k[rand()%10];
      printf("Player %d has %d coins\n",curPlayer,money);

      if (money >= 8){
	 printf("Player %d is trying to buy province\n",curPlayer);
	 if(buyCard(province,Ga)==-1){
	    printf("Buying Province Failed\n");}
      }
      else if (money >= getCost(buyCa)){
	 printf("Player %d is trying to by card %d \n"layer,buyCa);
	 if(buyCard(buyCa,Ga)==-1){
	    printf("Buying %d Failed\n", buyCa);}
      }
      else if (money >= 6){
	 printf("Player %d is trying to buy gold\n",curPlayer);
	 if(buyCard(gold,Ga)==-1){
	    printf("Buying Gold Faile\n");}
      }
      else if (money >= 3){
	 printf("Player %d is trying to buy silver\n",curPlayer);
	 if (buyCard(silver,Ga)==-1){
	    printf("Buying Silver Failed\n");}
      }
      printf("Player %d has %d Cards in hand\n",curPlayer,numHandCards(Ga));
      printf("Player %d ends turn\n",curPlayer);
      endTurn(Ga);


   };
   
   for(i=0;i<players;i++){
      printf("Player %d Score: %d\n",i,scoreFor(i,Ga));
   }


   return 0;
}
int playDominion(struct gameState *state, int k[10]) {
	int i;
	int cardPos, curCard, returnCard, toBuyCard, curPlayer, money;
	int numPlayers = state->numPlayers;

	while (!isGameOver(state)) {
    money = 0;
    curPlayer = whoseTurn(state);
    cardPos = -1;

		printf("\nPlayer %d's turn.\n", curPlayer);

		//Check money 
		for (i = 0; i < numHandCards(state); i++) {
			if (handCard(i, state) == copper) {
				money++;
			} else if (handCard(i, state) == silver) {
				money += 2;
			} else if (handCard(i, state) == gold) {
				money += 3;
			} else if (handCard(i, state) > 6) {
				cardPos = i;
			}
		}

		if (cardPos != -1) {
			curCard = handCard(cardPos, state);
			printf("Player %d plays %d\n", curPlayer, curCard);
			returnCard = playCard(cardPos, 1, 1, 1, state);
			if (returnCard == -1) {
				printf("Playing card %d failed\n", curCard);
			} else {
				printf ("Playing card %d succeded\n", curCard);
			}
		}

		toBuyCard = k[rand() % 10];
		printf("Player %d has %d coins\n", curPlayer, money);

		if (money >= 8) {
			printf("Player %d is trying to buy a province\n", curPlayer);
			if(buyCard(province, state) == -1) {
				printf("Failed to buy a province");
			}
		} else if (money >= getCost(toBuyCard)) {
			printf("Player %d is trying to buy card %s\n", curPlayer, getName(toBuyCard));
			if (buyCard(toBuyCard, state) == -1) {
				printf("Buying %s failed\n", getName(toBuyCard));
			}
		} else if (money >= 6) {
			printf("Player %d is trying to buy gold\n", curPlayer);
			if (buyCard(gold, state) == -1) {
				printf("Failed to buy gold\n");
			}
		} else if (money >= 3) {
			printf("Player %d is trying to buy silver\n", curPlayer);
			if (buyCard(silver, state) == -1) {
				printf("Failed to buy silver\n");
			}
		}
  printf("Player %d has %d cards in hand\n", curPlayer, numHandCards(state));
  printf("Player %d ends turn\n", curPlayer);
  endTurn(state);
	}

  for (i = 0; i < numPlayers; i++) {
    printf("Player %d's score: %d\n", i, scoreFor(i, state));
  }

	return 0;

}
Example #15
0
int main(int argc, char** argv) {
  struct gameState G;
  struct gameState *s = &G;
  int numPlayers;
  int seed;
  int k[10];
  int i;
  int j;
  int temp, check;
  int who;
  int r;

  if(argc != 2) {
    printf("Must give a random seed");
    return 0;
  } else {
    seed = atoi(argv[1]);
    printf("Seed is %d\n", seed);
  }

  srand(seed);
  numPlayers = rand() % 3 + 2;
  
  for(i = 0; i < 10;) {
    temp = rand() % (treasure_map - adventurer) + adventurer;
    check = 0;
    for(j = 0; j < i; j++) {
      if(temp == k[j]) {
	check = 1;
      }
    }
    if(check == 0) {
      printf("%d is in kingdom cards.\n", temp);
      k[i] = temp;
      i++;
    }
  }

  printf("Starting game with %d players.\n", numPlayers);

  initializeGame(numPlayers, k, seed, s);

  while(!isGameOver(s)) {
    who = s->whoseTurn;
    printf("Player %d turn:\n", who+1);

    //Action phase
    for(i = 0; i < numHandCards(s); i++) {
	if(handCard(i, s) <= gold) {
          continue;
	}
        if(s->numActions == 0) {
	  break;
	}
        if(handCard(i, s) == feast) {
          temp = 0;
	  if(k[temp] == adventurer) {
	    temp = 1;
	  }
	  playCard(i, temp, -1, -1, s);
	  printf("Played feast gaining %d\n", k[temp]);
	}
	else if(handCard(i, s) == mine) {
	  temp = -1;
          for(j = 0; j < numHandCards(s); j++) {
            if(handCard(j, s) == silver) { 
	      playCard(i, j, gold, -1, s);
	      printf("Played mine and upgraded to gold\n");
	      temp = 1;
	      break;
	    }
	  }
	  if(temp == 1) { break; }
          for(j = 0; j < numHandCards(s); j++) {
            if(handCard(j, s) == copper) {
	      playCard(i, j, silver, -1, s);
	      printf("Played mine and upgraded to silver\n");
	      break;
	    }
	  }
	}
	else if(handCard(i, s) == baron) {
          temp = 0;
	  for(j = 0; j < numHandCards(s); j++) {
	    if(handCard(j, s) == estate) {
              temp = 1;
	    } 
	  }
	  playCard(i, temp, -1, -1, s);
	  printf("Played baron\n");
	}
	else if(handCard(i, s) == minion) {
	  if(rand() % 2 == 0) {
	    playCard(i, 1, -1, -1, s);
	    printf("Played minion with choice 1\n");
	  } else {
	    playCard(i, 2, -1, -1, s);
	    printf("played minion with choice 2\n");
	  }
	}
	else if(handCard(i, s) == steward) {
          if(rand() % 2 == 0) {
	    playCard(i, 1, -1, -1, s);
	  } else {
	    playCard(i, 2, -1, -1, s);
	  }
	  printf("Played steward\n");
	}
	else if(handCard(i, s) == ambassador) {
	}
	else if(handCard(i, s) == embargo) {
          temp = rand() % 10;
	  playCard(i, temp, -1, -1, s);
	  printf("Played embargo on %d\n", temp);
	}
	else if(handCard(i, s) == salvager) {
	  temp = 0;
	  if(i == 0) {
	    temp = 1;
	  }
	  playCard(i, temp, -1, -1, s);
	  printf("Played salvager on %d\n", temp);
	}
	else {
	  printf("Played %d\n", i); 
	  playCard(i, -1, -1, -1, s);
	}
    }

    //Buy phase
    printf("money: %d\n", s->coins);
    if(s->coins >= 8) {
      buyCard(province, s);
      printf("Bought province\n");
    } else if(s->coins >= 6 && rand() % 2 == 0) {
      buyCard(gold, s);
      printf("Bought gold\n");
    } else if(s->coins >= 3 && rand() % 2 == 0) {
      buyCard(silver, s);
      printf("bought silver\n");
    }
    
    //give it the old college try
    
    for(i = 0; i < 15; i++) {
      temp = rand() % 10;
      r = buyCard(k[temp], s);
      if(r == 0) {
        printf("bought %d\n", k[temp]);
      }
    }
    //temp = rand() % 10;
    //buyCard(k[temp], s);
    //printf("Attempted to buy %d\n", temp);

    endTurn(s);
  }

  printf("FINAL SCORE:\n");
  for(i = 0; i < numPlayers; i++) {
    printf("Player %d: %d\n", i + 1, scoreFor(i, s));
  }
  return 0;
}
int main() {
	struct gameState G;
	FILE *out;
	int nplayers = 0, ntests=0,i=0,j=0,k[10],redo = 1,seed, currentp=0, actions =0, *played, turn, ncoins=0, buyA = -1;
	out = fopen("gameResults.out","w");
	srand(time(NULL));
	
	nplayers = rand() % 3 + 2;
	// iterate through multiple tests
	while(ntests < MAX_TESTS) {
		turn = 1;
		seed = rand();
		printf("random seed %d ", seed);
		printf("in tests\n");
		fprintf(out, "Initializing game: %d\n", ntests);
		//pick cards
		for(i=0;i < 10; i++){
			printf("stuck picking cards\n");
			//kingdom cards unique no repeats
			do {
			redo = 0;
			k[i] = rand() % 20 + 7;
			printf("%d ", k[i]);
				for(j=0; j < i; j++) {
					if(k[i] == k[j]){
						redo = 1;
					} 
				}
			} while(redo);
		}
		fprintf(out, "Kingdom cards: \n");
		for(i=0; i < 10; i++) {
			fprintf(out,"%s, ", numName(k[i]));
		}
		fprintf(out,"\n");
		initializeGame(nplayers, k, seed, &G);
		printf("past init games\n");
		//Print player hands
		/*fprintf(out, "Player hands: \n");
		for(i=0; i < nplayers; i++) {
			fprintf(out,"P%d: {\n",i);
			for(j=0; j < numHandCards(&G); j++) {
				//fprintf(out, "\tC%d: %s\n", j, numName(handCard(j, &G)));
				//debug
				fprintf(out, "\tC%d: %d\n", j, handCard(j, &G));
			}
			fprintf(out, "}\n");
		}
		*/
		
		while(!isGameOver(&G)) {
			//printf("stuck in game\n");
			currentp = whoseTurn(&G);
			//Print turn player cards and info
			fprintf(out, "-- P%d turn %d --\n Current hand: {", currentp,turn);
			for(i=0; i < numHandCards(&G); i++) {
				fprintf(out, "C%d: %s ", i, numName(handCard(i, &G)));
			}
			fprintf(out, "}\n <-- Action Phase -->\n");
			//start action phase
			actions = 0;
			ncoins = coins(&G);
			G.coins = ncoins;
			for(i=0;i < G.numActions;i++) {
				fprintf(out, "#A: %d\n", G.numActions);
				played = playing(k, &G);
				if(played == 0) {
					fprintf(out, "No playable cards\n");
					break;
				}
				fprintf(out, "Playing: %s\n Choices: %d, %d, %d\n", numName(played[0]), played[1], played[2], played[3]);
				
				if(playCard(played[0], played[1], played[2], played[3], &G) == -1)
					fprintf(out, "\tFailure to play %s\n", numName(played[0]));
			}
			
			//start buy phase
			fprintf(out, "<-- Buy Phase --> \n");
			for(i=0; i < G.numBuys; i++) {
				buyA = canBuy(k, &G);
				fprintf(out, "Buying a %s\n", numName(buyA));
				if(buyCard(buyA, &G) == -1)
					fprintf(out, "\tFailed to buy\n");
				G.coins -= getCost(buyA);
			}
			
			//end of turn
			//fprintf(out, "-- End P%d turn --\n", currentp);
			endTurn(&G);
			free(played);
			turn++;
		}
		
	
	ntests++;
	turn = 1;
	}
	fclose(out);
	return 0;
}
int main (int argc, char** argv) {
  struct gameState G;

  int i, j, players, player, handCount, deckCount, discardCount, handPos, difference, numActions, seed, coinBefore, coinAfter, testPass, testFail;

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

  int timeseed = 1457773124;
  //passing seeds: 1457773124, 1457764029, 1457764086, 1457764120, 1457764222, 1457764246
  //failing seeds: 1457764002, 1457764064, 1457764169, 1457764183, 1457764197, 1457764270

  srand(timeseed);
  players = 2;
	player = rand() % players;
  seed = rand();

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

  G.deckCount[player] = rand() % MAX_DECK; //Pick random deck size out of MAX DECK size
	G.discardCount[player] = rand() % MAX_DECK;
	G.handCount[player] = rand() % MAX_HAND;

  for (j = 0; j < G.deckCount[player]; j++) {
    G.deck[player][j] = rand() % (treasure_map + 1);
  }
  for (j = 0; j < G.handCount[player]; j++) {
    G.hand[player][j] = rand() % (treasure_map + 1);
  }
  for (j = 0; j < G.discardCount[player]; j++) {
    G.discard[player][j] = rand() % (treasure_map + 1);
  }

  //Copy state variables
  handCount = G.handCount[player];
  deckCount = G.deckCount[player];

  //test option 1
  G.hand[player][0] = steward;

  if (seed % 3 == 0) {
    G.deckCount[player] = 0;
  }

  int numCards = numHandCards(&G);
  cardEffect(steward, 1,0,0,&G,0,0);
  int numCardsAfter = numHandCards(&G);

  if(numCardsAfter - numCards == 1){
    testPass++;
  } else {
    testFail++;
  }
  //test option 2
  G.hand[player][0] = steward;

  coinBefore = G.coins;
  cardEffect(steward, 2,0,0,&G,0,0);
  coinAfter = G.coins;

  if((coinAfter-coinBefore == 2)){
    testPass++;
  } else {
    testFail++;
  }
  //test option 3
  G.hand[player][0] = steward;

  numCards = numHandCards(&G);
  cardEffect(steward, 3,0,0,&G,0,0);
  numCardsAfter = numHandCards(&G);

  if(numCards - numCardsAfter == 3){
    testPass++;
  } else {
    testFail++;
  }

  if (testFail > 0){
    printf("F\n");
  } else {
    printf("P\n");
  }
  return 0;
}
Example #18
0
static void playTurn(Node **queue1, Node **queue2, struct gameState *state) {
  // action phase
  int handPos = findCardToPlay(state);
  if (state->numActions > 0 && handPos >= 0) {
    int choice1;
    int choice2;
    int choice3;
    int card = handCard(handPos, state);
    if (card == smithy) {
      // play smithy card
      choice1 = 0;
      choice2 = 0;
      choice3 = 0;
    } else if (card == mine) {
      // play mine card
      if (hasCard(state->hand[state->whoseTurn], numHandCards(state), copper)) {
        choice1 = findCard(state->hand[state->whoseTurn], numHandCards(state), copper);
        choice2 = silver;
        playCard(handPos, choice1, choice2, 0, state);
      } else if (hasCard(state->hand[state->whoseTurn], numHandCards(state), silver)) {
        choice1 = findCard(state->hand[state->whoseTurn], numHandCards(state), silver);
        choice2 = gold;
        playCard(handPos, choice1, choice2, 0, state);
      } else if (hasCard(state->hand[state->whoseTurn], numHandCards(state), gold)) {
        choice1 = findCard(state->hand[state->whoseTurn], numHandCards(state), gold);
        choice2 = gold;
      }
      choice3 = 0;
    } else if (card == village) {
      // play village card
      choice1 = 0;
      choice2 = 0;
      choice3 = 0;
    } else {
      Verify362(card == adventurer);
      // play adventurer card
      choice1 = 0;
      choice2 = 0;
      choice3 = 0;
    }
    char play[MAX_STR_LEN] = { '\0' };
    int result = playCard(handPos, choice1, choice2, choice3, state);
    sprintf(play, "playCard(%d, %d, %d, %d, state) = %d", handPos, choice1, choice2, choice3, result);
    recordResult(queue1, queue2, state, play);
  }

  // buy phase
  int supplyPos = findCardToBuy(state);
  if (supplyPos >= 0) {
    char play[MAX_STR_LEN] = { '\0' };
    int result = buyCard(supplyPos, state);
    sprintf(play, "buyCard(%d, state) = %d", supplyPos, result);
    recordResult(queue1, queue2, state, play);
  }

  // clean-up phase
  char play[MAX_STR_LEN] = { '\0' };
  int result = endTurn(state);
  sprintf(play, "endTurn(state) = %d", result);
  recordResult(queue1, queue2, state, play);
}
Example #19
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:
   // Call ADVENTURE
   adventurer();
      while(drawntreasure<2){
	if (state->deckCount[currentPlayer] <1){//if the deck is empty we need to shuffle discard and add to deck
	  shuffle(currentPlayer, state);
	  }
	drawCard(currentPlayer, state);
	cardDrawn = state->hand[currentPlayer][state->handCount[currentPlayer]-1];//top card of hand is most recently drawn card.
	if (cardDrawn == copper || cardDrawn == silver || cardDrawn == gold)
	  drawntreasure++;
	else{
	  temphand[z]=cardDrawn;
	  state->handCount[currentPlayer]--; //this should just remove the top card (the most recently drawn one).
	  z++;
	}
      }
      while(z-1>=0){
	state->discard[currentPlayer][state->discardCount[currentPlayer]++]=temphand[z-1]; // discard all cards in play that have been drawn
	z=z-1;
      }
      return 0;
			
    case council_room:
      //+4 Cards
      for (i = 0; i < 4; i++)
	{
	  drawCard(currentPlayer, state);
	}
			
      //+1 Buy
      state->numBuys++;
			
      //Each other player draws a card
      for (i = 0; i < state->numPlayers; i++)
	{
	  if ( i != currentPlayer )
	    {
	      drawCard(i, state);
	    }
	}
			
      //put played card in played card pile
      discardCard(handPos, currentPlayer, state, 0);
			
      return 0;
			
    case feast:
      //gain card with cost up to 5
      //Backup hand
      for (i = 0; i <= state->handCount[currentPlayer]; i++){
	temphand[i] = state->hand[currentPlayer][i];//Backup card
	state->hand[currentPlayer][i] = -1;//Set to nothing
      }
      //Backup hand

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

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

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

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

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

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

	}
      }     

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

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

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

      gainCard(choice2, state, 2, currentPlayer);

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

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

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

      gainCard(choice2, state, 0, currentPlayer);

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

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


      return 0;
		
    case smithy:
      //+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;
}
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
{
  int i = 0;
  int j = 0;
  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 adventurerCard(currentPlayer, handPos, state, drawntreasure, cardDrawn, temphand);

			
			
			//Edit ****************************************
    case council_room:
		council_room_func(card, state, handPos, bonus, currentPlayer);
			
		return 0;
		
    case feast:

		//Checking supply and cost requirements
		if(supplyCount(choice1, state) <= 0 || getCost(choice1) > 5) return -1;

      //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");
		return -1;
		}
	}
    if (DEBUG){
		printf("Coins: %d < %d\n", state->coins, getCost(choice1));
	}
		
	else{


		//Add new card to discard
		gainCard(choice1, state, 0, currentPlayer);
		
		//remove feast!
		discardCard(handPos, currentPlayer, state, 1);

		return 0;
			
    case gardens:
      return -1;
			
			//Edit 2 *********************************************************************************************************************
    case mine:
		
		i = mine_func(card, i, j, choice1, choice2, state, handPos, bonus, currentPlayer);
			
        return i;
			//Edit 3 *********************************************************************************************************************
    case remodel:
		i=remodel_func(card, i, j, choice1, choice2, state, handPos, bonus, currentPlayer);


      return i;
		
    case smithy:
      smithy_func(card, i, j, choice1, choice2, state, handPos, bonus, currentPlayer);
      return 0;
		
    case village:
      village_func(card, i, j, choice1, choice2, state, handPos, bonus, currentPlayer);
      return 0;
		
    case baron:
		//increment purchase number
		state->numBuys++;
		
		if(choice1) //Checking bool if we going to discard victory card
		{
			for( i = 0; i < state->handCount[currentPlayer]; ++i)
			{
				if(state->hand[currentPlayer][i] == estate)
				{
					//increamenting coins
					state->coins += 4;
					//discard victory card
					discardCard(i, currentPlayer, state, 0); 
					//discard baron
					discardCard(baron, currentPlayer, state, 0); 
					return 0;
				}
			}

			
		}
		//No estate found, going to get one
		gainCard(estate, state, 0, currentPlayer); //try to get estate

		discardCard(handPos, currentPlayer, state, 0); //discard baron
		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 = (currentPlayer+1)%state->numPlayers; i != currentPlayer; i = (i+1)%state->numPlayers)
		{
		if (drawCard(i, state) != 1){
		  PUSH(discard, i, POP_R(hand, i));
		}  
		  gainCard(curse, state, 1, i);
		
	}
	discardCard(handPos, currentPlayer, state, 0);

	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;
	}
}
int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
{
	int i;
	int j;
	int k;
	int index;
	int currentPlayer = whoseTurn(state);
	int nextPlayer = currentPlayer + 1;

	int tributeRevealedCards[2] = {-1, -1};
	int drawntreasure=0;
	if (nextPlayer > (state->numPlayers - 1)){
		nextPlayer = 0;
	}
  
	
	//uses switch to select card and perform actions
	switch( card ) 
		{
		case adventurer:
			return adventurerCard (drawntreasure, state, currentPlayer);
		case council_room:
			return councilRoomCard (currentPlayer, state, handPos);
		case feast:
			return feastCard (currentPlayer, state, choice1);			
		case gardens:
			return -1;			
		case mine:
			return mineCard (currentPlayer, state, choice1, choice2, handPos);
		case remodel:
			return remodelCard (currentPlayer, state, choice1, choice2, handPos);
		case smithy:
			//+3 Cards
			for (i = 0; i < 3; i++)
				{
					drawCard(currentPlayer, state);
				}
			
			//discard card from hand
			discardCard(handPos, currentPlayer, state, 0);
			return 0;
		
		case village:
			//+1 Card
			drawCard(currentPlayer, state);
			
			//+2 Actions
			state->numActions = state->numActions + 2;
			
			//discard played card from hand
			discardCard(handPos, currentPlayer, state, 0);
			return 0;
		
		case baron:
			state->numBuys++;//Increase buys by 1!
			if (choice1 > 0){//Boolean true or going to discard an estate
				int p = 0;//Iterator for hand!
				int card_not_discarded = 1;//Flag for discard set!
				while(card_not_discarded){
					if (state->hand[currentPlayer][p] == estate){//Found an estate card!
						state->coins += 4;//Add 4 coins to the amount of coins
						state->discard[currentPlayer][state->discardCount[currentPlayer]] = state->hand[currentPlayer][p];
						state->discardCount[currentPlayer]++;
						for (;p < state->handCount[currentPlayer]; p++){
							state->hand[currentPlayer][p] = state->hand[currentPlayer][p+1];
						}
						state->hand[currentPlayer][state->handCount[currentPlayer]] = -1;
						state->handCount[currentPlayer]--;
						card_not_discarded = 0;//Exit the loop
					}
					else if (p > state->handCount[currentPlayer]){
						if(DEBUG) {
							printf("No estate cards in your hand, invalid choice\n");
							printf("Must gain an estate if there are any\n");
						}
						if (supplyCount(estate, state) > 0){
							gainCard(estate, state, 0, currentPlayer);
							state->supplyCount[estate]--;//Decrement estates
							if (supplyCount(estate, state) == 0){
								isGameOver(state);
							}
						}
						card_not_discarded = 0;//Exit the loop
					}
			    
					else{
						p++;//Next card
					}
				}
			}
			    
			else{
				if (supplyCount(estate, state) > 0){
					gainCard(estate, state, 0, currentPlayer);//Gain an estate
					state->supplyCount[estate]--;//Decrement Estates
					if (supplyCount(estate, state) == 0){
						isGameOver(state);
					}
				}
			}
	    
      
			return 0;
		
		case great_hall:
			//+1 Card
			drawCard(currentPlayer, state);
			
			//+1 Actions
			state->numActions++;
			
			//discard card from hand
			discardCard(handPos, currentPlayer, state, 0);
			return 0;
		
		case minion:
			//+1 action
			state->numActions++;
			
			//discard card from hand
			discardCard(handPos, currentPlayer, state, 0);
			
			if (choice1)		//+2 coins
				{
					state->coins = state->coins + 2;
				}
			
			else if (choice2)		//discard hand, redraw 4, other players with 5+ cards discard hand and draw 4
				{
					//discard hand
					while(numHandCards(state) > 0)
						{
							discardCard(handPos, currentPlayer, state, 0);
						}
				
					//draw 4
					for (i = 0; i < 4; i++)
						{
							drawCard(currentPlayer, state);
						}
				
					//other players discard hand and redraw if hand size > 4
					for (i = 0; i < state->numPlayers; i++)
						{
							if (i != currentPlayer)
								{
									if ( state->handCount[i] > 4 )
										{
											//discard hand
											while( state->handCount[i] > 0 )
												{
													discardCard(handPos, i, state, 0);
												}
							
											//draw 4
											for (j = 0; j < 4; j++)
												{
													drawCard(i, state);
												}
										}
								}
						}
				
				}
			return 0;
		
		case steward:
			if (choice1 == 1)
				{
					//+2 cards
					drawCard(currentPlayer, state);
					drawCard(currentPlayer, state);
				}
			else if (choice1 == 2)
				{
					//+2 coins
					state->coins = state->coins + 2;
				}
			else
				{
					//trash 2 cards in hand
					discardCard(choice2, currentPlayer, state, 1);
					discardCard(choice3, currentPlayer, state, 1);
				}
			
			//discard card from hand
			discardCard(handPos, currentPlayer, state, 0);
			return 0;
		
		case tribute:
			if ((state->discardCount[nextPlayer] + state->deckCount[nextPlayer]) <= 1){
				if (state->deckCount[nextPlayer] > 0){
					tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
					state->deckCount[nextPlayer]--;
				}
				else if (state->discardCount[nextPlayer] > 0){
					tributeRevealedCards[0] = state->discard[nextPlayer][state->discardCount[nextPlayer]-1];
					state->discardCount[nextPlayer]--;
				}
				else{
					//No Card to Reveal
					if (DEBUG){
						printf("No cards to reveal\n");
					}
				}
			}
	    
			else{
				if (state->deckCount[nextPlayer] == 0){
					for (i = 0; i < state->discardCount[nextPlayer]; i++){
						state->deck[nextPlayer][i] = state->discard[nextPlayer][i];//Move to deck
						state->deckCount[nextPlayer]++;
						state->discard[nextPlayer][i] = -1;
						state->discardCount[nextPlayer]--;
					}
			    
					shuffle(nextPlayer,state);//Shuffle the deck
				} 
				tributeRevealedCards[0] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
				state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
				state->deckCount[nextPlayer]--;
				tributeRevealedCards[1] = state->deck[nextPlayer][state->deckCount[nextPlayer]-1];
				state->deck[nextPlayer][state->deckCount[nextPlayer]--] = -1;
				state->deckCount[nextPlayer]--;
			}    
		       
			if (tributeRevealedCards[0] == tributeRevealedCards[1]){//If we have a duplicate card, just drop one 
				state->playedCards[state->playedCardCount] = tributeRevealedCards[1];
				state->playedCardCount++;
				tributeRevealedCards[1] = -1;
			}

			for (i = 0; i <= 2; i ++){
				if (tributeRevealedCards[i] == copper || tributeRevealedCards[i] == silver || tributeRevealedCards[i] == gold){//Treasure cards
					state->coins += 2;
				}
		    
				else if (tributeRevealedCards[i] == estate || tributeRevealedCards[i] == duchy || tributeRevealedCards[i] == province || tributeRevealedCards[i] == gardens || tributeRevealedCards[i] == great_hall){//Victory Card Found
					drawCard(currentPlayer, state);
					drawCard(currentPlayer, state);
				}
				else{//Action Card
					state->numActions = state->numActions + 2;
				}
			}
	    
			return 0;
		
		case ambassador:
			j = 0;		//used to check if player has enough cards to discard

			if (choice2 > 2 || choice2 < 0)
				{
					return -1;				
				}

			if (choice1 == handPos)
				{
					return -1;
				}

			for (i = 0; i < state->handCount[currentPlayer]; i++)
				{
					if (i != handPos && i == state->hand[currentPlayer][choice1] && i != choice1)
						{
							j++;
						}
				}
			if (j < choice2)
				{
					return -1;				
				}

			if (DEBUG) 
				printf("Player %d reveals card number: %d\n", currentPlayer, state->hand[currentPlayer][choice1]);

			//increase supply count for choosen card by amount being discarded
			state->supplyCount[state->hand[currentPlayer][choice1]] += choice2;
			
			//each other player gains a copy of revealed card
			for (i = 0; i < state->numPlayers; i++)
				{
					if (i != currentPlayer)
						{
							gainCard(state->hand[currentPlayer][choice1], state, 0, i);
						}
				}

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

			//trash copies of cards returned to supply
			for (j = 0; j < choice2; j++)
				{
					for (i = 0; i < state->handCount[currentPlayer]; i++)
						{
							if (state->hand[currentPlayer][i] == state->hand[currentPlayer][choice1])
								{
									discardCard(i, currentPlayer, state, 1);
									break;
								}
						}
				}			

			return 0;
		
		case cutpurse:

			updateCoins(currentPlayer, state, 2);
			for (i = 0; i < state->numPlayers; i++)
				{
					if (i != currentPlayer)
						{
							for (j = 0; j < state->handCount[i]; j++)
								{
									if (state->hand[i][j] == copper)
										{
											discardCard(j, i, state, 0);
											break;
										}
									if (j == state->handCount[i])
										{
											for (k = 0; k < state->handCount[i]; k++)
												{
													if (DEBUG)
														printf("Player %d reveals card number %d\n", i, state->hand[i][k]);
												}	
											break;
										}		
								}
					
						}
				
				}				

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

			return 0;

		
		case embargo: 
			//+2 Coins
			state->coins = state->coins + 2;
			
			//see if selected pile is in play
			if ( state->supplyCount[choice1] == -1 )
				{
					return -1;
				}
			
			//add embargo token to selected supply pile
			state->embargoTokens[choice1]++;
			
			//trash card
			discardCard(handPos, currentPlayer, state, 1);		
			return 0;
		
		case outpost:
			//set outpost flag
			state->outpostPlayed++;
			
			//discard card
			discardCard(handPos, currentPlayer, state, 0);
			return 0;
		
		case salvager:
			//+1 buy
			state->numBuys++;
			
			if (choice1)
				{
					//gain coins equal to trashed card
					state->coins = state->coins + getCost( handCard(choice1, state) );
					//trash card
					discardCard(choice1, currentPlayer, state, 1);	
				}
			
			//discard card
			discardCard(handPos, currentPlayer, state, 0);
			return 0;
		
		case sea_hag:
			for (i = 0; i < state->numPlayers; i++){
				if (i != currentPlayer){
					state->discard[i][state->discardCount[i]] = state->deck[i][state->deckCount[i]-1];
					state->discardCount[i]++;
					state->deck[i][state->deckCount[i]-1] = curse;//Top card now a curse
				}
			}
			return 0;
		
		case treasure_map:
			//search hand for another treasure_map
			index = -1;
			for (i = 0; i < state->handCount[currentPlayer]; i++)
				{
					if (state->hand[currentPlayer][i] == treasure_map && i != handPos)
						{
							index = i;
							break;
						}
				}
			if (index > -1)
				{
					//trash both treasure cards
					discardCard(handPos, currentPlayer, state, 1);
					discardCard(index, currentPlayer, state, 1);

					//gain 4 Gold cards
					for (i = 0; i < 4; i++)
						{
							gainCard(gold, state, 1, currentPlayer);
						}
				
					//return success
					return 1;
				}
			
			//no second treasure_map found in hand
			return -1;
		}
	
	return -1;
}
int main(int argc, char** argv){

    int i, j, random, boolean, players, temp, money, act_x, vil_x, action, buy;

    if(argc != 2)
    {
        printf("Usage: ./testdominion [random seed]");
        return 0;
    }
    else
    {
        random = atoi(argv[1]);
    }

    srand(random);

    struct gameState g;
    struct gameState* p = &g;

    int k[10];

    for(i = 0; i < 10; i++)
    {
        temp = (rand() % 20) + 7; 
        boolean = 1;
        for(j = 0; j < i; j++)
            if(k[j] == temp)
                boolean = 0;
        if(boolean)     //If the number does not already exist
            k[i] = temp;
        else            //If the number already exists in the array
            i--;
    }

    int not_bought[10];
    int not_played[10];

    for(i = 0; i < 10; i++)
    {
        not_bought[i] = k[i];
        not_played[i] = k[i];
    }

    players = (rand() % 3) + 2;

    int r = initializeGame(players, k, random, p);

    while(!isGameOver(p))        //Loop that continues for game
    {
        for(i = 0; i < players; i++)
        {                                           //Loop the loops through each player
            action = 1;
            buy = 1;
            money = 0;            
            while(action)             //Loop that continues for each players actions
            {
                vil_x = -1;
                act_x = -1;
                for(j = 0; j < numHandCards(p); j++)    //Loop runs through hand
                {
                    if(handCard(j, p) == village)
                    {
                        vil_x = j;
                        break;
                    }
                    else if(!played(not_played, p, handCard(j, p)))
                        act_x = j;
                }
                if(vil_x > -1)
                {
                    playCard(j, -1, -1, -1, p);
                    printf("Player %d played a village\n", j);
                }
                else if(act_x > -1)
                {
                    play(act_x, p);
                    action = 0;
                }
                else
                    action = 0;
            }

            buy_card(p, not_bought, k);

            endTurn(p);
        }
    }
    print_state(p, players);
    printf("\n");
    return 0;
}