예제 #1
0
        private static void GetKingCastlingPosition(ChessBoard board, char file, sbyte rank, List <ChessBoard> result, Square current)
        {
            ChessBoard tempboard;

            if (BlackKing.IsSafe(board) && DefaultInfo.BlackKingIsUnMoved && DefaultInfo.BlackHsideRookIsUnMoved)
            {
                char rookfile = 'h';
                for (char tfile = file; tfile < 'h'; tfile++)
                {
                    if (board[tfile, rank] == (sbyte)DefaultPieces.BlackRook)
                    {
                        rookfile = tfile;
                    }
                }
                tempboard = board.ShallowCopy();
                bool CastlingAvailable = true;

                for (char tfile = file; tfile <= 'g'; 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 >= 'f'; 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 <= 'f'; 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 <= 'g'; tfile++)
                {
                    ChessBoard temp2board = board.ShallowCopy();
                    temp2board[file, rank]  = 0;
                    temp2board[tfile, rank] = (sbyte)DefaultPieces.BlackKing;
                    if (!BlackKing.IsSafe(temp2board))
                    {
                        CastlingAvailable = false;
                        return;
                    }
                }
                if (CastlingAvailable)
                {
                    tempboard = Piece.PerformMove(board, current, new Square('g', rank));
                    tempboard = Piece.PerformMove(tempboard, new Square(rookfile, rank), new Square('f', rank));
                    result.Add(tempboard);
                }
            }
        }
예제 #2
0
 // Code Review: Назваргументів методу повинні починатися з малої літери.
 public static List <ChessBoard> AddNewPosition(List <ChessBoard> ResultedPositionsList, ChessBoard position, bool IsWhite)
 {
     if (IsWhite && WhiteKing.IsSafe(position))
     {
         ResultedPositionsList.Add(position);
     }
     else if (!IsWhite && BlackKing.IsSafe(position))
     {
         ResultedPositionsList.Add(position);
     }
     return(ResultedPositionsList);
 }
        private static ChessBoard PerformBlackKingCastling(ChessBoard board, ref ChessBoard tempboard)
        {
            char kingfile;

            tempboard = PerformCastling(board, false, true, out kingfile);
            if (BlackKing.GetPossiblePositions(board, kingfile, 8).Contains(tempboard))
            {
                DefaultInfo.BlackKingIsUnMoved      = false;
                DefaultInfo.BlackHsideRookIsUnMoved = false;
                return(tempboard);
            }
            else
            {
                throw new ArgumentException("Wrong move");
            }
        }