RosettaCodeData/Task/Generate-Chess960-starting-position/Elixir/generate-chess960-starting-position-2.elixir
2016-12-05 22:15:40 +01:00

13 lines
434 B
Text

defmodule Chess960 do
def construct do
row = Enum.reduce(~w[♕ ♘ ♘], ~w[♖ ♔ ♖], fn piece,acc ->
List.insert_at(acc, :rand.uniform(length(acc)+1)-1, piece)
end)
[Enum.random([0, 2, 4, 6]), Enum.random([1, 3, 5, 7])]
|> Enum.sort
|> Enum.reduce(row, fn pos,acc -> List.insert_at(acc, pos, "♗") end)
|> Enum.join
end
end
Enum.each(1..5, fn _ -> IO.puts Chess960.construct end)