-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathknight_actions_test.go
73 lines (70 loc) · 2.21 KB
/
knight_actions_test.go
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
package core
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestKnightActions(t *testing.T) {
ts := []struct {
name string
board Board
actions []Action
color color
xy XY
}{
{
name: "black knight: no actions because it's trapped",
board: Board{
Board: []string{
"♜ ♝♛♚♝♞♜",
" ♟ ♟ ",
" ♟ ♟ ",
" ♞ ",
" ♟ ♟ ",
" ♟ ♟ ",
"♙♙♙♙♙♙♙♙",
"♖♘♗♕♔♗♘♖",
},
Turn: "Black",
},
color: ColorBlack,
xy: XY{3, 3},
actions: []Action{},
},
{
name: "black knight: all actions including 2 captures",
board: Board{
Board: []string{
"♜ ♝♛♚♝♞♜",
"♟♟♟♟♟♟♟♟",
" ",
" ",
" ♞ ",
" ",
"♙♙♙♙♙♙♙♙",
"♖♘♗♕♔♗♘♖",
},
Turn: "Black",
},
color: ColorBlack,
xy: XY{3, 4},
actions: []Action{
{FromPiece: Piece{PieceType: PieceKnight, Owner: ColorBlack, XY: XY{3, 4}}, ToXY: XY{2, 2}},
{FromPiece: Piece{PieceType: PieceKnight, Owner: ColorBlack, XY: XY{3, 4}}, ToXY: XY{4, 2}},
{FromPiece: Piece{PieceType: PieceKnight, Owner: ColorBlack, XY: XY{3, 4}}, ToXY: XY{1, 3}},
{FromPiece: Piece{PieceType: PieceKnight, Owner: ColorBlack, XY: XY{3, 4}}, ToXY: XY{5, 3}},
{FromPiece: Piece{PieceType: PieceKnight, Owner: ColorBlack, XY: XY{3, 4}}, ToXY: XY{1, 5}},
{FromPiece: Piece{PieceType: PieceKnight, Owner: ColorBlack, XY: XY{3, 4}}, ToXY: XY{5, 5}},
{FromPiece: Piece{PieceType: PieceKnight, Owner: ColorBlack, XY: XY{3, 4}}, ToXY: XY{2, 6}, IsCapture: true, CapturedPiece: Piece{PieceType: PiecePawn, Owner: ColorWhite, XY: XY{2, 6}}},
{FromPiece: Piece{PieceType: PieceKnight, Owner: ColorBlack, XY: XY{3, 4}}, ToXY: XY{4, 6}, IsCapture: true, CapturedPiece: Piece{PieceType: PiecePawn, Owner: ColorWhite, XY: XY{4, 6}}},
},
},
}
for _, tc := range ts {
t.Run(tc.name, func(t *testing.T) {
g, err := NewGameFromBoard(tc.board)
require.NoError(t, err)
assert.ElementsMatch(t, tc.actions, g.Pieces[tc.color][tc.xy].calculateAllActions(g))
})
}
}