Beispiel #1
0
        /// <summary>
        /// Returns True if a requested move is valid
        /// </summary>
        /// <returns></returns>
        public bool canMove(int original_x, int original_y, int future_x, int future_y, Board board, Player p)
        {
            //depending on the piece in position, move accordingly
            // may need to include detection of other pieces???
            switch (board.squares[original_x, original_y].currentPiece.Type)
            {
                case PieceType.Bishop:
                    //return canMoveBishop(original_x, original_y, future_x, future_y, board);
                    break;
                case PieceType.King:
                    break;
                case PieceType.Knight:
                    return canMoveKnight(original_x, original_y, future_x, future_y, board, p);
                    break;
                case PieceType.Pawn:
                    break;
                case PieceType.Queen:
                    break;
                case PieceType.Rook:
                    return canMoveRook(original_x, original_y, future_x, future_y, board, p);
                    break;

            }
            return false;
        }
Beispiel #2
0
        public bool canMoveKnight(int original_x, int original_y, int future_x, int future_y, Board board, Player p)
        {
            //Move Piece, no take
            //move 1 on x, 2 on y
            if (
                (original_x + 1 == future_x && original_y + 2 == future_y && board.squares[future_x, future_y].currentPiece.Type == PieceType.None)
                || (original_x - 1 == future_x && original_y + 2 == future_y && board.squares[future_x, future_y].currentPiece.Type == PieceType.None)
                || (original_x + 1 == future_x && original_y - 2 == future_y && board.squares[future_x, future_y].currentPiece.Type == PieceType.None)
                || (original_x - 1 == future_x && original_y - 2 == future_y && board.squares[future_x, future_y].currentPiece.Type == PieceType.None)
                )
            { return true; }

            //move 2 on x 1 on y
            else if (
                (original_y + 1 == future_y && original_x + 2 == future_x && board.squares[future_x, future_y].currentPiece.Type == PieceType.None)
                || (original_y - 1 == future_y && original_x + 2 == future_x && board.squares[future_x, future_y].currentPiece.Type == PieceType.None)
                || (original_y + 1 == future_y && original_x - 2 == future_x && board.squares[future_x, future_y].currentPiece.Type == PieceType.None)
                || (original_y - 1 == future_y && original_x - 2 == future_x && board.squares[future_x, future_y].currentPiece.Type == PieceType.None)
                )
            { return true; }
            //Take piece
            //move 1 on x, 2 on y
            else if (
                (original_x + 1 == future_x && original_y + 2 == future_y && board.squares[future_x, future_y].currentPiece.Color != p.playerColor)
                || (original_x - 1 == future_x && original_y + 2 == future_y && board.squares[future_x, future_y].currentPiece.Color != p.playerColor)
                || (original_x + 1 == future_x && original_y - 2 == future_y && board.squares[future_x, future_y].currentPiece.Color != p.playerColor)
                || (original_x - 1 == future_x && original_y - 2 == future_y && board.squares[future_x, future_y].currentPiece.Color != p.playerColor)
                )
            { return true; }

             //move 2 on x 1 on y
            else if (
                (original_y + 1 == future_y && original_x + 2 == future_x && board.squares[future_x, future_y].currentPiece.Color != p.playerColor)
                || (original_y - 1 == future_y && original_x + 2 == future_x && board.squares[future_x, future_y].currentPiece.Color != p.playerColor)
                || (original_y + 1 == future_y && original_x - 2 == future_x && board.squares[future_x, future_y].currentPiece.Color != p.playerColor)
                || (original_y - 1 == future_y && original_x - 2 == future_x && board.squares[future_x, future_y].currentPiece.Color != p.playerColor)
                )
            { return true; }

            else
            { return false; }
        }
Beispiel #3
0
 //makes a manual move where i want;
 public Board makeMove(int original_x, int original_y, int future_x, int future_y, Board board, Player p)
 {
     //if there is something to move there
     if (board.squares[original_x, original_y].currentPiece.Type != PieceType.None)
     {
         board.squares[future_x, future_y].currentPiece.Type = board.squares[original_x, original_y].currentPiece.Type;
         board.squares[original_x, original_y].currentPiece.Type = PieceType.None;
         return board;
     }
     else
     { return board; }
 }
Beispiel #4
0
        public bool canMoveRook(int original_x, int original_y, int future_x, int future_y, Board board, Player p)
        {
            //Moving to empty space
            //Move vertical if x changes, y is constant, and there is no piece in the desired move space.
            if ((original_x != future_x) && (original_y == future_y) && (board.squares[future_x, future_y].currentPiece.Type == PieceType.None))
            {
                //is there any piece blocking??

                if (future_x > original_x)
                {
                    for (int ii = original_x + 1; ii < future_x; ii++)
                    {
                        if (board.squares[ii, future_y].currentPiece.Type != PieceType.None)
                        { return false; }
                    }
                    return true;
                }
                else if (original_x > future_x)
                {
                    for (int ii = original_x - 1; ii > future_x; ii--)
                    {
                        if (board.squares[ii, future_y].currentPiece.Type != PieceType.None)
                        { return false; }
                    }
                    return true;

                }
                else { return false; }
            }
            //Move horizontal if y changes, x is constant, and there is no piece in the desired move space.
            if ((original_y != future_y) && (original_x == future_x) && (board.squares[future_x, future_y].currentPiece.Type == PieceType.None))
            {
                if (future_y > original_y)
                {
                    for (int ii = original_y + 1; ii < future_y; ii++)
                    {
                        if (board.squares[future_x, ii].currentPiece.Type != PieceType.None)
                        { return false; }
                    }
                    return true;
                }
                else if (original_y > future_y)
                {
                    for (int ii = original_x - 1; ii > future_x; ii--)
                    {
                        if (board.squares[future_x, ii].currentPiece.Type != PieceType.None)
                        { return false; }
                    }
                    return true;
                }
                else { return false; }
            }
            //Moving to occupied space STILL MUST ACCOUNT FOR CHECK...
            if ((original_x != future_x) && (original_y == future_y) && (board.squares[future_x, future_y].currentPiece.Color != p.playerColor))
            {
                if (future_x > original_x)
                {
                    for (int ii = original_x + 1; ii < future_x; ii++)
                    {
                        if (board.squares[ii, future_y].currentPiece.Type != PieceType.None)
                        { return false; }
                    }
                    return true;
                }
                else if (original_x > future_x)
                {
                    for (int ii = original_x - 1; ii > future_x; ii--)
                    {
                        if (board.squares[ii, future_y].currentPiece.Type != PieceType.None)
                        { return false; }
                    }
                    return true;
                }
                else { return false; }
            }
            //Moving to occupied space
            if ((original_y != future_y) && (original_x == future_x) && (board.squares[future_x, future_y].currentPiece.Color != p.playerColor))
            { //is there any piece blocking??
                if (future_y > original_y)
                {
                    for (int ii = original_y + 1; ii < future_y; ii++)
                    {
                        if (board.squares[future_x, ii].currentPiece.Type != PieceType.None)
                        { return false; }
                    }
                    return true;
                }
                else if (original_y > future_y)
                {
                    for (int ii = original_x - 1; ii > future_x; ii--)
                    {
                        if (board.squares[future_x, ii].currentPiece.Type != PieceType.None)
                        { return false; }
                    }
                    return true;
                }
                else { return false; }
            }
            else
            { return false; }
        }