Exemple #1
0
        public virtual List <Vector2D> GetPossibleMoves()
        {
            List <Vector2D> possibleMoves = new List <Vector2D>();

            for (int y = 0; y < ChessBoard.Height; y++)
            {
                for (int x = 0; x < ChessBoard.Width; x++)
                {
                    Vector2D   currentCheck = new Vector2D(x, y);
                    ChessPiece pieceAtCheck = ChessGame.ChessBoard.Board[currentCheck.Y, currentCheck.X];

                    //if (currentCheck.ToCoordinate() == "g1") Debugger.Break();

                    bool isPieceKing       = (pieceAtCheck != null && pieceAtCheck.GetType() == typeof(King));
                    bool isValidMove       = IsValidMove(currentCheck);
                    bool pathNotObstructed = MovementValidation.IsPathNotObstructed(BoardPosition, currentCheck);
                    bool pieceIsValid      = (pieceAtCheck == null || (pieceAtCheck != null && PieceType != pieceAtCheck.PieceType));

                    if (isValidMove && pathNotObstructed && pieceIsValid && !isPieceKing)
                    {
                        possibleMoves.Add(currentCheck);
                    }
                }
            }

            return(possibleMoves);
        }
Exemple #2
0
        public override bool IsValidMove(Vector2D toPosition)
        {
            bool validBishop       = MovementValidation.IsValidBishopMovement(BoardPosition, toPosition);
            bool pathNotObstructed = MovementValidation.IsPathNotObstructed(BoardPosition, toPosition);

            return(validBishop && pathNotObstructed);
        }
Exemple #3
0
        public override bool IsValidMove(Vector2D toPosition)
        {
            bool isValidRook = MovementValidation.IsValidRookMovement(BoardPosition, toPosition);
            //if (toPosition.ToCoordinate() == "g1") Debugger.Break();
            bool isNotObstructed = MovementValidation.IsPathNotObstructed(BoardPosition, toPosition);

            return(isValidRook && isNotObstructed);
        }
Exemple #4
0
        public override bool IsValidMove(Vector2D toPosition)
        {
            bool isValidRook     = MovementValidation.IsValidRookMovement(BoardPosition, toPosition);
            bool isValidBishop   = MovementValidation.IsValidBishopMovement(BoardPosition, toPosition);
            bool isNotObstructed = MovementValidation.IsPathNotObstructed(BoardPosition, toPosition);

            return((isValidRook || isValidBishop) && isNotObstructed);
        }
Exemple #5
0
        public override List <Vector2D> GetPossibleMoves()
        {
            List <Vector2D> baseMoves  = base.GetPossibleMoves();
            List <Vector2D> validMoves = new List <Vector2D>();

            foreach (Vector2D move in baseMoves)
            {
                bool validMove         = IsValidMove(move);
                bool pathNotObstructed = MovementValidation.IsPathNotObstructed(BoardPosition, move);
                if (validMove && pathNotObstructed)
                {
                    validMoves.Add(move);
                }
            }

            return(validMoves);
        }
Exemple #6
0
        public override bool IsValidMove(Vector2D toPosition)
        {
            bool isValid = false;

            var pieceAtToPosition = ChessGame.ChessBoard.Board[toPosition.Y, toPosition.X];

            if ((MovementValidation.IsValidBishopMovement(BoardPosition, toPosition) ||
                 MovementValidation.IsValidRookMovement(BoardPosition, toPosition)) &&
                !(pieceAtToPosition != null && pieceAtToPosition.GetType() == typeof(King)))
            {
                int xDiff = Math.Abs(BoardPosition.X - toPosition.X);
                int yDiff = Math.Abs(BoardPosition.Y - toPosition.Y);

                isValid = ((xDiff == 0 || xDiff == 1) && (yDiff == 0 || yDiff == 1));
            }

            return(isValid);
        }