1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
'use strict';
import { apply } from '../util.js';
import { setup_board, create_world } from './game.js';
test("set up boards correctly", () => {
const _ = { type: 'empty', flags: {} };
const a = { type: 'empty', flags: { team: 0 } };
const b = { type: 'empty', flags: { team: 1 } };
const c = { type: 'empty', flags: { team: 2 } };
const d = { type: 'empty', flags: { team: 3 } };
const W = { type: 'immutable', flags: {} };
expect(setup_board(6)).toEqual([
[ W, W, W, W, W, W, ],
[ W, W, a, a, W, W, ],
[ W, d, _, _, b, W, ],
[ W, d, _, _, b, W, ],
[ W, W, c, c, W, W, ],
[ W, W, W, W, W, W, ],
]);
expect(setup_board(9)).toEqual([
[ W, W, W, W, W, W, W, W, W, ],
[ W, W, W, a, a, a, W, W, W, ],
[ W, W, W, a, a, a, W, W, W, ],
[ W, d, d, _, _, _, b, b, W, ],
[ W, d, d, _, _, _, b, b, W, ],
[ W, d, d, _, _, _, b, b, W, ],
[ W, W, W, c, c, c, W, W, W, ],
[ W, W, W, c, c, c, W, W, W, ],
[ W, W, W, W, W, W, W, W, W, ],
]);
});
test("creating a world works correctly", () => {
const id = 0;
const agent = (id) => ({ id, net: `${id}`, state: `s${id}` });
const team1 = [agent(0), agent(1)];
const team2 = [agent(2), agent(3)];
const team3 = [agent(4), agent(5)];
const team4 = [agent(6), agent(7)];
const world = create_world(6, [team1, team2, team3, team4]);
const agent_cell = (agent) => {
const { x, y } = agent;
return world.lattice[y][x];
};
expect(agent_cell(world.agents[0])).toEqual({ type: 'empty', flags: { team: 0 } });
expect(agent_cell(world.agents[1])).toEqual({ type: 'empty', flags: { team: 0 } });
expect(agent_cell(world.agents[2])).toEqual({ type: 'empty', flags: { team: 1 } });
expect(agent_cell(world.agents[3])).toEqual({ type: 'empty', flags: { team: 1 } });
expect(agent_cell(world.agents[4])).toEqual({ type: 'empty', flags: { team: 2 } });
expect(agent_cell(world.agents[5])).toEqual({ type: 'empty', flags: { team: 2 } });
expect(agent_cell(world.agents[6])).toEqual({ type: 'empty', flags: { team: 3 } });
expect(agent_cell(world.agents[7])).toEqual({ type: 'empty', flags: { team: 3 } });
});
|