forked from prayjourney/algorithm-in-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPosition.java
More file actions
33 lines (29 loc) · 1.02 KB
/
Position.java
File metadata and controls
33 lines (29 loc) · 1.02 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
// used to track position in the path
public class Position {
public int col;
public int row;
public String orientation; // "H" or "V"
public String direction; // "+": increase step; "-": decrease step
public Position(int c, int r, String o, String d) {
col = c;
row = r;
if (!o.equals("H") && !o.equals("V")) {
throw new RuntimeException("The " + o + " direction of mirror is not supported.");
}
orientation = o;
if (!d.equals("+") && !d.equals("-")) {
throw new RuntimeException("The " + d + " direction of movement is not supported.");
}
direction = d;
}
public String toString() {
return "position: " + col + "x" + row + " (" + orientation + direction + ") ";
}
public boolean equals(Position p) {
if (col == p.col && row == p.row
&& orientation.equals(p.orientation)
&& direction.equals(p.direction)) {
return true;
} else return false;
}
}