summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;