@@ -17,21 +17,21 @@ discard block |
||
17 | 17 | */ |
18 | 18 | final class Notation |
19 | 19 | { |
20 | - public const PIECE_PAWN = null; |
|
21 | - public const PIECE_BISHOP = 'B'; |
|
22 | - public const PIECE_KING = 'K'; |
|
23 | - public const PIECE_KNIGHT = 'N'; |
|
24 | - public const PIECE_QUEEN = 'Q'; |
|
25 | - public const PIECE_ROOK = 'R'; |
|
20 | + public const PIECE_PAWN=null; |
|
21 | + public const PIECE_BISHOP='B'; |
|
22 | + public const PIECE_KING='K'; |
|
23 | + public const PIECE_KNIGHT='N'; |
|
24 | + public const PIECE_QUEEN='Q'; |
|
25 | + public const PIECE_ROOK='R'; |
|
26 | 26 | |
27 | - public const CASTLING_KING_SIDE = 'O-O'; |
|
28 | - public const CASTLING_QUEEN_SIDE = 'O-O-O'; |
|
27 | + public const CASTLING_KING_SIDE='O-O'; |
|
28 | + public const CASTLING_QUEEN_SIDE='O-O-O'; |
|
29 | 29 | |
30 | - public const ANNOTATION_BLUNDER = '??'; |
|
31 | - public const ANNOTATION_MISTAKE = '?'; |
|
32 | - public const ANNOTATION_INTERESTING_MOVE = '?!'; |
|
33 | - public const ANNOTATION_GOOD_MOVE = '!'; |
|
34 | - public const ANNOTATION_BRILLIANT_MOVE = '!!'; |
|
30 | + public const ANNOTATION_BLUNDER='??'; |
|
31 | + public const ANNOTATION_MISTAKE='?'; |
|
32 | + public const ANNOTATION_INTERESTING_MOVE='?!'; |
|
33 | + public const ANNOTATION_GOOD_MOVE='!'; |
|
34 | + public const ANNOTATION_BRILLIANT_MOVE='!!'; |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * The original value. |
@@ -133,11 +133,11 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function __construct(string $value) |
135 | 135 | { |
136 | - $this->value = $value; |
|
137 | - $this->capture = false; |
|
138 | - $this->check = false; |
|
139 | - $this->checkmate = false; |
|
140 | - $this->longSan = false; |
|
136 | + $this->value=$value; |
|
137 | + $this->capture=false; |
|
138 | + $this->check=false; |
|
139 | + $this->checkmate=false; |
|
140 | + $this->longSan=false; |
|
141 | 141 | |
142 | 142 | $this->parse($value); |
143 | 143 | } |
@@ -152,179 +152,179 @@ discard block |
||
152 | 152 | { |
153 | 153 | // Check for castling: |
154 | 154 | if (preg_match('/^(O-O|O-O-O)(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
155 | - $this->castling = $matches[1]; |
|
156 | - $this->check = $matches[2] === '+'; |
|
157 | - $this->checkmate = $matches[2] === '#'; |
|
158 | - $this->annotation = isset($matches[3]) ? $matches[3] : null; |
|
155 | + $this->castling=$matches[1]; |
|
156 | + $this->check=$matches[2] === '+'; |
|
157 | + $this->checkmate=$matches[2] === '#'; |
|
158 | + $this->annotation=isset($matches[3]) ? $matches[3] : null; |
|
159 | 159 | return; |
160 | 160 | } |
161 | 161 | |
162 | 162 | // Pawn movement: |
163 | 163 | if (preg_match('/^([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
164 | - $this->targetColumn = $matches[1]; |
|
165 | - $this->targetRow = (int)$matches[2]; |
|
166 | - $this->check = $matches[3] === '+'; |
|
167 | - $this->checkmate = $matches[3] === '#'; |
|
168 | - $this->movedPiece = self::PIECE_PAWN; |
|
169 | - $this->annotation = isset($matches[4]) ? $matches[4] : null; |
|
164 | + $this->targetColumn=$matches[1]; |
|
165 | + $this->targetRow=(int) $matches[2]; |
|
166 | + $this->check=$matches[3] === '+'; |
|
167 | + $this->checkmate=$matches[3] === '#'; |
|
168 | + $this->movedPiece=self::PIECE_PAWN; |
|
169 | + $this->annotation=isset($matches[4]) ? $matches[4] : null; |
|
170 | 170 | return; |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Pawn movement (long san): |
174 | 174 | if (preg_match('/^([a-h])([1-8])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
175 | - $this->movedPieceDisambiguationColumn = $matches[1]; |
|
176 | - $this->movedPieceDisambiguationRow = (int)$matches[2]; |
|
177 | - $this->targetColumn = $matches[3]; |
|
178 | - $this->targetRow = (int)$matches[4]; |
|
179 | - $this->check = $matches[5] === '+'; |
|
180 | - $this->checkmate = $matches[5] === '#'; |
|
181 | - $this->movedPiece = self::PIECE_PAWN; |
|
182 | - $this->annotation = isset($matches[6]) ? $matches[6] : null; |
|
183 | - $this->longSan = true; |
|
175 | + $this->movedPieceDisambiguationColumn=$matches[1]; |
|
176 | + $this->movedPieceDisambiguationRow=(int) $matches[2]; |
|
177 | + $this->targetColumn=$matches[3]; |
|
178 | + $this->targetRow=(int) $matches[4]; |
|
179 | + $this->check=$matches[5] === '+'; |
|
180 | + $this->checkmate=$matches[5] === '#'; |
|
181 | + $this->movedPiece=self::PIECE_PAWN; |
|
182 | + $this->annotation=isset($matches[6]) ? $matches[6] : null; |
|
183 | + $this->longSan=true; |
|
184 | 184 | return; |
185 | 185 | } |
186 | 186 | |
187 | 187 | // Piece movement: |
188 | 188 | if (preg_match('/^([KQBNR])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
189 | - $this->movedPiece = $matches[1]; |
|
190 | - $this->targetColumn = $matches[2]; |
|
191 | - $this->targetRow = (int)$matches[3]; |
|
192 | - $this->check = $matches[4] === '+'; |
|
193 | - $this->checkmate = $matches[4] === '#'; |
|
194 | - $this->annotation = isset($matches[5]) ? $matches[5] : null; |
|
189 | + $this->movedPiece=$matches[1]; |
|
190 | + $this->targetColumn=$matches[2]; |
|
191 | + $this->targetRow=(int) $matches[3]; |
|
192 | + $this->check=$matches[4] === '+'; |
|
193 | + $this->checkmate=$matches[4] === '#'; |
|
194 | + $this->annotation=isset($matches[5]) ? $matches[5] : null; |
|
195 | 195 | return; |
196 | 196 | } |
197 | 197 | |
198 | 198 | // Piece movement from a specific column: |
199 | 199 | if (preg_match('/^([KQBNR])([a-h])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
200 | - $this->movedPiece = $matches[1]; |
|
201 | - $this->movedPieceDisambiguationColumn = $matches[2]; |
|
202 | - $this->targetColumn = $matches[3]; |
|
203 | - $this->targetRow = (int)$matches[4]; |
|
204 | - $this->check = $matches[5] === '+'; |
|
205 | - $this->checkmate = $matches[5] === '#'; |
|
206 | - $this->annotation = isset($matches[6]) ? $matches[6] : null; |
|
200 | + $this->movedPiece=$matches[1]; |
|
201 | + $this->movedPieceDisambiguationColumn=$matches[2]; |
|
202 | + $this->targetColumn=$matches[3]; |
|
203 | + $this->targetRow=(int) $matches[4]; |
|
204 | + $this->check=$matches[5] === '+'; |
|
205 | + $this->checkmate=$matches[5] === '#'; |
|
206 | + $this->annotation=isset($matches[6]) ? $matches[6] : null; |
|
207 | 207 | return; |
208 | 208 | } |
209 | 209 | |
210 | 210 | // Piece movement from a specific row: |
211 | 211 | if (preg_match('/^([KQBNR])([0-9])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
212 | - $this->movedPiece = $matches[1]; |
|
213 | - $this->movedPieceDisambiguationRow = (int)$matches[2]; |
|
214 | - $this->targetColumn = $matches[3]; |
|
215 | - $this->targetRow = (int)$matches[4]; |
|
216 | - $this->check = $matches[5] === '+'; |
|
217 | - $this->checkmate = $matches[5] === '#'; |
|
218 | - $this->annotation = isset($matches[6]) ? $matches[6] : null; |
|
212 | + $this->movedPiece=$matches[1]; |
|
213 | + $this->movedPieceDisambiguationRow=(int) $matches[2]; |
|
214 | + $this->targetColumn=$matches[3]; |
|
215 | + $this->targetRow=(int) $matches[4]; |
|
216 | + $this->check=$matches[5] === '+'; |
|
217 | + $this->checkmate=$matches[5] === '#'; |
|
218 | + $this->annotation=isset($matches[6]) ? $matches[6] : null; |
|
219 | 219 | return; |
220 | 220 | } |
221 | 221 | |
222 | 222 | // Piece movement from a specific column and row (long san): |
223 | 223 | if (preg_match('/^([KQBNR])([a-h])([0-9])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
224 | - $this->movedPiece = $matches[1]; |
|
225 | - $this->movedPieceDisambiguationColumn = $matches[2]; |
|
226 | - $this->movedPieceDisambiguationRow = (int)$matches[3]; |
|
227 | - $this->targetColumn = $matches[4]; |
|
228 | - $this->targetRow = (int)$matches[5]; |
|
229 | - $this->check = $matches[6] === '+'; |
|
230 | - $this->checkmate = $matches[6] === '#'; |
|
231 | - $this->annotation = isset($matches[7]) ? $matches[7] : null; |
|
232 | - $this->longSan = true; |
|
224 | + $this->movedPiece=$matches[1]; |
|
225 | + $this->movedPieceDisambiguationColumn=$matches[2]; |
|
226 | + $this->movedPieceDisambiguationRow=(int) $matches[3]; |
|
227 | + $this->targetColumn=$matches[4]; |
|
228 | + $this->targetRow=(int) $matches[5]; |
|
229 | + $this->check=$matches[6] === '+'; |
|
230 | + $this->checkmate=$matches[6] === '#'; |
|
231 | + $this->annotation=isset($matches[7]) ? $matches[7] : null; |
|
232 | + $this->longSan=true; |
|
233 | 233 | return; |
234 | 234 | } |
235 | 235 | |
236 | 236 | // Pawn capture: |
237 | 237 | if (preg_match('/^([a-h])x([a-h])([1-8])(?:=([KQBNR]))?(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
238 | - $this->targetColumn = $matches[2]; |
|
239 | - $this->targetRow = (int)$matches[3]; |
|
240 | - $this->movedPiece = self::PIECE_PAWN; |
|
241 | - $this->movedPieceDisambiguationColumn = $matches[1]; |
|
242 | - $this->capture = true; |
|
243 | - $this->promotedPiece = $matches[4] ?: null; |
|
244 | - $this->check = $matches[5] === '+'; |
|
245 | - $this->checkmate = $matches[5] === '#'; |
|
246 | - $this->annotation = isset($matches[6]) ? $matches[6] : null; |
|
238 | + $this->targetColumn=$matches[2]; |
|
239 | + $this->targetRow=(int) $matches[3]; |
|
240 | + $this->movedPiece=self::PIECE_PAWN; |
|
241 | + $this->movedPieceDisambiguationColumn=$matches[1]; |
|
242 | + $this->capture=true; |
|
243 | + $this->promotedPiece=$matches[4] ?: null; |
|
244 | + $this->check=$matches[5] === '+'; |
|
245 | + $this->checkmate=$matches[5] === '#'; |
|
246 | + $this->annotation=isset($matches[6]) ? $matches[6] : null; |
|
247 | 247 | return; |
248 | 248 | } |
249 | 249 | |
250 | 250 | // Pawn capture (long san): |
251 | 251 | if (preg_match('/^([a-h])([1-8])x([a-h])([1-8])(?:=([KQBNR]))?(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
252 | - $this->targetColumn = $matches[3]; |
|
253 | - $this->targetRow = (int)$matches[4]; |
|
254 | - $this->movedPiece = self::PIECE_PAWN; |
|
255 | - $this->movedPieceDisambiguationColumn = $matches[1]; |
|
256 | - $this->movedPieceDisambiguationRow = (int)$matches[2]; |
|
257 | - $this->capture = true; |
|
258 | - $this->promotedPiece = $matches[5] ?: null; |
|
259 | - $this->check = $matches[6] === '+'; |
|
260 | - $this->checkmate = $matches[6] === '#'; |
|
261 | - $this->annotation = isset($matches[7]) ? $matches[7] : null; |
|
262 | - $this->longSan = true; |
|
252 | + $this->targetColumn=$matches[3]; |
|
253 | + $this->targetRow=(int) $matches[4]; |
|
254 | + $this->movedPiece=self::PIECE_PAWN; |
|
255 | + $this->movedPieceDisambiguationColumn=$matches[1]; |
|
256 | + $this->movedPieceDisambiguationRow=(int) $matches[2]; |
|
257 | + $this->capture=true; |
|
258 | + $this->promotedPiece=$matches[5] ?: null; |
|
259 | + $this->check=$matches[6] === '+'; |
|
260 | + $this->checkmate=$matches[6] === '#'; |
|
261 | + $this->annotation=isset($matches[7]) ? $matches[7] : null; |
|
262 | + $this->longSan=true; |
|
263 | 263 | return; |
264 | 264 | } |
265 | 265 | |
266 | 266 | // Piece capture: |
267 | 267 | if (preg_match('/^([KQBNR])x([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
268 | - $this->movedPiece = $matches[1]; |
|
269 | - $this->targetColumn = $matches[2]; |
|
270 | - $this->targetRow = (int)$matches[3]; |
|
271 | - $this->check = $matches[4] === '+'; |
|
272 | - $this->checkmate = $matches[4] === '#'; |
|
273 | - $this->capture = true; |
|
274 | - $this->annotation = isset($matches[5]) ? $matches[5] : null; |
|
268 | + $this->movedPiece=$matches[1]; |
|
269 | + $this->targetColumn=$matches[2]; |
|
270 | + $this->targetRow=(int) $matches[3]; |
|
271 | + $this->check=$matches[4] === '+'; |
|
272 | + $this->checkmate=$matches[4] === '#'; |
|
273 | + $this->capture=true; |
|
274 | + $this->annotation=isset($matches[5]) ? $matches[5] : null; |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
278 | 278 | // Piece capture from a specific column: |
279 | 279 | if (preg_match('/^([KQBNR])([a-h])x([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
280 | - $this->movedPiece = $matches[1]; |
|
281 | - $this->movedPieceDisambiguationColumn = $matches[2]; |
|
282 | - $this->targetColumn = $matches[3]; |
|
283 | - $this->targetRow = (int)$matches[4]; |
|
284 | - $this->check = $matches[5] === '+'; |
|
285 | - $this->checkmate = $matches[5] === '#'; |
|
286 | - $this->capture = true; |
|
287 | - $this->annotation = isset($matches[6]) ? $matches[6] : null; |
|
280 | + $this->movedPiece=$matches[1]; |
|
281 | + $this->movedPieceDisambiguationColumn=$matches[2]; |
|
282 | + $this->targetColumn=$matches[3]; |
|
283 | + $this->targetRow=(int) $matches[4]; |
|
284 | + $this->check=$matches[5] === '+'; |
|
285 | + $this->checkmate=$matches[5] === '#'; |
|
286 | + $this->capture=true; |
|
287 | + $this->annotation=isset($matches[6]) ? $matches[6] : null; |
|
288 | 288 | return; |
289 | 289 | } |
290 | 290 | |
291 | 291 | // Piece capture from a specific row: |
292 | 292 | if (preg_match('/^([KQBNR])([0-9])x([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
293 | - $this->movedPiece = $matches[1]; |
|
294 | - $this->movedPieceDisambiguationRow = (int)$matches[2]; |
|
295 | - $this->targetColumn = $matches[3]; |
|
296 | - $this->targetRow = (int)$matches[4]; |
|
297 | - $this->check = $matches[5] === '+'; |
|
298 | - $this->checkmate = $matches[5] === '#'; |
|
299 | - $this->capture = true; |
|
300 | - $this->annotation = isset($matches[6]) ? $matches[6] : null; |
|
293 | + $this->movedPiece=$matches[1]; |
|
294 | + $this->movedPieceDisambiguationRow=(int) $matches[2]; |
|
295 | + $this->targetColumn=$matches[3]; |
|
296 | + $this->targetRow=(int) $matches[4]; |
|
297 | + $this->check=$matches[5] === '+'; |
|
298 | + $this->checkmate=$matches[5] === '#'; |
|
299 | + $this->capture=true; |
|
300 | + $this->annotation=isset($matches[6]) ? $matches[6] : null; |
|
301 | 301 | return; |
302 | 302 | } |
303 | 303 | |
304 | 304 | // Piece capture from a specific column and row (long san): |
305 | 305 | if (preg_match('/^([KQBNR])([a-h])([0-9])x([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
306 | - $this->movedPiece = $matches[1]; |
|
307 | - $this->movedPieceDisambiguationColumn = $matches[2]; |
|
308 | - $this->movedPieceDisambiguationRow = (int)$matches[3]; |
|
309 | - $this->targetColumn = $matches[4]; |
|
310 | - $this->targetRow = (int)$matches[5]; |
|
311 | - $this->check = $matches[6] === '+'; |
|
312 | - $this->checkmate = $matches[6] === '#'; |
|
313 | - $this->capture = true; |
|
314 | - $this->annotation = isset($matches[7]) ? $matches[7] : null; |
|
315 | - $this->longSan = true; |
|
306 | + $this->movedPiece=$matches[1]; |
|
307 | + $this->movedPieceDisambiguationColumn=$matches[2]; |
|
308 | + $this->movedPieceDisambiguationRow=(int) $matches[3]; |
|
309 | + $this->targetColumn=$matches[4]; |
|
310 | + $this->targetRow=(int) $matches[5]; |
|
311 | + $this->check=$matches[6] === '+'; |
|
312 | + $this->checkmate=$matches[6] === '#'; |
|
313 | + $this->capture=true; |
|
314 | + $this->annotation=isset($matches[7]) ? $matches[7] : null; |
|
315 | + $this->longSan=true; |
|
316 | 316 | return; |
317 | 317 | } |
318 | 318 | |
319 | 319 | // Check for pawn promotion: |
320 | 320 | if (preg_match('/^([a-h])([1-8])=?([KQBNR])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
321 | - $this->movedPiece = self::PIECE_PAWN; |
|
322 | - $this->targetColumn = $matches[1]; |
|
323 | - $this->targetRow = (int)$matches[2]; |
|
324 | - $this->promotedPiece = $matches[3]; |
|
325 | - $this->check = $matches[4] === '+'; |
|
326 | - $this->checkmate = $matches[4] === '#'; |
|
327 | - $this->annotation = isset($matches[5]) ? $matches[5] : null; |
|
321 | + $this->movedPiece=self::PIECE_PAWN; |
|
322 | + $this->targetColumn=$matches[1]; |
|
323 | + $this->targetRow=(int) $matches[2]; |
|
324 | + $this->promotedPiece=$matches[3]; |
|
325 | + $this->check=$matches[4] === '+'; |
|
326 | + $this->checkmate=$matches[4] === '#'; |
|
327 | + $this->annotation=isset($matches[5]) ? $matches[5] : null; |
|
328 | 328 | return; |
329 | 329 | } |
330 | 330 | |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | throw new RuntimeException('No row has been set.'); |
423 | 423 | } |
424 | 424 | |
425 | - $notation = chr(97 + $index) . $this->getTargetRow(); |
|
425 | + $notation=chr(97 + $index).$this->getTargetRow(); |
|
426 | 426 | |
427 | 427 | return new self($notation); |
428 | 428 | } |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | */ |
447 | 447 | public function withTargetRow(int $row): Notation |
448 | 448 | { |
449 | - $notation = $this->getTargetColumn() . $row; |
|
449 | + $notation=$this->getTargetColumn().$row; |
|
450 | 450 | |
451 | 451 | return new self($notation); |
452 | 452 | } |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | */ |
459 | 459 | public function getTargetNotation(): string |
460 | 460 | { |
461 | - return $this->getTargetColumn() . $this->getTargetRow(); |
|
461 | + return $this->getTargetColumn().$this->getTargetRow(); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | */ |
489 | 489 | public function setMovedPieceDisambiguationColumn(?string $movedPieceDisambiguationColumn): void |
490 | 490 | { |
491 | - $this->movedPieceDisambiguationColumn = $movedPieceDisambiguationColumn; |
|
491 | + $this->movedPieceDisambiguationColumn=$movedPieceDisambiguationColumn; |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | /** |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | */ |
509 | 509 | public function setMovedPieceDisambiguationRow(?int $movedPieceDisambiguationRow): void |
510 | 510 | { |
511 | - $this->movedPieceDisambiguationRow = $movedPieceDisambiguationRow; |
|
511 | + $this->movedPieceDisambiguationRow=$movedPieceDisambiguationRow; |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | /** |