Repository navigation
Expand file tree
/
Copy pathXYLocation.java
More file actions
92 lines (75 loc) · 1.71 KB
/
Copy pathXYLocation.java
File metadata and controls
92 lines (75 loc) · 1.71 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package aima.basic;
/**
* @author Ravi Mohan
*
*/
public class XYLocation {
int xCoOrdinate, yCoOrdinate;
public XYLocation(int i, int j) {
xCoOrdinate = i;
yCoOrdinate = j;
}
public int getXCoOrdinate() {
return xCoOrdinate;
}
@Override
public boolean equals(Object o) {
XYLocation anotherLoc = (XYLocation) o;
return ((anotherLoc.getXCoOrdinate() == xCoOrdinate) && (anotherLoc
.getYCoOrdinate() == yCoOrdinate));
}
public int getYCoOrdinate() {
return yCoOrdinate;
}
public XYLocation west() {
return new XYLocation(xCoOrdinate - 1, yCoOrdinate);
}
public XYLocation east() {
return new XYLocation(xCoOrdinate + 1, yCoOrdinate);
}
public XYLocation north() {
return new XYLocation(xCoOrdinate, yCoOrdinate - 1);
}
public XYLocation south() {
return new XYLocation(xCoOrdinate, yCoOrdinate + 1);
}
public XYLocation right() {
return east();
}
public XYLocation left() {
return west();
}
public XYLocation up() {
return north();
}
public XYLocation down() {
return south();
}
public XYLocation locationAt(String direction) {
if (direction.equals("North")) {
return north();
}
if (direction.equals("South")) {
return south();
}
if (direction.equals("East")) {
return east();
}
if (direction.equals("West")) {
return west();
} else {
throw new RuntimeException("Unknown direction " + direction);
}
}
@Override
public String toString() {
return " ( " + xCoOrdinate + " , " + yCoOrdinate + " ) ";
}
@Override
public int hashCode() {
int result = 17;
result = 37 * result + xCoOrdinate;
result = result + yCoOrdinate;
return result;
}
}