Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion lib/dojo/hand.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,38 @@ defmodule Dojo.Hand do
evaluate(cards)
end

defp evaluate(_), do: :high_card
defp sort_cards(cards) do
Enum.sort(cards)
end

defp evaluate(hand) do
sorted_hand = sort_cards(hand)
[first_card | tail] = sorted_hand
check_suit(first_card, tail, hand)
end

defp check_suit(card, [], hand) do
# suit is all the same
:flush
end

defp check_suit(first_card, list, hand) do
[next_card | rest] = list
case first_card.suit == next_card.suit do
true ->
check_suit(next_card, rest, hand)
false ->
# not all suits are same go here
:high_card
end
end

end

# cards = [
# %{rank: 13, suit: :hearts},
# %{rank: 10, suit: :hearts},
# %{rank: 11, suit: :hearts},
# %{rank: 12, suit: :hearts},
# %{rank: 14, suit: :hearts}
# ]