SirJames 10 Newbie Poster

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

SirJames 10 Newbie Poster

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);
}
SirJames 10 Newbie Poster

What does this do?

num=GetInteger();

you would need a scanf here...

SirJames 10 Newbie Poster

The above is undefined behavior in C?C++
https://www.securecoding.cert.org/confluence/display/cplusplus/EXP34-C.+Do+not+depend+on+order+of+evaluation+between+sequence+points
This code in Java & C# is defined, I would be:

int i,j=4;
i=j++*++j*j--;

i = 4(5) *(6)6 * 6(5) = 144- Which is what I got when running the program in Java...

Salem commented: Good answer +10
SirJames 10 Newbie Poster

I have a program evaluating a straight hand in poker: Here is my code:

int numInRank[14];

cin.get(rankCh);
    switch (toupper(rankCh))
     {
      case '-1':            exit(0);
      case '?':           rank = 0; break;
      case 'A':          rank = 1; break;
      case '2':           rank = 2; break;
      case '3':           rank = 3; break;
      case '4':           rank = 4; break;
      case '5':           rank = 5; break;
      case '6':           rank = 6; break;
      case '7':           rank = 7; break;
      case '8':           rank = 8; break;
      case '9':           rank = 9; break;
      case 'T':           rank = 10; break;
      case 'J':           rank = 11; break;
      case 'Q':          rank = 12; break;
      case 'K':          rank = 13; break;

bool isStraight(int numInRank[]){
    int count = 0;
    for(int i = 1; i  < 14; i++){
        if(numInRank[i] != 0){
            count++;
            if(i == 13 && numInRank[1] != 0) count++;
        }else{
            count = 0;
        }
        if(count == 5) return true;
    }
    return false;
}

I would like to modify the above code to handle A high and A low straights- I sized my array to 14 instead of 13 to hold both...
Any suggestions...