holdem-poker
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.0 • Public • Published

    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('Players',game.getState().players.map(function(m){return m.hand}))
    //round 1
    game.startRound();
    game.bet(0);//for player 1
    game.raise(1,20);//for player 2
    game.call(0)
    game.endRound()
    console.log('Table',game.getState().communityCards);
    //round 2
    game.startRound();
    game.check(0);//for player 1
    game.check(1);//for player 2
    game.endRound()
    console.log('Table',game.getState().communityCards);
    //round 3
    game.startRound();
    game.raise(0,50);//for player 1
    game.call(1);//for player 2
    game.endRound()
    console.log('Table',game.getState().communityCards);
    //end game
    var result=game.checkResult();
    if(result.type=='win'){
        console.log('Player'+(result.index+1)+' won with '+result.name);
    }else{
        console.log('Draw');
    }

    Keywords

    Install

    npm i holdem-poker

    DownloadsWeekly Downloads

    1

    Version

    0.2.0

    License

    MIT

    Unpacked Size

    45.2 kB

    Total Files

    10

    Last publish

    Collaborators

    • thekoushik