-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathMovement.java
More file actions
60 lines (49 loc) · 1.36 KB
/
Movement.java
File metadata and controls
60 lines (49 loc) · 1.36 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
package chess;
public enum Movement {
UP(0, 1),
UP_UP(UP.x * 2, UP.y * 2),
DOWN(0, -1),
DOWN_DOWN(DOWN.x * 2, DOWN.y * 2),
LEFT(-1, 0),
RIGHT(1, 0),
LEFT_UP(LEFT.x, UP.y),
RIGHT_UP(RIGHT.x, UP.y),
LEFT_DOWN(LEFT.x, DOWN.y),
RIGHT_DOWN(RIGHT.x, DOWN.y),
UP_UP_LEFT(LEFT_DOWN.x, UP_UP.y),
UP_UP_RIGHT(RIGHT_DOWN.x, UP_UP.y),
LEFT_LEFT_UP(LEFT.x * 2, UP.y),
LEFT_LEFT_DOWN(LEFT.x * 2, DOWN.y),
RIGHT_RIGHT_UP(RIGHT.x * 2, UP.y),
RIGHT_RIGHT_DOWN(RIGHT.x * 2, DOWN.y),
DOWN_DOWN_LEFT(LEFT_DOWN.x, DOWN_DOWN.y),
DOWN_DOWN_RIGHT(RIGHT_DOWN.x, DOWN_DOWN.y),
;
private final int x;
private final int y;
Movement(final int x, final int y) {
this.x = x;
this.y = y;
}
public int x() {
return x;
}
public int y() {
return y;
}
public boolean isVertical() {
return x == 0 && y != 0;
}
public boolean isDiagonal() {
return x != 0 && y != 0 && Math.abs(x) == Math.abs(y);
}
public boolean isStraightOneStep() {
return (x == 0 && Math.abs(y) == 1) || (y == 0 && Math.abs(x) == 1);
}
public boolean isCrossOneStep() {
return Math.abs(x) + Math.abs(y) == 2 && Math.abs(x) == 1 && Math.abs(y) == 1;
}
public boolean isMoveThreeStep() {
return Math.abs(x) + Math.abs(y) == 3;
}
}