summaryrefslogtreecommitdiffstats
path: root/game.cpp
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2011-01-29 22:14:31 -0600
committerKamil Kaminski <kamilkss@gmail.com>2011-01-29 22:14:31 -0600
commitea1022bb593ad714e1123951182ab540ab498d24 (patch)
treeb2009c0a9deb4ffa812d1e7d9b47a07eb7562ab4 /game.cpp
parent579915ba835cb0a1f0f893881c09e6b59c6a7f0e (diff)
downloadpoker-ea1022bb593ad714e1123951182ab540ab498d24.tar.gz
poker-ea1022bb593ad714e1123951182ab540ab498d24.tar.bz2
poker-ea1022bb593ad714e1123951182ab540ab498d24.zip
mild refactoring
Diffstat (limited to 'game.cpp')
-rw-r--r--game.cpp45
1 files changed, 27 insertions, 18 deletions
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
}