-
Notifications
You must be signed in to change notification settings - Fork 0
/
precompute_test.go
141 lines (137 loc) · 5.63 KB
/
precompute_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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Precompute", func() {
Describe("#SlidingAttacksBB", func() {
When("the piece is a rook", func() {
When("no obstructing pieces are on the board", func() {
It("returns all possible attacks", func() {
occupiedBB := BBWithSquares(SQ_D4)
expAttackBB := BBWithSquares(SQ_D1, SQ_D2, SQ_D3, SQ_D5, SQ_D6, SQ_D7, SQ_D8,
SQ_A4, SQ_B4, SQ_C4, SQ_E4, SQ_F4, SQ_G4, SQ_H4)
attacksBB := SlidingAttacksBB(occupiedBB, SQ_D4, ROOK)
Expect(attacksBB).To(Equal(expAttackBB))
})
})
When("one obstructing piece per direction exists", func() {
It("returns all possible attacks", func() {
occupiedBB := BBWithSquares(SQ_D4, SQ_B4, SQ_F4, SQ_D3, SQ_D8)
expAttackBB := BBWithSquares(SQ_B4, SQ_C4, SQ_E4, SQ_F4, SQ_D3, SQ_D5, SQ_D6, SQ_D7, SQ_D8)
attacksBB := SlidingAttacksBB(occupiedBB, SQ_D4, ROOK)
Expect(attacksBB).To(Equal(expAttackBB))
})
})
When("two obstructing pieces per direction exists", func() {
It("returns all possible attacks", func() {
occupiedBB := BBWithSquares(SQ_D4, SQ_A4, SQ_B4, SQ_F4, SQ_H4, SQ_D3, SQ_D1, SQ_D7, SQ_D8)
expAttackBB := BBWithSquares(SQ_B4, SQ_C4, SQ_D3, SQ_E4, SQ_F4, SQ_D5, SQ_D6, SQ_D7)
attacksBB := SlidingAttacksBB(occupiedBB, SQ_D4, ROOK)
Expect(attacksBB).To(Equal(expAttackBB))
})
})
})
When("the piece is a queen", func() {
When("no obstructing pieces are on the board", func() {
It("returns all possible attacks", func() {
occupiedBB := BBWithSquares(SQ_D4)
expAttackBB := BBWithSquares(SQ_D1, SQ_D2, SQ_D3, SQ_D5, SQ_D6, SQ_D7, SQ_D8,
SQ_A4, SQ_B4, SQ_C4, SQ_E4, SQ_F4, SQ_G4, SQ_H4,
SQ_A1, SQ_B2, SQ_C3, SQ_E5, SQ_F6, SQ_G7, SQ_H8,
SQ_A7, SQ_B6, SQ_C5, SQ_E3, SQ_F2, SQ_G1)
attacksBB := SlidingAttacksBB(occupiedBB, SQ_D4, QUEEN)
Expect(attacksBB).To(Equal(expAttackBB))
})
})
When("one obstructing piece per direction exists", func() {
It("returns all possible attacks", func() {
occupiedBB := BBWithSquares(SQ_D4, SQ_F4, SQ_H8, SQ_D5, SQ_B6, SQ_B4, SQ_C3, SQ_D2, SQ_F2)
expAttackBB := BBWithSquares(SQ_E4, SQ_F4, SQ_E5, SQ_F6, SQ_G7, SQ_H8, SQ_D5, SQ_C5,
SQ_B6, SQ_C4, SQ_B4, SQ_C3, SQ_D3, SQ_D2, SQ_E3, SQ_F2)
attacksBB := SlidingAttacksBB(occupiedBB, SQ_D4, QUEEN)
Expect(attacksBB).To(Equal(expAttackBB))
})
})
When("two obstructing pieces per direction exists", func() {
It("returns all possible attacks", func() {
occupiedBB := BBWithSquares(SQ_D4, SQ_F4, SQ_H4, SQ_G7, SQ_H8, SQ_D5, SQ_D8, SQ_B6,
SQ_A7, SQ_B4, SQ_A4, SQ_C3, SQ_B2, SQ_D3, SQ_D1, SQ_F2, SQ_G1)
expAttackBB := BBWithSquares(SQ_E4, SQ_F4, SQ_E5, SQ_F6, SQ_G7, SQ_D5, SQ_C5, SQ_B6, SQ_C4,
SQ_B4, SQ_C3, SQ_D3, SQ_E3, SQ_F2)
attacksBB := SlidingAttacksBB(occupiedBB, SQ_D4, QUEEN)
Expect(attacksBB).To(Equal(expAttackBB))
})
})
})
When("the piece is a bishop", func() {
When("no obstructing pieces are on the board", func() {
It("returns all possible attacks", func() {
occupiedBB := BBWithSquares(SQ_D4)
expAttackBB := BBWithSquares(SQ_E5, SQ_F6, SQ_G7, SQ_H8, SQ_C5, SQ_B6, SQ_A7, SQ_C3, SQ_B2,
SQ_A1, SQ_E3, SQ_F2, SQ_G1)
attacksBB := SlidingAttacksBB(occupiedBB, SQ_D4, BISHOP)
Expect(attacksBB).To(Equal(expAttackBB))
})
})
When("one obstructing piece per direction exists", func() {
It("returns all possible attacks", func() {
occupiedBB := BBWithSquares(SQ_D4, SQ_H8, SQ_A7, SQ_B2, SQ_E3)
expAttackBB := BBWithSquares(SQ_E5, SQ_F6, SQ_G7, SQ_H8, SQ_C5, SQ_B6, SQ_A7, SQ_C3, SQ_B2, SQ_E3)
attacksBB := SlidingAttacksBB(occupiedBB, SQ_D4, BISHOP)
Expect(attacksBB).To(Equal(expAttackBB))
})
})
When("two obstructing pieces per direction exists", func() {
It("returns all possible attacks", func() {
occupiedBB := BBWithSquares(SQ_E5, SQ_H8, SQ_C5, SQ_B6, SQ_B2, SQ_A1, SQ_E3, SQ_G1)
expAttackBB := BBWithSquares(SQ_E5, SQ_C5, SQ_C3, SQ_B2, SQ_E3)
attacksBB := SlidingAttacksBB(occupiedBB, SQ_D4, BISHOP)
Expect(attacksBB).To(Equal(expAttackBB))
})
})
})
})
Describe("#genRankOccupiedBBs", func() {
It("generates the appropriate number of bitboards", func() {
bbs := genRankOccupiedBBs()
Expect(bbs).To(HaveLen(8 * 255))
})
})
Describe("#genFileOccupiedBBs", func() {
It("generates the appropriate number of bitboards", func() {
bbs := genFileOccupiedBBs()
Expect(bbs).To(HaveLen(8 * 255))
})
})
Describe("#genPosDiagOccupiedBBs", func() {
It("generates the appropriate number of bitboards", func() {
bbs := genPosDiagOccupiedBBs()
var expNBBs int
expNBBs += 2 * ((1 << 1) - 1) // corners
expNBBs += 2 * ((1 << 2) - 1) // diags 1 & 13
expNBBs += 2 * ((1 << 3) - 1) // diags 2 & 12
expNBBs += 2 * ((1 << 4) - 1) // diags 3 & 11
expNBBs += 2 * ((1 << 5) - 1) // diags 4 & 10
expNBBs += 2 * ((1 << 6) - 1) // diags 5 & 9
expNBBs += 2 * ((1 << 7) - 1) // diags 6 & 8
expNBBs += (1 << 8) - 1 // diag 7
Expect(bbs).To(HaveLen(expNBBs))
})
})
Describe("#genNegDiagOccupiedBBs", func() {
It("generates the appropriate number of bitboards", func() {
bbs := genNegDiagOccupiedBBs()
var expNBBs int
expNBBs += 2 * ((1 << 1) - 1) // corners
expNBBs += 2 * ((1 << 2) - 1) // diags 1 & 13
expNBBs += 2 * ((1 << 3) - 1) // diags 2 & 12
expNBBs += 2 * ((1 << 4) - 1) // diags 3 & 11
expNBBs += 2 * ((1 << 5) - 1) // diags 4 & 10
expNBBs += 2 * ((1 << 6) - 1) // diags 5 & 9
expNBBs += 2 * ((1 << 7) - 1) // diags 6 & 8
expNBBs += (1 << 8) - 1 // diag 7
Expect(bbs).To(HaveLen(expNBBs))
})
})
})