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

holdem-poker

v0.4.0

Published

Javascript Holdem Poker Engine

Downloads

134

Readme

holdem-poker

Javascript Holdem Poker Engine

Install

npm install holdem-poker --save

API

Suit

string with value any one of CLUB, DIAMOND, HEART, SPADE

Card

  • suit: Suit
  • value: number

Note: value is in the range from 2 to 14 where 11 = J, 12 = Q, 13 = K and 14 = A

GameState

  • pot: number

Current pot amount

  • communityCards: Array

Community cards at the table

  • players: Array
  • money: number

Amount of money a player have

  • hand: Array

Player cards

  • folded: boolean

Whether the player already folded

  • active: boolean

Is the player left the game or not

  • currentDecision: string

Current decision the player has made

  • currentBet: number

Betting amount for current round

  • availableActions: Array

Actions the player can take at the moment

Game

  • constructor(playerMoney: Array<number>, initialBet: number) ⇒ Inititalizes the Game. The deck is shuffled randomly with 'Fisher-Yates' algorithm. Number of players will be the same length as playerMoney
  • getState(): GameState ⇒ Returns the current game state
  • startRound(): void ⇒ Starts the round if not started yet
  • bet(index: number): void ⇒ Bet the initial betting amount(only in the opening round)
  • check(index: number): void ⇒ Bet 0 unit of money(only after the opening round)
  • raise(index: number, money: number): void ⇒ Raise by a player(can re-raise in the same round)
  • call(index: number): void ⇒ Match the highest bet in the same round
  • fold(index: number): void ⇒ Fold by a player
  • canEndRound(): boolean ⇒ Whether the current round can be ended
  • endRound(): void ⇒ Ends the current round.
  • checkResult(): Result ⇒ Returns the result of the current round
  • computeHand(hand: Array<Card>): HandValue ⇒ Returns the max possible hand value. Note: Community cards are ignored.

Usage

Browser

var game = Poker.Game(...)

Node

var {Game} = require('holdem-poker');
var game=new Game(...);

Example:

var {Game} = require('holdem-poker');
//initialize with 2 players, each having 100 unit money, and initial bet is 10 unit
var game=new Game([ 100, 100 ], 10);
//a demo gameplay is shown bellow
console.log('round 1 - no cards dealt (ante up)');
console.log(
  'Players',
  game.getState().players.map(function (m) {
    return m.hand;
  })
);
console.log('Table', game.getState().communityCards);
game.startRound();
game.bet(0); //for player 1
game.raise(1, 20); //for player 2
game.call(0);
game.endRound();

console.log('round 2 - 3 cards dealt (flop)');
console.log('Table', game.getState().communityCards);
game.startRound();
game.check(0); //for player 1
game.check(1); //for player 2
game.endRound();

console.log('round 3 - 4 cards dealt');
console.log('Table', game.getState().communityCards);
game.startRound();
game.raise(0, 50); //for player 1
game.call(1); //for player 2
game.endRound();

console.log('round 4 - 5 cards dealt (river)');
console.log('Table', game.getState().communityCards);
game.startRound();
game.call(0); //for player 1
game.call(1); //for player 2
game.endRound();

console.log('end game');
var result = game.checkResult();
if (result.type == 'win') {
  console.log('Player' + (result.index + 1) + ' won with ' + result.name);
} else {
  console.log('Draw');
}