poker v0.0.1 Poker

An Elixir library to work with Poker hands.

Source: https://github.com/wojtekmach/poker_elixir

Documentation: http://hexdocs.pm/poker/

Example

hand1 = "As Ks Qs Js Ts"
hand2 = "Ac Ad Ah As Kc"

Poker.hand_rank(hand1) # => {:straight_flush, :A}
Poker.hand_rank(hand2) # => {:four_of_a_kind, :A, :K}

Poker.hand_compare(hand1, hand2) # => 1

Summary

Functions

Returns the best rank & hand out of hole cards and community cards

Compares two poker hands and returns 1, 0 or -1 when the first hand is respectively more valuable, equally valuable or less valuable than the second hand

Returns rank of a given hand

Returns hand value - a number than uniquely identifies a given hand. The bigger the number the more valuable a given hand is

Accepts a string and returns a tuple of cards. A card is a tuple of rank and suit

Functions

best_hand(hole_cards, community_cards)

Returns the best rank & hand out of hole cards and community cards.

iex> Poker.best_hand("4c 5d", "3c 6c 7d Ad Ac")
{{:straight, :"7"}, {{:"7",:d}, {:"6",:c}, {:"5",:d}, {:"4",:c}, {:"3",:c}}}
hand_compare(hand1, hand2)

Compares two poker hands and returns 1, 0 or -1 when the first hand is respectively more valuable, equally valuable or less valuable than the second hand.

iex> Poker.hand_compare("Ac Qd Ah As Kc", "Ac Ad Ah Kc Kc")
-1
hand_rank(str)

Returns rank of a given hand.

iex> Poker.hand_rank("Ac Kc Qc Jc Tc")
{:straight_flush, :A}

iex> Poker.hand_rank("Kc Qc Jc Tc 9c")
{:straight_flush, :K}

iex> Poker.hand_rank("5c 4c 3c 2c Ac")
{:straight_flush, :"5"}

iex> Poker.hand_rank("Ac Ad Ah As Kd")
{:four_of_a_kind, :A, :K}

iex> Poker.hand_rank("Ac Ad Ah Kc Kd")
{:full_house, :A, :K}

iex> Poker.hand_rank("Kc Kd Kh Ac Ad")
{:full_house, :K, :A}

iex> Poker.hand_rank("Ac Qc Jc Tc 9c")
{:flush, :c, :A, :Q, :J, :T, :"9"}

iex> Poker.hand_rank("Ac Kc Qc Jc Td")
{:straight, :A}

iex> Poker.hand_rank("Kc Qc Jc Tc 9d")
{:straight, :K}

iex> Poker.hand_rank("5c 4c 3c 2c Ad")
{:straight, :"5"}

iex> Poker.hand_rank("Ac Ad Ah Kc Qc")
{:three_of_a_kind, :A, :K, :Q}

iex> Poker.hand_rank("Ac Ad Kc Kd Qc")
{:two_pair, :A, :K, :Q}

iex> Poker.hand_rank("Ac Ad Kc Qc Jd")
{:one_pair, :A, :K, :Q, :J}

iex> Poker.hand_rank("Ac Qc Jd Td 9c")
{:high_card, :A, :Q, :J, :T, :"9"}
hand_value(str)

Returns hand value - a number than uniquely identifies a given hand. The bigger the number the more valuable a given hand is.

iex> Poker.hand_value("Ac Kc Qc Jc Tc")
8014
parse_hand(str)

Accepts a string and returns a tuple of cards. A card is a tuple of rank and suit.

iex> Poker.parse_hand("Ac Kd")
{{:A, :c}, {:K, :d}}