예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function possibleCapturesBy($color, BoardInterface $board)
 {
     $moves = [];
     $criteria = ['piece_color' => $color];
     foreach ($board->getSquaresBy($criteria) as $square) {
         $moves = array_merge($moves, $this->possibleCapturesFrom($square->getPosition(), $board));
     }
     return $moves;
 }
예제 #2
0
 /**
  * @param BoardInterface $board
  * @param int            $color
  *
  * @return int
  */
 public static function getKingPosition(BoardInterface $board, $color)
 {
     $kingSquares = $board->getSquaresBy(['piece_type' => PieceInterface::TYPE_KING, 'piece_color' => $color]);
     if (count($kingSquares) !== 1) {
         throw new \RuntimeException(sprintf('There should always be one king of a given color on the board, found %d', count($kingSquares)));
     }
     return reset($kingSquares)->getPosition();
 }