Anonymous user
Maze generation: Difference between revisions
→{{header|Elixir}}: change :random -> :rand module, Process dictionary -> Map
m (J: add some comments - probably should make a sub-page which goes into more detail) |
(→{{header|Elixir}}: change :random -> :rand module, Process dictionary -> Map) |
||
Line 1,815:
<lang elixir>defmodule Maze do
def generate(w, h) do
maze = (for i <- 1..w, j <- 1..h, into: Map.new, do: {{:vis, i, j}, true})
print(maze, w, h)▼
maze
▲ print(w, h)
end
defp walk(map, x, y) do
|> Enum.
if
{k, v} = if i == x, do:
else:
walk(Map.put(acc, k, v), i, j)
else
acc
end
end)
end
defp print(map, w, h) do
Enum.each(1..h, fn j ->
IO.puts
IO.puts
end)
IO.puts String.duplicate("+---", w) <> "+"
Line 1,868 ⟶ 1,869:
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
</pre>
=={{header|Elm}}==
<lang elm>import Maybe as M
|