summaryrefslogtreecommitdiff
path: root/src/world
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-09 15:25:33 -0600
committersanine <sanine.not@pm.me>2023-11-09 15:25:33 -0600
commit819d8a51c5ba8b1bec06163dba9c3e0212f1120a (patch)
tree275316506cf85392d4cdd9a6eacb4a247f842c7d /src/world
parent5f2683c0aff63880794b2f3262e0d6abc76bd80a (diff)
add world.js
Diffstat (limited to 'src/world')
-rw-r--r--src/world/world.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/world/world.js b/src/world/world.js
new file mode 100644
index 0000000..c824e91
--- /dev/null
+++ b/src/world/world.js
@@ -0,0 +1,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
+ );
+}