-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCell.java
executable file
·53 lines (45 loc) · 1.39 KB
/
Cell.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
public class Cell {
private int column, row;
public Cell(int column, int row) {
this.column = column;
this.row = row;
}
/*public Cell(Cell other) {
this.column = other.column;
this.row = other.row;
}*/
public int getColumn() {
return column;
}
public int getRow() {
return row;
}
@Override
public boolean equals(Object obj) {
if (obj == null || !obj.getClass().equals(getClass())) {
return false;
}
Cell cell = (Cell) obj;
return column == cell.getColumn() && row == cell.getRow();
}
@Override
public int hashCode() {
return column * (Parameters.NUM_ROWS) + row;
}
public boolean isValid() {
return 1 <= column && column <= Parameters.NUM_COLUMNS && 1 <= row && row <= Parameters.NUM_ROWS;
}
// checks if this cell blocks a horizontal or vertical move
public boolean blocks(Cell source, Cell destination) {
if (source.getColumn() == destination.getColumn() && column == source.getColumn()) {
int minRow = Math.min(source.getRow(), destination.getRow());
int maxRow = Math.max(source.getRow(), destination.getRow());
return minRow < row && row < maxRow;
} else if (source.getRow() == destination.getRow() && row == source.getRow()) {
int minColumn = Math.min(source.getColumn(), destination.getColumn());
int maxColumn = Math.max(source.getColumn(), destination.getColumn());
return minColumn < column && column < maxColumn;
}
return false;
}
}