canMove(int x, int y, int destX, int destY, Side s): This method returns true if the player of color s can move the piece at coordinates (x,y) can move to coordinates (destX, destY) on the board in its current state. This means that here you do need to consider this piece’s interaction with other pieces on the board. Conditions for this method to return false are given in the code.
-
canMove(int x, int y, int destX, int destY, Side s): This method returns true if the player of color s can move the piece at coordinates (x,y) can move to coordinates (destX, destY) on the board in its current state. This means that here you do need to consider this piece’s interaction with other pieces on the board. Conditions for this method to return false are given in the code.
public boolean canMove(int x, int y, int destX, int destY, Side s){
/* TODO write a method that checks if a piece at coordinates x,y can move to coordinates destX,destY
Conditions for false:
- Origin or destination coordinates are outside the board
- Piece at origin is null
- If source and destination coordinates are the same
- Piece at origin is not of the same side as s
- You can check this using piece.getSide()
- Piece cannot move to the destination by piece movement rules
- You should check this using Piece.canMove(destX, destY)
- Destination has a piece of the same Side as the player
- piece must move "through" a piece to get from (x,y) to (destX,destY) (use isVisible())
- The knight is the exception to this rule. The knight can hop "over" pieces, so be sure to check for this.
*/
return false;
}
Step by step
Solved in 3 steps