summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2011-01-29 19:09:57 -0600
committerKamil Kaminski <kamilkss@gmail.com>2011-01-29 19:09:57 -0600
commit63a098d36fcf53b2cad48d042f6efd3174d93717 (patch)
tree90f42c9dd4124476fd0f20e4500376a43406e44f
parent597f9a05c1cde173c1475ddba4830eb51e96a533 (diff)
downloadpoker-63a098d36fcf53b2cad48d042f6efd3174d93717.tar.gz
poker-63a098d36fcf53b2cad48d042f6efd3174d93717.tar.bz2
poker-63a098d36fcf53b2cad48d042f6efd3174d93717.zip
begun opponentAI
-rw-r--r--game.cpp26
-rw-r--r--main.cpp2
-rw-r--r--opponent.cpp5
-rw-r--r--opponent.h1
4 files changed, 33 insertions, 1 deletions
diff --git a/game.cpp b/game.cpp
index 7e6e866..385ff2f 100644
--- a/game.cpp
+++ b/game.cpp
@@ -288,30 +288,54 @@ void Game::discardAndDraw(Card **cards, int amount, int offset)
void Game::opponentAI(Card **cards)
{
- struct countAndSuit tmp;
+ struct countAndSuit tmp = numOfSameSuit(cards);
if (pairOrBetter(cards))
{
+ PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, there's a pair or better\n");
/* discard 4 other cards*/
return;
}
+
else if ( (tmp = numOfSameSuit(cards)).count == 5)
{
+ PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, 5 cards are of the same suit!\n");
/* keep 5 cards of the same suit */
return;
}
+
else if (tmp.count == 4)
{
+ PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, 4 cards are of the same suit\n");
/* keep 4 cards of the same suit and discard 1 of different suit */
+
+ /* we need to loop through cards[] and find a card with different suit */
+ int i;
+ for (i = 0; i < 5; i++)
+ {
+ if (cards[i]->getSuit() != tmp.whatSuit)
+ break;
+ }
+ /* no i should be the index of card that we want to discard */
+
+ discardAndDraw(cards, 1, i);
+
return;
}
+
else if (doWeHaveAnAce(cards))
{
+ PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, High Hand with Ace detected\n");
/* discard 4 cards */
+ discardAndDraw(cards, 4, 1);
+ return;
}
+
else
{
+ PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponentAI, High Hand detected\n");
/* discard 3 cards */
+ discardAndDraw(cards, 3, 2);
}
}
diff --git a/main.cpp b/main.cpp
index 9fa9d51..a01b1fb 100644
--- a/main.cpp
+++ b/main.cpp
@@ -62,6 +62,8 @@ int main(int argc, char *argv[])
cout << "Opponents' cards:" << endl;
pokerGame->printOpponentCards(pokerGame->numOfOpponents);
+ //pokerGame->opponentAI
+
#ifdef DEBUG
PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: deck after being delt to opponents and user\n");
pokerGame->printPile();
diff --git a/opponent.cpp b/opponent.cpp
index 82f297a..8c23478 100644
--- a/opponent.cpp
+++ b/opponent.cpp
@@ -42,3 +42,8 @@ void Opponent::sortOpponentCards(int opponentsAmount)
sortCards(opponentCards[j]);
}
+Card **Opponent::getOpponentsCards(int whichOpponent)
+{
+ return opponentCards[whichOpponent];
+}
+
diff --git a/opponent.h b/opponent.h
index f754561..71dc792 100644
--- a/opponent.h
+++ b/opponent.h
@@ -16,6 +16,7 @@ class Opponent : virtual public CardPile
void dealOpponentCards(int);
void printOpponentCards(int);
void sortOpponentCards(int);
+ Card **getOpponentsCards(int);
};
#endif