| | |
Check for winner and tie
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2007
Posts: 5
Reputation:
Solved Threads: 0
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.
Java Syntax (Toggle Plain Text)
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); }
•
•
Join Date: Jul 2007
Posts: 5
Reputation:
Solved Threads: 0
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...
Thanks
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...
Java Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- C++ n C (C++)
- Tic Tac Toe game (C++)
- Tic Tac Mess (C++)
- Tic-Tac-Toe Game (Visual Basic 4 / 5 / 6)
- Tic-Tac-Toe Game - Need some information or help (C++)
- Nid help...how to cre8 tic tac toe programe using C++ (Game Development)
- C++ Tic Tac Toe using classes & operator overloading (C++)
- error checking of user input (C++)
- If statement problem (Java)
Other Threads in the Java Forum
- Previous Thread: Inventory part 5
- Next Thread: RunTime error
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component database desktop draw ebook eclipse encode equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop mac main map method methods mobile netbeans newbie number object open-source oracle parameter print problem program programming project properties recursion reference replaysolutions rotatetext scanner score screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows working xstream





