-
Notifications
You must be signed in to change notification settings - Fork 0
/
moverook.js
113 lines (71 loc) · 2.5 KB
/
moverook.js
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
113
const simplechess = require('../');
const assert = require('assert');
const White = simplechess.White;
const Black = simplechess.Black;
const Rook = simplechess.Rook;
// First test
{
const board = simplechess.createBoard();
board.putContent(0, 0, { color: White, piece: Rook });
const game = simplechess.createGame(board);
const moves = game.getMoves(White);
assert.ok(moves);
assert.equal(moves.length, 14);
}
// Blocking rook
{
const board = simplechess.createBoard();
board.putContent(0, 0, { color: White, piece: Rook });
board.putContent(0, 1, { color: Black, piece: Rook });
const game = simplechess.createGame(board);
const moves = game.getMoves(White);
assert.ok(moves);
assert.equal(moves.length, 8);
const moves2 = game.getMoves(Black);
assert.ok(moves2);
assert.equal(moves2.length, 14);
board.putContent(1, 0, { color: Black, piece: Rook });
const moves3 = game.getMoves(White);
assert.ok(moves3);
assert.equal(moves3.length, 2);
const moves4 = game.getMoves(Black);
assert.ok(moves4);
assert.equal(moves4.length, 28);
}
// Blocking rook using same color
{
const board = simplechess.createBoard();
board.putContent(0, 0, { color: White, piece: Rook });
board.putContent(0, 1, { color: White, piece: Rook });
const game = simplechess.createGame(board);
const moves = game.getMoves(White);
assert.ok(moves);
assert.equal(moves.length, 20);
const moves2 = game.getMoves(Black);
assert.ok(moves2);
assert.equal(moves2.length, 0);
}
// Single rook at center
{
const board = simplechess.createBoard();
board.putContent(4, 4, { color: White, piece: Rook });
const game = simplechess.createGame(board);
const moves = game.getMoves(White);
assert.ok(moves);
assert.equal(moves.length, 14);
const moves2 = game.getMoves(Black);
assert.ok(moves2);
assert.equal(moves2.length, 0);
}
// New board
{
const board = simplechess.createBoard();
const game = simplechess.createGame(board);
board.putContent(3, 3, { color: Black, piece: Rook });
const moves = game.getMoves(Black);
assert.ok(moves);
assert.equal(moves.length, 14);
const moves2 = game.getMoves(White);
assert.ok(moves2);
assert.equal(moves2.length, 0);
}