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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
import _ from 'lodash';
import assert from 'assert';
import Tile, { Direction } from '../Tile/Tile';
import Board from './Board';
const { North, East } = 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 Tile('R', 'CRFR'));
});
});
describe('getAttachments', () => {
it('Should correctly determine legal attachments for 1-tile board', () => {
const board = new Board();
const attachTo = board.tiles[0];
const tile = new Tile('C', 'FCFC');
const attachments = board.getAttachments(tile);
assert.strictEqual(attachments.length, 4);
assert.deepStrictEqual(attachments[0], { edge: 0, orientation: 1, attachTo, tile });
assert.deepStrictEqual(attachments[1], { edge: 0, orientation: 3, attachTo, tile });
assert.deepStrictEqual(attachments[2], { edge: 2, orientation: 0, attachTo, tile });
assert.deepStrictEqual(attachments[3], { edge: 2, orientation: 2, attachTo, tile });
});
it.skip('Should correctly return legal attachments for complex board', () => {
const board = new Board();
board.attach({
tile: new Tile('C', 'CFCF'),
attachTo: board.tiles[0],
orientation: 0,
edge: North,
});
board.attach({
tile: new Tile('C', 'RCCR'),
attachTo: board.tiles[0],
orientation: 0,
edge: East,
});
const tile = new Tile('F', 'CFFF');
const attachments = board.getAttachments(tile);
// attachments.forEach(attachment => board.previewAttachment(attachment));
// assert.strictEqual(attachments.length, 9);
assert.deepStrictEqual(attachments[0], { edge: 2, orientation: 1, tile, attachTo: board.tiles[0] });
assert.deepStrictEqual(attachments[1], { edge: 2, orientation: 2, tile, attachTo: board.tiles[0] });
assert.deepStrictEqual(attachments[2], { edge: 2, orientation: 3, tile, attachTo: board.tiles[0] });
assert.deepStrictEqual(attachments[3], { edge: 0, orientation: 2, tile, attachTo: board.tiles[1] });
assert.deepStrictEqual(attachments[4], { edge: 3, orientation: 0, tile, attachTo: board.tiles[1] });
assert.deepStrictEqual(attachments[5], { edge: 3, orientation: 2, tile, attachTo: board.tiles[1] });
assert.deepStrictEqual(attachments[6], { edge: 3, orientation: 3, tile, attachTo: board.tiles[1] });
assert.deepStrictEqual(attachments[7], { edge: 1, orientation: 3, tile, attachTo: board.tiles[2] });
assert.deepStrictEqual(attachments[8], { edge: 2, orientation: 0, tile, attachTo: board.tiles[2] });
});
});
describe('attach', () => {
it('Should push new tile to the list and assign correct coordinates', () => {
const board = new Board();
const attachment = {
tile: new Tile('C', 'FCFC'),
attachTo: board.tiles[0],
orientation: 0,
edge: North,
};
const expectedTileOnBoard = new Tile(
'C',
'FCFC',
false,
{ x: 0, y: 1 },
0
);
board.attach(attachment);
assert.strictEqual(board.tiles.length, 2);
assert.deepStrictEqual(board.tiles[1], expectedTileOnBoard);
});
});
it.skip('TODO', () => {
const board = new Board();
const tiles = [
new Tile('F', 'CFFF'),
new Tile('C', 'RCCR'),
new Tile('C', 'CFCF'),
new Tile('C', 'CCRR'),
];
_.times(15, () => {
const tile = _.sample(tiles);
const attachments = board.getAttachments(tile);
const attachment = _.sample(attachments);
console.log(attachment);
if (attachment) board.attach(attachment);
board.print();
})
}).timeout(10000);
});
|