How to code poker logic

I’ve been learning to code for a couple of weeks now and I’m trying to create an in console game of Texas holdem as my first coding project. I’ve created an array, with a nested object for the deck of cards so that I could easily give the cards properties like suit and rank, strength etc. so it would help me code the logic I’d need later.

I’ve cloned and shuffled the array so I can successfully get random cards with no repeats but now I’m struggling to make the logic for the program to know which hands are better than others.

It’s easy to check if 2 cards match and are a pair, or if 4 cards equal 4 of a kind, or if all five cards have the same suit and are a flush. But I have no idea how to get it to check all 7 cards, and figure out the best combination of 5 cards. I don’t know how to get it to check for 5 of the same suit within 7 cards. I could individually have it check each card against every other card, and after a LOT of coding I could probably get it to work but I know there has to be an easier way.

This sort of thing is much easier to answer if you show us what you’ve done so far.

1 Like

Oh yeah I forgot to link that in the original post. https://codepen.io/randomaccountname/pen/poaozMz

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.