mw-engine.core

Functions to transform a world and run rules.

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 :y as the old cell. Anything else can be modified.

While any function of two arguments can be used as a rule, a special high level rule language is provided by the mw-parser package, which compiles rules expressed in a subset of English rules into suitable functions.

A cell is a map containing at least values for the keys :x, :y, and :state; a transformation should not alter the values of :x or :y, and should not return a cell without a keyword as the value of :state. Anything else is legal.

A world is a two dimensional matrix (sequence of sequences) of cells, such that every cell’s :x and :y properties reflect its place in the matrix. See world.clj.

Each time the world is transformed (see transform-world), for each cell, rules are applied in turn until one matches. Once one rule has matched no further rules can be applied to that cell.

*with-history*

dynamic

I suspect that caching history on the cells is greatly worsening the memory problems. Make it optional, but by default false.

apply-rule

(apply-rule world cell rule)

Apply a single rule to a cell. What this is about is that I want to be able, for debugging purposes, to tag a cell with the rule text of the rule which fired (and especially so when an exception is thrown).

known-rule-types

Types of rules we know about.

run-world

(run-world world rules generations)(run-world world init-rules rules generations)

Run this world with these rules for this number of generations.

  • world a world as discussed above;
  • init-rules a sequence of rules as defined above, to be run once to initialise the world;
  • rules a sequence of rules as defined above, to be run iteratively for each generation;
  • generations an (integer) number of generations.

NOTE THAT all rules must be tagged with rule-type metadata, or they will not be executed.

Return the final generation of the world.

transform-world

(transform-world world rules)

Return a world derived from this world by applying the production rules found among these rules to each cell.