summaryrefslogtreecommitdiff
path: root/src/world/world.js
blob: c824e913304aa8ba88a9392e03ddf5d7f37ca681 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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);

  const agent_props = world.agents
    .map(a => agent_decide(world.lattice, agent, world.senses, world.actions))
    .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 = world.agents.map(a => agent_apply(a, agent_props));

  const world = {...world, lattice, agents};
  return postprocess.reduce(
    (acc, f) => f(acc),
    world
  );
}