npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

poker-hand-evaluator

v1.0.1

Published

Poker Texas Holdem Hand Evaluator using Cactus Kev's algorithm

Downloads

3,395

Readme

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());
// { hand: [ 'KS', 'KH', 'QC', 'AH', 'AD' ],
//   score: 2468,
//   rank: 'TWO_PAIRS' }

console.log(hisPokerHand.describe());
// { hand: [ 'KD', 'KC', 'AS', 'AH', 'TD' ],
//   score: 2470,
//   rank: 'TWO_PAIRS' }

console.log(myPokerHand.getRank());
// TWO_PAIRS
console.log(hisPokerHand.getRank());
// TWO_PAIRS

console.log(myPokerHand.getScore());
// 2468
console.log(hisPokerHand.getScore());
// 2470

console.log(myPokerHand.toString());
// KS KH QC AH AD
console.log(hisPokerHand.toString());
// KD KC AS AH TD


/**
 * return 1 if it's a Win
 * return 2 if it's a Loss
 * return 3 if it's a Tie
 */
console.log(myPokerHand.compareWith(hisPokerHand));
// 1

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
# Install dev dependencies (Webpack, babel, Jest ...)
npm install
# Launch an example
npm run dev

How to test

npm run 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
# Now go to http://localhost:8000

TO DO

  • [ ] Load the C code of Kev Cactus directly in Node.js to compare the result between my code and his results.
  • [ ] Add the Paul Senzee's optimisation mentioned in the blog post here