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); }
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); }
void testDeckShuffle(struct gameState* G){ int deckCount; int player= G->whoseTurn; int empty_deck[MAX_DECK]; int i; for (i = 0; i < MAX_DECK; i++) { empty_deck[i]=""; } int j; G->discardCount[player]=G->deckCount[player]; for(j=0;j<G->discardCount[player]; j++){ G->discard[player][j]= j; } printf("Test 1) Testing when deck is empty, discard pile is shuffled, then added to deck\npreconditions: deck is empty, discard is full of unique cards (to check shuffle)\npostconditions: deck has cards\n"); deckCount=G->deckCount[player]; //deck count stored G->deckCount[player]=0; // deck count in state set to zero G->hand[player][0]=7; // adventurer card put in player's hand at pos zero memcpy(G->deck[player], empty_deck, sizeof(int) * deckCount); // player's deck is emptied printf("\n(before function call, to compare with deck cards post function call)\n"); printDiscard(player,G); printf("\n(deckCount before calling play_adventurer: %d)\n",G->deckCount[player]); printf("results: \n"); play_adventurer(player,G,0); //takes player, game ptr, and hand position of adventurer card printf("(deck count after calling play_adventurer)\n - Expected: at least 1 Actual: %d\n\n", G->deckCount[player]); printf("(Visual check to see that new cards in deck are shuffled)\n"); printDeck(player,G); }
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; }