Dec 8, 2011 at 4:48am UTC
How would I do a straight for example?
Dec 8, 2011 at 8:34am UTC
Most of these can be solved easily if you sort the cards by rank first.
For example, to check for a straight, just iterate through the sorted cards and see if each rank is one more than the previous card.
For two pair, check if two successive cards have the same rank, twice. Also make sure there are no more than two of the same rank.
A full house is basically the same as a two pair, but the second (or first) pair is actually a triplet.
Four of a kind can be done the same way as three of a kind.
Straight flush is just a combination of straight and flush. A royal flush is a straight flush that begins with a 10 when sorted.
Dec 8, 2011 at 10:41am UTC
Im sorting by value first so I can check. Its not done but this is my approach. Suggestions on the rest of the hand types?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
NewGame.SortByValue();
for ( int i = 0; i < 5; i++ )
tempHand[ i ] = NewGame.SetArray( i );
if ( tempHand[ 0 ].GetValue() == tempHand[ 1 ].GetValue() + 1 && tempHand[ 0 ].GetValue() == tempHand[ 2 ].GetValue() + 2 &&
tempHand[ 0 ].GetValue() == tempHand[ 3 ].GetValue() + 3 && tempHand[ 0 ].GetValue() == tempHand[ 4 ].GetValue() + 4 )
winType = 4;
//straight
//if( tempHand[ 0 ].GetValue() == tempHand[ 1 ].GetValue() && tempHand[ 1 ].GetValue() == tempHand[ 2 ].GetValue()
for ( int i = 0; i < 5; i++ )
{
if ( tempHand[ i ].GetValue() >= 11 || tempHand[ i ].GetValue() == 1 )
{
if ( tempHand[ 0 ].GetValue() == tempHand[ 1 ].GetValue() || tempHand[ 1 ].GetValue() == tempHand[ 2 ].GetValue() ||
tempHand[ 2 ].GetValue() == tempHand[ 3 ].GetValue() || tempHand[ 3 ].GetValue() == tempHand[ 4 ].GetValue() )
winType = 1;
}
}//jack or better
Last edited on Dec 8, 2011 at 10:57am UTC