/
Move.java
61 lines (55 loc) · 1.35 KB
/
Move.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
57
58
59
60
61
package actions;
//holds a move, which is a sequence of steps
public class Move {
//a move occupies a turn. A move has one or more steps.
public enum Side {
BLACK,WHITE
};
int startingLocation = -1;
int endingLocation = -1;
boolean becomeKing = false;
int captures = -1;
Side whoseTurn = null;
java.util.ArrayList <Step> theSteps = null;
public Move(){
theSteps = new java.util.ArrayList <Step>();
}
public Move(Side s){
theSteps = new java.util.ArrayList <Step>();
this.whoseTurn = s;
}
public void init() {
theSteps.clear();
startingLocation = -1;
endingLocation = -1;
}
public void addStep (Step s){
Step lastStep = theSteps.get(theSteps.size()-1);
if (lastStep.getEndLocation() == s.getStartLocation()){
theSteps.add(s);
endingLocation = s.getEndLocation();
}
}
public void revokeStep (){
theSteps.remove(theSteps.size()-1);
if(theSteps.size() == 0) {
this.startingLocation = -1;
this.endingLocation = -1;}
else this.endingLocation = theSteps.get(theSteps.size()-1).getEndLocation();
}
public int getHowManySteps(){
return theSteps.size();
}
public Step getStep(int i){
return theSteps.get(i);
}
public Side getSide(){
return this.whoseTurn;
}
public int getStartLocation(){
return this.startingLocation;
}
public int getEndLocation(){
return this.endingLocation;
}
}