Download

How to compare poker hands

Hi
im working on a poker game. Ive made a function that recieves an array of 7 cards and then analaizes it and returns 5 integers. For example 02 08 08 05 05 11, the 02 means its two pairs the 08’s are the top pair the 05’s are the low pair and the 11 is the kicker. This way i can determine the winning hand by just compairing the numbers starting from the left. Optimally i would have liked to store this whole number in a int for easy comparison instead of compairing each in in sequence. But integer cant hold a number that big. Is there a way to increase the size of a int? Or do i have to keep the result separated? Its not a big problem but it would be so much easier to have them all in one variable as a large number.

@P19923

I know I’d find that approach pretty head-wrecking to debug: 11, WTF is that? But hey, if you’re happy with it, then rock on…
You can store it as a truncated float. But neither option will pad a zero at the front which may be a PITA when debugging?..
So overall think I’d probably use strings, with helper or wrapper functions to separate out individual cards or hand ranking.

There’s probably Algos on Stackoverflow / Reddit / Github that take a string and generate quick hand ranking comparison.
If you need to save to a database or replicate zillions of hands, you could still use wrappers to convert to an internal format.
So something that’s harder for humans to read but takes up minimal byte-space. Just 2c. Haven’t ever made a card game! :slight_smile:

Hi. thank you for your reply. “11, WTF is that?” 11 is the fith card, in this case a jack. Ill post a screenshot so you can see a example of the cards and the number.
I dont know if this approach is good, but as im not much of a programmer its what i came up with that seemed easiest to me, im sure there are better solutions that
better programmers could come up with. Although the function that analyzes the cards is HUGE and will be a nigthmare to debug. But it works most of the time. An also i made it early in the development of this game so it will probably take a while to get into it again.I dont even want to think about it atm :stuck_out_tongue: I will debug it when the game is playable and all the graphics are in. So when the game is almost finished (At least the single player part). Ill look into truncated float, i havent heard about that, if it can hold a 12 character long number it will be perfect cause then i can
just do comparions with only one variable per player it will make for much nicer cleaner code.

@P19923

Out of Int, Float, String, Struct… Struct would be the best option overall I think. As its a single variable, but inside it can contain a combination of nested Ints / Floats / Strings or other Structs etc. To see how this might work, take a common BP node such as Spawn-Actor-of-Class. Look at the Transform PIN. Now, Right-Click on each PIN and choose Split-Struct, and go down the rabbit-hole, until you get to individual types, such as Float etc. Do you see how this all works? You can create a definition for a Struct in the Content-Browser. A possible Struct in Texas Hold’em might be…

Poker_Hand_Struct:

…[Hole-card1 Int / String]
…[Hole-card2 Int / String]

…[FlopCard1 Int / String]
…[FlopCard2 Int / String]
…[FlopCard3 Int / String]

…[TurnCard Int]
…[RiverCard Int]

…[Hand Ranking Int / Float]

Personally if I was doing this, I’d be tempted to use Strings inside Structs, to get to prototype stage anyway. Afterwards I’d review things. The reason is, during debugging, I’d prefer to see friendly card names i.e. AA … JJ … KK (not 00 / 14 … 11 …13 etc). As the latter is just too like Hex programming for me! But that’s just me… For sure, take a break from that function from hell for now… But go back and improve it eventually. Re-factoring code is just part of the development process…