Exemplo n.º 1
0
        private static Bitboard[] InitializeKnightAttacks()
        {
            var result = new Bitboard[ChessConstants.SquareCount];

            for (var squareIndex = 0; squareIndex < ChessConstants.SquareCount; squareIndex++)
            {
                var square      = new Square(squareIndex);
                var moveSquares = ChessHelper.GetKnightMoveSquares(square);
                var bitboard    = new Bitboard(moveSquares);
                result[squareIndex] = bitboard;
            }

            return(result);
        }
Exemplo n.º 2
0
        public Square[] GetPotentialMoveSquares(
            CastlingOptions castlingOptions,
            [CanBeNull] EnPassantCaptureInfo enPassantCaptureInfo,
            Square sourceSquare)
        {
            var piece     = PiecePosition[sourceSquare];
            var pieceType = piece.GetPieceType();

            if (pieceType == PieceType.None)
            {
                throw new ArgumentException(
                          $@"No piece at the source square '{sourceSquare}'.",
                          nameof(sourceSquare));
            }

            var pieceSide = piece.GetSide().EnsureNotNull();

            switch (pieceType)
            {
            case PieceType.Knight:
                //// TODO [HarinezumiSama] Use bitboard instead of squares
                var result = ChessHelper.GetKnightMoveSquares(sourceSquare)
                             .Where(square => PiecePosition[square].GetSide() != pieceSide)
                             .ToArray();

                return(result);

            case PieceType.King:
            case PieceType.Pawn:
                throw new InvalidOperationException("MUST NOT go into this branch anymore.");

            case PieceType.None:
                throw new ArgumentException(
                          $@"No piece at the source square '{sourceSquare}'.",
                          nameof(sourceSquare));

            case PieceType.Bishop:
            case PieceType.Rook:
            case PieceType.Queen:
                // Just go ahead
                break;

            default:
                throw pieceType.CreateEnumValueNotImplementedException();
            }

            var resultList = new List <Square>();

            if (pieceType.IsSlidingStraight())
            {
                GetPotentialMoveSquaresByRays(
                    sourceSquare,
                    pieceSide,
                    ChessHelper.StraightRays,
                    ChessHelper.MaxSlidingPieceDistance,
                    true,
                    resultList);
            }

            if (pieceType.IsSlidingDiagonally())
            {
                GetPotentialMoveSquaresByRays(
                    sourceSquare,
                    pieceSide,
                    ChessHelper.DiagonalRays,
                    ChessHelper.MaxSlidingPieceDistance,
                    true,
                    resultList);
            }

            return(resultList.ToArray());
        }