-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnight.java
More file actions
31 lines (29 loc) · 959 Bytes
/
Copy pathKnight.java
File metadata and controls
31 lines (29 loc) · 959 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
/**
* Knight.java
*
* @author Deep Patel
*
* REMARKS: This is a class which stores information about the knight
* piece and how it moves, which is in an "L" shape and can jump over pieces
*/
public class Knight extends Piece{
//Constructor
public Knight(boolean myPiece) {
super(myPiece);
}
/**
* This method is used to check if the move made by the Knight 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 == 2) || (rowDiff == 2 && colDiff == 1);
}
}