Poker Texas Holdem Cactus Kev's algorithm in JavaScript
Evaluate the score (the lower the better) of a poker hand as described in this post blog : http://suffe.cool/poker/evaluator.html.
You can compare two poker hands to find out who wins or if it's a tie.
I've ported some part Cactus Kev's C code : http://suffe.cool/poker/code/
It works on browser side too although the lib is a little heavy ~102 Kb because of the use of lookup tables. But it's robust and really fast. You can evaluate all the cards combinations in few seconds.
How to install
Node.js >= 6
npm install --save poker-hand-evaluator
How to use
const PokerHand = require('poker-hand-evaluator');
const myPokerHand = new PokerHand('KS KH QC AH AD');
const hisPokerHand = new PokerHand('KD KC AS AH TD')
console.log(myPokerHand.describe());
console.log(hisPokerHand.describe());
console.log(myPokerHand.getRank());
console.log(hisPokerHand.getRank());
console.log(myPokerHand.getScore());
console.log(hisPokerHand.getScore());
console.log(myPokerHand.toString());
console.log(hisPokerHand.toString());
console.log(myPokerHand.compareWith(hisPokerHand));
How to develop
Node.js >= 8.5.0 is necessary to run the tests
git clone https://github.com/codeKonami/poker-hand.git
cd poker-hand
npm install
npm run dev
How to test
npm run test
This command will run the unit tests (through Jest) and will also evaluate the time it takes to evaluate all the combinations. Finally it will display 10 random comparisons.
How to build
npm run build
This command generates a pokerhand.min.js file in the dist/
folder to be used on browser. You can try an example of implementation on browser by launching a web server in the root folder.
python -m SimpleHTTPServer
TO DO