Skip to content

Commit

Permalink
Refactored updateCastle()
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Jan 28, 2025
1 parent ec2255f commit 22830cc
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Variant/AbstractPiece.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,21 +439,20 @@ public function capture(): void
*/
public function updateCastle(): AbstractPiece
{
$search = '';
if ($this->id === Piece::K) {
$search = $this->board->turn === Color::W ? 'KQ' : 'kq';
$this->board->castlingAbility = str_replace($search, '', $this->board->castlingAbility)
?: CastlingRule::NEITHER;
} elseif ($this->id === Piece::R) {
if ($this->type === RType::CASTLE_SHORT) {
$search = $this->board->turn === Color::W ? 'K' : 'k';
$this->board->castlingAbility = str_replace($search, '', $this->board->castlingAbility)
?: CastlingRule::NEITHER;
} elseif ($this->type === RType::CASTLE_LONG) {
$search = $this->board->turn === Color::W ? 'Q' : 'q';
$this->board->castlingAbility = str_replace($search, '', $this->board->castlingAbility)
?: CastlingRule::NEITHER;
}
}
if ($search) {
$this->board->castlingAbility = str_replace($search, '', $this->board->castlingAbility)
?: CastlingRule::NEITHER;
}

return $this;
}
Expand Down

0 comments on commit 22830cc

Please sign in to comment.