Esempio n. 1
0
        private static void GetQueenCastlingPosition(ChessBoard board, char file, sbyte rank, List <ChessBoard> result, Square current)
        {
            ChessBoard tempboard;

            if (BlackKing.IsSafe(board) && DefaultInfo.BlackKingIsUnMoved && DefaultInfo.BlackAsideRookIsUnMoved)
            {
                char rookfile = 'a';
                for (char tfile = file; tfile > 'a'; tfile--)
                {
                    if (board[tfile, rank] == (sbyte)DefaultPieces.BlackRook)
                    {
                        rookfile = tfile;
                    }
                }
                tempboard = board.ShallowCopy();
                bool CastlingAvailable = true;
                for (char tfile = file; tfile >= 'c'; tfile--)
                {
                    if (board[tfile, rank] != 0 && board[tfile, rank] != (sbyte)DefaultPieces.BlackKing && board[tfile, rank] != (sbyte)DefaultPieces.BlackRook)
                    {
                        CastlingAvailable = false;
                        return;
                    }
                }
                for (char tfile = rookfile; tfile <= 'd'; tfile++)
                {
                    if (board[tfile, rank] != 0 && board[tfile, rank] != (sbyte)DefaultPieces.BlackKing && board[tfile, rank] != (sbyte)DefaultPieces.BlackRook)
                    {
                        CastlingAvailable = false;
                        return;
                    }
                }
                for (char tfile = rookfile; tfile >= 'd'; tfile--)
                {
                    if (board[tfile, rank] != 0 && board[tfile, rank] != (sbyte)DefaultPieces.BlackKing && board[tfile, rank] != (sbyte)DefaultPieces.BlackRook)
                    {
                        CastlingAvailable = false;
                        return;
                    }
                }
                for (char tfile = file; tfile >= 'c'; tfile--)
                {
                    ChessBoard temp2board = Piece.PerformMove(board, current, new Square(tfile, rank));
                    if (!BlackKing.IsSafe(temp2board))
                    {
                        CastlingAvailable = false;
                        return;
                    }
                }
                if (file == 'b')
                {
                    ChessBoard temp2board = Piece.PerformMove(board, current, new Square('c', rank));
                    if (!BlackKing.IsSafe(temp2board))
                    {
                        CastlingAvailable = false;
                    }
                }
                if (CastlingAvailable)
                {
                    tempboard = Piece.PerformMove(board, current, new Square('c', rank));
                    tempboard = Piece.PerformMove(tempboard, new Square(rookfile, rank), new Square('d', rank));
                    result.Add(tempboard);
                }
            }
        }