blob: f4e1c27be3105134bb2c81ca9c5b743562070d05 (
plain)
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 ch.asynk.tankontank.engine;
import java.util.Iterator;
import java.util.Collection;
import java.util.LinkedHashSet;
public class PawnSet extends LinkedHashSet<Pawn> implements Board.PawnCollection
{
private final Board board;
private int overlay;
public PawnSet(Board board, int overlay, int n)
{
super(n);
this.board = board;
this.overlay = overlay;
}
public Pawn first()
{
if (isEmpty()) return null;
return iterator().next();
}
public void show()
{
enable(overlay, true);
}
public void hide()
{
enable(overlay, false);
}
public void enable(int i, boolean enable)
{
for (Pawn pawn : this)
pawn.enableOverlay(i, enable);
}
public void collectTiles(Board.TileCollection tiles)
{
tiles.clear();
for (Pawn pawn : this)
tiles.add(pawn.getTile());
}
public int fromNodes(Collection<SearchBoard.Node> nodes)
{
clear();
for (SearchBoard.Node node : nodes) {
Tile tile = board.getTile(node.col, node.row);
Iterator<Pawn> pawns = tile.iterator();
while(pawns.hasNext())
add(pawns.next());
}
return size();
}
}
|