summaryrefslogtreecommitdiff
path: root/src/simulation/game.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-11 21:23:38 -0600
committersanine <sanine.not@pm.me>2023-11-11 21:23:38 -0600
commitd39a74930ec054628f8c65d33ef797fdea6f44ce (patch)
tree0eda8f851410c4c1bfe57755b59a69bf332fd237 /src/simulation/game.js
parent4715baef25b39d2614b1d0cc67d8bcff5676b6ce (diff)
add create_world()
Diffstat (limited to 'src/simulation/game.js')
-rw-r--r--src/simulation/game.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/simulation/game.js b/src/simulation/game.js
index 991d125..f0c4815 100644
--- a/src/simulation/game.js
+++ b/src/simulation/game.js
@@ -1,6 +1,13 @@
'use strict';
+import { random_choice, apply } from '../util.js';
+import { senses } from './senses.js';
+import { actions } from './actions.js';
+import { lattice_rules } from './lattice_rules.js';
+import { validity } from './validity.js';
+
+
function is_wall(size, x, y) {
return (
x === 0 || x === size-1 ||
@@ -44,3 +51,48 @@ export function setup_board(size) {
}));
return lattice;
}
+
+
+export function create_world(size, teams) {
+ const lattice = setup_board(size);
+
+ const agents = teams.reduce(
+ (agents, team, team_num) => {
+ const team_cells = lattice.map((row, y) => row.map((cell, x) => [x, y, cell])).flat()
+ // only check cells with the right team
+ .filter(([x, y, cell]) => cell.type === 'empty' && cell.flags.team === team_num)
+ return agents.concat(team.reduce(
+ (acc, agent) => {
+ const available_cells = team_cells.filter(([x, y, cell]) => acc.reduce(
+ (occupied, a) => occupied && ((a.x !== x) || (a.y !== y)),
+ true
+ ))
+ const [x, y, ..._] = random_choice(available_cells);
+ const orientation = random_choice([ 'n', 'e', 's', 'w' ]);
+ return [...acc, {...agent, x, y, flags: { ...agent.flags, orientation } }];
+ },
+ []
+ ));
+ },
+ []
+ ).flat();
+
+ return { lattice, lattice_rules, agents, actions, senses, validity };
+};
+
+
+// team structure:
+// {
+// agents
+// genome
+// }
+
+
+//export function create_team(size, genome_size, n_internal) {
+// const n_input = senses.reduce((acc, sense) => acc + sense.size, 0);
+// const n_output = senses.reduce((acc, sense) => acc + sense.size, 0);
+// const genome = apply(
+// s => mut_genome_insert(
+// ),
+// );
+//}