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-evaluator

v2.1.0

Published

A library to evaluate 3, 5, 6 or 7 card poker hands

Downloads

335

Readme

Poker Hand Evaluator

This is the official repository of the npm module poker-evaluator.

This is a poker hand evaluator using the Two Plus Two algorithm and lookup table. The lookup table HandRanks.dat is included in the module.

Capable of evaluating 3, 5, 6 and 7 card hands. The highest hand possible in a 3 card hand is 3 of a kind (straights & flushes do not apply to 3 cards).

This can evaluate about 22MM hands per second on a quad-core 2.7GHz Macbook Pro. Run the speedtest.js file under /test to try it.


Installation

npm install poker-evaluator OR
yarn add poker-evaluator


Usage:

Call the public evalHand method with a single argument, an array of 3, 5, 6 or 7 cards as:

  • Strings in the format 'Xy' where X = rank and y = suit. This is case insensitive so xy or XY (or any other combination) work fine too.
    • Ranks: A, 1, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K
    • Suits: c, d, h, s
  • Numbers corresponding to the values in the deck (currently does not work for 3 card hands)

Call the public winningOddsForPlayer method to estimate the odds of winning a hand given your cards. This returns a single PlayerOdds record. Example usage:

winningOddsForPlayer(['ah','as'],[],5, 1000) // {'winRate':0.56,'splitRates':[{'rate':0.006, 'ways':2},...{'rate':...,'ways':n}]}
winningOddsForPlayer(['ah','as'],['2c','3c','4c','5c'],5, 1000) // {'winRate':0.03...}
winningOddsForPlayer(['ah','as'],[],2, 1000) // {'winRate':0.85,...}

Call the public winningHandsForTable method to get spectator odds for each players hand. This returns a TableOdds record. Example usage:

winningOddsForTable([['ah','as'],['kd','kh']], [], 2, 1000) // {'players':[{'winRate'...},...]}

This can be called with partial hands, such as:

winningOddsForTable([['ah','as'],['kd'],[]], [], 3, 1000)

See odds types for the structure of odds.

See src/constants/deck.const.ts for the full deck

Typescript:

import * as PokerEvaluator from 'poker-evaluator-ts';

PokerEvaluator.evalHand(['As', 'Ks', 'Qs', 'Js', 'Ts', '3c', '5h']);
//{ handType: 9,
//  handRank: 10,
//  value: 36874,
//  handName: 'straight flush' }

PokerEvaluator.evalHand(['As', 'Ac', 'Qs']);
//{ handType: 2,
//  handRank: 2761,
//  value: 10953,
//  handName: 'one pair' }

Importing in JavaScript:

const PokerEvaluator = require('poker-evaluator');

Passing numbers as arguments (values from deck.const.ts):

PokerEvaluator.evalHand([17, 22, 27, 32, 33]);
//{ handType: 5,
//  handRank: 6,
//  value: 20486,
//  handName: 'straight' }

The returned object is an EvaluatedHand (src/types/evaluated-hand.interface.ts). An explanation of its properties is as follows:

handType: number; // Index of the HAND_TYPES array  
handRank: number; // Rank within the handType  
value: number; // Overall value of this hand, the higher the better. USE THIS TO DETERMINE WINNER OF A HAND  
handName: HandName; // Human readable name of the hand

Contributing

To contribute create a pull request from your fork to this repository.

Contributors

David Chen - Wrote original poker-evaluator

Rory Mcgit - Made project typescript friendly

Aaron Segal - Added odds calculator