From 601c7d74a6b1aa2618250921d57c6109616f9d9a Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Mon, 14 Jul 2014 23:21:09 +0100 Subject: [PATCH] Still some bugs in rules generated from rule-language source. However, a great deal does work. --- src/mw_engine/core.clj | 11 +++++++++-- src/mw_engine/natural_rules.clj | 2 +- src/mw_engine/utils.clj | 11 +++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/mw_engine/core.clj b/src/mw_engine/core.clj index 6e4c0dc..a80103e 100644 --- a/src/mw_engine/core.clj +++ b/src/mw_engine/core.clj @@ -39,8 +39,15 @@ exception is thrown, cache its message on the cell and set state to error" [cell world rules] (try - (apply-rules cell world rules) - (catch Exception e (merge {:state :error :error (.getMessage e)} cell)))) + (merge + (apply-rules cell world rules) + {:generation (+ (or (:generation cell) 0) 1)}) + (catch Exception e + (merge cell {:error + (format "%s at generation %d when in state %s" + (.getMessage e) + (:generation cell) + (:state cell))})))) (defn- transform-world-row "Return a row derived from this row of this world by applying these rules to each cell." diff --git a/src/mw_engine/natural_rules.clj b/src/mw_engine/natural_rules.clj index 153210c..a7c86ef 100644 --- a/src/mw_engine/natural_rules.clj +++ b/src/mw_engine/natural_rules.clj @@ -147,7 +147,7 @@ (fn [cell world] (cond (and (= (:state cell) :new) (> (get-int cell :altitude) snowline)) (merge cell {:state :snow}))) ;; in between, we have a wasteland. - (fn [cell world] (cond (= (:state cell) :new) (merge cell {:state :waste})) + (fn [cell world] (cond (= (:state cell) :new) (merge cell {:state :grassland})) ))) (def natural-rules (flatten diff --git a/src/mw_engine/utils.clj b/src/mw_engine/utils.clj index ebe8e20..7fcc691 100644 --- a/src/mw_engine/utils.clj +++ b/src/mw_engine/utils.clj @@ -88,10 +88,13 @@ * `cell` a cell within that world; * `depth` an integer representing the distance from [x,y] that should be searched; - * `property` a keyword representing a property of the neighbours. - * `value` a value of that property" - ([world x y depth property value comparator] - (filter #(apply comparator (list (get % property) value)) (get-neighbours world x y depth))) + * `property` a keyword representing a property of the neighbours; + * `value` a value of that property; + * `op` a comparator function to use in place of `=`. + + It gets messy." + ([world x y depth property value op] + (filter #(eval (list op (get % property) value)) (get-neighbours world x y depth))) ([world x y depth property value] (get-neighbours-with-property-value world x y depth property value =)) ([world cell depth property value]