Poker Texas Hold'em Hand Evaluator using pure Lua.
This is a pure Lua library to calculate the rank of the best [Texas Holdem] hand out of 5, 6, or 7 cards. It does not run the board for you, or calculate winning percentage, EV, or anything like that. But if you give it two hands and the same board, you will be able to tell which hand wins.
Also there is a two-card ranking/percentile algorithm (Credit to Zach Wissner-Gross).
This is a Lua port from the python library.
This repository is based on Ivan Ribeiro (@irr) work: https://github.com/irr/lua-pokerhand-eval
Lua version required: 5.1 or 5.2.
If using LuaRocks:
luarocks install pokerhand-eval
Otherwise, download https://github.com/AlberTajuelo/pokerhand-eval/zipball/master.
Alternately, if using GIT:
git clone git://github.com/AlberTajuelo/pokerhand-eval.git
cd pokerhand-eval
luarocks make
Calculate Hand winning percentile without board cards:
card = require "holdem.card"
lookup = require "holdem.lookup"
analysis = require "holdem.analysis"
hand = { Card.new(2, 1), Card.new(2, 2) }
board = {}
rank, percentile = analysis.evaluate(hand, board)
print(rank, percentile)
-- Output: nil 0.52337858220211
-- For 2 cards, rank will be nil and you must use percentile
Calculate hand winning percentile with three board cards:
card = require "holdem.card"
lookup = require "holdem.lookup"
analysis = require "holdem.analysis"
hand = { Card.new(2, 1), Card.new(2, 2) }
board = { Card.new(10, 2), Card.new(14, 2), Card.new(13, 2), Card.new(7, 2) }
rank, percentile = analysis.evaluate(hand, board)
print(rank, percentile)
-- Output: 420 0.6792270531401
-- ps: less rank is better
This table represents given a card rank what index is assigned. Rank is 2-14 representing 2-A (Ace).
Card Rank | Index | Symbol |
---|---|---|
2 | 2 | 2 |
3 | 3 | 3 |
4 | 4 | 4 |
5 | 5 | 5 |
6 | 6 | 6 |
7 | 7 | 7 |
8 | 8 | 8 |
9 | 9 | 9 |
10 | 10 | T |
Jack | 11 | J |
Queen | 12 | Q |
King | 13 | K |
Ace | 14 | A |
This table represents given a card suit what index is assigned. Suit is 1-4 representing in given order Spades, Hearts, Diamonds and Clubs.
Card Suit | Index | Symbol |
---|---|---|
Spades (♠) | 1 | S |
Hearts (♥) | 2 | H |
Diamonds (♦) | 3 | D |
Clubs (♣) | 4 | C |
The Card constructor accepts two arguments, rank, and suit.
card = require "holdem.card"
aceOfSpades = card.Card(14, 1)
twoOfDiamonds = card.Card(2, 3)
-- or
aceOfSpades = card.Card("AS")
twoOfDiamonds = card.Card("2D")
PokerHand-eval is currently in development.
WARNING: Not all corner cases have been tested and documented.
The algorithm for 5 cards is just a port of this algorithm.
Six and seven card evaluators using a very similar card representation and applying some of the same ideas with prime numbers. The idea was to strike a balance between lookup table size and speed.
You can search for more info using following references: