summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2011-02-03 13:31:12 -0600
committerKamil Kaminski <kamilkss@gmail.com>2011-02-03 13:31:12 -0600
commite58830a28eb89d8a3d885e3ec15e4bc993aed263 (patch)
tree6a378603c90e86fed6f0cd7748af116c5a7591fa
parent88cc199bd6ece7a21b094849e4971abb92f238ba (diff)
downloadpoker-e58830a28eb89d8a3d885e3ec15e4bc993aed263.tar.gz
poker-e58830a28eb89d8a3d885e3ec15e4bc993aed263.tar.bz2
poker-e58830a28eb89d8a3d885e3ec15e4bc993aed263.zip
finalize ties
-rw-r--r--game.cpp52
1 files changed, 40 insertions, 12 deletions
diff --git a/game.cpp b/game.cpp
index 03a66f0..550b2a8 100644
--- a/game.cpp
+++ b/game.cpp
@@ -898,7 +898,6 @@ void Game::showHands(void)
void Game::determineWinner(void)
{
/* check for 'whatHand' variable from User and Opponent class */
-
int numOfPlayers = 1 + numOfOpponents;
int *playerHands = new int[numOfPlayers]();
@@ -937,24 +936,53 @@ void Game::determineWinner(void)
#ifdef DEBUG
if (numOfTies > 1)
cout << ANSI_COLOR_CYAN << "\ndebug: there's a tie between " << numOfTies
- << " players" << endl << ANSI_COLOR_RESET;
+ << " players, same hands detected" << endl << ANSI_COLOR_RESET;
#endif
-#if 0
- /* deal with ties */
- int j, k, rank1, rank2;
- for (i = 0; i < 5; i++)
+ int maxFoundAt = -1;
+
+ if (numOfTies > 1)
{
- if (ties[i] == false)
- continue;
+ int tmpRank = 0;
+ int maxRank = 0;
+ int numOfAssignmentsMade = 0;
+ Card **cards = NULL;
- for (j = 0; j < 5; j++)
+ int j;
+ /* for all cards */
+ for (i = 0; i < 5; i++)
{
- if ((i == j) || (ties[j] == false))
- continue;
+ if (numOfAssignmentsMade > 1)
+ break;
+
+ numOfAssignmentsMade = 0;
+
+ /* for all players */
+ for (j = 0; j < numOfPlayers; j++)
+ {
+ if (ties[j] == false)
+ continue;
+
+ if (j == 0)
+ cards = getUserCards();
+ else
+ cards = getOpponentsCards(j);
+
+ tmpRank = cards[i]->getRank();
+ if (tmpRank > maxRank)
+ {
+ maxRank = tmpRank;
+ maxFoundAt = j;
+ numOfAssignmentsMade++;
+ }
+ }
}
}
-#endif
+
+ cout << "\nmaxFoundAt: " << maxFoundAt << endl;
+
+ if (numOfTies > 1)
+ whatIndex = maxFoundAt;
cout << ANSI_COLOR_CYAN << endl << *winmsg[whatIndex] << endl
<< ANSI_COLOR_RESET;