/
RelativePinEvalTest.php
241 lines (187 loc) · 6.68 KB
/
RelativePinEvalTest.php
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
namespace Chess\Tests\Unit\Eval;
use Chess\Eval\RelativePinEval;
use Chess\Variant\Classical\FEN\StrToBoard;
use Chess\Tests\AbstractUnitTestCase;
use Chess\Variant\Classical\Board;
class RelativePinEvalTest extends AbstractUnitTestCase
{
/**
* @test
*/
public function c62_ruy_lopez_steinitz_defense()
{
$expected = [
'w' => 0,
'b' => 0,
];
$board = (new StrToBoard('r1bqkbnr/ppp2ppp/2np4/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R w KQkq -'))
->create();
$result = (new RelativePinEval($board))->getResult();
$this->assertSame($expected, $result);
}
/**
* @test
*/
public function c62_ruy_lopez_steinitz_defense_center_gambit_Bg4()
{
$expectedResult = [
'w' => 0,
'b' => 5.47,
];
$expectedExplanation = [
"Black has a total relative pin advantage.",
];
$expectedElaboration = [
"The knight on f3 is pinned shielding a piece that is more valuable than the attacking piece.",
];
$board = (new StrToBoard('r2qkbnr/ppp2ppp/2np4/1B2p3/3PP1b1/5N2/PPP2PPP/RNBQK2R w KQkq -'))
->create();
$relativePinEval = new RelativePinEval($board);
$this->assertSame($expectedResult, $relativePinEval->getResult());
$this->assertSame($expectedExplanation, $relativePinEval->getExplanation());
$this->assertSame($expectedElaboration, $relativePinEval->getElaboration());
}
/**
* @test
*/
public function pinning_rook_pinned_knight_shielded_queen()
{
$expectedResult = [
'w' => 3.7,
'b' => 0,
];
$expectedExplanation = [
"White has a moderate relative pin advantage.",
];
$expectedElaboration = [
"The knight on e6 is pinned shielding a piece that is more valuable than the attacking piece.",
];
$board = (new StrToBoard('4q1k1/8/4n3/8/8/4R3/8/6K1 w - -'))
->create();
$relativePinEval = new RelativePinEval($board);
$this->assertSame($expectedResult, $relativePinEval->getResult());
$this->assertSame($expectedExplanation, $relativePinEval->getExplanation());
$this->assertSame($expectedElaboration, $relativePinEval->getElaboration());
}
/**
* @test
*/
public function pinning_bishop_pinned_knight_shielded_queen()
{
$expectedResult = [
'w' => 5.47,
'b' => 0,
];
$expectedExplanation = [
"White has a total relative pin advantage.",
];
$expectedElaboration = [
"The knight on c6 is pinned shielding a piece that is more valuable than the attacking piece.",
];
$board = (new StrToBoard('4q1k1/8/2n5/8/B7/8/8/6K1 w - -'))
->create();
$relativePinEval = new RelativePinEval($board);
$this->assertSame($expectedResult, $relativePinEval->getResult());
$this->assertSame($expectedExplanation, $relativePinEval->getExplanation());
$this->assertSame($expectedElaboration, $relativePinEval->getElaboration());
}
/**
* @test
*/
public function pinning_bishop_pinned_knight_shielded_rook()
{
$expectedResult = [
'w' => 1.77,
'b' => 0,
];
$expectedExplanation = [
"White has a slight relative pin advantage.",
];
$expectedElaboration = [
"The knight on c6 is pinned shielding a piece that is more valuable than the attacking piece.",
];
$board = (new StrToBoard('4r1k1/8/2n5/8/B7/8/8/6K1 w - -'))
->create();
$relativePinEval = new RelativePinEval($board);
$this->assertSame($expectedResult, $relativePinEval->getResult());
$this->assertSame($expectedExplanation, $relativePinEval->getExplanation());
$this->assertSame($expectedElaboration, $relativePinEval->getElaboration());
}
/**
* @test
*/
public function pinning_bishop_pinned_knight_shielded_rook_and_attacked_rook()
{
$expectedResult = [
'w' => 1.77,
'b' => 0,
];
$expectedExplanation = [
"White has a slight relative pin advantage.",
];
$expectedElaboration = [
"The knight on c6 is pinned shielding a piece that is more valuable than the attacking piece.",
];
$board = (new StrToBoard('4r1k1/8/2n5/8/B2R4/8/8/6K1 w - -'))
->create();
$relativePinEval = new RelativePinEval($board);
$this->assertSame($expectedResult, $relativePinEval->getResult());
$this->assertSame($expectedExplanation, $relativePinEval->getExplanation());
$this->assertSame($expectedElaboration, $relativePinEval->getElaboration());
}
/**
* @test
*/
public function e6_pawn()
{
$expectedResult = [
'w' => 0,
'b' => 0,
];
$expectedExplanation = [];
$expectedElaboration = [];
$board = (new StrToBoard('4r1k1/4r3/4p3/8/8/8/8/4R1K1 w - -'))
->create();
$relativePinEval = new RelativePinEval($board);
$this->assertSame($expectedResult, $relativePinEval->getResult());
$this->assertSame($expectedExplanation, $relativePinEval->getExplanation());
$this->assertSame($expectedElaboration, $relativePinEval->getElaboration());
}
/**
* @test
*/
public function b5_knight()
{
$expectedResult = [
'w' => 0,
'b' => 0,
];
$expectedExplanation = [];
$expectedElaboration = [];
$board = (new StrToBoard('rrb3k1/3qn1bp/3p4/1NpP4/P7/1PN1Bp1P/R2Q1P1K/1R6 w - -'))
->create();
$relativePinEval = new RelativePinEval($board);
$this->assertSame($expectedResult, $relativePinEval->getResult());
$this->assertSame($expectedExplanation, $relativePinEval->getExplanation());
$this->assertSame($expectedElaboration, $relativePinEval->getElaboration());
}
/**
* @test
*/
public function f5_pawn()
{
$expectedResult = [
'w' => 0,
'b' => 0,
];
$expectedExplanation = [];
$expectedElaboration = [];
$board = (new StrToBoard('8/7p/1pnnk3/3N1p2/2K2P2/P2B3P/8/8 w - -'))
->create();
$relativePinEval = new RelativePinEval($board);
$this->assertSame($expectedResult, $relativePinEval->getResult());
$this->assertSame($expectedExplanation, $relativePinEval->getExplanation());
$this->assertSame($expectedElaboration, $relativePinEval->getElaboration());
}
}