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/simulation/validity.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/simulation/validity.js (limited to 'src/simulation/validity.js') diff --git a/src/simulation/validity.js b/src/simulation/validity.js new file mode 100644 index 0000000..de4acd1 --- /dev/null +++ b/src/simulation/validity.js @@ -0,0 +1,14 @@ +export const validity = [ + // prevent agents from moving onto immutables + (world, proposal) => (proposal.agent_changes || []).reduce( + (acc, change) => { + const {x, y} = change; + if (x !== undefined && y !== undefined && world.lattice[y][x].type === 'immutable') { + return false; + } else { + return acc; + } + }, + true, + ), +]; -- cgit v1.2.1