diff options
-rw-r--r-- | game.cpp | 45 | ||||
-rw-r--r-- | game.h | 2 | ||||
-rw-r--r-- | main.cpp | 22 |
3 files changed, 44 insertions, 25 deletions
@@ -317,6 +317,8 @@ bool Game::sanityCheck(Card **cards) return true; } + + void Game::discardAndDraw(Card **cards, int amount, int offset) { if (offset + amount > 5) @@ -352,22 +354,21 @@ void Game::discardAndDraw(Card **cards, int amount, int offset) } } -void Game::opponentAI(Card **cards) + + +void Game::opponentAI(int whichOpponent) { + Card **cards = getOpponentsCards(whichOpponent); if (cards == NULL) - { -#ifdef DEBUG - PRINT_COLOR(ANSI_COLOR_RED, "\ngetopponentAI(): cards parameter is NULL!\n"); -#endif return; - } struct countAndSuit tmp = numOfSameSuit(cards); if (pairOrBetter(cards)) { #ifdef DEBUG - PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, there's a pair or better\n"); + cout << ANSI_COLOR_CYAN << "\ndebug: opponent " << whichOpponent + << ", there's a pair or better" << endl << ANSI_COLOR_RESET; #endif /* discard 4 other cards*/ return; @@ -376,7 +377,8 @@ void Game::opponentAI(Card **cards) else if ( (tmp = numOfSameSuit(cards)).count == 5) { #ifdef DEBUG - PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, 5 cards are of the same suit!\n"); + cout << ANSI_COLOR_CYAN << "\ndebug: opponent " << whichOpponent + << ", 5 cards are of the same suit!" << endl << ANSI_COLOR_RESET; #endif /* keep 5 cards of the same suit */ return; @@ -385,7 +387,8 @@ void Game::opponentAI(Card **cards) else if (tmp.count == 4) { #ifdef DEBUG - PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, 4 cards are of the same suit\n"); + cout << ANSI_COLOR_CYAN << "\ndebug: opponent " << whichOpponent + << ", 4 cards are of the same suit" << endl << ANSI_COLOR_RESET; #endif /* keep 4 cards of the same suit and discard 1 of different suit */ @@ -405,9 +408,11 @@ void Game::opponentAI(Card **cards) else if (doWeHaveAnAce(cards)) { -#ifdef DEBUG - PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, High Hand with Ace detected\n"); -#endif + #ifdef DEBUG + cout << ANSI_COLOR_CYAN << "\ndebug: opponent " << whichOpponent + << ", High Hand with Ace detected" << endl << ANSI_COLOR_RESET; + #endif + /* discard 4 cards */ discardAndDraw(cards, 4, 1); return; @@ -415,16 +420,20 @@ void Game::opponentAI(Card **cards) else if (sanityCheck(cards)) { -#ifdef DEBUG - PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, High Hand detected\n"); -#endif + #ifdef DEBUG + cout << ANSI_COLOR_CYAN << "\ndebug: opponent " << whichOpponent + << ", High Hand detected" << endl << ANSI_COLOR_RESET; + #endif + /* discard 3 cards */ discardAndDraw(cards, 3, 2); } -#ifdef DEBUG + #ifdef DEBUG else - PRINT_COLOR(ANSI_COLOR_RED, "\nopponentAI(): FATAL, cards did not match any of the criterias!\n"); -#endif + cout << ANSI_COLOR_RED << "\ndebug: opponent " << whichOpponent + << ", FATAL: cards did not match any of the criterias!" + << endl << ANSI_COLOR_RESET; + #endif } @@ -44,7 +44,7 @@ class Game : virtual public CardPile, public User, public Opponent bool doWeHaveAnAce(Card **); bool sanityCheck(Card **); void discardAndDraw(Card **, int, int); - void opponentAI(Card **); + void opponentAI(int); /* variables */ int handsPlayed; @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) cout << "\n> Dealing cards to the user" << endl; pokerGame->dealUserCards(); pokerGame->sortUserCards(); - cout << "> Cards in your hand: "; + cout << "Cards in your hand: "; pokerGame->printUserCards(); cout << "Number of same cards: " << @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) cout << "You have an Ace!" << endl; pokerGame->discardAndDraw( pokerGame->getUserCards(), 2, 3 ); - cout << "> Cards in your hand after discarding: "; + cout << "Cards in your hand after discarding: "; pokerGame->printUserCards(); cout << "\n> Dealing cards to opponent(s)" << endl; @@ -61,12 +61,22 @@ int main(int argc, char *argv[]) pokerGame->sortOpponentCards(); #ifdef DEBUG - cout << "Opponents' cards:" << endl; + PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponents' cards:\n"); pokerGame->printOpponentCards(); - cout << "\nComputer's AI"; - pokerGame->opponentAI(pokerGame->getOpponentsCards(1)); - cout << "Resorted Opponents' cards:" << endl; + PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: \"Computer's AI\""); +#endif + + /* perform AI for each opponent */ + int i; + for (i = 0; i < pokerGame->numOfOpponents; i++) + pokerGame->opponentAI(i+1); + + /* resort the cards after the AI */ + pokerGame->sortOpponentCards(); + +#ifdef DEBUG + PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: resorted opponents' cards:\n"); pokerGame->printOpponentCards(); PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: deck after being delt to opponents and user\n"); |