Skip to content

Instantly share code, notes, and snippets.

@amalloy
Forked from anonymous/gist:1086926
Created July 16, 2011 23:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save amalloy/1086948 to your computer and use it in GitHub Desktop.
(defn add-buildings
([world]
(add-buildings world 0.5))
([world prob]
(let [maxy (dec (count world))
maxx (dec (count (world 0)))]
(loop [world world, cury maxy, curx maxx]
(if (and (zero? curx) (zero? cury))
world
(let [new-world (update-in world [cury curx]
(fn [arg]
(if (> (rand) prob)
(make-building 1.0 0.0 {})
arg)))]
(if (zero? curx)
(recur new-world (dec cury) maxx)
(recur new-world cury (dec curx)))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment