Added settlement ruleset

This commit is contained in:
Simon Brooke 2014-07-20 15:17:09 +01:00
parent 1c838a79bd
commit 4a48acee20
4 changed files with 21 additions and 19 deletions

View file

@ -3366,7 +3366,7 @@ important.</p>
</ul> </ul>
</td><td class="codes"><pre class="brush: clojure">(defn get-int </td><td class="codes"><pre class="brush: clojure">(defn get-int
[map key] [map key]
(cond map (cond (map? map)
(let [v (map key)] (let [v (map key)]
(cond (and v (integer? v)) v (cond (and v (integer? v)) v
true 0)) true 0))
@ -3415,14 +3415,19 @@ important.</p>
* `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 (or, possibly, the name of another);
* `op` a comparator function to use in place of `=`. * `op` a comparator function to use in place of `=`.
</code></pre> </code></pre>
<p> It gets messy.</p> <p> It gets messy.</p>
</td><td class="codes"><pre class="brush: clojure">(defn get-neighbours-with-property-value </td><td class="codes"><pre class="brush: clojure">(defn get-neighbours-with-property-value
([world x y depth property value op] ([world x y depth property value op]
(filter #(eval (list op (get % property) value)) (get-neighbours world x y depth))) (filter
#(eval
(list op
(or (get % property) (get-int % 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]

View file

@ -3053,18 +3053,11 @@ objective is to parse rules out of a block of text from a textarea</p>
function, and return the sequence of such functions.</p> function, and return the sequence of such functions.</p>
</td><td class="codes"><pre class="brush: clojure">(defn compile-string </td><td class="codes"><pre class="brush: clojure">(defn compile-string
[string] [string]
(map #(compile-rule % true) (remove comment? (split string #&quot;\n&quot;))))</pre></td></tr><tr><td class="docs"><p>Compile each non-comment line of the file indicated by this <code>filename</code> into (map #(compile-rule % true) (remove comment? (trim (split string #&quot;\n&quot;)))))</pre></td></tr><tr><td class="docs"><p>Compile each non-comment line of the file indicated by this <code>filename</code> into
an executable anonymous function, and return the sequence of such functions.</p> an executable anonymous function, and return the sequence of such functions.</p>
</td><td class="codes"><pre class="brush: clojure">(defn compile-file </td><td class="codes"><pre class="brush: clojure">(defn compile-file
[filename] [filename]
(compile-string (slurp filename)))</pre></td></tr><tr><td class="docs"><p> (let [lines (compile-string (slurp filename)))</pre></td></tr><tr><td class="spacer docs">&nbsp;</td><td class="codes" /></tr><tr><td class="docs"><div class="docs-header"><a class="anchor" href="#mw-parser.core" name="mw-parser.core"><h1 class="project-name">mw-parser.core</h1><a class="toc-link" href="#toc">toc</a></a></div></td><td class="codes" /></tr><tr><td class="docs"><p>A very simple parser which parses production rules of the following forms:</p>
(doall (with-open [rdr (reader filename)] (line-seq rdr)))]
(map parse-line lines)))</p>
</td><td class="codes"></td></tr><tr><td class="docs"><p>(defn parse-string
"Parse rules from successive lines in this <code>string</code>"
[string]
(parse-from-reader (BufferedReader. (StringReader. string))))</p>
</td><td class="codes"></td></tr><tr><td class="spacer docs">&nbsp;</td><td class="codes" /></tr><tr><td class="docs"><div class="docs-header"><a class="anchor" href="#mw-parser.core" name="mw-parser.core"><h1 class="project-name">mw-parser.core</h1><a class="toc-link" href="#toc">toc</a></a></div></td><td class="codes" /></tr><tr><td class="docs"><p>A very simple parser which parses production rules of the following forms:</p>
<ul> <ul>
<li>"if altitude is less than 100 and state is forest then state should be climax and deer should be 3"</li> <li>"if altitude is less than 100 and state is forest then state should be climax and deer should be 3"</li>

View file

@ -3142,7 +3142,7 @@ net.brehaut.ClojureTools = (function (SH) {
(let [state (:state cell)] (let [state (:state cell)]
[:td {:class (format-css-class state) :title (format-mouseover cell)} [:td {:class (format-css-class state) :title (format-mouseover cell)}
[:a {:href (format &quot;inspect?x=%d&amp;amp;y=%d&quot; (:x cell) (:y cell))} [:a {:href (format &quot;inspect?x=%d&amp;amp;y=%d&quot; (: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> [:img {:alt (:state 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 </td><td class="codes"><pre class="brush: clojure">(defn render-world-row
[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> (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>
@ -3151,8 +3151,8 @@ net.brehaut.ClojureTools = (function (SH) {
(let [world (or (session/get :world) (let [world (or (session/get :world)
(engine/transform-world (engine/transform-world
(heightmap/apply-heightmap (heightmap/apply-heightmap
;;&quot;resources/public/img/20x20/hill.png&quot; &quot;resources/public/img/20x20/hill.png&quot;
&quot;resources/public/img/heightmaps/great_britain_and_ireland_small.png&quot;) ;; &quot;resources/public/img/heightmaps/great_britain_and_ireland_small.png&quot;)
rules/init-rules)) rules/init-rules))
rules (or (session/get :rules) rules (or (session/get :rules)
(do (session/put! :rules (compiler/compile-file &quot;resources/rulesets/basic.txt&quot;)) (do (session/put! :rules (compiler/compile-file &quot;resources/rulesets/basic.txt&quot;))

View file

@ -9,7 +9,7 @@ if state is in grassland or heath and some neighbours are camp then state should
;; and more herds support more people ;; and more herds support more people
if state is in grassland or heath and more than 2 neighbours are meadow then state should be camp if state is in grassland or heath and more than 2 neighbours are meadow then state should be camp
if state is meadow and more than 3 neighbours are meadow and if state is meadow and more than 3 neighbours are meadow and fewer than 1 neighbours are camp and fewer than 1 neighbours within 2 are house then state should be camp
;; the idea of agriculture spreads ;; the idea of agriculture spreads
if state is in grassland or heath and some neighbours are meadow and some neighbours within 3 are house then state should be meadow if state is in grassland or heath and some neighbours are meadow and some neighbours within 3 are house then state should be meadow
@ -20,6 +20,9 @@ if state is camp then 1 chance in 5 state should be waste
;; meadow that's too far from a house or camp will be abandoned ;; meadow that's too far from a house or camp will be abandoned
if state is meadow and fewer than 1 neighbours within 3 are house and fewer than 1 neighbours within 2 are camp then state should be heath if state is meadow and fewer than 1 neighbours within 3 are house and fewer than 1 neighbours within 2 are camp then state should be heath
;; markets spring up near settlements
if state is in grassland or meadow and more than 1 neighbours are house then 1 chance in 10 state should be market
;; good fertile pasture close to settlement will be ploughed for crops ;; good fertile pasture close to settlement will be ploughed for crops
if state is meadow and fertility is more than 10 and altitude is less than 100 and some neighbours are camp or some neighbours are house then state should be ploughland if state is meadow and fertility is more than 10 and altitude is less than 100 and some neighbours are camp or some neighbours are house then state should be ploughland
@ -30,12 +33,10 @@ if state is crop then state should be grassland
;; if there's reliable food available, nomads build permanent settlements ;; if there's reliable food available, nomads build permanent settlements
if state is in camp or abandoned and some neighbours are crop then state should be house if state is in camp or abandoned and some neighbours are crop then state should be house
if state is abandoned and some neighbours are meadow then state should be house
;; people camp near to markets ;; people camp near to markets
if state is in waste or grassland and some neighbours are market then state should be camp if state is in waste or grassland and some neighbours are market then state should be camp
;; markets spring up near settlements
if state is meadow and more than 1 neighbours are house then 1 chance in 10 state should be market
;; a market in a settlement survives ;; a market in a settlement survives
if state is market and more than 3 neighbours are house then state should be market if state is market and more than 3 neighbours are house then state should be market
if state is market and some neighbours are inn then state should be market if state is market and some neighbours are inn then state should be market
@ -81,6 +82,9 @@ if state is climax then 1 chance in 500 state should be fire
;; Climax forest neighbouring fires is likely to catch fire. So are buildings. ;; Climax forest neighbouring fires is likely to catch fire. So are buildings.
if state is in climax or camp or house or inn and some neighbours are fire then 1 chance in 3 state should be fire if state is in climax or camp or house or inn and some neighbours are fire then 1 chance in 3 state should be fire
;; Climax forest near to settlement may be cleared for timber
if state is in climax and more than 3 neighbours within 2 are house then state should be waste
;; After fire we get waste ;; After fire we get waste
if state is fire then state should be waste if state is fire then state should be waste