/
DefenseEvalTest.php
224 lines (174 loc) · 6.32 KB
/
DefenseEvalTest.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
<?php
namespace Chess\Tests\Unit\Eval;
use Chess\Eval\DefenseEval;
use Chess\Variant\Classical\FEN\StrToBoard;
use Chess\Tests\AbstractUnitTestCase;
use Chess\Variant\Classical\Board;
class DefenseEvalTest extends AbstractUnitTestCase
{
/**
* @test
*/
public function c62_ruy_lopez_steinitz_defense_center_gambit_Bg4()
{
$expectedResult = [
'w' => 0,
'b' => 0,
];
$expectedExplanation = [];
$expectedElaboration = [];
$board = (new StrToBoard('r2qkbnr/ppp2ppp/2np4/1B2p3/3PP1b1/5N2/PPP2PPP/RNBQK2R w KQkq -'))
->create();
$defenseEval = new DefenseEval($board);
$this->assertSame($expectedResult, $defenseEval->getResult());
$this->assertSame($expectedExplanation, $defenseEval->getExplanation());
$this->assertSame($expectedElaboration, $defenseEval->getElaboration());
}
/**
* @test
*/
public function attacking_rook_with_a_knight_shielding_the_queen()
{
$expectedResult = [
'w' => 0,
'b' => 0,
];
$expectedExplanation = [];
$expectedElaboration = [];
$board = (new StrToBoard('4qk2/8/4n3/8/8/4R3/8/6K1 w - -'))
->create();
$defenseEval = new DefenseEval($board);
$this->assertSame($expectedResult, $defenseEval->getResult());
$this->assertSame($expectedExplanation, $defenseEval->getExplanation());
$this->assertSame($expectedElaboration, $defenseEval->getElaboration());
}
/**
* @test
*/
public function attacking_rook_with_a_knight_shielding_the_unprotected_queen()
{
$expectedResult = [
'w' => 8.8,
'b' => 0,
];
$expectedExplanation = [
"White has a moderate defense advantage."
];
$expectedElaboration = [
"If the knight on e6 moved, these pieces may well be exposed to attack: The rook on e3, Black's queen on e8.",
];
$board = (new StrToBoard('4q1k1/8/4n3/8/8/4R3/8/6K1 w - -'))
->create();
$defenseEval = new DefenseEval($board);
$this->assertSame($expectedResult, $defenseEval->getResult());
$this->assertSame($expectedExplanation, $defenseEval->getExplanation());
$this->assertSame($expectedElaboration, $defenseEval->getElaboration());
}
/**
* @test
*/
public function attacking_bishop_with_a_knight_shielding_the_queen()
{
$expectedResult = [
'w' => 0,
'b' => 0,
];
$expectedExplanation = [];
$expectedElaboration = [];
$board = (new StrToBoard('4qk2/8/2n5/8/B7/8/8/6K1 w - -'))
->create();
$defenseEval = new DefenseEval($board);
$this->assertSame($expectedResult, $defenseEval->getResult());
$this->assertSame($expectedExplanation, $defenseEval->getExplanation());
$this->assertSame($expectedElaboration, $defenseEval->getElaboration());
}
/**
* @test
*/
public function attacking_bishop_with_a_knight_shielding_the_unprotected_queen()
{
$expectedResult = [
'w' => 8.8,
'b' => 0,
];
$expectedExplanation = [
"White has a moderate defense advantage."
];
$expectedElaboration = [
"If the knight on c6 moved, these pieces may well be exposed to attack: The bishop on a4, Black's queen on e8.",
];
$board = (new StrToBoard('4q1k1/8/2n5/8/B7/8/8/6K1 w - -'))
->create();
$defenseEval = new DefenseEval($board);
$this->assertSame($expectedResult, $defenseEval->getResult());
$this->assertSame($expectedExplanation, $defenseEval->getExplanation());
$this->assertSame($expectedElaboration, $defenseEval->getElaboration());
}
/**
* @test
*/
public function attacking_bishop_with_a_knight_shielding_the_unprotected_rook()
{
$expectedResult = [
'w' => 1.9,
'b' => 0,
];
$expectedExplanation = [
"White has a slight defense advantage."
];
$expectedElaboration = [
"If the knight on c6 moved, the rook on e8 may well be exposed to attack.",
];
$board = (new StrToBoard('4r1k1/8/2n5/8/B7/8/8/6K1 w - -'))
->create();
$defenseEval = new DefenseEval($board);
$this->assertSame($expectedResult, $defenseEval->getResult());
$this->assertSame($expectedExplanation, $defenseEval->getExplanation());
$this->assertSame($expectedElaboration, $defenseEval->getElaboration());
}
/**
* @test
*/
public function c60()
{
$expectedResult = [
'w' => 1.0,
'b' => 0,
];
$expectedExplanation = [
"White has a slight defense advantage."
];
$expectedElaboration = [
"If the knight on c6 moved, the pawn on e5 may well be exposed to attack.",
];
$board = (new StrToBoard('r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq -'))
->create();
$defenseEval = new DefenseEval($board);
$this->assertSame($expectedResult, $defenseEval->getResult());
$this->assertSame($expectedExplanation, $defenseEval->getExplanation());
$this->assertSame($expectedElaboration, $defenseEval->getElaboration());
}
/**
* @test
*/
public function a13()
{
$expectedResult = [
'w' => 5.1,
'b' => 9.8,
];
$expectedExplanation = [
"Black has a slight defense advantage."
];
$expectedElaboration = [
"If the pawn on a7 moved, these pieces may well be exposed to attack: White's queen on a4, the rook on a8.",
"If the knight on b5 moved, these pieces may well be exposed to attack: White's queen on a4, the pawn on b2.",
];
$board = (new StrToBoard('rn2k1nr/pp1b1ppp/1q6/1N1p4/Q1pP4/4P3/PP1K1PPP/R4BNR w kq -'))
->create();
$defenseEval = new DefenseEval($board);
$this->assertSame($expectedResult, $defenseEval->getResult());
$this->assertSame($expectedExplanation, $defenseEval->getExplanation());
$this->assertSame($expectedElaboration, $defenseEval->getElaboration());
}
}