Added ruleset to model thaw after ice-age, and separated out the

herbivore/predation rules into a separate ruleset 'ecology.txt'
This commit is contained in:
Simon Brooke 2014-07-21 11:20:38 +01:00
parent cbdf01c4c2
commit ea1af2103f
7 changed files with 212 additions and 22 deletions

View file

@ -6,10 +6,22 @@ td.water {
background-color: blue; background-color: blue;
} }
td.pasture, td.grassland { td.pasture, td.grassland, td.meadow {
background-color: lime; background-color: lime;
} }
td.crop {
background-color: yellow;
}
td.camp, td.house, td.inn, td.market {
background-color: gray;
}
td.ploughland {
background-color: brown;
}
td.heath { td.heath {
background-color: chartreuse; background-color: chartreuse;
} }
@ -29,3 +41,12 @@ td.climax {
td.fire { td.fire {
background-color: orange; background-color: orange;
} }
td.error, td.plague {
background-color: red;
}
td.snow, td.ice {
background-color: white;
}

View file

@ -3033,7 +3033,6 @@ net.brehaut.ClojureTools = (function (SH) {
</td><td class="codes"></td></tr><tr><td class="docs"> </td><td class="codes"></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(ns mw-engine.core </td><td class="codes"><pre class="brush: clojure">(ns mw-engine.core
(:require [mw-engine.world :as world] (:require [mw-engine.world :as world]
mw-engine.natural-rules
mw-engine.utils))</pre></td></tr><tr><td class="docs"><p>Every rule is a function of two arguments, a cell and a world. If the rule mw-engine.utils))</pre></td></tr><tr><td class="docs"><p>Every rule is a function of two arguments, a cell and a world. If the rule
fires, it returns a new cell, which should have the same values for :x and fires, it returns a new cell, which should have the same values for :x and
:y as the old cell. Anything else can be modified.</p> :y as the old cell. Anything else can be modified.</p>

View file

@ -3053,7 +3053,7 @@ 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? (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 (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
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]
@ -3404,7 +3404,7 @@ front of the sequence of tokens it returns nil.</p>
(use 'mw-engine.utils) (use 'mw-engine.utils)
(let [afn (eval (parse-rule rule-text))] (let [afn (eval (parse-rule rule-text))]
(cond (cond
(and afn return-tuple?)(list afn rule-text) (and afn return-tuple?)(list afn (trim rule-text))
true afn)))) true afn))))
([rule-text] ([rule-text]
(compile-rule rule-text false)))</pre></td></tr><tr><td class="spacer docs">&nbsp;</td><td class="codes" /></tr></table><div class="footer">Generated by <a href="https://github.com/fogus/marginalia">Marginalia</a>.&nbsp;&nbsp;Syntax highlighting provided by Alex Gorbatchev's <a href="http://alexgorbatchev.com/SyntaxHighlighter/">SyntaxHighlighter</a></div><script type="text/javascript">SyntaxHighlighter.defaults['gutter'] = false; (compile-rule rule-text false)))</pre></td></tr><tr><td class="spacer docs">&nbsp;</td><td class="codes" /></tr></table><div class="footer">Generated by <a href="https://github.com/fogus/marginalia">Marginalia</a>.&nbsp;&nbsp;Syntax highlighting provided by Alex Gorbatchev's <a href="http://alexgorbatchev.com/SyntaxHighlighter/">SyntaxHighlighter</a></div><script type="text/javascript">SyntaxHighlighter.defaults['gutter'] = false;

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 B

View file

@ -0,0 +1,99 @@
## Ruleset which attempts to model predator/prey ecology (not very well yet)
## Vegetation rules
;; rules which populate the world with plants
;; Occasionally, passing birds plant tree seeds into grassland
if state is grassland then 1 chance in 10 state should be heath
;; heath below the treeline grows gradually into forest, providing browsing pressure is not to high
if state is heath and deer are fewer than 6 and altitude is less than 120 then state should be scrub
if state is scrub then 1 chance in 5 state should be forest
;; Forest on fertile land at low altitude grows to climax
if state is forest and fertility is more than 5 and altitude is less than 70 then state should be climax
;; Climax forest occasionally catches fire (e.g. lightning strikes)
if state is climax then 1 chance in 500 state should be fire
;; Climax forest neighbouring fires is likely to catch fire
if state is climax and some neighbours are fire then 1 chance in 3 state should be fire
;; After fire we get waste
if state is fire then state should be waste
;; And after waste we get pioneer species; if there's a woodland seed
;; source, it's going to be heath, otherwise grassland.
if state is waste and some neighbours are scrub then state should be heath
if state is waste and some neighbours are forest then state should be heath
if state is waste and some neighbours are climax then state should be heath
if state is waste then state should be grassland
## Herbivore rules
;; rules describing the impact of herbivores on the environment
;; if there are too many deer for the fertility of the area to sustain,
;; some die or move on.
;; if deer are more than fertility then deer should be fertility / 2
;; deer arrive occasionally at the edge of the map.
if x is 0 or y is 0 and deer are 0 then 1 chance in 50 deer should be 2
;; deer gradually spread through the world by breeding or migrating.
if fertility is more than 10 and deer is 0 and some neighbours have deer more than 2 then deer should be 2
;; deer breed.
if deer are more than 1 then deer should be deer * 2
## Predator rules
;; rules describing the impact of predator behaviour on the environment
if deer are more than wolves then deer should be deer - wolves
;; if there are not enough deer to sustain the population of wolves,
;; some wolves die or move on.
if wolves are more than deer then deer should be 0 and wolves should be deer + 0
;; wolves arrive occasionally at the edge of the map.
if x is 0 or y is 0 and wolves are 0 then 1 chance in 50 wolves should be 2
;; wolves gradually spread through the world by breeding or migrating.
if state is not water and wolves is 0 and some neighbours have wolves more than 2 then 1 chance in 5 wolves should be 2
;; wolves breed.
if wolves are more than 1 then wolves should be wolves * 2
## Potential blockers
;; Forest increases soil fertility.
if state is in forest or climax then fertility should be fertility + 1
## Initialisation rules
;; Rules which deal with state 'new' will waste less time if they're near the
;; end of the file
;; below the waterline we have water.
if state is new and altitude is less than 10 then state should be water
;; above the snowline we have snow.
if state is new and altitude is more than 200 then state should be snow
;; otherwise, we have grassland.
if state is new then state should be grassland

View file

@ -0,0 +1,65 @@
## Ruleset which attempts to model retreat of ice after an iceage
if generation is less than 5 then state should be ice
;; Limitations: because the rule language doesn't (yet) allow sophisticated
;; arithmetic, the ice retreats north to south (southern hemisphere).
## Vegetation rules
;; rules which populate the world with plants
;; Occasionally, passing birds plant tree seeds into grassland
if state is grassland then 1 chance in 10 state should be heath
;; heath below the treeline grows gradually into forest, providing browsing pressure is not to high
if state is heath and fertility is more than 10 and altitude is less than 120 then state should be scrub
if state is scrub and fertility is more than 20 then 1 chance in 20 state should be forest
;; Forest on fertile land grows to climax
if state is forest and fertility is more than 30 and altitude is less than 70 then state should be climax
;; Climax forest occasionally catches fire (e.g. lightning strikes)
if state is climax then 1 chance in 500 state should be fire
;; Climax forest neighbouring fires is likely to catch fire
if state is climax and some neighbours are fire then 1 chance in 3 state should be fire
;; After fire we get waste
if state is fire then state should be waste
;; And after waste we get pioneer species; if there's a woodland seed
;; source, it's going to be heath, otherwise grassland.
if state is waste and some neighbours are scrub then state should be heath
if state is waste and some neighbours are forest then state should be heath
if state is waste and some neighbours are climax then state should be heath
if state is waste then state should be grassland
## Potential blockers
;; Woody plants increase soil fertility over time.
if state is in heath or scrub or forest or climax then fertility should be fertility + 1
## Initialisation rules
;; Rules which deal with state 'new' will waste less time if they're near the
;; end of the file
if state is new then state should be ice
;; thaw moves gradually southwards (the distinction between 'ice' and 'snow' is
;; just a hack because I can't do complex arithmetic in rules)
;; below the waterline ice thaws to water.
if state is ice and generation is more than y and altitude is less than 10 then state should be water
;; otherwise it thaws to snow
if state is ice and generation is more than y then state should be snow
;; thaw moves gradually up the hills
if state is snow and generation is more than altitude then state should be waste

View file

@ -1,3 +1,6 @@
;; hack to speed up processing on the 'great britain and ireland' map
if state is water then state should be water
# Human settlement # Human settlement
;; nomads make their first significant camp near water because of fish and ;; nomads make their first significant camp near water because of fish and
@ -5,26 +8,26 @@
if state is in grassland or heath and more than 3 neighbours are water and generation is more than 20 then state should be camp if state is in grassland or heath and more than 3 neighbours are water and generation is more than 20 then state should be camp
;; sooner or later nomads learn to keep flocks ;; sooner or later nomads learn to keep flocks
if state is in grassland or heath and some neighbours are camp then state should be meadow if state is in grassland or heath and some neighbours are camp then state should be pasture
;; 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 pasture then state should be camp
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 if state is pasture and more than 3 neighbours are pasture 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 pasture and some neighbours within 3 are house then state should be pasture
;; nomads move on ;; nomads move on
if state is camp then 1 chance in 5 state should be waste 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 ;; pasture 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 pasture 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 ;; 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 if state is in grassland or pasture 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 pasture 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 ploughland then state should be crop if state is ploughland then state should be crop
@ -33,25 +36,25 @@ 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 if state is abandoned and some neighbours are pasture 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
;; 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 some neighbours are inn then state should be market if state is market and some neighbours are inn then state should be market
if state is market then state should be grassland if state is market then state should be grassland
;; a house near a market in a settlement will become an inn ;; a house near a market in a settlement will become an inn
if state is house and some neighbours are market and more than 1 neighbours are house then state should be inn if state is house and some neighbours are market and more than 1 neighbours are house then 1 chance in 5 state should be inn
;; but it will need some local custom to survive ;; but it will need some local custom to survive
if state is inn and fewer than 2 neighbours are house then state should be house if state is inn and fewer than 3 neighbours are house then state should be house
;; if there aren't enough resources houses should be abandoned ;; if there aren't enough resources houses should be abandoned
;; resources from fishing ;; resources from fishing
if state is house and more than 2 neighbours are water then state should be house if state is house and more than 2 neighbours are water then state should be house
;; from farming ;; from farming
if state is house and some neighbours are meadow then state should be house if state is house and some neighbours are pasture then state should be house
if state is house and some neighbours are ploughland then state should be house
if state is house and some neighbours are crop then state should be house if state is house and some neighbours are crop then state should be house
;; from the market ;; from the market
if state is house and some neighbours are market then state should be house if state is house and some neighbours are market then state should be house
@ -66,14 +69,14 @@ if state is abandoned then 1 chance in 5 state should be waste
if state is grassland then 1 chance in 10 state should be heath if state is grassland then 1 chance in 10 state should be heath
;; heath below the treeline grows gradually into forest, providing browsing pressure is not to high ;; heath below the treeline grows gradually into forest
if state is heath and deer are fewer than 6 and altitude is less than 150 then state should be scrub if state is heath and altitude is less than 120 then state should be scrub
if state is scrub then 1 chance in 5 state should be forest if state is scrub then 1 chance in 5 state should be forest
;; Forest on fertile land grows to climax ;; Forest on fertile land grows to climax
if state is forest and fertility is more than 5 then state should be climax if state is forest and fertility is more than 5 and altitude is less than 70 then state should be climax
;; Climax forest occasionally catches fire (e.g. lightning strikes) ;; Climax forest occasionally catches fire (e.g. lightning strikes)
@ -83,12 +86,15 @@ if state is climax then 1 chance in 500 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 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 ;; 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 if state is in climax and more than 3 neighbours within 2 are house then state should be scrub
;; 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
;; waste near settlement that is fertile becomes ploughland
if state is waste and fertility is more than 10 and some neighbours are house or some neighbours are camp then state should be ploughland
;; And after waste we get pioneer species; if there's a woodland seed ;; And after waste we get pioneer species; if there's a woodland seed
;; source, it's going to be heath, otherwise grassland. ;; source, it's going to be heath, otherwise grassland.