-
-
Save rightfold/32c337a1a44670f4ed6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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