-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoveDescription.java
executable file
·56 lines (48 loc) · 1.31 KB
/
MoveDescription.java
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
public class MoveDescription {
private String pieceToMove;
private int destinationColumn, destinationRow;
public MoveDescription(String pieceToMove, int destinationColumn, int destinationRow) {
this.pieceToMove = pieceToMove;
this.destinationColumn = destinationColumn;
this.destinationRow = destinationRow;
}
public String getPieceToMove() {
return pieceToMove;
}
public int getDestinationColumn() {
return destinationColumn;
}
public int getDestinationRow() {
return destinationRow;
}
public String toString() {
return "(" + pieceToMove + ", " + destinationColumn + ", " + destinationRow + ")";
}
public int toInt() {
// Format: bit 0 indicates which piece to move; 0 for king, 1 for rook
// bits 1-2 indicate column, bits 3-4 indicate row.
int piecebit = 0;
switch (pieceToMove) {
case "king":
piecebit = 0;
break;
case "rook":
piecebit = 1;
break;
}
return (piecebit) + ((destinationColumn - 1) << 1) + ((destinationRow - 1) << 3);
}
public MoveDescription(int moveint) {
int piecebit = moveint - ((moveint >> 1) << 1);
switch (piecebit) {
case 0:
pieceToMove = "king";
break;
case 1:
pieceToMove = "rook";
break;
}
destinationColumn = ((moveint >> 1) - ((moveint >> 3) << 2)) + 1;
destinationRow = ((moveint >> 3) - ((moveint >> 5) << 2)) + 1;
}
}