Skip to content

Randomize dealer selection#30

Open
bmchrist wants to merge 4 commits intomasterfrom
randomize_dealer
Open

Randomize dealer selection#30
bmchrist wants to merge 4 commits intomasterfrom
randomize_dealer

Conversation

@bmchrist
Copy link
Owner

No description provided.

@bmchrist bmchrist requested a review from dweinand May 2, 2020 02:31
@bmchrist
Copy link
Owner Author

bmchrist commented May 2, 2020

@dweinand this feels a bit hack-y -- curious for your thoughts

@dweinand
Copy link
Collaborator

dweinand commented May 2, 2020

We can simplify the logic around order in State with something like:

defp play_order(dealer) do
  {_, order} = Enum.reduce(1..4, {dealer, []}, fn _, {player, order} ->
    next = next_player(player)
    {next, order ++ [next]}
  end)

  order
end

defp next_player(:a), do: :b
defp next_player(:b), do: :c
defp next_player(:c), do: :d
defp next_player(:d), do: :a

We could then add a new function to State to encapsulate the logic of setting initial values:

def new do
  dealer = Enum.random([:a, :b, :c, :d])
  %State{dealer: dealer, play_order: play_order(dealer)}
end

And also update the logic for determining the new dealer to just use next_player directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants