Git Product home page Git Product logo

pokersolver's Introduction

Description

pokersolver is a poker hand solver and comparison tool written in Javascript. It was written for and is being used in production on CasinoRPG, an HTML5 MMORPG that features Texas Hold'em as one of its main casino games. It is designed for use on either the client (browser) or the server (Node.js). This library is capable of:

  • Evaluating a hand of up to 7 cards
  • Calculating the score of the hand (0-9)
  • Returning the name of the hand (Pair, Flush, etc)
  • Returning a detailed description (Two Pair, A's & 8's)
  • Comparing an array of hands and returning the winner(s)
  • Identifying all cards involved in creating the winning hand
  • Support for wilds and other game types
  • Works in both the browser and Node.js

Installation

npm install pokersolver

Examples

Server Usage

var Hand = require('pokersolver').Hand;

Browser Usage

<script src="/path/to/pokersolver.js"></script>
<script>
  var hand = Hand.solve(['...']);
  ...
</script>

Solve two hands and then determine the winner between the two of them.

var hand1 = Hand.solve(['Ad', 'As', 'Jc', 'Th', '2d', '3c', 'Kd']);
var hand2 = Hand.solve(['Ad', 'As', 'Jc', 'Th', '2d', 'Qs', 'Qd']);
var winner = Hand.winners([hand1, hand2]); // hand2

Solve a hand and return the type and the description.

var hand = Hand.solve(['Ad', 'As', 'Jc', 'Th', '2d', 'Qs', 'Qd']);
console.log(hand.name); // Two Pair
console.log(hand.descr); // Two Pair, A's & Q's

API

Hand Methods

solve(cards, game, canDisqualify)

Solves the hand passed in, whether 3 cards or 7. Returns various information such as name, description, score and cards involved.

  • cards: Array All cards involved in the hand, example: ['Ad', '2d', '3d', '4d', 'Qc', 'Ks', '7h']. Note that a 10 should be passed as a T (Th for example).
  • game: String Which rule set is used, based on the game being played. Default: 'standard'
  • canDisqualify: Boolean Is this hand subject to qualification rules, which some games have? Default: false

winners(hands)

Compare the passed hands and determine which is the best hand(s). Can return multiple if there is a tie.

  • hands Array All hands solved with Hand.solve that should be compared.

toString()

Returns a formatted string of all cards involved in the identified hand type (maximum of 5 cards).

Solved Hand Properties

cardPool Array

All of the cards passed into the hand.

cards Array

All of the cards involved in the identified hand type.

descr String

Detailed description of the identified hand type (Two Pair, A's & Q's for example).

name String

Type of hand identified (Two Pair for example).

rank Number

Ranking of the hand type (Varies from game to game; 0 being the lowest hand).

PaiGowPokerHelper Methods

solve(cards)

Solves the hand passed in, sets it according to House Way, and solves both hands.

  • cards: Array All cards involved in the hand, example: ['Ad', '2d', '3d', '4d', 'Qc', 'Ks', '7h'].

setHands(hiHand, loHand)

Sets the hands according to the input, and solves both hands.

  • hiHand Array Five cards involved in the high hand, example: ['Ad', '2d', '3d', '4d', '7h'].
  • loHand Array Two cards involved in the low hand, example: ['Qc', 'Ks'].

winners(player, banker)

Compare the passed PaiGowPokerHelper hands and determine who wins. 1 = Player, -1 = Banker, 0 = Push.

  • player PaiGowPokerHelper Non-banking hand solved with PaiGowPokerHelper.solve or PaiGowPokerHelper.setHands.
  • banker PaiGowPokerHelper Banking hand solved with PaiGowPokerHelper.solve or PaiGowPokerHelper.setHands.

Solved PaiGowPokerHelper Properties

baseHand Hand

All of the cards passed into the helper, run against Hand.solve.

hiHand Hand

Five card high hand, whether calculated or passed into the helper, run against Hand.solve.

loHand Hand

Two card low hand, whether calculated or passed into the helper, run against Hand.solve.

Games Available

standard

Useful for Texas Hold'em, Seven Card Stud, Five Card Draw, and other Standard Poker Games.

jacksbetter

Useful for Jacks or Better Video Poker. Use qualification to determine if a hand is a Pair of Jacks or better.

joker

Useful for Joker Video Poker. Jokers are notated as 'Or' and may be anything. Qualification: Kings or better.

deuceswild

Useful for Deuces Wild Video Poker. Deuces may be anything. Hands lower than Three of a Kind are High Card and not paying hands.

threecard

Useful for Three Card Poker. Qualification: Dealer must have Queen High or better.

fourcard

Useful for Four Card Poker. No qualifying hand.

fourcardbonus

Useful for calculating the Aces Up Bonus for Four Card Poker. Qualification: Pair of Aces or better.

paigowpokerfull

HELPER GAME: Used by PaiGowPokerHelper to create a hand that will eventually be split.

paigowpokeralt

HELPER GAME: Used by PaiGowPokerHelper on a straight and/or flush to create another possible hand.

paigowpokersf6

HELPER GAME: Used by PaiGowPokerHelper to determine if a six-card straight and/or flush is possible.

paigowpokersf7

HELPER GAME: Used by PaiGowPokerHelper to determine if a seven-card straight and/or flush is possible.

paigowpokerhi

Useful for Pai Gow Poker's High Hand. A2345 is the second highest straight. One joker in the deck as 'Or'; it may be used to complete a straight and/or flush, else is counted as an Ace.

paigowpokerlo

Useful for Pai Gow Poker's Low Hand. One joker in the deck as 'Or'; it is counted as an Ace.

Testing

npm install
npm test

License

Copyright (c) 2016 James Simpson and GoldFire Studios, Inc.

Released under the MIT License.

pokersolver's People

Contributors

fvilers avatar goldfire avatar okaybenji avatar smyrick avatar wschmrdr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pokersolver's Issues

Can't run example code as shown on npm page.

I'm running on Ubuntu.

I'm installing pokersolver like so, while in the directory of my project:

npm install pokersolver

I'm trying to run a file where this is the only line:

var Hand = require('pokersolve').Hand;

This causes a "Can't find module 'pokersolve'" error. I figure it's a type so I've changed it to:

var Hand = require('pokersolver').Hand;

Which causes the following error

/media/E/Storage/Code/project/node_modules/pokersolver/pokersolver.js:16
  class Card {
  ^^^^^

SyntaxError: Unexpected reserved word
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/media/E/Storage/Code/flopzilla/new_zilla.js:1:74)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

Are sub rankings given?

Sorry if I missed this but just wonder if there’s a global sub ranking for each possible hand?

10's coming out as 10's without suit

I hope I am not doing anything wrong here but looks like all 10's comes out without suit when I use poker solver solve method and return cards from that object. Everything else works, see example picture:

image

this should have come out as 10h, 10s

h.qualifiesHigh is not a function

Hand.solve() seems to be working fine, but when trying to compare hands with Hand.winners(), I get the following error: 'h.qualifiesHigh is not a function'

console.log(hand1, hand2)
// ['9h', '4s', '5s', 'Ts', '7d', 'Jh', 'Jc'] (7) ['9h', '4s', '5s', 'Ts', '7d', 'As', 'Ks']

console.log(Hand.solve(hand1), Hand.solve(hand2))
// OnePair {cardPool: Array(7), cards: Array(5), suits: {…}, values: Array(11), wilds: Array(0), …}
// Flush {cardPool: Array(7), cards: Array(5), suits: {…}, values: Array(14), wilds: Array(0), …}

console.log(Hand.winners([hand1, hand2]))
// TypeError: h.qualifiesHigh is not a function

error seems to stem from the following lines of code

  hands = hands.filter(function(h) {
    return h.qualifiesHigh();
  });

Winner

How do you output which hand is a winner? If I get two hands that are both A-high, the description doesn't include the kicker. How do I know which won?

return the position of winner/s when Hand.winners(hands_list) ?

When applying the module for my poker server I found interesting that the method winners doesn't return the position of the winner in the array of hands passed. I think it would be really useful. Do I start working on that or is there some solution to this problem that I'm not seeing?

Omaha Hold'em

I'd like to add the Omaha Hold'em rules to this library (I've been using the standard and works hells good).

Looking at how rules are set up, I was thinking on running all combinations of 2 from the hand cards and 3 from the table, but that might not be that performant.

Do you think there's a better approach for this @goldfire ?

Thanks in advance

Joker Wild Ranking Issue

Joker Wild does not payout a pair of Kings yet is says in the documentation that it does.

Two Pair is currently ranked 2,

Using kickers in combinations

First of all, thank you for making this useful module.
I'm working with this product and found some interesting point:

  • Desk has 9c Kh Kd 9s Ah
  • First user has Qc 5h
  • Second user has 5d Jd

Library returns two winners, but as we can assume, due to kicker, winner is 1st player. Is it possible to distinguish somehow community cards or hand cards to make correct output for Hand.winners method?
Thanks in advance!

can you predict the output for the below example ? as per the documentation it should give two winners. However, giving me only one winner and that too precedence of the player in the array passed.

var hand1 = Hand.solve(['Ad', '2s', '9h', '4d', '5h']);
hand1.name = 'preetham';
console.log('hand1 ==>'+hand1.name); // Two Pair 
console.log('hand1 ==> '+hand1.descr);

var hand2 = Hand.solve(['Ad', 'As', 'Jc', '3h', '2d']);
hand2.name='rocker';
console.log('hand2 ==> '+hand2.name); // Two Pair 
console.log('hand2 ==>'+hand2.descr);

var hand3 = Hand.solve(['Ah', 'Ac', 'Jd', '3c', '2f']);
hand3.name='Baxish';
console.log('hand2 ==> '+hand3.name); // Two Pair 
console.log('hand2 ==>'+hand3.descr);


var winner = Hand.winners([hand1, hand3,hand2]);
console.log(winner[0].name)

isPossible === true with duplicate cards

Hi, I'm poking around with the library and making a few tests before using it. If I solve a handle with two duplicate cards (Queen of diamond for example) the returning structure still has a isPossible flag to true. Shouldn't it be false?

How to use for evaluating low hands?

Hey.

I want to evaluate low hands(worst hand) (7 cards), standard deck, game type = standard. Is that possible using this library ? How to achieve that ?

Thanks.

flush boars

take look at this
Screenshot (19)

if the board is flush with heart and some players have heart then all players are winners !!! WRONGG

for more information : flush board rules

Royal Flushes Not Evaluated Correctly for Deuces Wild

console.log(Hand.solve(['2s','Kc','Jc','2d','Qc'],'deuceswild').name) evaluates to only a straight flush. Same goes for a natural royal.

If you change .name to .descr it works, but adds extra info for all the other hands. I am trying to figure out a fix, but these evaluation libraries are always convoluted to the person that didn't write them.

Straight not evaluated correctly.

For the statement, console.log("output", Hand.solve([ 'Ts', 'Qh', '7c', '8s', '9s'])), it is returning me
High Card, and expected result is Straight.

Solving as a "Full House" instead of "Four of a Kind".

The following will give me "Four of a Kind, A's" as expected:
Hand.solve(['Ad', 'As', 'Jc', 'Th', '2d', '0r', '0r']).descr;

However, the following is giving me "Full House, 10's over A's" instead of the expected "Four of a Kind, A's":
Hand.solve(['Ad', 'As', 'Ac', 'Th', '2d', '0r', '0r']).descr

Wrong Hand Strength Name

Hi Team

I got an issue with Royal Flush Hand Strength with these cards.

var communityCardss = ["3s","Jh","Qh","Th","8c"];
Var Playercards = [
"Kh",
"Kd",
"5h",
"5d",
"Ah"
];

OutPut:
name: 'Straight Flush',
descr: 'Royal Flush',
cardCombination: [ 'Ah', 'Kh', 'Qh', 'Jh', 'Th' ],
rankname: 'Straight Flush',
rankdesc: 'Royal Flush' } ]

But it should be
Name: 'Royal Flush'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.