From 7a3fc898def0283ed6655b5c45a5f413638272a7 Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 11 Nov 2023 13:46:59 -0600 Subject: prevent agents from moving into immutable tiles --- src/world/world.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/world/world.js') diff --git a/src/world/world.js b/src/world/world.js index e1ba0cf..4bab4d3 100644 --- a/src/world/world.js +++ b/src/world/world.js @@ -19,21 +19,21 @@ export function world_update(world, postprocess=[]) { const intermediate_lattice = lattice_apply(world.lattice, lattice_props); const decisions = world.agents - .map(a => agent_decide(world, agent, world.senses, world.actions)) + .map(a => agent_decide(world, a, world.senses, world.actions)) .reduce( ([agents, props], [agent, prop]) => [[...agents, agent], [...props, prop]], [[], []] ); const intermediate_agents = decisions[0]; - const agent_props = decisions[1] - .flat() - .reduce((acc, prop) => proposal_merge(acc, prop), []) - .filter(prop => lattice_valid(intermediate_lattice, prop)) + const agent_props = world.validity.reduce( + (acc, rule) => acc.filter(prop => rule({...world, lattice: intermediate_lattice}, prop)), + decisions[1] + .flat() + .reduce((acc, prop) => proposal_merge(acc, prop), []) + .filter(prop => lattice_valid(intermediate_lattice, prop)) + ); - const lattice = lattice_apply(intermediate_lattice, world.validity.reduce( - (acc, rule) => acc.filter(rule), - agent_props - )); + const lattice = lattice_apply(intermediate_lattice, agent_props); const agents = intermediate_agents.map(a => agent_apply(a, agent_props)); const new_world = {...world, lattice, agents}; -- cgit v1.2.1