Wanted to verify that this actually does check for all wins- if so I need to a statement that a tie does still exist and where to add it...Opinions and suggestions please.. method displayHandName() writes out the hand found.

public static void determineWinner(int[] finalHands, int[][] hands) throws
IOException
{
int maxHand = 0; // The best hand value seen so far.
int winner = 0; // The winner.
// Look at each player's hand to find the winner.
for (int i = 0; i < NUM_PLAYERS; i++) {
// The current player has the best hand so far.
if (finalHands[i] > maxHand) {
maxHand = finalHands[i];
winner = i;
}
// The current player is tied with the best hand so far...
else if (finalHands[i] == maxHand)
// ... but wins on the tiebreak.
if (hands[i][0] > hands[winner][0]) {
maxHand = finalHands[i];
winner = i;
}
}
System.out.println("Hit return to see who won...");
stdin.readLine();
System.out.println("----------------------------------------------
\n");
System.out.println("PLAYER " + (winner+1) + ", YOU WIN!!!");
displayHandName(maxHand);
}

1. Poker is the game...
2. Checking for the best of hands to determine winner.
3. Ties are possible...but I do not think my code handes the tie (ie. two straights of the same rank- different suits)

Here is determine hands if needed...

public static void displayHand(int[] hand)
{
// Display each card.
for (int card = 0; card < HAND_SIZE; card++) {
System.out.print(" " + (card+1) + ": ");
// Display the card's numerical value.
switch (hand[card] / 4) {
case 14 : System.out.print("Ace");
break;
case 13 : System.out.print("King");
break;
case 12 : System.out.print("Queen");
break;
case 11 : System.out.print("Jack");
break;
default: System.out.print(hand[card] / 4);
}
System.out.print(" of ");
// Display the card's suit.
switch (hand[card] % 4) {
case 0 : System.out.println("hearts");
break;
case 1 : System.out.println("clubs");
break;
case 2 : System.out.println("diamonds");
break;
case 3 : System.out.println("spades");
break;
}
}
System.out.println();
}

Thanks

This article has been dead for over six months. Start a new discussion instead.