summaryrefslogtreecommitdiff
path: root/src/world/lattice.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-16 14:50:00 -0600
committersanine <sanine.not@pm.me>2023-11-16 14:50:00 -0600
commitf9fc4d26ec5fca9ee175c8a6fbcdd0fa36f10947 (patch)
treef190e6e465bb563c608a916f41fc8bf686ea2897 /src/world/lattice.js
parent7825b92ce3be95a0ce1dfea9388adbaadce83b1f (diff)
clear out js files
Diffstat (limited to 'src/world/lattice.js')
-rw-r--r--src/world/lattice.js54
1 files changed, 0 insertions, 54 deletions
diff --git a/src/world/lattice.js b/src/world/lattice.js
deleted file mode 100644
index 066a5ca..0000000
--- a/src/world/lattice.js
+++ /dev/null
@@ -1,54 +0,0 @@
-'use strict';
-
-// get the proposals for cell updates
-export function lattice_update(lattice, update_rules) {
- return lattice
- .map((row, y) => row.map((cell, x) => [x, y, cell.type]))
- .flat()
- .reduce((acc, [x, y, type]) => [...acc, update_rules[type](lattice, x, y)], [])
- .filter(x => x !== undefined)
-}
-
-
-// check if, given the current lattice configuration, a proposal is valid
-export function lattice_valid(lattice, proposal) {
- if (!proposal.world_updates) { return true; }
- return proposal.world_updates.reduce(
- (acc, update) => {
- const valid =
- (update.x >= 0 && update.x < lattice[0].length) &&
- (update.y >= 0 && update.y < lattice.length) &&
- (lattice[update.y][update.x].type == update.from)
- return valid && acc;
- },
- true
- );
-}
-
-
-// apply a set of proposals, returning the new lattice
-export function lattice_apply(lattice, proposals) {
- const result = proposals.reduce(
- (acc, prop) => {
- const change = (prop.world_updates || []).reduce(
- (acc_, update) => {
- const cell = acc_[update.y][update.x];
- if (update.to) { cell.type = update.to; }
- if (update.flags) {
- cell.flags = { ...(cell.flags || {}), ...update.flags };
- //cell.flags = cell.flags || {}
- //// this is very side-effect-y but i couldn't think of a nicer compatible way of doing it 😔
- //for (let k of Object.keys(update.flags)) {
- // cell.flags[k] = update.flags[k];
- //}
- }
- return acc_
- },
- [...acc]
- );
- return change;
- },
- [...lattice]
- );
- return result;
-}