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

lnp-tx-holdem

v1.0.1

Published

This is the module for creating own Texas Holdem poker game! It allows you to track cards, compose hands, compare hands by combination and even calculate draw combinations. # Browsers support Since version 0.2.2 tx-holdem is available for browsers! See [d

Downloads

6

Readme

Texas Holdem Poker

This is the module for creating own Texas Holdem poker game! It allows you to track cards, compose hands, compare hands by combination and even calculate draw combinations.

Browsers support

Since version 0.2.2 tx-holdem is available for browsers! See demo app

import * as txHoldem from 'tx-holdem/browser';
// OR
var txHoldem = require('tx-holdem/browser');

Usage

Compare combinations:

const { Pack, Hand } = require('tx-holdem');

const pack = new Pack();

const pairHand = new Hand(
	pack.createCard('clubs', 3),
	pack.createCard('diamonds', 3)
);
const fourOfAKindHand = new Hand(
	pack.createCard('clubs', 4),
	pack.createCard('diamonds', 4),
	pack.createCard('hearts', 4),
	pack.createCard('spades', 4),
);

const pairIsLower = pairHand.compare(fourOfAKindHand) === -1;
console.log('Pair is lower than four of a kind:', pairIsLower);

Select highest combination from two hands (board and pocket cards):

const { Pack, Hand, HandsCollection } = require('tx-holdem');

const pack = new Pack();

const board = new Hand([
	pack.createCard('clubs', 5),
	pack.createCard('diamonds', 6),
	pack.createCard('spades', 8),
	pack.createCard('hearts', 2),
	pack.createCard('hearts', 9),
]);

const pocket = new Hand([
	pack.createCard('spades', 7),
	pack.createCard('spades', 9),
]);

const coll = HandsCollection.createCombinations(board, pocket);

console.log('Highest is', coll.highestCombination.name);

API

Card

  • constructor(suit, rank)
    • suit: Number
    • rank: Number

Methods:

  • static create(suit, rank): Card | null — creates Card instance, returns null if suit or rank is not a number
    • suit: Number
    • rank: Number
  • toString(): String — returns string representation of card
  • toJSON(): Object — returns JSON representation of card
  • rankOf(): Number — returns rank representation of card (card.rank property)
  • compare(card): Number — compares current card with given by rank, returns 1 if current is higher; -1 if current is lower; 0 if both are equal
    • card: Card
  • equalBySuit(card): Boolean — compares cards by suit
    • card: Card
  • equalByRank(card): Boolean — compares cards by rank
    • card: Card

Properties:

  • suit: Number
  • rank: Number
  • static readonly CLUBS: Number
  • static readonly DIAMONDS: Number
  • static readonly HEARTS: Number
  • static readonly SPADES: Number
  • static readonly SUIT_MAX: Number — constant rank of max suit (spades)
  • static readonly TWO: Number
  • static readonly THREE: Number
  • static readonly FOUR: Number
  • static readonly FIVE: Number
  • static readonly SIX: Number
  • static readonly SEVEN: Number
  • static readonly EIGHT: Number
  • static readonly NINE: Number
  • static readonly TEN: Number
  • static readonly JACK: Number
  • static readonly QUEEN: Number
  • static readonly KING: Number
  • static readonly ACE: Number
  • static readonly RANK_MAX: Number — constant rank of max rank (ace)

Hand

  • constructor(...cards)
    • ...cards: Card — enumeration or array of cards

Methods:

  • addCards(...cards): Boolean — adds multiple cards to hand
    • ...cards: Card — enumeration or array of cards
  • addCard(card): Boolean — adds single card to hand
    • card: Card
  • isFull(): Boolean — returns true if hand has reached maximum capacity
  • has(card): Boolean — returns true if hand has given card
    • card: Card
  • has(suit, rank): Boolean — returns true if hand has card with given suit and rank
    • suit: Number
    • rank: Number
  • compare(hand): Number — returns -1 if current had has lower combination, 0 if hands are equal, 1 if hand is greater
    • hand: Hand
  • isKicker(): Boolean
  • isPair(): Boolean
  • isTwoPairs(): Boolean
  • isThreeOfKind(): Boolean
  • isStraight(): Boolean
  • isFlush(): Boolean
  • isFullHouse(): Boolean
  • isFourOfKind(): Boolean
  • isStraightFlush(): Boolean
  • isRoyalFlush(): Boolean
  • reduce(aggregate, start): any — applies aggregate function to each card in hand and returns single rank; works in the same way as Array.reduce
    • aggregate: Function
    • start: any
  • sort(order): undefined — sorts cards in hand by given order
    • order: String — "asc" by default
  • every(predicate): Boolean — returns true if every card matches given predicate
    • predicate: Function
  • forEach(aggregate): undefined — applies aggregate function to each card in hand

Properties:

  • readonly combination: Combination
  • readonly drawCombination: DrawCombination
  • readonly size: Number
  • static readonly MAX_HAND_SIZE: Number

Pack

  • constructor()

Methods:

  • destroy(): undefined — removes all cards from pack
  • createCards(count) — creates given number of random cards
    • count: Number
  • createCard(suit, rank): Card | null — creates card with given suit and rank, in case one of arguments is not specified random card will be generated; returns null in case card with given suit and rank already exists
    • suit: Number
    • rank: Number
  • has(card): Boolean — returns true if given card already exists in pack, false otherwise
    • card: Card
  • has(suit, rank) — returns true if card with given suit and rank already exists in pack, false otherwise

Properties:

  • readonly count: Number — number of created cards in pack

HandsCollection

  • constructor(hands)
    • hands: Array

Methods:

  • static createCombinations(hand1, hand2): HandsCollection — composes all possible card combinations with two given hands and returns HandsCollection instance
    • hand1: Hand
    • hand2: Hand

Properties:

  • readonly highestHand: Hand — strongest hand by combination in collection
  • readonly highestCombination: Combination — strongest combination in collection
  • readonly count: Number — number of hands in collection

DrawCombination

  • constructor(hand)
    • hand: Hand

Properties:

  • readonly outs: Number — outs for hand to achieve strong combination

Combination

  • constructor(hand)
    • hand: Hand

Methods:

  • compare(combination): Number — compares current combination with given, returns -1 if current is lower, 0 if both are equal, 1 if current is higher
    • combination: Combination
  • isKicker(): Boolean
  • isPair(): Boolean
  • isTwoPairs(): Boolean
  • isThreeOfKind(): Boolean
  • isStraight(): Boolean
  • isFlush(): Boolean
  • isFullHouse(): Boolean
  • isFourOfKind(): Boolean
  • isRoyalFlush(): Boolean
  • isStraightFlush(): Boolean
  • rankOf(): Number — represents combination as its rank
  • static readonly KICKER: Number
  • static readonly PAIR: Number
  • static readonly TWO_PAIR: Number
  • static readonly THREE_OF_A_KIND: Number
  • static readonly STRAIGHT: Number
  • static readonly FLUSH: Number
  • static readonly FULL_HOUSE: Number
  • static readonly FOUR_OF_A_KIND: Number

Properties:

  • readonly highestCard: Card — highest card in combination
  • readonly cards: Array — cards which compose combination
  • readonly rank: Number
  • readonly name: String