Carcigenicate

Game of Life Enviro

May 21st, 2016
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defrecord Point [x y])
  2.  
  3. (defrecord Enviro [cells dims])
  4.  
  5. (defn create-dead-enviro [width height]
  6.   (Enviro.
  7.     (replicate (* width height) :dead)
  8.     (->Point width height)))
  9.  
  10. (defn index-of [width x y]
  11.   (+ (* y width) x))
  12.  
  13. (defn enviro-index-of [enviro x y]
  14.   (let [width (-> enviro :dims :x)]
  15.     (index-of width x y)))
  16.  
  17. (defn set-cell-at [enviro x y cell]
  18.   (let [cells (:cells enviro)
  19.         index (enviro-index-of enviro x y)]
  20.     (assoc enviro :cells (assoc cells index cell))))
Advertisement
Add Comment
Please, Sign In to add comment