Exemple #1
0
 /**
  * Handle castling
  **/
 protected function castle(King $king, Square $to)
 {
     $isKingSide = $this->isCastleKingSide($king, $to);
     $y = $king->getY();
     if ($isKingSide) {
         $rook = $this->analyser->getCastleRookKingSide($king->getPlayer());
         $newRookSquare = $this->board->getSquareByPos(6, $y);
         $newKingSquare = $this->board->getSquareByPos(7, $y);
     } else {
         $rook = $this->analyser->getCastleRookQueenSide($king->getPlayer());
         $newRookSquare = $this->board->getSquareByPos(4, $y);
         $newKingSquare = $this->board->getSquareByPos(3, $y);
     }
     if (!$rook) {
         throw new \LogicException(sprintf('No rook for castle on %s side, king %s to %s', $isKingSide ? 'King' : 'Queen', $king->getSquareKey(), $to->getKey()));
     }
     $kingSquare = $king->getSquare();
     $rookSquare = $rook->getSquare();
     $this->board->castle($king, $rook, $newKingSquare->getX(), $newRookSquare->getX());
     $king->setFirstMove($this->game->getTurns());
     $rook->setFirstMove($this->game->getTurns());
     $this->stack->addEvent(array('type' => 'castling', 'king' => array($kingSquare->getKey(), $newKingSquare->getKey()), 'rook' => array($rookSquare->getKey(), $newRookSquare->getKey()), 'color' => $king->getColor()));
 }