-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKing.java
More file actions
63 lines (53 loc) · 1.75 KB
/
Copy pathKing.java
File metadata and controls
63 lines (53 loc) · 1.75 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package edu.unlv.mis768.finalproject;
/**
* This class designs the King
* @author William Brasic and Sergio Torres
*
*/
public class King extends Piece {
// private boolean castlingComplete = false;
/**
* Constructor for king
* @param whitePiece
*/
public King(boolean whitePiece){
super(whitePiece);
}
// public boolean isCastlingComplete(){
// return this.castlingComplete;
// }
//
// public void setCastlingComplete(boolean castlingComplete){
// this.castlingComplete = castlingComplete;
// }
/**
* Method for determining if the king move is legal
* @param board
* @param start
* @param end
* @return boolean value if legal move; false otherwise
*/
public boolean legalMove(ChessBoard board, Square start, Square end){
// if the piece at Square end is the same color as the king trying to move, return false, i.e., cannot move
if (end.hasPiece()) {
if (end.getPiece().isWhitePiece() == this.isWhitePiece()) {
return false;
}
}
// move is legal if and only if the king moves one spot
return Math.abs(start.getX() - end.getX()) + Math.abs(start.getY() - end.getY()) == 1;
// return this.isValidCastling(board, start, end);
}
// private boolean isValidCastling(ChessBoard board, Square start, Square end){
//
// if (this.isCastlingComplete()) {
// return false;
// }
//
// // castle logic for returning true or false
// }
// public boolean isCastlingComplete(Square start, Square end){
// // check if the starting and
// // ending position are correct
// }
}