Pure JavaScript poker hand analyzer to be used (also) in puzzle games

There are a lot of games you can make starting from a Poker card game. The most obvious is the poker itself, but there also are puzzle games which used Poker cards and rules in the gameplay, like Sage Solitaire.

Anyway, no matter the kind of game you are about to make using Poker rules, you have to be able to check what’s in the players hand.

I was sure I would have found a lot of scripts in the web, so I made some searches and the most popular examples out there are:

Poker Hand Evaluator: the most complete in my opinion but needs a 124MB lookup table which makes it useless in HTML5 game development.

Poker Evaluator: a nice example on jsfiddle using regular expressions but it only works with cards taken from a single deck, and in a puzzle game you can also have more than one deck or completely random cards such as two tens of hearts.

Poker Hand Evaluator (yes, another): evaluates two hands of poker to see what’s the best. The code isn’t that clear but it’s a nice tool although it cannot manages completely random cards.

Poker Hand Analyzer: the most clever analyzer I found, using bit & mathematical operations you can analyze your poker hands in less than 10 lines, but only works with a 52 cards deck.

So I ended making my own engine capable of working with any card combination, including 5 of a kind, pairs with flush, and all and every five cards combination you can imagine.

Have a try:

Play with the selectors and see your hand in real time.

And this is the source code, easy and plain, you can port it to any language.

Hope this will be useful in your card games, I am making my own. Download the source code.

  • Lex

    Love your work! … There is a bug in the above … Your code outputs “Ace Straight and Flush” when the Ace straight isn’t fully complete. eg Ace, King, Queen, Jack, Five (all suited) is incorrect.

    • Emanuele Feronato

      Thank you. Will be fixed in today’s post.