Page 1 of 3

### How do I create poker game?

Posted: Fri Apr 10, 2015 9:56 am
Hi guys,
I'm trying to make Poker Game in Construct. But I have no idea how to make combinations and compare cards where there are few players.

Everything i found is scirra[dot]com/forum/viewtopic.php?t=64076&start=0
But it's not enough. Any ideas?

You can check what have i done so far: dropbox[dot]com/s/9onfsh1p1o9i1a3/game.capx?dl=0

### Re: How do I create poker game?

Posted: Fri Apr 10, 2015 12:50 pm
Why not assigning to each card two constants, one for the color (1 to 4) and one for the value (1 to 13 with King = 13) ?

### Re: How do I create poker game?

Posted: Fri Apr 10, 2015 12:55 pm
And if you use 32 cards, just forget to assign values from 2 to 6.

Also, you can set the 1 value to 14, as it is the higher value in poker...

### Re: How do I create poker game?

Posted: Fri Apr 10, 2015 8:21 pm
ok..that's the easy part

how to check the hand?
(one pair.two pair,three of kind.straigh,flush,full house,four of kind,straight flush,royal flush)

Please check the capx and feel free to modify it

capx:

Thanks!

### Re: How do I create poker game?

Posted: Sat Apr 11, 2015 1:40 pm
First, you can, for example, copy the 5 values of the hand in an array of 5x2 values and sort them from the higher to the lower cards value.

Now, check them in this order :

Check in the array if the 5 cards have the same color value first.
- In this case, check the cards value : 14,13,12,11,10 is a Royal Flush.
- ELSE 13,12,11,10,9 or 12,11,10,9,8 or 11,10,9,8,7 are Straight Flush.
- ELSE the other case is a Flush.

ELSE If the 5 cards does not have the same color value, check the number of sames cards value in the array.
If 4 are the sames, it's Four of a Kind.
ELSE if 3 are the sames, check if the two others are the sames together, if yes, it's a FullHouse, ELSE it's Three of a Kind.
ELSE if 2 are the sames, check if the three others are the sames together, if yes, it's a FullHouse, ELSE if there is another pair, it's TWO PAIR, ELSE it's one pair.
ELSE check for a Straight.
ELSE if no cards are the same, check for the Higher Card.

If you have multiple players in your game, don't forget, in some cases, to compare others cards next.
Example :
If two players have one pair of 7, check the Higher next card to see who win.

I don't know what's happens if two players have the exact same hand... lol

http://en.wikipedia.org/wiki/List_of_poker_hands

### Re: How do I create poker game?

Posted: Sat Apr 11, 2015 1:56 pm
If you have multiple players, don't forget to also give a constant value to each possibility of winner hand.
Example :
- HigherCard = 1
- OnePair = 2
- TwoPair = 3
etc...

Then, compare first who has the most powerful hand. (TwoPair > OnePair because 3 > 2 ...)

In case of equality, compare the cards in the array and in the order (one array per player is needed !)

### Re: How do I create poker game?

Posted: Sat Apr 11, 2015 5:09 pm
Wow,
Thanks guys Will try to make everything!

### Re: How do I create poker game?

Posted: Sat Apr 11, 2015 7:59 pm
korbaach wrote:ok..that's the easy part

how to check the hand?
(one pair.two pair,three of kind.straigh,flush,full house,four of kind,straight flush,royal flush)

Please check the capx and feel free to modify it

capx:Thanks!

capx has helped me a lot. But I cant get how for example I should compare values when there will be 2 players?

Can you help me with that? I very appreciate it!
Thanks

### Re: How do I create poker game?

Posted: Sun Apr 12, 2015 9:57 am
first. @DjPoke.
.Thank you mister Dj ... for tips..
..now I see the logic..i need to start from top,not from bottom(one pair,tree of kind,4 of kind...)

.but...i still struggle with Video Poker game(for only one player ) ....and capx was cry for help

### Re: How do I create poker game?

Posted: Mon Apr 13, 2015 12:47 am
First make constants in this order, from the bottom to the top :
- HigherCard = 1
- OnePair = 2
- TwoPair = 3
- Three of a kind = 4
Etc...

Create an array called, for example, "HandValue" with the players count cases, for example, we will take 4 players, so an array of 4 cases.

Once you checked the hand of Player1, give him the constant corresponding, set it to his array case.
Once you checked the hand of Player2, give him the constant corresponding, set it to his array case.
Etc...

Then compare in the HandValue array who has the best value.

In case of equality, as you have an other array (of 5x2) with each hand sorted from the greater card to the lower, do a loop.
In this loops, compare the first cards of the "winners".
If one of them has the greater 1st card, he is THE winner.
Else, if equality, compare the second cards of the "new winners"... If someone has a lower card, he is eliminated.
If one of them has the greater 2nd card, he is THE winner.
Etc...
In case of 5 equals card for two or more players, you have to deal with total equalities.