-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMove.java
More file actions
79 lines (69 loc) · 2.2 KB
/
Move.java
File metadata and controls
79 lines (69 loc) · 2.2 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
70
71
72
73
74
75
76
77
78
import java.io.Serializable;
import java.util.Objects;
/**
* The Move class represents the move of a piece from
* one spot to another and the value of that move.
*
*/
public class Move implements Serializable {
private static final long serialVersionUID = 5918469248348323737L;
private final int fromCol;
private final int fromRow;
private final int toCol;
private final int toRow;
private final int from;
private final int to;
private int value;
public Move(int fromCol, int fromRow, int toCol, int toRow, int value) {
this.fromCol = fromCol;
this.fromRow = fromRow;
this.toCol = toCol;
this.toRow = toRow;
this.from = fromCol + fromRow * 8;
this.to = toCol + toRow * 8;
this.value = value;
}
public Move(final Move ref) {
this.fromCol = ref.fromCol;
this.fromRow = ref.fromRow;
this.toCol = ref.toCol;
this.toRow = ref.toRow;
this.from = ref.from;
this.to = ref.to;
this.value = ref.value;
}
public int getFromCol() { return fromCol; }
public int getFromRow() { return fromRow; }
public int getToCol() { return toCol; }
public int getToRow() { return toRow; }
public int getFrom() { return from; }
public int getTo() { return to; }
public int getValue() { return value; }
public void setValue(int value) {
this.value = value;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Move move = (Move) o;
return from == move.from
&& to == move.to;
}
@Override
public int hashCode() {
return Objects.hash(from, to);
}
@Override
public String toString() {
String chessNotation = String.format("%c%d to %c%d",
fromCol + 'a', 8 - fromRow,
toCol + 'a', 8 - toRow);
return String.format("[Move from:%d,%d to %d,%d (%s) value:%d]",
fromCol, fromRow, toCol, toRow, chessNotation, value);
}
}