Skip to content

Instantly share code, notes, and snippets.

@SkAZi
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SkAZi/05784610ebb80ac27989 to your computer and use it in GitHub Desktop.
Save SkAZi/05784610ebb80ac27989 to your computer and use it in GitHub Desktop.
defmodule MobCas3.Poker1 do
@cards([{99, :joker},{98, :joker}] ++
for m <- 2..14, v <- [:spades, :clubs, :diamonds, :hearts] do {m,v} end)
def match(comb) when is_list(comb), do: apply(MobCas3.Poker, :match, Enum.sort(comb))
def match(comb) when is_tuple(comb), do: match(Tuple.to_list(comb))
def match({10,m}, {11,m}, {12,m}, {13,m}, {14,m}), do: {:royal_flush, {m}}
def match({a,m}, {b,m}, {c,m}, {d,m}, {e,m})
when b==a+1 and c==b+1 and d==c+1 and e==d+1, do: {:straight_flush, {e,m}}
def match({2,m}, {3,m}, {4,m}, {5,m}, {14,m}), do: {:straight_flush, {5,m}}
def match({a,_}, {a,_}, {a,_}, {a,_}, _), do: {:four_of_a_kind, {a}}
def match(_, {a,_}, {a,_}, {a,_}, {a,_}), do: {:four_of_a_kind, {a}}
def match({a,_}, {a,_}, {b,_}, {b,_}, {b,_}), do: {:full_house, {b,a}}
def match({a,_}, {a,_}, {a,_}, {b,_}, {b,_}), do: {:full_house, {a,b}}
def match({_,m}, {_,m}, {_,m}, {_,m}, {_,m}), do: {:flush, {m}}
def match({a,_}, {b,_}, {c,_}, {d,_}, {e,_})
when b==a+1 and c==b+1 and d==c+1 and e==d+1, do: {:straight, {e} }
def match({2,_}, {3,_}, {4,_}, {5,_}, {14,_}), do: {:straight, {5}}
def match({a,_}, {a,_}, {a,_}, _, _), do: {:three_of_a_kind, {a}}
def match(_, {a,_}, {a,_}, {a,_}, _), do: {:three_of_a_kind, {a}}
def match(_, _, {a,_}, {a,_}, {a,_}), do: {:three_of_a_kind, {a}}
def match({a,_}, {a,_}, {b,_}, {b,_}, _), do: {:two_pairs, {a,b}}
def match(_, {a,_}, {a,_}, {b,_}, {b,_}), do: {:two_pairs, {a,b}}
def match({a,_}, {a,_}, _, {b,_}, {b,_}), do: {:two_pairs, {a,b}}
def match({a,_}, {a,_}, _, _, _) do: {:pair, {a}}
def match(_, {a,_}, {a,_}, _, _) do: {:pair, {a}}
def match(_, _, {a,_}, {a,_}, _) do: {:pair, {a}}
def match(_, _, _, {a,_}, {a,_}) do: {:pair, {a}}
def match(_, _, _, _, _), do: :none
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment