Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Mazes Ch.10

ch_10.livemd

Mazes Ch.10

Mix.install([{:mazes, path: "~/projects/elixir_mazes"}])

Kruskal’s Algorithm

state = Grid.new(25,25)
|> Grid.prepare_grid()
|> Kruskal.State.new()
|> Kruskal.on()

state.grid

Weaves

state = Grid.new(30,30,:square,true)
|> Grid.prepare_grid()
|> Map.put(:simple_neighbors, true)
|> Kruskal.State.new()

weave_count = 100 #Enum.count(state.grid.grid)
state = Enum.reduce(1..weave_count, state, fn (_, state) ->
  grid = state.grid.grid
  row = 1 + :random.uniform(state.grid.rows - 3)
  col = 1 + :random.uniform(state.grid.cols - 3)
  Kruskal.State.add_crossing(state, Map.get(grid, {row, col}))
end)
state = Kruskal.on(state)

state.grid