Exemple #1
0
        private static void GetEnPassantPositions(ref List <ChessBoard> result, ChessBoard board, Square currentposition)
        {
            ChessBoard tempboard      = board.ShallowCopy();
            bool       CheckEnPassant = DefaultInfo.EnPassantPossibleCapture.rank == currentposition.rank - 1 && (DefaultInfo.EnPassantPossibleCapture.file == (char)(currentposition.file + 1) || DefaultInfo.EnPassantPossibleCapture.file == (char)(currentposition.file - 1));

            if (CheckEnPassant)
            {
                tempboard = Piece.PerformMove(board, currentposition, DefaultInfo.EnPassantPossibleCapture);
                tempboard[DefaultInfo.EnPassantPossibleCapture.file, DefaultInfo.EnPassantPossibleCapture.rank + 1] = 0;
                result = Piece.AddNewPosition(result, tempboard, false);
            }
        }
Exemple #2
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);
                }
            }
        }
Exemple #3
0
        private static void GetKingCastlingPosition(ChessBoard board, char file, sbyte rank, List <ChessBoard> result, Square current)
        {
            ChessBoard tempboard;

            if (WhiteKing.IsSafe(board) && DefaultInfo.WhiteKingIsUnMoved && DefaultInfo.WhiteHsideRookIsUnMoved)
            {
                char rookfile = 'h';
                for (char tfile = file; tfile < 'h'; tfile++)
                {
                    if (board[tfile, rank] == (sbyte)DefaultPieces.WhiteRook)
                    {
                        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.WhiteKing && board[tfile, rank] != (sbyte)DefaultPieces.WhiteRook)
                    {
                        CastlingAvailable = false;
                        break;
                    }
                }
                for (char tfile = rookfile; tfile >= 'f'; tfile--)
                {
                    if (board[tfile, rank] != 0 && board[tfile, rank] != (sbyte)DefaultPieces.WhiteKing && board[tfile, rank] != (sbyte)DefaultPieces.WhiteRook)
                    {
                        CastlingAvailable = false;
                        break;
                    }
                }
                for (char tfile = rookfile; tfile <= 'f'; tfile++)
                {
                    if (board[tfile, rank] != 0 && board[tfile, rank] != (sbyte)DefaultPieces.WhiteKing && board[tfile, rank] != (sbyte)DefaultPieces.WhiteRook)
                    {
                        CastlingAvailable = false;
                        break;
                    }
                }
                for (char tfile = file; tfile <= 'g'; tfile++)
                {
                    ChessBoard temp2board = board.ShallowCopy();
                    temp2board[file, rank]  = 0;
                    temp2board[tfile, rank] = (sbyte)DefaultPieces.WhiteKing;
                    if (!WhiteKing.IsSafe(temp2board))
                    {
                        CastlingAvailable = false;
                        break;
                    }
                }
                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);
                }
            }
        }
Exemple #4
0
        public static List <Square> GetPossibleWhiteAttackersToSquare(ChessBoard board, Square goalsquare)
        {
            ChessBoard tempboard = board.ShallowCopy();

            tempboard.DebugConsoleSimpleDraw();
            Console.WriteLine();
            tempboard.ReverseSides();
            //tempboard.DebugConsoleSimpleDraw();
            Square tempsquare = new Square(goalsquare.file, goalsquare.rank);

            tempsquare.Reverse();
            var result = WhitePiece.GetPossibleBlackAttackersToSquare(tempboard, tempsquare);

            for (int i = 0; i < result.Count; i++)
            {
                Square temp = result[i];
                temp.Reverse();
                result[i] = temp;
            }
            return(result);
        }
Exemple #5
0
        private static void GetDiagonalBlackAttackers(ChessBoard board, List <Square> result, Square current, int multfile, int multrank)
        {
            char file = current.file;
            int  rank = current.rank;

            for (int i = 1; i < 8; i++)
            {
                Square tempsquare = new Square((char)(file + multfile * i), rank + multrank * i);
                if (!tempsquare.IsOK())
                {
                    break;
                }
                else if (board[tempsquare] > 0)
                {
                    break;
                }
                else if (board[tempsquare] < 0 && board[tempsquare] != (sbyte)DefaultPieces.BlackBishop && board[tempsquare] != (sbyte)DefaultPieces.BlackQueen)
                {
                    break;
                }
                else if (board[tempsquare] == (sbyte)DefaultPieces.BlackBishop || board[tempsquare] == (sbyte)DefaultPieces.BlackQueen)
                {
                    result.Add(new Square((char)(file + multfile * i), rank + multrank * i));
                    break;
                }
            }
        }
Exemple #6
0
        public static List <Square> GetPossibleBlackAttackersToSquare(ChessBoard board, Square goalsquare)
        {
            List <Square> result = new List <Square>();
            char          file = goalsquare.file; int rank = goalsquare.rank;

            //check for Pawn
            if (file >= 'a' && file <= 'g' && rank <= 7 && board[(char)(file + 1), rank + 1] == (sbyte)DefaultPieces.BlackPawn)
            {
                result.Add(new Square((char)(file + 1), rank + 1));
            }
            if (file >= 'b' && file <= 'h' && rank <= 7 && board[(char)(file - 1), rank + 1] == (sbyte)DefaultPieces.BlackPawn)
            {
                result.Add(new Square((char)(file - 1), rank + 1));
            }
            Square[] moves_array = Piece.GetSimplekNightMoveDestinations(goalsquare);
            foreach (Square move in moves_array)
            {
                if (move.IsOK() && board[move] == (sbyte)DefaultPieces.BlackkNight)
                {
                    result.Add(move);
                }
            }
            GetVerticalUpBlackAttackers(board, result, file, rank);
            GetVerticalDownBlackAttackers(board, result, file, rank);
            GetHorizontalRightBlackAttacker(board, result, file, rank);
            GetHorizontalLeftBlackAttackers(board, result, file, rank);
            GetDiagonalBlackAttackers(board, result, goalsquare, 1, 1);
            GetDiagonalBlackAttackers(board, result, goalsquare, 1, -1);
            GetDiagonalBlackAttackers(board, result, goalsquare, -1, 1);
            GetDiagonalBlackAttackers(board, result, goalsquare, -1, -1);
            Square[] moves = Piece.GetSimpleKingMoveDestinations(goalsquare);
            foreach (Square move in moves)
            {
                if (move.IsOK() && board[move] == (sbyte)DefaultPieces.BlackKing)
                {
                    result.Add(move); break;
                }
            }
            return(result);
        }
Exemple #7
0
 public static void GetHorizontalRightDestinations(ChessBoard board, List <Square> moves, Square current)
 {
     for (char tchar = (char)(current.file + 1); tchar <= 'h'; tchar++)
     {
         if (board[tchar, current.rank] > 0)
         {
             break;
         }
         else
         {
             if (board[tchar, current.rank] < 0)
             {
                 moves.Add(new Square(tchar, current.rank));
                 break;
             }
             else
             {
                 moves.Add(new Square(tchar, current.rank));
             }
         }
     }
 }
Exemple #8
0
 public static void GetVerticalDownDestinations(ChessBoard board, List <Square> moves, Square current)
 {
     for (int i = current.rank - 1; i >= 1; i--)
     {
         if (board[current.file, i] > 0)
         {
             break;
         }
         else
         {
             if (board[current.file, i] < 0)
             {
                 moves.Add(new Square(current.file, i));
                 break;
             }
             else
             {
                 moves.Add(new Square(current.file, i));
             }
         }
     }
 }
Exemple #9
0
        public static void GetDiagonalDestinations(ChessBoard board, ref List <Square> moves, Square current, int multfile, int multrank)
        {
            char file = current.file;
            int  rank = current.rank;

            for (int i = 1; i < 8; i++)
            {
                Square tempsquare = new Square((char)(file + multfile * i), rank + multrank * i);
                if (!tempsquare.IsOK())
                {
                    break;
                }
                else if (board[tempsquare] > 0)
                {
                    break;
                }
                else if (board[tempsquare] < 0)
                {
                    moves.Add(tempsquare);
                    break;
                }
                else
                {
                    moves.Add(tempsquare);
                }
            }
        }