PokerHandValue v0.1.0 PokerHandValue View Source

A library to rate and compare poker hands. Any hand with 5 or more cards can be rated and is therefore suitable for texas hold em and other > 5 card poker types.

Example

hand = "As Ad Ac Js Jd"
PokerHandValue.rate_hand(hand) # => {:full_house, 7.1411}

hand2 = "2c 3d 4h 5s 6c"
PokerHandValue.rate_hand(hand2) # => {:straight, 5.06}

PokerHandValue.compare_hands(hand, hand2) # => :gt

Link to this section Summary

Functions

Compares two hands. returns :gt if the value of the first hand is greater, :lt if lesses and :eq if they have same value

Matches a flush

Matches four of a kind, specifying the value

Matches a full house, specifying the three of a kind value

Matches every hand

Matches a pair

Matches a straight

Matches a straight flush

Matches three of a kind

Matches two pairs

Matches four of a kind, specifying the value

Converts a hand to a rating

Link to this section Functions

Link to this function

compare_hands(first, second) View Source

Compares two hands. returns :gt if the value of the first hand is greater, :lt if lesses and :eq if they have same value

Examples

iex> PokerHandValue.compare_hands("Js Jh 2h 2c 3h", "Qs 2c 5h Jh 10s")
:gt

iex> PokerHandValue.compare_hands("As Ah Ad 7h 3d", "2h 3h 4h 5h 6h")
:lt

iex> PokerHandValue.compare_hands("Ks Kh 2d 2h 3d", "Kc Kd 2c 2s 3c")
:eq

Matches a flush

Examples

iex> PokerHandValue.match_flush([{:hearts, 9}, {:hearts, 11}, {:hearts, 14}, {:hearts, 7}, {:hearts, 3}])
{:flush, 0.1411090703}

iex> PokerHandValue.match_flush([{:hearts, 9}, {:hearts, 11}, {:hearts, 14}, {:hearts, 7}, {:hearts, 3}, {:hearts, 2}])
{:flush, 0.1411090703}

iex> PokerHandValue.match_flush([{:hearts, 9}, {:diamonds, 11}, {:hearts, 2}, {:spades, 7}, {:hearts, 3}])
nil
Link to this function

match_four_of_a_kind(hand) View Source

Matches four of a kind, specifying the value

Examples

iex> PokerHandValue.match_four_of_a_kind([{:hearts, 12}, {:diamonds, 12}, {:spades, 12}, {:hearts, 12}, {:diamonds, 6}])
{:four_of_a_kind, 0.1206}

iex> PokerHandValue.match_four_of_a_kind([{:hearts, 12}, {:diamonds, 12}, {:spades, 12}, {:hearts, 12}, {:diamonds, 6}, {:spades, 4}])
{:four_of_a_kind, 0.1206}

iex> PokerHandValue.match_four_of_a_kind([{:hearts, 12}, {:diamonds, 11}, {:spades, 12}, {:hearts, 12}, {:diamonds, 6}])
nil

Matches a full house, specifying the three of a kind value

Examples

iex> PokerHandValue.match_full_house([{:hearts, 9}, {:diamonds, 9}, {:spades, 9}, {:hearts, 3}, {:diamonds, 3}])
{:full_house, 0.0903}

iex> PokerHandValue.match_full_house([{:hearts, 2}, {:diamonds, 9}, {:spades, 9}, {:hearts, 3}, {:diamonds, 3}])
nil

Matches every hand

Examples

iex> PokerHandValue.match_high_card([{:hearts, 4}, {:diamonds, 2}, {:spades, 9}, {:hearts, 11}, {:diamonds, 3}])
{:high_card, 0.1109040302}

iex> PokerHandValue.match_high_card([{:hearts, 4}, {:diamonds, 2}, {:spades, 9}, {:hearts, 11}, {:diamonds, 3}, {:clubs, 12}])
{:high_card, 0.1211090403}

Matches a pair

Examples

iex> PokerHandValue.match_pair([{:hearts, 4}, {:diamonds, 2}, {:spades, 9}, {:hearts, 9}, {:diamonds, 3}])
{:pair, 0.09040302}

iex> PokerHandValue.match_pair([{:hearts, 5}, {:diamonds, 2}, {:spades, 13}, {:hearts, 13}, {:diamonds, 3}])
{:pair, 0.13050302}

iex> PokerHandValue.match_pair([{:hearts, 5}, {:diamonds, 2}, {:spades, 13}, {:hearts, 13}, {:diamonds, 3}, {:clubs, 7}])
{:pair, 0.13070503}

iex> PokerHandValue.match_pair([{:hearts, 5}, {:diamonds, 2}, {:spades, 13}, {:hearts, 7}, {:diamonds, 3}])
nil

Matches a straight

Examples

iex> PokerHandValue.match_straight([{:hearts, 4}, {:diamonds, 5}, {:spades, 6}, {:hearts, 7}, {:diamonds, 8}])
{:straight, 0.08}

iex> PokerHandValue.match_straight([{:hearts, 14}, {:diamonds, 5}, {:spades, 3}, {:hearts, 4}, {:diamonds, 2}])
{:straight, 0.05}

iex> PokerHandValue.match_straight([{:hearts, 14}, {:diamonds, 5}, {:spades, 3}, {:hearts, 4}, {:diamonds, 2}, {:spades, 10}])
{:straight, 0.05}

iex> PokerHandValue.match_straight([{:hearts, 14}, {:diamonds, 13}, {:spades, 12}, {:hearts, 11}, {:diamonds, 10}])
{:straight, 0.14}

iex> PokerHandValue.match_straight([{:hearts, 13}, {:diamonds, 5}, {:spades, 9}, {:hearts, 7}, {:diamonds, 8}])
nil
Link to this function

match_straight_flush(hand) View Source

Matches a straight flush

Examples

iex> PokerHandValue.match_straight_flush([{:hearts, 9}, {:hearts, 5}, {:hearts, 6}, {:hearts, 7}, {:hearts, 8}])
{:straight_flush, 0.09}

iex> PokerHandValue.match_straight_flush([{:hearts, 9}, {:hearts, 5}, {:hearts, 10}, {:hearts, 7}, {:hearts, 8}])
nil
Link to this function

match_three_of_a_kind(hand) View Source

Matches three of a kind

Examples

iex> PokerHandValue.match_three_of_a_kind([{:hearts, 12}, {:diamonds, 12}, {:spades, 12}, {:hearts, 3}, {:diamonds, 6}])
{:three_of_a_kind, 0.120603}

iex> PokerHandValue.match_three_of_a_kind([{:hearts, 12}, {:diamonds, 12}, {:spades, 12}, {:hearts, 3}, {:diamonds, 6}, {:spades, 2}])
{:three_of_a_kind, 0.120603}

iex> PokerHandValue.match_three_of_a_kind([{:hearts, 12}, {:diamonds, 12}, {:spades, 10}, {:hearts, 3}, {:diamonds, 6}])
nil

iex> PokerHandValue.match_three_of_a_kind([{:hearts, 12}, {:diamonds, 10}, {:spades, 9}, {:hearts, 3}, {:diamonds, 6}])
nil

Matches two pairs

Examples

iex> PokerHandValue.match_two_pair([{:hearts, 4}, {:diamonds, 4}, {:spades, 9}, {:hearts, 6}, {:diamonds, 6}])
{:two_pair, 0.060409}

iex> PokerHandValue.match_two_pair([{:hearts, 4}, {:diamonds, 4}, {:spades, 9}, {:hearts, 6}, {:diamonds, 6}, {:hearts, 2}])
{:two_pair, 0.060409}

iex> PokerHandValue.match_two_pair([{:hearts, 4}, {:diamonds, 2}, {:spades, 9}, {:hearts, 6}, {:diamonds, 6}])
nil

iex> PokerHandValue.match_two_pair([{:hearts, 4}, {:diamonds, 2}, {:spades, 9}, {:hearts, 10}, {:diamonds, 6}])
nil

Matches four of a kind, specifying the value

Examples

iex> PokerHandValue.parse_hand("Qs 10s 2d Ah 5c")
[{:spades, 12}, {:spades, 10}, {:diamonds, 2}, {:hearts, 14}, {:clubs, 5}]

iex> PokerHandValue.parse_hand("Invalid hand")
** (RuntimeError) Unable to parse hand

Converts a hand to a rating

Examples

iex> PokerHandValue.rate_hand("Qh Jh 2h 7h 3h")
{:flush, 6.1211070302}

iex> PokerHandValue.rate_hand("As Ah Ad 7h 3d")
{:three_of_a_kind, 4.140703}

iex> PokerHandValue.rate_hand("As Ah Kd 2h 3d")
{:pair, 2.14130302}