Exemplo n.º 1
0
void print_info(struct gameState state)
{
	printSupply(&state);
	printHand(state.whoseTurn, &state);
	printDeck(state.whoseTurn, &state);
	printDiscard(state.whoseTurn, &state);
	printPlayed(state.whoseTurn, &state);
	printState(&state);
	printScores(&state);
}
Exemplo n.º 2
0
void display(struct gameState *g,int player)
{
	printSupply(g);
	displayPlayers(g,player);
	printDeck(player,g);
	printHand(player,g);
	printDiscard(player,g);
	printDeck(player+1,g);
	printHand(player+1,g);
	printDiscard(player+1,g);
}
Exemplo n.º 3
0
int main(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};

	gameState g;
	gameState * game = &g;

	memset(game,0,sizeof(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 = game->whoseTurn;
		
		//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 = game->whoseTurn;
				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 = game->whoseTurn;
				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 =	game->whoseTurn;
			printf("Player %d's turn\n", playerNum);
		} 
    	}
	
    	return EXIT_SUCCESS;

}
Exemplo n.º 4
0
int playHand(struct gameState *game){

  if(isGameOver(game)) {
    return 0;
  }

  if(hasNegative(game)) {
    printf("Negative card count\n\r");
    return -1;
  }


  int i, count, retVal,player = whoseTurn(game);

  printf("Current Player: %d\n\r",player+1);

  game->phase=0;

  count = 0;
  while(game->handCount[player]<hand_size){
    if(hasNegative(game)) {
      printf("Error encountered: Negative card count\n\r");
      return -1;
    }
    retVal = drawCard(player,game);
    if (retVal != 0) {
      if (game->deckCount[player]+game->discardCount[player] == 0)
	break;
      else {
	printf("Error encountered in previous draw card!\n\r");
	return -1;
      }
    }
    if(count++ > MAX_HAND) {
      printf("Error encountered in previous draw card!\n\r");
      printf("Too many draw cards!\n\r");
      return -1;
    }
  }
  printf("Cards in hand: ");
  count = 0;
  for(i=0;i<game->handCount[player]; i++) {
    printCard(game->hand[player][i]);
    printf("\t");
  }

  printf("\n\r");

  count = 0;
  while(game->numActions > 0) {
    if(hasNegative(game)) {
      printf("Error encountered: Negative card count\n\r");
      return -1;
    }
    retVal = randAction(game);
    if (retVal != 0){
      printf("Error encountered in previous action!\n\r");
      return -1;
    }
    if(count++ > MAX_HAND) {
      printf("Error encountered in previous action!\n\r");
      printf("Too many actions tried!\n\r");
      return -1;
    }
  }
  count = 0;
  while(game->numBuys > 0){
    if(hasNegative(game)) {
      printf("Error encountered: Negative card count\n\r");
      return -1;
    }
    retVal = randBuy(game);
    if (retVal != 0){
      printf("Error encountered in previous buy!\n\r");
      printSupply(game);
      return -1;
    }
    if(count++ > MAX_HAND) {
      game->numBuys=0;
      /*
      printf("Error encountered in previous buy!\n\r");
      printf("Too many buys!\n\r");
      printSupply(game);
      return -1;
      */
    }
  }
  
  if(!isGameOver(game)){
    printf("End of turn\n\r");
    printf("-----------------------------------------------------------\n\r");
    endTurn(game);
  }
  if(hasNegative(game)) {
    printf("Error encountered: Negative card count\n\r");
    return -1;
  }
  
  return 0;
}