diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-01 14:08:46 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-01 14:08:46 +0200 |
commit | 0ff51a456823af3a416f16d2bb92427a4c9f3d68 (patch) | |
tree | 8da91269a97f5c64496e31a5679945745986a88e /core | |
parent | bf8de88fc7a2971e5f4fde1bcab5374336efb965 (diff) | |
download | RustAndDust-0ff51a456823af3a416f16d2bb92427a4c9f3d68.zip RustAndDust-0ff51a456823af3a416f16d2bb92427a4c9f3d68.tar.gz |
Board: add possiblePaths(Pawn, int, int, int, int, Set<GridPoint2>)
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 3d8afd5..8884b0f 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -1,5 +1,6 @@ package ch.asynk.tankontank.engine; +import java.util.Set; import java.util.List; import java.util.Vector; import java.util.Iterator; @@ -335,16 +336,35 @@ public abstract class Board implements Disposable public void possibleMovesFrom(Pawn pawn, int col, int row, Vector<GridPoint2> moves) { - List <SearchBoard.Node> nodes = searchBoard.possibleMovesFrom(pawn, col, row); + List<SearchBoard.Node> nodes = searchBoard.possibleMovesFrom(pawn, col, row); nodesToPoints(nodes, moves); } public void possibleTargetsFrom(Pawn pawn, int col, int row, Vector<GridPoint2> targets) { - List <SearchBoard.Node> nodes = searchBoard.possibleTargetsFrom(pawn, col, row); + List<SearchBoard.Node> nodes = searchBoard.possibleTargetsFrom(pawn, col, row); nodesToPoints(nodes, targets); } + public void possiblePaths(Pawn pawn, int col0, int row0, int col1, int row1, Set<GridPoint2> points) + { + // FIXME : optimize this + for (GridPoint2 point : points) + gridPoint2Pool.free(point); + points.clear(); + + List<Vector<SearchBoard.Node>> paths = searchBoard.possiblePaths(pawn, col0, row0, col1, row1); + for (Vector<SearchBoard.Node> path : paths) { + for (int i = 0, n = path.size(); i < n; i++) { + GridPoint2 point = gridPoint2Pool.obtain(); + SearchBoard.Node node = path.get(i); + point.set(node.col, node.row); + if (!points.add(point)) + gridPoint2Pool.free(point); + } + } + } + public void disableOverlaysOn(int col, int row) { disableOverlaysOn(getTile(col, row)); |