Esempio n. 1
0
        private static List <BoardPosition> CheckCastling(BoardPosition bp, ChessBoard aBoard)
        {
            List <BoardPosition> boardPositionList = new List <BoardPosition>();

            boardPositionList.Add(bp);
            Piece p = aBoard.GetBoard()[bp.X, bp.Y].GetPiece();


            int i = bp.X;
            int j = bp.Y;

            if (p.GetColor() == Piece.Color.WHITE)
            {
                if (!p.GetHasMoved())
                {
                    if (aBoard.GetBoard()[0, 7].GetPiece() != null)
                    {
                        if (aBoard.GetBoard()[0, 7].GetPiece().GetPieceType() == Piece.PieceType.ROOK)
                        {
                            if (!aBoard.GetBoard()[0, 7].GetPiece().GetHasMoved())
                            {
                                if (!aBoard.GetBoard()[1, 7].HasPiece() &&
                                    !aBoard.GetBoard()[2, 7].HasPiece() &&
                                    !aBoard.GetBoard()[3, 7].HasPiece())
                                {
                                    if (!SquareIsThreatened(aBoard.GetBoard()[4, 7].GetPiece(), new BoardPosition(0, 7), aBoard) &&
                                        !SquareIsThreatened(aBoard.GetBoard()[4, 7].GetPiece(), new BoardPosition(1, 7), aBoard) &&
                                        !SquareIsThreatened(aBoard.GetBoard()[4, 7].GetPiece(), new BoardPosition(2, 7), aBoard) &&
                                        !SquareIsThreatened(aBoard.GetBoard()[4, 7].GetPiece(), new BoardPosition(3, 7), aBoard) &&
                                        !SquareIsThreatened(aBoard.GetBoard()[4, 7].GetPiece(), new BoardPosition(5, 7), aBoard))
                                    {
                                        boardPositionList.Add(new BoardPosition(2, 7));
                                    }
                                }
                            }
                        }
                    }
                    if (aBoard.GetBoard()[7, 7].GetPiece() != null)
                    {
                        if (aBoard.GetBoard()[7, 7].GetPiece().GetPieceType() == Piece.PieceType.ROOK)
                        {
                            if (!aBoard.GetBoard()[7, 7].GetPiece().GetHasMoved())
                            {
                                if (!aBoard.GetBoard()[6, 7].HasPiece() &&
                                    !aBoard.GetBoard()[5, 7].HasPiece())
                                {
                                    if (!SquareIsThreatened(aBoard.GetBoard()[4, 7].GetPiece(), new BoardPosition(4, 7), aBoard) &&
                                        !SquareIsThreatened(aBoard.GetBoard()[4, 7].GetPiece(), new BoardPosition(5, 7), aBoard) &&
                                        !SquareIsThreatened(aBoard.GetBoard()[4, 7].GetPiece(), new BoardPosition(6, 7), aBoard) &&
                                        !SquareIsThreatened(aBoard.GetBoard()[4, 7].GetPiece(), new BoardPosition(7, 7), aBoard))
                                    {
                                        boardPositionList.Add(new BoardPosition(6, 7));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (p.GetColor() == Piece.Color.BLACK)
            {
                if (!p.GetHasMoved())
                {
                    if (aBoard.GetBoard()[0, 0].GetPiece() != null)
                    {
                        if (aBoard.GetBoard()[0, 0].GetPiece().GetPieceType() == Piece.PieceType.ROOK)
                        {
                            if (!aBoard.GetBoard()[0, 0].GetPiece().GetHasMoved())
                            {
                                if (!aBoard.GetBoard()[1, 0].HasPiece() &&
                                    !aBoard.GetBoard()[2, 0].HasPiece() &&
                                    !aBoard.GetBoard()[3, 0].HasPiece())
                                {
                                    if (!SquareIsThreatened(aBoard.GetBoard()[4, 0].GetPiece(), new BoardPosition(1, 0), aBoard) &&
                                        !SquareIsThreatened(aBoard.GetBoard()[4, 0].GetPiece(), new BoardPosition(2, 0), aBoard) &&
                                        !SquareIsThreatened(aBoard.GetBoard()[4, 0].GetPiece(), new BoardPosition(3, 0), aBoard))
                                    {
                                        boardPositionList.Add(new BoardPosition(2, 0));
                                    }
                                }
                            }
                        }
                    }
                    if (aBoard.GetBoard()[7, 0].GetPiece() != null)
                    {
                        if (aBoard.GetBoard()[7, 0].GetPiece().GetPieceType() == Piece.PieceType.ROOK)
                        {
                            if (!aBoard.GetBoard()[7, 0].GetPiece().GetHasMoved())
                            {
                                if (!aBoard.GetBoard()[6, 0].HasPiece() &&
                                    !aBoard.GetBoard()[5, 0].HasPiece())
                                {
                                    if (!SquareIsThreatened(aBoard.GetBoard()[4, 7].GetPiece(), new BoardPosition(5, 0), aBoard) &&
                                        !SquareIsThreatened(aBoard.GetBoard()[4, 7].GetPiece(), new BoardPosition(6, 0), aBoard))
                                    {
                                        boardPositionList.Add(new BoardPosition(6, 0));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(boardPositionList);
        }