Пример #1
0
        internal bool IsThreatened(Piece piece)
        {
            Position position = piece.Position;
            int      row      = position.Row;
            int      col      = position.Col;

            while (row > 0 && col > 0 && Board.GetPiece(row - 1, col - 1) is Empty)
            {
                row--;
                col--;
            }

            if (row > 0 && col > 0 && IsThreat(piece, Board.GetPiece(row - 1, col - 1)))
            {
                return(true);
            }

            row = position.Row;
            col = position.Col;

            while (row > 0 && col < 7 && Board.GetPiece(row - 1, col + 1) is Empty)
            {
                row--;
                col++;
            }

            if (row > 0 && col < 7 && IsThreat(piece, Board.GetPiece(row - 1, col + 1)))
            {
                return(true);
            }

            row = position.Row;
            col = position.Col;

            while (row < 7 && col > 0 && Board.GetPiece(row + 1, col - 1) is Empty)
            {
                row++;
                col--;
            }

            if (row < 7 && col > 0 && IsThreat(piece, Board.GetPiece(row + 1, col - 1)))
            {
                return(true);
            }

            row = position.Row;
            col = position.Col;

            while (row < 7 && col < 7 && Board.GetPiece(row + 1, col + 1) is Empty)
            {
                row++;
                col++;
            }

            if (row < 7 && col < 7 && IsThreat(piece, Board.GetPiece(row + 1, col + 1)))
            {
                return(true);
            }

            row = position.Row;
            col = position.Col;

            while (col > 0 && Board.GetPiece(row, col - 1) is Empty)
            {
                col--;
            }

            if (col > 0 && IsThreat(piece, Board.GetPiece(row, col - 1)))
            {
                return(true);
            }

            col = position.Col;

            while (col < 7 && Board.GetPiece(row, col + 1) is Empty)
            {
                col++;
            }

            if (col < 7 && IsThreat(piece, Board.GetPiece(row, col + 1)))
            {
                return(true);
            }

            col = position.Col;

            while (row > 0 && Board.GetPiece(row - 1, col) is Empty)
            {
                row--;
            }

            if (row > 0 && IsThreat(piece, Board.GetPiece(row - 1, col)))
            {
                return(true);
            }

            row = position.Row;

            while (row < 7 && Board.GetPiece(row + 1, col) is Empty)
            {
                row++;
            }

            if (row < 7 && IsThreat(piece, Board.GetPiece(row + 1, col)))
            {
                return(true);
            }

            row = position.Row;

            if (row + 2 <= 7 && col - 1 >= 0 && IsThreat(piece, Board.GetPiece(row + 2, col - 1)))
            {
                return(true);
            }

            if (row + 2 <= 7 && col + 1 <= 7 && IsThreat(piece, Board.GetPiece(row + 2, col + 1)))
            {
                return(true);
            }

            if (row - 2 >= 0 && col - 1 >= 0 && IsThreat(piece, Board.GetPiece(row - 2, col - 1)))
            {
                return(true);
            }

            if (row - 2 >= 0 && col + 1 <= 7 && IsThreat(piece, Board.GetPiece(row - 2, col + 1)))
            {
                return(true);
            }

            if (row + 1 <= 7 && col - 2 >= 0 && IsThreat(piece, Board.GetPiece(row + 1, col - 2)))
            {
                return(true);
            }

            if (row + 1 <= 7 && col + 2 <= 7 && IsThreat(piece, Board.GetPiece(row + 1, col + 2)))
            {
                return(true);
            }

            if (row - 1 >= 0 && col - 2 >= 0 && IsThreat(piece, Board.GetPiece(row - 1, col - 2)))
            {
                return(true);
            }

            if (row - 1 >= 0 && col + 2 <= 7 && IsThreat(piece, Board.GetPiece(row - 1, col + 2)))
            {
                return(true);
            }

            return(false);
        }
Пример #2
0
        internal string PrintBoard()
        {
            string boardString = "  A  B  C  D  E  F  G  H\n";

            for (int i = 0; i < 8; i++)
            {
                boardString += 8 - i + " ";

                for (int j = 0; j < 8; j++)
                {
                    switch (Board.GetPiece(i, j).Enum)
                    {
                    case PieceEnum.BlackBishop:
                        boardString += "BB ";
                        break;

                    case PieceEnum.BlackKing:
                        boardString += "BK ";
                        break;

                    case PieceEnum.BlackKingNoCastle:
                        boardString += "BK ";
                        break;

                    case PieceEnum.BlackKnight:
                        boardString += "BN ";
                        break;

                    case PieceEnum.BlackPawn:
                        boardString += "BP ";
                        break;

                    case PieceEnum.BlackPawnEnPassant:
                        boardString += "BP ";
                        break;

                    case PieceEnum.BlackQueen:
                        boardString += "BQ ";
                        break;

                    case PieceEnum.BlackRook:
                        boardString += "BR ";
                        break;

                    case PieceEnum.WhiteBishop:
                        boardString += "WB ";
                        break;

                    case PieceEnum.WhiteKing:
                        boardString += "WK ";
                        break;

                    case PieceEnum.WhiteKingNoCastle:
                        boardString += "WK ";
                        break;

                    case PieceEnum.WhiteKnight:
                        boardString += "WN ";
                        break;

                    case PieceEnum.WhitePawn:
                        boardString += "WP ";
                        break;

                    case PieceEnum.WhitePawnEnPassant:
                        boardString += "WP ";
                        break;

                    case PieceEnum.WhiteQueen:
                        boardString += "WQ ";
                        break;

                    case PieceEnum.WhiteRook:
                        boardString += "WR ";
                        break;

                    default:
                        boardString += "   ";
                        break;
                    }
                }

                boardString += " " + (8 - i) + "\n";
            }

            boardString += "  A  B  C  D  E  F  G  H";

            return(boardString);
        }