internal CastlingInfo2(
            CastlingType castlingType,
            GameMove2 kingMove,
            GameMove2 rookMove,
            [NotNull] params Square[] emptySquares)
        {
            castlingType.EnsureDefined();

            if (emptySquares is null)
            {
                throw new ArgumentNullException(nameof(emptySquares));
            }

            if (kingMove.From.Rank != kingMove.To.Rank ||
                Math.Abs(kingMove.From.SquareIndex - kingMove.To.SquareIndex) != 2)
            {
                throw new ArgumentException(
                          $@"Invalid castling move '{kingMove.ToUciNotation()}'.",
                          nameof(kingMove));
            }

            CastlingType = castlingType;
            CastlingSide = castlingType.GetSide();
            Option       = castlingType.ToOption();
            KingMove     = kingMove;
            RookMove     = rookMove;
            EmptySquares = emptySquares.AsReadOnly();
            PassedSquare = new Square((kingMove.From.SquareIndex + kingMove.To.SquareIndex) / 2);
            GameSide     = Option.IsAnySet(CastlingOptions.WhiteMask) ? GameSide.White : GameSide.Black;
        }
Exemple #2
0
        private static void PopulateKingCastlingMoves(
            ICollection <GameMoveData2> resultMoves,
            Square sourceSquare,
            Bitboard target,
            CastlingOptions allowedCastlingOptions,
            Bitboard nonEmptySquares,
            CastlingType castlingType)
        {
            var option = castlingType.ToOption();

            if ((allowedCastlingOptions & option) == 0)
            {
                return;
            }

            var info = KingCastlingInfos[GetCastlingTypeArrayIndexInternal(castlingType)];

            if (info.KingMove.From != sourceSquare || (info.ExpectedEmptySquares & nonEmptySquares).IsAny ||
                (info.KingMove.To.Bitboard & target).IsNone)
            {
                return;
            }

            var moveData = new GameMoveData2(info.KingMove, GameMoveFlags.IsKingCastling);

            resultMoves.Add(moveData);
        }