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:
:source
, whose value is a location;:destination
, whose value is a location;:property
, whose value is a keyword;:quantity
, whose value is a positive real number.
A location object is a map with the following properties:
:x
, whose value is a natural number not greater than the extent of the world;: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-quantity
macro
(create-flow-quantity source dest prop quantity)
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-world
(flow-world world rules)
Return a world derived from this world
by applying the flow rules found among these rules
to each cell, and executing all the flows planned.
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
.
plan-flows
(plan-flows world rules)
Plan, but do not execute, all the flows in this world
implied by those of these rules
(which are expected to be pre-compiled) which are flow rules. Return the list of plans, as flow objects.