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
|
import assert from 'assert';
import Tile, { Feature, Direction } from '../Tile/Tile';
import TileOnBoard from '../Tile/TileOnBoard';
import Board from './Board';
const { Road, Town, Grass } = Feature;
const { North } = Direction;
describe('Board', () => {
describe('constructor', () => {
it('Should initialize empty board with a starting tile', () => {
const board = new Board();
assert.strictEqual(board.tiles.length, 1);
assert.deepStrictEqual(board.tiles[0], new TileOnBoard(Road, [Town, Road, Grass, Road]));
});
});
describe('getAttachments', () => {
it('Should correctly determine legal moves for 1-tile board', () => {
const board = new Board();
const attachTo = board.tiles[0];
const tile = new Tile(Town, [Grass, Town, Grass, Town]);
const legalMoves = board.getAttachments(tile);
assert.strictEqual(legalMoves.length, 4);
assert.deepStrictEqual(legalMoves[0], { side: 0, rotation: 1, attachTo, tile });
assert.deepStrictEqual(legalMoves[1], { side: 0, rotation: 3, attachTo, tile });
assert.deepStrictEqual(legalMoves[2], { side: 2, rotation: 0, attachTo, tile });
assert.deepStrictEqual(legalMoves[3], { side: 2, rotation: 2, attachTo, tile });
});
});
describe('attach', () => {
it('Should push new tile to the list and assign correct coordinates', () => {
const board = new Board();
const attachment = {
tile: new Tile(Town, [Grass, Town, Grass, Town]),
attachTo: board.tiles[0],
orientation: 0,
side: North,
};
const expectedTileOnBoard = new TileOnBoard(
Town,
[Grass, Town, Grass, Town],
false,
{ x: 0, y: 1 },
0
);
board.attach(attachment);
assert.strictEqual(board.tiles.length, 2);
assert.deepStrictEqual(board.tiles[1], expectedTileOnBoard);
});
});
});
|