summaryrefslogtreecommitdiffstats
path: root/game.cpp
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2011-02-01 17:25:46 -0600
committerKamil Kaminski <kamilkss@gmail.com>2011-02-01 17:25:46 -0600
commit97290be5e03ba2299de0e0988404fb4979852b5c (patch)
treec7f57a2d8b49718a2648b8b6a9ae6e524069153c /game.cpp
parent1523b889daa27904fbc1bf2c8b722b78af7db917 (diff)
downloadpoker-97290be5e03ba2299de0e0988404fb4979852b5c.tar.gz
poker-97290be5e03ba2299de0e0988404fb4979852b5c.tar.bz2
poker-97290be5e03ba2299de0e0988404fb4979852b5c.zip
baby steps
Diffstat (limited to 'game.cpp')
-rw-r--r--game.cpp51
1 files changed, 45 insertions, 6 deletions
diff --git a/game.cpp b/game.cpp
index c7b78ae..fd9806e 100644
--- a/game.cpp
+++ b/game.cpp
@@ -212,6 +212,7 @@ int Game::numOfSameCards(Card **cards)
return max;
}
+/* returns the max number of the same suit along with the suit itself */
struct countAndSuit Game::numOfSameSuit(Card **cards)
{
struct countAndSuit same[5] =
@@ -268,7 +269,7 @@ struct countAndSuit Game::numOfSameSuit(Card **cards)
return same[whereMaxWasFound];
}
-/* returns the max count of a particular card in a hand */
+/* returns the max count of a particular card in a hand */
struct countAndType Game::numOfSameType(Card **cards)
{
struct countAndType same[14] =
@@ -427,6 +428,7 @@ int *Game::whichCardsToDiscard(Card **cards)
return howManyOfSameCards;
}
+/* helper function for opponentAI */
void Game::oppDiscardFromPairOrBetter(Card **cards, int whichOpponent)
{
if (cards == NULL) {
@@ -641,7 +643,17 @@ void Game::userAI(Card **cards)
int howManyUserCanDiscard = 0;
int i;
- /* XXX: handle straight */
+ if (isInOrderByOne(cards))
+ {
+ howManyUserCanDiscard = 3;
+
+ cout << "You have a straight, you should definitely\n"
+ << "keep all of the cards but you can discard "
+ << howManyUserCanDiscard << " card(s)" << endl;
+
+ userDiscardCards(cards, howManyUserCanDiscard);
+ return;
+ }
if (pairOrBetter(cards))
{
@@ -757,6 +769,34 @@ bool Game::isInOrder(Card **cards)
return true;
}
+bool Game::hasFullHouse(Card **cards, struct countAndType *threeCount)
+{
+ if (cards == NULL) {
+ PRINT_COLOR(ANSI_COLOR_RED, "\nhasFullHouse(): cards parameter is NULL!\n");
+ return false;
+ }
+
+ int i;
+ for (i = 0; i < 5; i++)
+ if (cards[i]->getType()[0] != threeCount->type)
+ break;
+
+ int j;
+ for (j = 0; j < 5; j++)
+ if ((cards[j]->getType()[0] != threeCount->type) && i != j)
+ break;
+
+ bool ret = cards[i]->getType()[0] == cards[j]->getType()[0];
+
+#ifdef DEBUG
+ cout << ANSI_COLOR_CYAN << "\ndebug: hasFullHouse(): does " << cards[i]->getType()
+ << " have the same value as " << cards[j]->getType() << "? " << ret
+ << endl << ANSI_COLOR_RESET;
+#endif
+
+ return ret;
+}
+
bool Game::hasTwoPairs(Card **cards)
{
if (cards == NULL) {
@@ -787,8 +827,6 @@ void Game::evaluateHand(Card **cards, int who)
struct countAndSuit tmp = numOfSameSuit(cards);
struct countAndType tmp2 = numOfSameType(cards);
- /* XXX: Some hands need to be sorted */
-
/* royal flush */
if (haveAce && inOrderByOne && (tmp.count == 5))
whatHand = 0;
@@ -804,10 +842,11 @@ void Game::evaluateHand(Card **cards, int who)
sortFourOfAKind(cards, &tmp2);
}
- /* XXX: flawed */
/* full house */
- else if ((tmp2.count == 3) && (cards[3]->getType()[0] == cards[4]->getType()[0]))
+ else if ((tmp2.count == 3) && hasFullHouse(cards, &tmp2))
+ {
whatHand = 3;
+ }
/* flush */
else if (tmp.count == 5)