Skip to content

Instantly share code, notes, and snippets.

@rightfold
Created September 16, 2014 17:56
Show Gist options
  • Save rightfold/32c337a1a44670f4ed6d to your computer and use it in GitHub Desktop.
Save rightfold/32c337a1a44670f4ed6d to your computer and use it in GitHub Desktop.
def add_river(chunk, rng) do
{x, rng} = random(0..chunk_size - 1, rng)
y = 0
{cells, rng} = add_river_parts({x, y}, chunk[:cells], rng)
{%__MODULE__{ chunk | cells: cells }, rng}
end
defp add_river_parts({x, y}, cells, rng) do
if y == chunk_size do
{cells, rng}
else
{dx, rng} = random(-1..1, rng)
x = x + dx
y = if(dx == 0, do: y + 1, else: y)
cells = Dict.put(cells, {x, y}, :water)
add_river_parts({x, y}, cells, rng)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment