Exemplo n.º 1
0
 /**
  * Handle pawn enpassant
  **/
 protected function enpassant(Pawn $pawn, Square $to)
 {
     $passedSquare = $to->getSquareByRelativePos(0, $pawn->getPlayer()->isWhite() ? -1 : 1);
     $killed = $passedSquare->getPiece();
     if (!$killed || $killed->getPlayer() === $pawn->getPlayer()) {
         throw new \LogicException(sprintf('Manipulator:move game:%s, Can not enpassant to ' . $to, $this->game->getId()));
     }
     $killed->setIsDead(true);
     $this->board->remove($killed);
     $this->stack->addEvent(array('type' => 'enpassant', 'killed' => $passedSquare->getKey()));
 }
Exemplo n.º 2
0
 /**
  * Handle castling
  **/
 protected function castling(King $king, Square $to)
 {
     if (7 === $to->getX()) {
         $rookSquare = $to->getSquareByRelativePos(1, 0);
         $newRookSquare = $to->getSquareByRelativePos(-1, 0);
     } else {
         $rookSquare = $to->getSquareByRelativePos(-2, 0);
         $newRookSquare = $to->getSquareByRelativePos(1, 0);
     }
     $rook = $rookSquare->getPiece();
     $this->board->move($rook, $newRookSquare->getX(), $newRookSquare->getY());
     $rook->setFirstMove($this->game->getTurns());
     if ($this->stack) {
         $this->stack->add(array('type' => 'castling', 'from' => $rookSquare->getKey(), 'to' => $newRookSquare->getKey()));
     }
 }