diff --git a/src/Variant/AbstractPiece.php b/src/Variant/AbstractPiece.php index 644af09ef..466f22227 100644 --- a/src/Variant/AbstractPiece.php +++ b/src/Variant/AbstractPiece.php @@ -10,7 +10,6 @@ use Chess\Variant\Classical\PGN\AN\Castle; use Chess\Variant\Classical\PGN\AN\Color; use Chess\Variant\Classical\PGN\AN\Piece; -use Chess\Variant\Classical\PGN\AN\Square; use Chess\Variant\Classical\Rule\CastlingRule; abstract class AbstractPiece @@ -29,13 +28,6 @@ abstract class AbstractPiece */ public string $sq; - /** - * Square. - * - * @var \Chess\Variant\Classical\PGN\AN\Square - */ - public Square $square; - /** * Identifier. * @@ -67,14 +59,12 @@ abstract class AbstractPiece /** * @param string $color * @param string $sq - * @param \Chess\Variant\Classical\PGN\AN\Square $square * @param string $id */ - public function __construct(string $color, string $sq, Square $square, string $id) + public function __construct(string $color, string $sq, string $id) { $this->color = $color; $this->sq = $sq; - $this->square = $square; $this->id = $id; } diff --git a/src/Variant/Capablanca/Piece/A.php b/src/Variant/Capablanca/Piece/A.php index e0faeaca9..59e06c409 100644 --- a/src/Variant/Capablanca/Piece/A.php +++ b/src/Variant/Capablanca/Piece/A.php @@ -14,7 +14,7 @@ class A extends AbstractLinePiece public function __construct(string $color, string $sq, Square $square) { - parent::__construct($color, $sq, $square, Piece::A); + parent::__construct($color, $sq, Piece::A); $this->mobility = [ ...(new B($color, $sq, $square))->mobility, diff --git a/src/Variant/Capablanca/Piece/C.php b/src/Variant/Capablanca/Piece/C.php index d956f0de4..89eda5bc4 100644 --- a/src/Variant/Capablanca/Piece/C.php +++ b/src/Variant/Capablanca/Piece/C.php @@ -15,7 +15,7 @@ class C extends AbstractLinePiece public function __construct(string $color, string $sq, Square $square) { - parent::__construct($color, $sq, $square, Piece::C); + parent::__construct($color, $sq, Piece::C); $this->mobility = [ ...(new R($color, $sq, $square, RType::R))->mobility, diff --git a/src/Variant/Classical/Piece/B.php b/src/Variant/Classical/Piece/B.php index ce65621fa..3397fdd81 100644 --- a/src/Variant/Classical/Piece/B.php +++ b/src/Variant/Classical/Piece/B.php @@ -10,7 +10,7 @@ class B extends AbstractLinePiece { public function __construct(string $color, string $sq, Square $square) { - parent::__construct($color, $sq, $square, Piece::B); + parent::__construct($color, $sq, Piece::B); $this->mobility = [ 0 => [], @@ -21,7 +21,7 @@ public function __construct(string $color, string $sq, Square $square) $file = ord($this->file()) - 1; $rank = $this->rank() + 1; - while ($file >= 97 && $rank <= $this->square::SIZE['ranks']) { + while ($file >= 97 && $rank <= $square::SIZE['ranks']) { $this->mobility[0][] = chr($file) . $rank; $file -= 1; $rank += 1; @@ -29,7 +29,7 @@ public function __construct(string $color, string $sq, Square $square) $file = ord($this->file()) + 1; $rank = $this->rank() + 1; - while ($file <= 97 + $this->square::SIZE['files'] - 1 && $rank <= $this->square::SIZE['ranks']) { + while ($file <= 97 + $square::SIZE['files'] - 1 && $rank <= $square::SIZE['ranks']) { $this->mobility[1][] = chr($file) . $rank; $file += 1; $rank += 1; @@ -45,7 +45,7 @@ public function __construct(string $color, string $sq, Square $square) $file = ord($this->file()) + 1; $rank = $this->rank() - 1; - while ($file <= 97 + $this->square::SIZE['files'] - 1 && $rank >= 1) { + while ($file <= 97 + $square::SIZE['files'] - 1 && $rank >= 1) { $this->mobility[3][] = chr($file) . $rank; $file += 1; $rank -= 1; diff --git a/src/Variant/Classical/Piece/K.php b/src/Variant/Classical/Piece/K.php index 5b16550c9..d2d24be8f 100644 --- a/src/Variant/Classical/Piece/K.php +++ b/src/Variant/Classical/Piece/K.php @@ -13,12 +13,12 @@ class K extends AbstractPiece { public function __construct(string $color, string $sq, Square $square) { - parent::__construct($color, $sq, $square, Piece::K); + parent::__construct($color, $sq, Piece::K); $this->mobility = []; $rank = $this->rank() + 1; - if ($rank <= $this->square::SIZE['ranks']) { + if ($rank <= $square::SIZE['ranks']) { $this->mobility[] = $this->file() . $rank; } @@ -33,19 +33,19 @@ public function __construct(string $color, string $sq, Square $square) } $file = ord($this->file()) + 1; - if ($file <= 97 + $this->square::SIZE['files'] - 1) { + if ($file <= 97 + $square::SIZE['files'] - 1) { $this->mobility[] = chr($file) . $this->rank(); } $file = ord($this->file()) - 1; $rank = $this->rank() + 1; - if ($file >= 97 && $rank <= $this->square::SIZE['ranks']) { + if ($file >= 97 && $rank <= $square::SIZE['ranks']) { $this->mobility[] = chr($file) . $rank; } $file = ord($this->file()) + 1; $rank = $this->rank() + 1; - if ($file <= 97 + $this->square::SIZE['files'] - 1 && $rank <= $this->square::SIZE['ranks']) { + if ($file <= 97 + $square::SIZE['files'] - 1 && $rank <= $square::SIZE['ranks']) { $this->mobility[] = chr($file) . $rank; } @@ -57,7 +57,7 @@ public function __construct(string $color, string $sq, Square $square) $file = ord($this->file()) + 1; $rank = $this->rank() - 1; - if ($file <= 97 + $this->square::SIZE['files'] - 1 && $rank >= 1) { + if ($file <= 97 + $square::SIZE['files'] - 1 && $rank >= 1) { $this->mobility[] = chr($file) . $rank; } } @@ -169,7 +169,7 @@ public function castle(string $rookType): bool new K( $this->color, $this->board->castlingRule->rule[$this->color][Piece::K][rtrim($this->move['pgn'], '+')]['to'], - $this->square + $this->board->square ) ); $this->board->detach($rook); @@ -177,7 +177,7 @@ public function castle(string $rookType): bool new R( $rook->color, $this->board->castlingRule->rule[$this->color][Piece::R][rtrim($this->move['pgn'], '+')]['to'], - $this->square, + $this->board->square, $rook->type ) ); diff --git a/src/Variant/Classical/Piece/N.php b/src/Variant/Classical/Piece/N.php index 1f346e548..451dae517 100644 --- a/src/Variant/Classical/Piece/N.php +++ b/src/Variant/Classical/Piece/N.php @@ -11,14 +11,14 @@ class N extends AbstractPiece { public function __construct(string $color, string $sq, Square $square) { - parent::__construct($color, $sq, $square, Piece::N); + parent::__construct($color, $sq, Piece::N); $this->mobility = []; try { $file = chr(ord($this->file()) - 1); $rank = $this->rank() + 2; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -27,7 +27,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->file()) - 2); $rank = $this->rank() + 1; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -36,7 +36,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->file()) - 2); $rank = $this->rank() - 1; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -45,7 +45,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->file()) - 1); $rank = $this->rank() - 2; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -54,7 +54,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->file()) + 1); $rank = $this->rank() - 2; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -63,7 +63,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->file()) + 2); $rank = $this->rank() - 1; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -72,7 +72,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->file()) + 2); $rank = $this->rank() + 1; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -81,7 +81,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->file()) + 1); $rank = $this->rank() + 2; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { diff --git a/src/Variant/Classical/Piece/P.php b/src/Variant/Classical/Piece/P.php index 7edd3b857..8c6da2e8d 100644 --- a/src/Variant/Classical/Piece/P.php +++ b/src/Variant/Classical/Piece/P.php @@ -17,16 +17,16 @@ class P extends AbstractPiece public function __construct(string $color, string $sq, Square $square) { - parent::__construct($color, $sq, $square, Piece::P); + parent::__construct($color, $sq, Piece::P); $this->ranks = $this->color === Color::W ? [ 'start' => 2, 'next' => $this->rank() + 1, - 'end' => $this->square::SIZE['ranks'], + 'end' => $square::SIZE['ranks'], ] : [ - 'start' => $this->square::SIZE['ranks'] - 1, + 'start' => $square::SIZE['ranks'] - 1, 'next' => $this->rank() - 1, 'end' => 1, ]; @@ -36,29 +36,29 @@ public function __construct(string $color, string $sq, Square $square) $this->mobility = []; // next rank - if ($this->ranks['next'] <= $this->square::SIZE['ranks']) { + if ($this->ranks['next'] <= $square::SIZE['ranks']) { $this->mobility[] = $this->file() . $this->ranks['next']; } // two square advance if ($this->rank() === 2 && $this->ranks['start'] == 2) { $this->mobility[] = $this->file() . ($this->ranks['start'] + 2); - } elseif ($this->rank() === $this->square::SIZE['ranks'] - 1 && - $this->ranks['start'] == $this->square::SIZE['ranks'] - 1 + } elseif ($this->rank() === $square::SIZE['ranks'] - 1 && + $this->ranks['start'] == $square::SIZE['ranks'] - 1 ) { $this->mobility[] = $this->file() . ($this->ranks['start'] - 2); } // capture square $file = ord($this->file()) - 1; - if ($file >= 97 && $this->ranks['next'] <= $this->square::SIZE['ranks']) { + if ($file >= 97 && $this->ranks['next'] <= $square::SIZE['ranks']) { $this->captureSqs[] = chr($file) . $this->ranks['next']; } // capture square $file = ord($this->file()) + 1; - if ($file <= 97 + $this->square::SIZE['files'] - 1 && - $this->ranks['next'] <= $this->square::SIZE['ranks'] + if ($file <= 97 + $square::SIZE['files'] - 1 && + $this->ranks['next'] <= $square::SIZE['ranks'] ) { $this->captureSqs[] = chr($file) . $this->ranks['next']; } @@ -89,7 +89,7 @@ public function moveSqs(): array $end = end($history); if ($end && $end['id'] === Piece::P && $end['color'] === $this->oppColor()) { if ($this->color === Color::W) { - if ($this->rank() === $this->square::SIZE['ranks'] - 3) { + if ($this->rank() === $this->board->square::SIZE['ranks'] - 3) { $captureSq = $end['to'][0] . ($this->rank() + 1); if (in_array($captureSq, $this->captureSqs)) { $this->enPassantSq = $captureSq; diff --git a/src/Variant/Classical/Piece/Q.php b/src/Variant/Classical/Piece/Q.php index 319199ae1..788e46480 100644 --- a/src/Variant/Classical/Piece/Q.php +++ b/src/Variant/Classical/Piece/Q.php @@ -11,7 +11,7 @@ class Q extends AbstractLinePiece { public function __construct(string $color, string $sq, Square $square) { - parent::__construct($color, $sq, $square, Piece::Q); + parent::__construct($color, $sq, Piece::Q); $this->mobility = [ ...(new R($color, $sq, $square, RType::R))->mobility, diff --git a/src/Variant/Classical/Piece/R.php b/src/Variant/Classical/Piece/R.php index b35a4da4c..2d02ea0dc 100644 --- a/src/Variant/Classical/Piece/R.php +++ b/src/Variant/Classical/Piece/R.php @@ -12,7 +12,7 @@ class R extends AbstractLinePiece public function __construct(string $color, string $sq, Square $square, string $type) { - parent::__construct($color, $sq, $square, Piece::R); + parent::__construct($color, $sq, Piece::R); $this->type = $type; @@ -23,7 +23,7 @@ public function __construct(string $color, string $sq, Square $square, string $t 3 => [], ]; - for ($i = $this->rank() + 1; $i <= $this->square::SIZE['ranks']; $i++) { + for ($i = $this->rank() + 1; $i <= $square::SIZE['ranks']; $i++) { $this->mobility[0][] = $this->file() . $i; } @@ -35,7 +35,7 @@ public function __construct(string $color, string $sq, Square $square, string $t $this->mobility[2][] = chr($i) . $this->rank(); } - for ($i = ord($this->file()) + 1; $i <= 97 + $this->square::SIZE['files'] - 1; $i++) { + for ($i = ord($this->file()) + 1; $i <= 97 + $square::SIZE['files'] - 1; $i++) { $this->mobility[3][] = chr($i) . $this->rank(); } } diff --git a/src/Variant/Losing/Piece/M.php b/src/Variant/Losing/Piece/M.php index 36bff12e3..ede2aae17 100644 --- a/src/Variant/Losing/Piece/M.php +++ b/src/Variant/Losing/Piece/M.php @@ -11,14 +11,14 @@ class M extends AbstractPiece { public function __construct(string $color, string $sq, Square $square) { - parent::__construct($color, $sq, $square, Piece::M); + parent::__construct($color, $sq, Piece::M); $this->mobility = []; try { $file = $this->sq[0]; $rank = $this->rank() + 1; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -27,7 +27,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = $this->sq[0]; $rank = $this->rank() - 1; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -36,7 +36,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->sq[0]) - 1); $rank = $this->rank(); - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -45,7 +45,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->sq[0]) + 1); $rank = $this->rank(); - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -54,7 +54,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->sq[0]) - 1); $rank = $this->rank() + 1; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -63,7 +63,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->sq[0]) + 1); $rank = $this->rank() + 1; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -72,7 +72,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->sq[0]) - 1); $rank = $this->rank() - 1; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) { @@ -81,7 +81,7 @@ public function __construct(string $color, string $sq, Square $square) try { $file = chr(ord($this->sq[0]) + 1); $rank = $this->rank() - 1; - if ($this->square->validate($file . $rank)) { + if ($square->validate($file . $rank)) { $this->mobility[] = $file . $rank; } } catch (UnknownNotationException $e) {