diff options
author | sanine <sanine.not@pm.me> | 2023-11-11 13:19:34 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-11-11 13:19:34 -0600 |
commit | 50f27be0cd94744a7f217ecfae2f913803ae6c44 (patch) | |
tree | 962e28feabbd6d3083adff79ebec764849a4e9da /src/world | |
parent | 5535ff5b2894e97b5387b52caee6078d461c2210 (diff) |
add world update validity pass
Diffstat (limited to 'src/world')
-rw-r--r-- | src/world/world.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/world/world.js b/src/world/world.js index e1d984d..e1ba0cf 100644 --- a/src/world/world.js +++ b/src/world/world.js @@ -3,6 +3,17 @@ import { agent_decide, agent_apply } from './agent.js'; import { proposal_merge } from './proposal.js'; +// world structure: +// { +// lattice +// lattice_rules: object +// agents: agent[] +// senses: sense[] +// actions: action[] +// validity: (function(proposal) => bool)[] +// } + + export function world_update(world, postprocess=[]) { const lattice_props = lattice_update(world.lattice, world.lattice_rules); const intermediate_lattice = lattice_apply(world.lattice, lattice_props); @@ -19,7 +30,10 @@ export function world_update(world, postprocess=[]) { .reduce((acc, prop) => proposal_merge(acc, prop), []) .filter(prop => lattice_valid(intermediate_lattice, prop)) - const lattice = lattice_apply(intermediate_lattice, agent_props); + const lattice = lattice_apply(intermediate_lattice, world.validity.reduce( + (acc, rule) => acc.filter(rule), + agent_props + )); const agents = intermediate_agents.map(a => agent_apply(a, agent_props)); const new_world = {...world, lattice, agents}; |