diff --git a/src/mw_engine/natural_rules.clj b/src/mw_engine/natural_rules.clj index b21ce61..06de00c 100644 --- a/src/mw_engine/natural_rules.clj +++ b/src/mw_engine/natural_rules.clj @@ -87,13 +87,13 @@ (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))})))) - ;; deer breed. + (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 (>= (population cell :deer) 2) @@ -114,13 +114,13 @@ (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})))) - ;; wolves breed. + (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 (>= (population cell :wolves) 2) diff --git a/src/mw_engine/utils.clj b/src/mw_engine/utils.clj index 86cc016..5b2b7ec 100644 --- a/src/mw_engine/utils.clj +++ b/src/mw_engine/utils.clj @@ -48,11 +48,12 @@ (defn get-neighbours ([world x y depth] "Get the neighbours to distance depth of the cell at x, y in this world." - (map #(get-cell world (first %) (first (rest %))) - (remove #(= % (list x y)) - (combo/cartesian-product - (range (- x depth) (+ x depth)) - (range (- y depth) (+ y depth)))))) + (remove nil? + (map #(get-cell world (first %) (first (rest %))) + (remove #(= % (list x y)) + (combo/cartesian-product + (range (- x depth) (+ x depth 1)) + (range (- y depth) (+ y depth 1))))))) ([world cell depth] "Get the neighbours to distance depth of this cell in this world." (get-neighbours world (:x cell) (:y cell) depth))