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

two-to-seven-triple-draw

v0.7.0

Published

Poker hand solver

Downloads

27

Readme

two-to-seven-triple-draw

CI Release

Poker hand solver. Supports:

  • solving the best hand from up to nine cards.
  • solving hands from single array input.
  • solving hands from table and hand card array inputs when N cards from the hand array must be used to form the hand.
  • comparing hands.
  • finding the best hand from given inputs. Similarly than Math.max(...).

Installation

npm i two-to-seven-triple-draw

Usage example

Hand = require('two-to-seven-triple-draw').Hand;
Card = require('two-to-seven-triple-draw').Card;

// Solve five card hand
const acequads = Hand.solve(
    [0, 13, 26, 39, 2].map(i => new Card(i))
);

// Solve Omaha hold em hand
const fullhouse = Hand.solveHoldEm(
    [0, 13, 26, 39, 2].map(i => new Card(i)),
    [25, 38, 11, 24].map(i => new Card(i)),
    2
);

// Get best hand
console.log(Hand.max(acequads, fullhouse).toString());

Documentation

This package provides three classes: Card, Deck and Hand. Card class implements logic for comparing and handling cards, which are passed around as Cards. Deck class provides an implementation to generate shuffled or unshuffled array of cards. Hand class implements logit for comparing and solving poker hands, which are created from arrays of integers.

All of the classed provide a static method fromJSON(...) which allows regenerating an instance of a respective class.

Card

Card provides getters for the suit and value of the card as well as static methods Card.getSuit(num), Card.getValue(num), and Card.compare(cardA, cardB). The Card.compare(...) method can be used to sort cards from high to low.

Cards are passed around as Cards. The suit of the cards is defined as Math.floor(num/13) % 4. The output integer maps to card suit as:

Integer | Suit ------- | ------- 0 | ♥ Hearts 1 | ♠ Spades 2 | ♦ Diamonds 3 | ♣ Clubs

The value of the card is defined as num % 13 || low_ace ? 0 : 13. This results to value being represented as one smaller than it would be in an actual playing card. Aces are high by default.

Deck

Deck provides a pop method to get the next available card as a Card object, popN(n) method to get multiple cards at a time, cardsRemaining getter to check number of cards left in the Deck, and methods to shuffle as well as to check if the Deck is shuffled.

Hand

Hand provides Hand.solve(cards, num=5), Hand.solveHoldEm(table_cards, hand_cards, must_use=0), Hand.compare(a, b), and Hand.max([hand1[, hand2[, ...]]]) functions to solve and compare poker hands. Hand.solveHoldEm(...) is a helper function to support games where N number of cards from players hand cards must be used, such as Omaha hold em. Hand is passed in to the solver as a array of Cards. Solver returns object with fields for uuid, rank of the hand and cards included in the hand. For example, ace to five straight-flush would result to:

{
    "uuid": "2d82f594-579b-4dbe-ae06-187c66229734",
    "rank": 40,
    "cards": [
        {"num":4}, {"num":3}, {"num":2}, {"num":1}, {"num":0}
    ]
}

where the number for hand rank is the one defined in Hand.Rank:

Number | Hand ------ | ------------ 45 | Five of a kind 40 | Straight flush 35 | Four of a kind 30 | Full house 25 | Flush 20 | Straight 15 | Three of a kind 10 | Two pairs 5 | Pair 0 | High

The Hand.compare(...) function takes in two output objects from Hand.solve(...) function and returns a value, that when passed to Array.prototype.sort(...) would sort the array from the best to the worst hand. The Hand.max(...) function return the best of the input hands and is used similarly to Math.max(...).