From b666540ac9fa32337422ad3ddec7b04d9bab4263 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Mon, 14 Jul 2014 23:23:11 +0100 Subject: [PATCH] Still some bugs in rules generated from rule-language source. However, a great deal does work. --- README.md | 2 +- resources/public/docs/mw-engine/uberdoc.html | 24 +++++++++++++------ resources/public/docs/mw-parser/uberdoc.html | 4 ++-- resources/public/docs/mw-ui/uberdoc.html | 10 +++++--- resources/public/img/tiles/camp.png | Bin 0 -> 395 bytes resources/public/img/tiles/crop.png | Bin 0 -> 641 bytes resources/public/img/tiles/error.png | Bin 0 -> 160 bytes resources/public/img/tiles/house.png | Bin 0 -> 591 bytes resources/public/img/tiles/market.png | Bin 0 -> 805 bytes resources/public/img/tiles/meadow.png | Bin 0 -> 368 bytes resources/public/img/tiles/ploughland.png | Bin 0 -> 718 bytes src/mw_ui/render_world.clj | 10 +++++--- 12 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 resources/public/img/tiles/camp.png create mode 100644 resources/public/img/tiles/crop.png create mode 100644 resources/public/img/tiles/error.png create mode 100644 resources/public/img/tiles/house.png create mode 100644 resources/public/img/tiles/market.png create mode 100644 resources/public/img/tiles/meadow.png create mode 100644 resources/public/img/tiles/ploughland.png diff --git a/README.md b/README.md index 9375cea..59eb55b 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ spread across everywhere except the very top of the mountain. But after the flood, the waters should drain away again. Go back to [rules](rules) and add this rule at the very top: - if altitude is more than 9 and state is water then state should be grassland + if altitude is more than 9 and state is water then state should be grassland Now the world alternates between *new* and *grassland*. That's no good! Go back to [rules](rules) and delete the rule that you first added - the one that says diff --git a/resources/public/docs/mw-engine/uberdoc.html b/resources/public/docs/mw-engine/uberdoc.html index e83d53a..81e3588 100644 --- a/resources/public/docs/mw-engine/uberdoc.html +++ b/resources/public/docs/mw-engine/uberdoc.html @@ -3065,8 +3065,15 @@ further rules can be applied.

(defn- transform-cell
   [cell world rules]
   (try
-    (apply-rules cell world rules)
-    (catch Exception e (merge {:state :error :error (.getMessage e)} cell)))) 

Return a row derived from this row of this world by applying these rules to each 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))}))))

Return a row derived from this row of this world by applying these rules to each cell.

(defn- transform-world-row
   [row world rules]
   (map #(transform-cell % world rules) row))

Return a world derived from this world by applying these rules to each cell.

@@ -3287,7 +3294,7 @@ ignored). Darker shades are higher.

(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
                     (list
                      vegetation-rules
@@ -3373,12 +3380,15 @@ ignored). Darker shades are higher.

* `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 +* `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.

(defn get-neighbours-with-property-value
-  ([world x y depth property value comparator]
-    (filter #(apply comparator (list (get % property) value)) (get-neighbours world x y depth)))
+  ([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]
diff --git a/resources/public/docs/mw-parser/uberdoc.html b/resources/public/docs/mw-parser/uberdoc.html
index 0c68227..7032d5b 100644
--- a/resources/public/docs/mw-parser/uberdoc.html
+++ b/resources/public/docs/mw-parser/uberdoc.html
@@ -3226,9 +3226,9 @@ front of the sequence of tokens it returns nil.

(cond (and (= comp1 "equal") (= comp2 "to")) (gen-neighbours-condition comparator quantity property value remainder '=) (and (= comp1 "more") (= comp2 "than")) - (gen-neighbours-condition '> quantity property value remainder '>) + (gen-neighbours-condition comparator quantity property value remainder '>) (and (= comp1 "less") (= comp2 "than")) - (gen-neighbours-condition '< quantity property value remainder '<)))))))
+ (gen-neighbours-condition comparator quantity property value remainder '<)))))))
(defn parse-some-neighbours-condition
   [[SOME NEIGHBOURS & rest]]
   (cond
diff --git a/resources/public/docs/mw-ui/uberdoc.html b/resources/public/docs/mw-ui/uberdoc.html
index 4a5d41a..c2cde8a 100644
--- a/resources/public/docs/mw-ui/uberdoc.html
+++ b/resources/public/docs/mw-ui/uberdoc.html
@@ -3124,6 +3124,7 @@ net.brehaut.ClojureTools = (function (SH) {
             [mw-engine.world :as world]
             [mw-engine.heightmap :as heightmap]
             [mw-engine.natural-rules :as rules]
+            [mw-parser.bulk :as compiler]
             [hiccup.core :refer [html]]
             [noir.session :as session]))
(defn format-css-class [statekey]
@@ -3135,12 +3136,13 @@ net.brehaut.ClojureTools = (function (SH) {
   [statekey]
   (format "img/tiles/%s.png" (format-css-class statekey)))
(defn format-mouseover [cell]
-  (str "State " (:state cell) "; altitude: " (:altitude cell) "; fertility: " (:fertility cell)))

Render this world cell as a Hiccup table cell.

+ (str cell))

Render this world cell as a Hiccup table cell.

(defn render-cell
   [cell]
   (let [state (:state cell)]
     [:td {:class (format-css-class state) :title (format-mouseover cell)}
-            [:img {:alt (world/format-cell cell) :src (format-image-path state)}]]))

Render this world row as a Hiccup table row.

+ [:a {:href (format "inspect?x=%d&amp;y=%d" (:x cell) (:y cell))} + [:img {:alt (world/format-cell cell) :src (format-image-path state)}]]]))

Render this world row as a Hiccup table row.

(defn render-world-row
   [row]
   (apply vector (cons :tr (map render-cell row))))

Render the world implied by the session as a complete HTML page.

@@ -3152,7 +3154,9 @@ net.brehaut.ClojureTools = (function (SH) { (world/make-world 20 20) "resources/public/img/20x20/hill.png") rules/init-rules)) - rules (or (session/get :rules) rules/natural-rules) + rules (or (session/get :rules) + (do (session/put! :rules (compiler/compile-file "resources/rulesets/basic.txt")) + (session/get :rules))) generation (+ (or (session/get :generation) 0) 1) w2 (engine/transform-world world rules) ] diff --git a/resources/public/img/tiles/camp.png b/resources/public/img/tiles/camp.png new file mode 100644 index 0000000000000000000000000000000000000000..c2ecf86bc01c4877959c8f10ff6ce3c0adcf8ec1 GIT binary patch literal 395 zcmV;60d)R}P)2-cgcVC76a`;BLylqZ=3%6l z@B}_8tdQVKp}Xn$U>lnzv8H0@X?Ee8k70I)H%}=}4TC?#|G%KwfBexgs}>v(xo_*|i`*~HC`LWqJi0$DUmcYW1Ob8TZ422^G+cJAZf?cN7r3!4B} z3PK%EdrYTHv(+G)d;`j94HV! zjij81uyGnGlJa^CRoN9>(4i~x_5LVGlUB%OxOp}3s#oc|V#TqMm5q=cWWy4FdgVkDX6QMrzZF^-qC9k|nMYCC>S|xv6<249-QVi6yBi3gww484B*6z5(HleBwYw zQl2i3Ar_~T|D1QQOGuKqYO|^`(R5;7Ul)G*dK@^7nGdttGcrO^_$gy$aBuZo_n}C3d z3RzGjRFo8mR0wzi9*3F-AQCS?MMDV!1#v4tD4W>pwRd+8g~`UTgk*>ir#l*b^Nr4B zsPV$V--f^$;!Lpo-GKpEfB-Te0eE&;0Tmca5LbYg(EHF4m}h}YKoznhoSX7O6|~C3 zXW5T8oJ8P!>UI7-RU`x`U>oU9Z=$-9$vfP{^nK@0fEH@3S{ou*|B}xwn0O({f7+5|RM}LIwgM zE=03(>HqL=xm6c~E2HV1&L^)BATFx24?1USKZ^H`i(kd-mA?m`rPWOTleeJ zwmZ+_*f0aBMQHQR!OU=L^Uj+ngajcd71Hq+O?j9b2J{&^Gt8QvyJZ5DDu!az5Fv;V z?9Q`x=UJD|W=YbkrboutF3#G-?2+-63mbZAra3J~1+b!7YL zL)#CIWF#}*x^XzQx+T2#@d59AzMzCK;N3450F)3BkWvRlkf)L# zIy@c#3myWz(Via^9n**Z=@B57*o25^Cpfd^Y@KRJXa3t1v{LW0p@38+%nX|VeD0}^ z$2N@)M=nx=+jmE1Q&V=H%`65{B@CnM;D`H#jbw~fq|NL^KrPc&4tqBb!M)XSEWUnu zlf9dVTy?k>aMj`aDP9Zk2vG%n66a56lCQzTSM!zJ8`!PetR3r8?By4F#>zw1w$3HYz(7FYk2&7KUVT+m(OLT!>u_2j025mk&!x3LEBsV6(!p)(kYNN)V{XJ!9j(w}g;&Z#vpGeU6x zuZpXED1<}}h}ss^5V?bx96R`z)8^DhOtv1FdgVkDX6Y&noRhDl1S(vcxr_#5q4VH#M(>!MP|ku_QG`p**uBL&4qCHz2%`PaLS| zm8Xkih{fsTDff;Zb|g)?@78&d zZf3qd8mWrf# ztqc5Y4E-I9|IJWeAX$ILSm?}opy-A)prFN;k4J1=Kk_g%m^ZXHxLvys^fiO0tDnm{ Hr-UW|nW~kA literal 0 HcmV?d00001 diff --git a/resources/public/img/tiles/ploughland.png b/resources/public/img/tiles/ploughland.png new file mode 100644 index 0000000000000000000000000000000000000000..0df26f87ceb137762d3fe8d8ebd353ed3eec46d7 GIT binary patch literal 718 zcmV;<0x|uGP)ry7` z`0s-d8Fc$6{JELRq|FMC%-cnVPVwlzX3V6Us=nQHo7#r~gdlVcuBl9bjQqYcQvjBv zwfnhP+igxc0-GU`p#+5NbqJ6&GVT{`-u5++7@|TUB0N(L#%*XMZE=XygbbeBr@S`` zuGCKEz>VQP{b|(pXd~2ZL#C!^(J!AeQ&_9m)kzdiX$)mh?QX_McC*`o+-53F`v=Cc z*W3Rsd>Ps1y`7i3F~kRPHOJoNZd=?Y833|(BQX=CYM-*;nz~X^b_+=(u8CXF`5y4Ds-Um00+lo*~5g@SEG5UB;H<(i{dsP3}-|Z3Mri4T$ z-AEouNP&yb&v=!wPcf<)soU^wGQq6!X$x0#O8dC&KQBo*L{RJyw_1_GkG~ z?bBdosO^w{e+BSshQxDqwJ&4{F@kH59|xNM0fj)$H7u=^8vp