From b666540ac9fa32337422ad3ddec7b04d9bab4263 Mon Sep 17 00:00:00 2001 From: Simon Brooke <simon@journeyman.cc> 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.</p> </td><td class="codes"><pre class="brush: clojure">(defn- transform-cell [cell world rules] (try - (apply-rules cell world rules) - (catch Exception e (merge {:state :error :error (.getMessage e)} cell)))) </pre></td></tr><tr><td class="docs"><p>Return a row derived from this row of this world by applying these rules to each cell.</p> + (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))})))) </pre></td></tr><tr><td class="docs"><p>Return a row derived from this row of this world by applying these rules to each cell.</p> </td><td class="codes"><pre class="brush: clojure">(defn- transform-world-row [row world rules] (map #(transform-cell % world rules) row))</pre></td></tr><tr><td class="docs"><p>Return a world derived from this world by applying these rules to each cell.</p> @@ -3287,7 +3294,7 @@ ignored). Darker shades are higher.</p> (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})))))</pre></td></tr><tr><td class="docs"> + (fn [cell world] (cond (= (:state cell) :new) (merge cell {:state :grassland})))))</pre></td></tr><tr><td class="docs"> </td><td class="codes"><pre class="brush: clojure">(def natural-rules (flatten (list vegetation-rules @@ -3373,12 +3380,15 @@ ignored). Darker shades are higher.</p> * `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 `=`. </code></pre> + +<p> It gets messy.</p> </td><td class="codes"><pre class="brush: clojure">(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.</p> (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 '<)))))))</pre></td></tr><tr><td class="docs"> + (gen-neighbours-condition comparator quantity property value remainder '<)))))))</pre></td></tr><tr><td class="docs"> </td><td class="codes"><pre class="brush: clojure">(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]))</pre></td></tr><tr><td class="docs"> </td><td class="codes"><pre class="brush: clojure">(defn format-css-class [statekey] @@ -3135,12 +3136,13 @@ net.brehaut.ClojureTools = (function (SH) { [statekey] (format "img/tiles/%s.png" (format-css-class statekey)))</pre></td></tr><tr><td class="docs"> </td><td class="codes"><pre class="brush: clojure">(defn format-mouseover [cell] - (str "State " (:state cell) "; altitude: " (:altitude cell) "; fertility: " (:fertility cell)))</pre></td></tr><tr><td class="docs"><p>Render this world cell as a Hiccup table cell.</p> + (str cell))</pre></td></tr><tr><td class="docs"><p>Render this world cell as a Hiccup table cell.</p> </td><td class="codes"><pre class="brush: clojure">(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)}]]))</pre></td></tr><tr><td class="docs"><p>Render this world row as a Hiccup table row.</p> + [:a {:href (format "inspect?x=%d&amp;y=%d" (:x cell) (:y cell))} + [:img {:alt (world/format-cell cell) :src (format-image-path state)}]]]))</pre></td></tr><tr><td class="docs"><p>Render this world row as a Hiccup table row.</p> </td><td class="codes"><pre class="brush: clojure">(defn render-world-row [row] (apply vector (cons :tr (map render-cell row))))</pre></td></tr><tr><td class="docs"><p>Render the world implied by the session as a complete HTML page.</p> @@ -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)<h;3K|Lk000e1NJLTq000yK000yS0ssI20_%!e00009a7bBm000XU z000XU0RWnu7ytkO2XskIMF-vo4iPdQyoB6|0000PbVXQnLvL+uWo~o;Lvm$dbY)~9 zcWHEJAV*0}P*;Ht7XSbO1xZ9fR5;7Mlu=5<KoExie>2-cgcVC76a`;BLylqZ=3%6l z@B}_8tdQVKp}Xn$U>lnzv8H0@X?Ee8k70I)H%}=}4TC?#|G<n$N@Y9=Hl?P^jVX0B z%n0$2R}~M2k?@yx@}lXoHkFQmw_2}U?UL|oc-w8I2l;XMTN`?gN8qmN2e}#2T4C<Q z3U`<2&fN5B3FJ;5ip$&y0aNwQ+ze^wGkbSEna`{hGC;g`<)&AgIaw6${&u=3TsACk znUhKxpnwAFsP7*!L<OJ#1Cr|SsY{copw0*dfH$chpGzwYQT;_7rvy-ERB6w(Sq6+S pd*6sn(Y@-Ms}|oj=RDss_yi!HoexEZnl=Cc002ovPDHLkV1ja4oaO)k literal 0 HcmV?d00001 diff --git a/resources/public/img/tiles/crop.png b/resources/public/img/tiles/crop.png new file mode 100644 index 0000000000000000000000000000000000000000..b154cdc249dd80f015bab3f95c7595c5fe8f1c00 GIT binary patch literal 641 zcmV-{0)G98P)<h;3K|Lk000e1NJLTq000yK000yS0ssI20_%!e00009a7bBm000XU z000XU0RWnu7ytkO2XskIMF-vo4iX72q^Z3`0000PbVXQnLvL+uWo~o;Lvm$dbY)~9 zcWHEJAV*0}P*;Ht7XSbO`$<GWR5;63lu=F`F%U#wwLOc%E}&e5L^*sek$i-EL?V!d zknFfCAMIISG#bmAF1!16*?RtZ0D}Nwka_#Oo9X?uZ*zli*nt5V*%Fqr7L<(gt-cGu zM$T|9ws3%KY)L64VIW58`Q$6;764%|Vh!CZ|2B`FW677!&*qmU*IkZXt~-y;BklX( zQRmVEV~2l5d`lkX3>%KwfBexgs}>v(xo_*|i`*~HC`LWqJi0$D<F@5xBL(uMPPa=Q zBzZE-aBF!ZWQ@F8qvMX7)qUM<QLn<+M(MP`GOReTkX1CK$kCkLXhJYHo-Gn5={`AO z0*BqO(4-xVZpYNgsCtu%Br=}X<?czpN1>UmcYW1Ob8TZ422^G+cJAZf?cN7r3!4B} z3PK%EdrYTHv(+G)d;`j94H<BGN$$i@hAWgU|5w|Ag!IO&l7kc?6p8S8^D_;=fk3&H zTGfP&5mXI`Rq-%5d1|UF=j}9*HBt|Qk*LyCc_rhxE_X*A2L_+BD2x^Bcs}j!p5kd0 zDH5yCkVBk4U9u095L@z|km`6`v3|Mm0W|7=pJ#1JJ_-*Z+moD9+hJ5oHM3*70I>V! zjij81uyGnGlJa^CRoN9>(4i~x_5LVGlUB%OxOp}3s#oc|V#TqMm5q=cWWy4<DXmfh bWUcZaC)HuVZ2Teo00000NkvXXu0mjf!#@`W literal 0 HcmV?d00001 diff --git a/resources/public/img/tiles/error.png b/resources/public/img/tiles/error.png new file mode 100644 index 0000000000000000000000000000000000000000..f4409bc61f2ce2b2f8969573aeac1ef50c676d9f GIT binary patch literal 160 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1SFYWcSQjy&H|6fVg?3oVGw3ym^DWND9B#o z>FdgVkDX6QMrzZF^-qC9k|nMYCC>S|xv6<249-QVi6yBi3gww484B*6z5(HleBwYw zQl2i3Ar_~T|D1QQOGuKqYO|^`<nxMWj8}OWl;$w13;8J&0aY=0y85}Sb4q9e0NnE_ ANB{r; literal 0 HcmV?d00001 diff --git a/resources/public/img/tiles/house.png b/resources/public/img/tiles/house.png new file mode 100644 index 0000000000000000000000000000000000000000..222e81af7a3a0b53349839b4257b8e870943c4eb GIT binary patch literal 591 zcmV-V0<iswP)<h;3K|Lk000e1NJLTq000yK000yS0ssI20_%!e00009a7bBm000XU z000XU0RWnu7ytkO2XskIMF-vo4iPytgv-p70000PbVXQnLvL+uWo~o;Lvm$dbY)~9 zcWHEJAV*0}P*;Ht7XSbO$w@>(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><T)dbiBhhSy%5+jezY10U$5&v|m%FHbu~4Mr$~u6Z#m zcNUs=9lKSoT%(UqacHRFhu6CQZNh(Iwtxn#PzE=w=9b%DUcB%4mqn?jRHbY;%;f7i zJ?iCyK4$~4o`g$49ctZhyVk;{*J&;8+Wr<90YD^7r2@xpTFGZWA06tr$9V$QW0-&d zScBY=_0U~gYCUw^4Kn<q6eO%MZy&u4M!iq^D1sgqLsDjRBfSzE)w#!xA5M_R7Z{%H zt-I%U=VSMF1e=d1jDhcj>oU9Z=$-9$vfP{^nK@0fEH@3S{ou*|B}xwn0O({f7+<yr zI@d%ri5003B281NWPQ&DO|^=^`d1g@=MDg8CmyF)mlc3l?^7WJYX<$h#VDMA3^VhL dX8LbG$xkU0mzz;WQ-J^g002ovPDHLkV1lC7^CAEM literal 0 HcmV?d00001 diff --git a/resources/public/img/tiles/market.png b/resources/public/img/tiles/market.png new file mode 100644 index 0000000000000000000000000000000000000000..a4f3bdbbf7a30c3950e7d7c9442943947c648fb4 GIT binary patch literal 805 zcmV+=1KRwFP)<h;3K|Lk000e1NJLTq000yK000yS1^@s6jfou%00009a7bBm000XU z000XU0RWnu7ytkO2XskIMF-vo4iW_f)2BP00000PbVXQnLvL+uWo~o;Lvm$dbY)~9 zcWHEJAV*0}P*;Ht7XSbPpGibPR5;6pl|hRgMHGd<d%LRV4I+x*7$VB>5|RM}LIwgM zE=03(>HqL=xm6c~E<yxRF>2HV1&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+-63mbZAr<X%Jl`ZQ#VRXJyW~{CBWY+Fu-GV-^ z-mp(b4X`Wcd!-IiXWV^Im_L)K0eym$jO@nk9|vCC&fK~;a&f-FP=Z>a3J~1+b!7YL zL<!*`a5I*7{mHF?>)#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<zztn@DY6X z+sL`onT_1|Ox`NKacAJl&Ww+~J><gknNmcNDAkA%KmA_u8eka7+M?98oj&|x!P}oL zFo_!C%?}!n`-=*|^-mY<eKk<4QHpr~>#>zw1w$3HYz(7FYk2&7KUVT+m(OLT<Rs$= zg`fW@C*INaR>!>u_2j025mk&!x3LEBsV6(!p)(kYNN)V{XJ!9j(w}g;&Z#vpGeU6x zuZpXED1<}}h}ss^5V?bx96R`z)8^DhOtv1<kz3iNvsvzjw6uF2`Qxm&qhG*KrjtZ7 jg5-vz=JMVMsTKYKl00uh3(!T(00000NkvXXu0mjf5PfzY literal 0 HcmV?d00001 diff --git a/resources/public/img/tiles/meadow.png b/resources/public/img/tiles/meadow.png new file mode 100644 index 0000000000000000000000000000000000000000..44453f997e30d003276c90e0469c1dcfcccc437e GIT binary patch literal 368 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1SFYWcSQjy&H|6fVg?3oVGw3ym^DWND9B#o z>FdgVkDX6Y&noRhDl1S(vcxr_#5q4VH#M(>!MP|ku_QG`p**uBL&4qCHz2%`PaLS| zm8Xkih{fsTDff;Zb<j&lTEM_FCr!-c-~anO|Kt8ACnO{Yr6#4Qx_$-<>|g)?@78&d zZf<TCUBC73uTQt1|M%Db$q(%XXZ^4J^Zz?X_r!)w*Q(Y%jc*p)f0xb=wfR%`-=6QT z#;ln?C7(8_DzhF|H90CNA@P6D&;S3;?b3}G9X0+OZFVsD(I37$JUl$|{5942-yW_1 zpr2&=|Nq$!?;qEv)v2+uwe6SxZ~W2t0jJrQ3u!5-31W#U2|vysIB-D6>3qd8mWrf# 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)<h;3K|Lk000e1NJLTq000yK000yS0ssI20_%!e00009a7bBm000XU z000XU0RWnu7ytkO2XskIMF-vo4iX0?t@ueo0000PbVXQnLvL+uWo~o;Lvm$dbY)~9 zcWHEJAV*0}P*;Ht7XSbPNJ&INR5;5mlS`6ZISd06r1YxV9lpd|VeWq_d+H;J#4M`0 zM+5?y)W82s0B93J!p0zh$v_e?lMDfE8*EN7KFMmH%fIgmVd=g6edjhJg43Mh>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_+=(<R*f!B#p`a zuG^3xrCqpf1W39KWiq~Itj(Wy|GJByO{%NyRzRi{zE7^Ct=R~TX<I;idfqQ)lBq6$ z5u_vtNpiQY5hG>u8CXF`5y4Ds-Um00+lo*~5g@SEG5UB;H<(i{dsP3}-|Z3Mri4T$ z-AEouNP&yb&v=!wPcf<)soU^wGQq6!X$x0#O8dC&KQBo<R-e+@wn%A|S;wb&Z_csB zUS93LPiJz9*LH{uNn}R0tBr&_+&<{Ftne-@KTd;o@#=P~Oa!}}qS2|o&nQ!7fLxAH zh-1_2qtpJr`4l0}aUaH@#rt6MgBzmF`*@u`O_!^Au6{1Rj%~_R>*L{RJyw_1_GkG~ z?bBdosO^w{e+BSshQxDqwJ&4{F@kH59|xNM0fj)$H7u=^8vp<R07*qoM6N<$f)fQr Awg3PC literal 0 HcmV?d00001 diff --git a/src/mw_ui/render_world.clj b/src/mw_ui/render_world.clj index a4cc30c..473eb79 100644 --- a/src/mw_ui/render_world.clj +++ b/src/mw_ui/render_world.clj @@ -3,6 +3,7 @@ [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])) @@ -19,14 +20,15 @@ (format "img/tiles/%s.png" (format-css-class statekey))) (defn format-mouseover [cell] - (str "State " (:state cell) "; altitude: " (:altitude cell) "; fertility: " (:fertility cell))) + (str cell)) (defn render-cell "Render this world cell as a Hiccup table 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)}]])) + [:a {:href (format "inspect?x=%d&y=%d" (:x cell) (:y cell))} + [:img {:alt (world/format-cell cell) :src (format-image-path state)}]]])) (defn render-world-row "Render this world row as a Hiccup table row." @@ -42,7 +44,9 @@ (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) ]