Poker Hand Eval Problem

I'm working on getting my Poker to evaluate the player hand. I can get the Flush and the jack or better pair to work but am running into problems figuring out how I would do the rest. Any suggestions on how I can evaluate the cards to the appropriate type?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    int Game::HandCheck()
    {
    	//ROYAL FLUSH
    	//return 9;
    	
    	//STRAIGHT FLUSH
    	//return 8;
    	
    	//FOUR OF A KIND
    	//return 7;
    	
    	//FULL HOUSE
    	//return 6;
    	
    	//FLUSH
    	if( currentHand[ 0 ].GetSuit() == currentHand[ 1 ].GetSuit() && currentHand[ 1 ].GetSuit() == currentHand[ 2 ].GetSuit() &&
    		currentHand[ 2 ].GetSuit() == currentHand[ 3 ].GetSuit() && currentHand[ 3 ].GetSuit() == currentHand[ 4 ].GetSuit() ) 
    		return 5;
    
    	//STRAIGHT
    	//return 4;
    	
    	//THREE OF A KIND
    	if( currentHand[ 0 ].GetValue() == currentHand[ 2 ].GetValue() && currentHand[ 0 ].GetValue() == currentHand[ 3 ].GetValue()
    	//return 3;
    	
    	//TWO PAIR
    	//return 2;
    	
    	//JACKS OR BETTER PAIR
    	for( int i = 0; i < 5; i++ )
    	{
    		if( currentHand[ i ].GetValue() == 11 || currentHand[ i ].GetValue() == 12 || currentHand[ i ].GetValue() == 13 || currentHand[ i ].GetValue() == 1 )
    		{
    			if( currentHand[ i ].GetValue() == currentHand[ i + 1 ].GetValue() || currentHand[ i ].GetValue() == currentHand[ i + 2 ].GetValue() || //pair
    			currentHand[ i ].GetValue() == currentHand[ i + 3 ].GetValue() || currentHand[ i ].GetValue() == currentHand[ i + 4 ].GetValue() )
    			return 1;
    		}
    	}
    
    	return 0;
    
    }
anyone??
How would I do a straight for example?
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.
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
Topic archived. No new replies allowed.