@@ -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. |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function __construct(string $value) |
128 | 128 | { |
129 | - $this->value = $value; |
|
130 | - $this->capture = false; |
|
131 | - $this->check = false; |
|
132 | - $this->checkmate = false; |
|
129 | + $this->value=$value; |
|
130 | + $this->capture=false; |
|
131 | + $this->check=false; |
|
132 | + $this->checkmate=false; |
|
133 | 133 | |
134 | 134 | $this->parse($value); |
135 | 135 | } |
@@ -144,120 +144,120 @@ discard block |
||
144 | 144 | { |
145 | 145 | // Check for castling: |
146 | 146 | if (preg_match('/^(O-O|O-O-O)(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
147 | - $this->castling = $matches[1]; |
|
148 | - $this->check = $matches[2] === '+'; |
|
149 | - $this->checkmate = $matches[2] === '#'; |
|
150 | - $this->annotation = isset($matches[3]) ? $matches[3] : null; |
|
147 | + $this->castling=$matches[1]; |
|
148 | + $this->check=$matches[2] === '+'; |
|
149 | + $this->checkmate=$matches[2] === '#'; |
|
150 | + $this->annotation=isset($matches[3]) ? $matches[3] : null; |
|
151 | 151 | return; |
152 | 152 | } |
153 | 153 | |
154 | 154 | // Pawn movement: |
155 | 155 | if (preg_match('/^([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
156 | - $this->targetColumn = $matches[1]; |
|
157 | - $this->targetRow = (int)$matches[2]; |
|
158 | - $this->check = $matches[3] === '+'; |
|
159 | - $this->checkmate = $matches[3] === '#'; |
|
160 | - $this->movedPiece = self::PIECE_PAWN; |
|
161 | - $this->annotation = isset($matches[4]) ? $matches[4] : null; |
|
156 | + $this->targetColumn=$matches[1]; |
|
157 | + $this->targetRow=(int) $matches[2]; |
|
158 | + $this->check=$matches[3] === '+'; |
|
159 | + $this->checkmate=$matches[3] === '#'; |
|
160 | + $this->movedPiece=self::PIECE_PAWN; |
|
161 | + $this->annotation=isset($matches[4]) ? $matches[4] : null; |
|
162 | 162 | return; |
163 | 163 | } |
164 | 164 | |
165 | 165 | // Piece movement: |
166 | 166 | if (preg_match('/^([KQBNR])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
167 | - $this->movedPiece = $matches[1]; |
|
168 | - $this->targetColumn = $matches[2]; |
|
169 | - $this->targetRow = (int)$matches[3]; |
|
170 | - $this->check = $matches[4] === '+'; |
|
171 | - $this->checkmate = $matches[4] === '#'; |
|
172 | - $this->annotation = isset($matches[5]) ? $matches[5] : null; |
|
167 | + $this->movedPiece=$matches[1]; |
|
168 | + $this->targetColumn=$matches[2]; |
|
169 | + $this->targetRow=(int) $matches[3]; |
|
170 | + $this->check=$matches[4] === '+'; |
|
171 | + $this->checkmate=$matches[4] === '#'; |
|
172 | + $this->annotation=isset($matches[5]) ? $matches[5] : null; |
|
173 | 173 | return; |
174 | 174 | } |
175 | 175 | |
176 | 176 | // Piece movement from a specific column: |
177 | 177 | if (preg_match('/^([KQBNR])([a-h])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
178 | - $this->movedPiece = $matches[1]; |
|
179 | - $this->movedPieceDisambiguationColumn = $matches[2]; |
|
180 | - $this->targetColumn = $matches[3]; |
|
181 | - $this->targetRow = (int)$matches[4]; |
|
182 | - $this->check = $matches[5] === '+'; |
|
183 | - $this->checkmate = $matches[5] === '#'; |
|
184 | - $this->annotation = isset($matches[6]) ? $matches[6] : null; |
|
178 | + $this->movedPiece=$matches[1]; |
|
179 | + $this->movedPieceDisambiguationColumn=$matches[2]; |
|
180 | + $this->targetColumn=$matches[3]; |
|
181 | + $this->targetRow=(int) $matches[4]; |
|
182 | + $this->check=$matches[5] === '+'; |
|
183 | + $this->checkmate=$matches[5] === '#'; |
|
184 | + $this->annotation=isset($matches[6]) ? $matches[6] : null; |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
188 | 188 | // Piece movement from a specific row: |
189 | 189 | if (preg_match('/^([KQBNR])([0-9])([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
190 | - $this->movedPiece = $matches[1]; |
|
191 | - $this->movedPieceDisambiguationRow = (int)$matches[2]; |
|
192 | - $this->targetColumn = $matches[3]; |
|
193 | - $this->targetRow = (int)$matches[4]; |
|
194 | - $this->check = $matches[5] === '+'; |
|
195 | - $this->checkmate = $matches[5] === '#'; |
|
196 | - $this->annotation = isset($matches[6]) ? $matches[6] : null; |
|
190 | + $this->movedPiece=$matches[1]; |
|
191 | + $this->movedPieceDisambiguationRow=(int) $matches[2]; |
|
192 | + $this->targetColumn=$matches[3]; |
|
193 | + $this->targetRow=(int) $matches[4]; |
|
194 | + $this->check=$matches[5] === '+'; |
|
195 | + $this->checkmate=$matches[5] === '#'; |
|
196 | + $this->annotation=isset($matches[6]) ? $matches[6] : null; |
|
197 | 197 | return; |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Pawn capture: |
201 | 201 | if (preg_match('/^([a-h])x([a-h])([1-8])(?:=([KQBNR]))?(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
202 | - $this->targetColumn = $matches[2]; |
|
203 | - $this->targetRow = (int)$matches[3]; |
|
204 | - $this->movedPiece = self::PIECE_PAWN; |
|
205 | - $this->movedPieceDisambiguationColumn = $matches[1]; |
|
206 | - $this->capture = true; |
|
207 | - $this->promotedPiece = $matches[4] ?: null; |
|
208 | - $this->check = $matches[5] === '+'; |
|
209 | - $this->checkmate = $matches[5] === '#'; |
|
210 | - $this->annotation = isset($matches[6]) ? $matches[6] : null; |
|
202 | + $this->targetColumn=$matches[2]; |
|
203 | + $this->targetRow=(int) $matches[3]; |
|
204 | + $this->movedPiece=self::PIECE_PAWN; |
|
205 | + $this->movedPieceDisambiguationColumn=$matches[1]; |
|
206 | + $this->capture=true; |
|
207 | + $this->promotedPiece=$matches[4] ?: null; |
|
208 | + $this->check=$matches[5] === '+'; |
|
209 | + $this->checkmate=$matches[5] === '#'; |
|
210 | + $this->annotation=isset($matches[6]) ? $matches[6] : null; |
|
211 | 211 | return; |
212 | 212 | } |
213 | 213 | |
214 | 214 | // Piece capture: |
215 | 215 | if (preg_match('/^([KQBNR])x([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
216 | - $this->movedPiece = $matches[1]; |
|
217 | - $this->targetColumn = $matches[2]; |
|
218 | - $this->targetRow = (int)$matches[3]; |
|
219 | - $this->check = $matches[4] === '+'; |
|
220 | - $this->checkmate = $matches[4] === '#'; |
|
221 | - $this->capture = true; |
|
222 | - $this->annotation = isset($matches[5]) ? $matches[5] : null; |
|
216 | + $this->movedPiece=$matches[1]; |
|
217 | + $this->targetColumn=$matches[2]; |
|
218 | + $this->targetRow=(int) $matches[3]; |
|
219 | + $this->check=$matches[4] === '+'; |
|
220 | + $this->checkmate=$matches[4] === '#'; |
|
221 | + $this->capture=true; |
|
222 | + $this->annotation=isset($matches[5]) ? $matches[5] : null; |
|
223 | 223 | return; |
224 | 224 | } |
225 | 225 | |
226 | 226 | // Piece capture from a specific column: |
227 | 227 | if (preg_match('/^([KQBNR])([a-h])x([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
228 | - $this->movedPiece = $matches[1]; |
|
229 | - $this->movedPieceDisambiguationColumn = $matches[2]; |
|
230 | - $this->targetColumn = $matches[3]; |
|
231 | - $this->targetRow = (int)$matches[4]; |
|
232 | - $this->check = $matches[5] === '+'; |
|
233 | - $this->checkmate = $matches[5] === '#'; |
|
234 | - $this->capture = true; |
|
235 | - $this->annotation = isset($matches[6]) ? $matches[6] : null; |
|
228 | + $this->movedPiece=$matches[1]; |
|
229 | + $this->movedPieceDisambiguationColumn=$matches[2]; |
|
230 | + $this->targetColumn=$matches[3]; |
|
231 | + $this->targetRow=(int) $matches[4]; |
|
232 | + $this->check=$matches[5] === '+'; |
|
233 | + $this->checkmate=$matches[5] === '#'; |
|
234 | + $this->capture=true; |
|
235 | + $this->annotation=isset($matches[6]) ? $matches[6] : null; |
|
236 | 236 | return; |
237 | 237 | } |
238 | 238 | |
239 | 239 | // Piece capture from a specific column: |
240 | 240 | if (preg_match('/^([KQBNR])([0-9])x([a-h])([1-8])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
241 | - $this->movedPiece = $matches[1]; |
|
242 | - $this->movedPieceDisambiguationRow = (int)$matches[2]; |
|
243 | - $this->targetColumn = $matches[3]; |
|
244 | - $this->targetRow = (int)$matches[4]; |
|
245 | - $this->check = $matches[5] === '+'; |
|
246 | - $this->checkmate = $matches[5] === '#'; |
|
247 | - $this->capture = true; |
|
248 | - $this->annotation = isset($matches[6]) ? $matches[6] : null; |
|
241 | + $this->movedPiece=$matches[1]; |
|
242 | + $this->movedPieceDisambiguationRow=(int) $matches[2]; |
|
243 | + $this->targetColumn=$matches[3]; |
|
244 | + $this->targetRow=(int) $matches[4]; |
|
245 | + $this->check=$matches[5] === '+'; |
|
246 | + $this->checkmate=$matches[5] === '#'; |
|
247 | + $this->capture=true; |
|
248 | + $this->annotation=isset($matches[6]) ? $matches[6] : null; |
|
249 | 249 | return; |
250 | 250 | } |
251 | 251 | |
252 | 252 | // Check for pawn promotion: |
253 | 253 | if (preg_match('/^([a-h])([1-8])=?([KQBNR])(\+|\#?)(\?\?|\?|\?\!|\!|\!\!)?$/', $value, $matches)) { |
254 | - $this->movedPiece = self::PIECE_PAWN; |
|
255 | - $this->targetColumn = $matches[1]; |
|
256 | - $this->targetRow = (int)$matches[2]; |
|
257 | - $this->promotedPiece = $matches[3]; |
|
258 | - $this->check = $matches[4] === '+'; |
|
259 | - $this->checkmate = $matches[4] === '#'; |
|
260 | - $this->annotation = isset($matches[5]) ? $matches[5] : null; |
|
254 | + $this->movedPiece=self::PIECE_PAWN; |
|
255 | + $this->targetColumn=$matches[1]; |
|
256 | + $this->targetRow=(int) $matches[2]; |
|
257 | + $this->promotedPiece=$matches[3]; |
|
258 | + $this->check=$matches[4] === '+'; |
|
259 | + $this->checkmate=$matches[4] === '#'; |
|
260 | + $this->annotation=isset($matches[5]) ? $matches[5] : null; |
|
261 | 261 | return; |
262 | 262 | } |
263 | 263 | |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | throw new RuntimeException('No row has been set.'); |
356 | 356 | } |
357 | 357 | |
358 | - $notation = chr(97 + $index) . $this->getTargetRow(); |
|
358 | + $notation=chr(97 + $index).$this->getTargetRow(); |
|
359 | 359 | |
360 | 360 | return new self($notation); |
361 | 361 | } |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | */ |
380 | 380 | public function withTargetRow(int $row): Notation |
381 | 381 | { |
382 | - $notation = $this->getTargetColumn() . $row; |
|
382 | + $notation=$this->getTargetColumn().$row; |
|
383 | 383 | |
384 | 384 | return new self($notation); |
385 | 385 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | */ |
392 | 392 | public function getTargetNotation(): string |
393 | 393 | { |
394 | - return $this->getTargetColumn() . $this->getTargetRow(); |
|
394 | + return $this->getTargetColumn().$this->getTargetRow(); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | */ |
422 | 422 | public function setMovedPieceDisambiguationColumn(?string $movedPieceDisambiguationColumn): void |
423 | 423 | { |
424 | - $this->movedPieceDisambiguationColumn = $movedPieceDisambiguationColumn; |
|
424 | + $this->movedPieceDisambiguationColumn=$movedPieceDisambiguationColumn; |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | */ |
442 | 442 | public function setMovedPieceDisambiguationRow(?int $movedPieceDisambiguationRow): void |
443 | 443 | { |
444 | - $this->movedPieceDisambiguationRow = $movedPieceDisambiguationRow; |
|
444 | + $this->movedPieceDisambiguationRow=$movedPieceDisambiguationRow; |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |