Hello
I am writing a program that will be just like texas holdem.
I have a question about how to score the hands. I was wondering if there was an easier way to make sure you have the right cards in your hand to be able to score it.
I mean if you have a royal flush you have a 10,j,q,k,a in the same suit. And for a flush you have any five card sequence in the same suit. (eg. 8,9,10,J,Q and A, 2,3,4,5 of same suit). All the cards are of the same suit, and all are consecutive i dont even know if this is right or not I guess what i am asking is, is there a way to shorten my if statment?

here...this is what I was thinking, instead of what I have up top. Is there an easier way to write the outcome instead of having to write out every single outcome there could be.
this is what im going off from:

Royal Flush:
Five card sequence from 10 to the Ace in the same suit (10,J,Q,K,A).

Straight Flush:
Any five card sequence in the same suit. (eg. 8,9,10,J,Q and A, 2,3,4,5 of same suit). All the cards are of the same suit, and all are consecutive. Ranking between straights is determined by the value of the high end of the straight.

Four of a Kind: All four cards of the same index (eg. J,J,J,J).

Full House:
Three of a kind combined with a pair (eg. A,A,A,5,5). Ties on a full house are broken by the three of a kind, as you cannot have two equal sets of three of a kind in any single deck.

Flush:
Any five cards of the same suit, but not in sequence. Don't be tricked into thinking that all five cards are the same color. The high card determines the winner if two or more people have a flush.

Straight:
Five cards in sequence, but not in the same suit. A straight cannot wrap, meaning it is not a straight if you have a Queen, King, Ace, Two, Three. The higher straight wins if two or more people have a straight. In case of straights that tie, the pot is split.

Three of a Kind:
Three cards of the same value. The highest set of three cards wins.

Two Pair:
Two seperate pairs (eg. 4,4,Q,Q). As usual the pair with the higher value is used to determine the winner of a tie.

Pair:
One pair of two equal value cards constitutes a pair.

High Card:
If no one has any of the above winning hands, the tie is determined by the highest value card in the hand. If the highest cards are a tie then the tie is broken by the second highest card. Suits are not used to break ties.

if()//not sure of how to write the if statements
{
cout<<"You have a Royal Flush"<<endl;
playerhandscore=10;
}
if()
{
cout<<"You have a Flush"<<endl;
playerhandscore=9;
}
if()
{
cout<<"You have four of a kind"<<endl;
playerhandscore=8;
}
if()
{
cout<<"You have a full house"<<endl;
playerhandscore=7;
}
if()
{
cout<<"You have a flush"<<endl;
playerhandscore=6;
}
if()
{
cout<<"You have a straight"<<endl;
playerhandscore=5;
}
if()
{
cout<<"You have three of a kind"<<endl;
playerhandscore=4;
}
if()
{
cout<<"You have two pair"<<endl;
playerhandscore=3;
}
if()
{
cout<<"You have a pair"<<endl;
playerhandscore=2;
}
if()
{
cout<<"Nobody has anything, you have a high card"<<endl;
playerhandscore=1;
}

}

12-08-2010

nimitzhunter

Code:

card1==10,11,12,13,1

card1 is only an interger per your argument. I assume you're trying to compare arrays. If so, compare them element by element; and use "int * card1" instead of "int card1" to pass in the array.

Before you attempt to assign values to winning hands, why don't you write a program to sort the cards first.

here's one function to check for a straight, maynot be the best algorithm:

There are several other problems with this code besides not giving you random cards.
Maybe you are aware of these issues and they're just caused by carelessness (doing things too quickly or something like that).

You have an infinite loop because you used:

for(int i=13;i>0;i++) // i = 13 sets i to a number larger then 0, adding to it never makes it
// less then or equal to 0

changing i++ to i-- fixes this

Your 'A' char isn't returned, and your '10' char is returned as 0

Changing char to char* and using " instead of ' fixes the return of 10.
Adding a "", before "A" fixes the return of A.

Your "of Spades" char isn't returned.

Adding a "", before "of Spades" fixes the return of of Spades.

after all those changes your code would look like this (added some spaces here and there to make things more readable for me):