예제 #1
0
 /**
  * @param MoveInterface $move
  * @param GameInterface $game
  *
  * @throws InvalidMoveException
  */
 private static function validate(MoveInterface $move, GameInterface $game)
 {
     if ($game->hasFinished()) {
         throw new InvalidMoveException('Game has already finished');
     }
     if (null === ($piece = $move->getPiece())) {
         if (null === ($piece = $game->getBoard()->getSquare($move->getFrom())->getPiece())) {
             var_export($game->getBoard()->getSquaresAsString());
             throw new InvalidMoveException(sprintf('There must be a piece to move on that position: %s', $move->getFromLabel()));
         }
     }
     if ($game->getCurrentColor() !== $piece->getColor()) {
         throw new InvalidMoveException(sprintf('You can only move your own pieces: the %s on %s belongs to %s', $piece->getTypeLabel(), $move->getFromLabel(), $game->getOpposingPlayer()->getColor()));
     }
 }