Still some bugs in rules generated from rule-language source. However,
a great deal does work.
This commit is contained in:
parent
76ab08534c
commit
601c7d74a6
|
@ -39,8 +39,15 @@
|
||||||
exception is thrown, cache its message on the cell and set state to error"
|
exception is thrown, cache its message on the cell and set state to error"
|
||||||
[cell world rules]
|
[cell world rules]
|
||||||
(try
|
(try
|
||||||
|
(merge
|
||||||
(apply-rules cell world rules)
|
(apply-rules cell world rules)
|
||||||
(catch Exception e (merge {:state :error :error (.getMessage e)} cell))))
|
{: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
|
(defn- transform-world-row
|
||||||
"Return a row derived from this row of this world by applying these rules to each cell."
|
"Return a row derived from this row of this world by applying these rules to each cell."
|
||||||
|
|
|
@ -147,7 +147,7 @@
|
||||||
(fn [cell world]
|
(fn [cell world]
|
||||||
(cond (and (= (:state cell) :new) (> (get-int cell :altitude) snowline)) (merge cell {:state :snow})))
|
(cond (and (= (:state cell) :new) (> (get-int cell :altitude) snowline)) (merge cell {:state :snow})))
|
||||||
;; in between, we have a wasteland.
|
;; 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
|
(def natural-rules (flatten
|
||||||
|
|
|
@ -88,10 +88,13 @@
|
||||||
* `cell` a cell within that world;
|
* `cell` a cell within that world;
|
||||||
* `depth` an integer representing the distance from [x,y] that
|
* `depth` an integer representing the distance from [x,y] that
|
||||||
should be searched;
|
should be searched;
|
||||||
* `property` a keyword representing a property of the neighbours.
|
* `property` a keyword representing a property of the neighbours;
|
||||||
* `value` a value of that property"
|
* `value` a value of that property;
|
||||||
([world x y depth property value comparator]
|
* `op` a comparator function to use in place of `=`.
|
||||||
(filter #(apply comparator (list (get % property) value)) (get-neighbours world x y depth)))
|
|
||||||
|
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]
|
([world x y depth property value]
|
||||||
(get-neighbours-with-property-value world x y depth property value =))
|
(get-neighbours-with-property-value world x y depth property value =))
|
||||||
([world cell depth property value]
|
([world cell depth property value]
|
||||||
|
|
Loading…
Reference in a new issue