From ea1022bb593ad714e1123951182ab540ab498d24 Mon Sep 17 00:00:00 2001 From: Kyle K Date: Sat, 29 Jan 2011 22:14:31 -0600 Subject: mild refactoring --- game.cpp | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'game.cpp') diff --git a/game.cpp b/game.cpp index 6325731..5f2b3a1 100644 --- a/game.cpp +++ b/game.cpp @@ -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 } -- cgit v1.2.3