-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKing.java
More file actions
32 lines (29 loc) · 931 Bytes
/
Copy pathKing.java
File metadata and controls
32 lines (29 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* King.java
*
* @author Deep Patel
*
* REMARKS: This is a class which stores information about the king
* piece and how it moves, which is one square at a time
*/
public class King extends Piece {
//Constructor
public King(boolean myPiece) {
super(myPiece);
}
/**
* This method is used to check if the move made by the king piece is a valid
* move for the piece
*
* Parameters:
* Board board - The method take in the current state of the board to validate the move
* Move move - The method takes in the move being made
*
* Returns a boolean to indicate whether the move was valid
*/
public boolean isValidMove(Board board, Move move) {
int rowDiff = Math.abs(move.getToRow() - move.getFromRow());
int colDiff = Math.abs(move.getToCol() - move.getFromCol());
return (rowDiff == 1 || colDiff == 1) && (rowDiff <= 1 && colDiff <= 1);
}
}