Separated herbivore rule from predator rules so they can be added

separately.
This commit is contained in:
simon 2014-07-02 23:02:39 +01:00
parent 19db0e0673
commit 580ebb0e8e

View file

@ -63,8 +63,8 @@
(merge cell {:fertility (+ (:fertility cell) 1)}))) (merge cell {:fertility (+ (:fertility cell) 1)})))
)) ))
;; rules describing animal behaviour ;; rules describing herbivore behaviour
(def predation-rules (def herbivore-rules
(list (list
;; deer arrive occasionally at the edge of the map. ;; deer arrive occasionally at the edge of the map.
(fn [cell world] (fn [cell world]
@ -88,7 +88,11 @@
(fn [cell world] (fn [cell world]
(cond (cond
(>= (population cell :deer) 2) (>= (population cell :deer) 2)
(merge cell {:deer (int (* (:deer cell) 4))}))) (merge cell {:deer (int (* (:deer cell) 4))})))))
;; rules describing predator behaviour
(def predator-rules
(list
;; wolves arrive occasionally at the edge of the map. ;; wolves arrive occasionally at the edge of the map.
(fn [cell world] (fn [cell world]
(cond (and (< (count (get-neighbours world cell)) 8) (cond (and (< (count (get-neighbours world cell)) 8)
@ -117,4 +121,4 @@
(merge cell {:deer (- (population cell :deer) (population cell :wolves))})) (merge cell {:deer (- (population cell :deer) (population cell :wolves))}))
)) ))
(def natural-rules (flatten (list vegetation-rules predation-rules))) (def natural-rules (flatten (list vegetation-rules herbivore-rules predator-rules)))