-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPosition.java
53 lines (48 loc) · 1.2 KB
/
Position.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
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
public class Position
{
private int row;
private int column;
//private ArrayList<ConcretePiece> pieceWasHere = new ArrayList<>();
private Set<ConcretePiece> pieceWasHere = new HashSet<>();
public Position(int column, int row)
{
this.row = row;
this.column = column;
}
public int getRow()
{
return row;
}
public int getColumn()
{
return column;
}
public String toString()
{
return "(" + column + ", " + row + ")";
}
public int lengthPieceWasHere()
{
return pieceWasHere.size();
}
public void addPieceWasHere(ConcretePiece piece)
{
pieceWasHere.add(piece);
}
}
class tailsComparator implements Comparator<Position>
{
public int compare(Position a, Position b)
{
if(a.lengthPieceWasHere() != b.lengthPieceWasHere())
return b.lengthPieceWasHere() - a.lengthPieceWasHere();
if (a.getColumn() != b.getColumn())
return a.getColumn() - b.getColumn();
if (a.getRow() != b.getRow())
return a.getRow() - b.getRow();
return 0;
}
}