From f9fc4d26ec5fca9ee175c8a6fbcdd0fa36f10947 Mon Sep 17 00:00:00 2001 From: sanine Date: Thu, 16 Nov 2023 14:50:00 -0600 Subject: clear out js files --- src/world/world.js | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 src/world/world.js (limited to 'src/world/world.js') diff --git a/src/world/world.js b/src/world/world.js deleted file mode 100644 index 63d974a..0000000 --- a/src/world/world.js +++ /dev/null @@ -1,47 +0,0 @@ -import { lattice_update, lattice_valid, lattice_apply } from './lattice.js'; -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.map(row => row.map(cell => ({ ...cell, flags: {} }))), - lattice_props - ); - - const decisions = world.agents - .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 = 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, agent_props); - const agents = intermediate_agents.map(a => agent_apply(a, agent_props)); - - const new_world = {...world, lattice, agents}; - return postprocess.reduce( - (acc, f) => f(acc), - new_world - ); -} -- cgit v1.2.1