-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMove.java
More file actions
69 lines (51 loc) · 1.63 KB
/
Move.java
File metadata and controls
69 lines (51 loc) · 1.63 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
64
65
66
67
68
69
public class Move {
private int startX;
private int startY;
private int endX;
private int endY;
private static final int SIZE = 8;
private static final int SQUARE_SIZE = 60;
// ... existing attributes like startX, startY, etc.
private ChessPiece piece; // Add a reference to the chess piece
public Move(ChessPiece piece, int startY, int startX, int endY, int endX) {
// ... initialization
this.startY= startY;
this.startX = startX;
this.endY = endY;
this.endX = endX;
this.piece = piece;
}
public int getInitX(){
return this.startX;
}
public int getInitY(){
return this.startY;
}
public int getNewX(){
return this.endX;
}
public int getNewY(){
return this.endY;
}
@Override
public String toString() {
String startSquare = toBoardCoordinate(startX, startY);
String endSquare = toBoardCoordinate(endX, endY);
return piece.getType(piece) + " from " + startSquare + " to " + endSquare;
}
public String toBoardCoordinate(int row, int col) {
char colLetter = (char) ('A' + col);
int rowNumber = SIZE - row; // Assuming your board rows start from 0 at the bottom
return "" + colLetter + rowNumber;
}
public String toThreatState(Move move){
return toBoardCoordinate(move.endY, move.endX);
}
public boolean capturesOpponentPiece(int x, int y, ChessBoard chessBoard) {
if (chessBoard.getPiece(x,y) != null){
return true;
}
return false;
}
// ... other methods and constructors
}