mw-engine.flow

Allow flows of values between cells in the world.

The design here is: a flow object is a map with the following properties:

  1. :source, whose value is a location;
  2. :destination, whose value is a location;
  3. :property, whose value is a keyword;
  4. :quantity, whose value is a positive real number.

A location object is a map with the following properties:

  1. :x, whose value is a natural number not greater than the extent of the world;
  2. :y, whose value is a natural number not greater than the extent of the world.

To execute a flow is transfer the quantity specified of the property specified from the cell at the source specified to the cell at the destination specified; if the source doesn’t have sufficient of the property, then all it has should be transferred, but no more: properties to be flowed cannot be pulled negative.

Flowing values through the world is consequently a two stage process: firstly there’s a planning stage, in which all the flows to be executed are computed without changing the world, and then an execution stage, where they’re all executed. This namespace deals with mainly with execution.

coordinate?

(coordinate? o world)

Return true if this object o is a valid coordinate with respect to this world, else false. Assumes square worlds.

create-flow-fraction

macro

(create-flow-fraction source dest prop fraction)

TODO: write docs

create-flow-percent

macro

(create-flow-percent source dest prop percent)

TODO: write docs

create-flow-quantity

macro

(create-flow-quantity source dest prop quantity)

TODO: write docs

create-location

macro

(create-location cell)

TODO: write docs

execute

(execute world flow)

Return a world like this world, except with the quantity of the property described in this flow object transferred from the source of that flow to its destination.

execute-flows

(execute-flows world flows)

Return a world like this world, but with each of these flows executed.

flow?

(flow? o world)

Return true if this object o is a flow as defined above with respect to this world, else false. Assumes square worlds.

location?

(location? o world)

Return true if this object o is a location as defined above with respect to this world, else false.