/** * {@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; }
/** * @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(); }