There's a null pointer exception that currently occurs when a rule maps
onto neighbours, e.g.: (map #(population % :deer) (get-neighbours world cell)) I've worked around it for now by commenting out the rules which do this, but the bug is in get-neighbours and should be fixed there.
This commit is contained in:
parent
8a00e5c0da
commit
6320b3e5b0
|
@ -87,12 +87,12 @@
|
|||
(cond (> (* (population cell :deer) 10) (get-int cell :fertility))
|
||||
(merge cell {:deer (int (/ (get-int cell :fertility) 10))})))
|
||||
;; deer gradually spread through the world by breeding or migrating.
|
||||
(fn [cell world]
|
||||
(let [n (apply + (map #(population % :deer) (get-neighbours world cell)))]
|
||||
(cond (and
|
||||
(= (population cell :deer) 0)
|
||||
(>= n 2))
|
||||
(merge cell {:deer (int (/ n 2))}))))
|
||||
;; (fn [cell world]
|
||||
;; (let [n (apply + (map #(population % :deer) (get-neighbours world cell)))]
|
||||
;; (cond (and
|
||||
;; (= (population cell :deer) 0)
|
||||
;; (>= n 2))
|
||||
;; (merge cell {:deer (int (/ n 2))}))))
|
||||
;; deer breed.
|
||||
(fn [cell world]
|
||||
(cond
|
||||
|
@ -110,16 +110,16 @@
|
|||
(merge cell {:wolves 2})))
|
||||
;; if there are not enough deer to sustain the population of wolves,
|
||||
;; some wolves die or move on.
|
||||
(fn [cell world]
|
||||
(cond (> (population cell :wolves) (population cell :deer))
|
||||
(merge cell {:wolves 0})))
|
||||
(fn [cell world]
|
||||
(cond (> (population cell :wolves) (population cell :deer))
|
||||
(merge cell {:wolves 0})))
|
||||
;; wolves gradually spread through the world by breeding or migrating.
|
||||
(fn [cell world]
|
||||
(let [n (apply + (map #(population % :wolves) (get-neighbours world cell)))]
|
||||
(cond (and
|
||||
(= (population cell :wolves) 0)
|
||||
(>= n 2))
|
||||
(merge cell {:wolves 2}))))
|
||||
;; (fn [cell world]
|
||||
;; (let [n (apply + (map #(population % :wolves) (get-neighbours world cell)))]
|
||||
;; (cond (and
|
||||
;; (= (population cell :wolves) 0)
|
||||
;; (>= n 2))
|
||||
;; (merge cell {:wolves 2}))))
|
||||
;; wolves breed.
|
||||
(fn [cell world]
|
||||
(cond
|
||||
|
|
|
@ -30,9 +30,11 @@
|
|||
(defn get-int
|
||||
"Get the value of a property expected to be an integer from a map; if not present (or not an integer) return 0."
|
||||
[map key]
|
||||
(let [v (map key)]
|
||||
(cond (integer? v) v
|
||||
true 0)))
|
||||
(cond map
|
||||
(let [v (map key)]
|
||||
(cond (and v (integer? v)) v
|
||||
true 0))
|
||||
true (throw (Exception. "No map passed?"))))
|
||||
|
||||
(defn population
|
||||
"Return the population of this species in this cell.
|
||||
|
|
Loading…
Reference in a new issue