From 50f27be0cd94744a7f217ecfae2f913803ae6c44 Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 11 Nov 2023 13:19:34 -0600 Subject: add world update validity pass --- src/world/world.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/world/world.js') 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}; -- cgit v1.2.1