Exemplo n.º 1
0
 /**
  * Handle pawn promotion
  **/
 protected function promotion(Pawn $pawn, $promotionClass)
 {
     $player = $pawn->getPlayer();
     $this->board->remove($pawn);
     $player->removePiece($pawn);
     $fullClass = 'Bundle\\LichessBundle\\Document\\Piece\\' . $promotionClass;
     $new = new $fullClass($pawn->getX(), $pawn->getY());
     $new->setBoard($player->getGame()->getBoard());
     $player->addPiece($new);
     $this->board->add($new);
     $this->stack->addEvent(array('type' => 'promotion', 'pieceClass' => strtolower($promotionClass), 'key' => $new->getSquareKey()));
 }
Exemplo n.º 2
0
 /**
  * Handle pawn promotion
  **/
 protected function promotion(Pawn $pawn, array $options)
 {
     $promotionClass = isset($options['promotion']) ? ucfirst($options['promotion']) : 'Queen';
     if (!in_array($promotionClass, array('Queen', 'Knight', 'Bishop', 'Rook'))) {
         throw new \InvalidArgumentException('Bad promotion class: ' . $promotionClass);
     }
     $player = $pawn->getPlayer();
     $this->board->remove($pawn);
     $player->removePiece($pawn);
     $fullClass = 'Bundle\\LichessBundle\\Entities\\Piece\\' . $promotionClass;
     $new = new $fullClass($pawn->getX(), $pawn->getY());
     $new->setPlayer($player);
     $new->setBoard($player->getGame()->getBoard());
     $player->addPiece($new);
     $this->board->add($new);
     if ($this->stack) {
         $this->stack->add(array('type' => 'promotion', 'pieceClass' => strtolower($promotionClass), 'key' => $new->getSquareKey()));
     }
 }