diff options
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 20 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/SearchBoard.java | 30 |
2 files changed, 46 insertions, 4 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 8884b0f..62e03f2 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -346,16 +346,16 @@ public abstract class Board implements Disposable nodesToPoints(nodes, targets); } - public void possiblePaths(Pawn pawn, int col0, int row0, int col1, int row1, Set<GridPoint2> points) + public int nodesToSet(List<Vector<SearchBoard.Node>> nodes, 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 (Vector<SearchBoard.Node> path : nodes) { for (int i = 0, n = path.size(); i < n; i++) { + // FIXME : optimize this GridPoint2 point = gridPoint2Pool.obtain(); SearchBoard.Node node = path.get(i); point.set(node.col, node.row); @@ -363,6 +363,20 @@ public abstract class Board implements Disposable gridPoint2Pool.free(point); } } + + return nodes.size(); + } + + public int possiblePaths(Pawn pawn, int col0, int row0, int col1, int row1, Set<GridPoint2> points) + { + List<Vector<SearchBoard.Node>> paths = searchBoard.possiblePaths(pawn, col0, row0, col1, row1); + return nodesToSet(paths, points); + } + + public int possiblePathsFilterAdd(int col, int row, Set<GridPoint2> points) + { + List<Vector<SearchBoard.Node>> paths = searchBoard.possiblePathsFilterAdd(col, row); + return nodesToSet(paths, points); } public void disableOverlaysOn(int col, int row) diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java index 7e03153..9a11835 100644 --- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java +++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java @@ -36,6 +36,7 @@ public class SearchBoard private ArrayDeque<Node> path = new ArrayDeque<Node>(20); private List<Vector<Node>> possiblePaths = new LinkedList<Vector<Node>>(); + private List<Node> possiblePathsFilters = new Vector<Node>(5); private List<Node> moves; private List<Node> targets; @@ -487,10 +488,37 @@ public class SearchBoard return los; } - public List<Vector<Node>> possiblePaths(Pawn pawn, int col0, int row0, int col1, int row1) + public void clearPossiblePaths() { path.clear(); + for (Vector<Node> v : possiblePaths) + v.clear(); possiblePaths.clear(); + possiblePathsFilters.clear(); + } + + public List<Vector<Node>> possiblePathsFilterAdd(int col, int row) + { + possiblePathsFilters.add(getNode(col, row)); + int n = possiblePathsFilters.size(); + + List<Vector<Node>> paths = new LinkedList<Vector<Node>>(); + for (Vector<Node> path : possiblePaths) { + int ok = 0; + for (Node filter : possiblePathsFilters) { + if (path.contains(filter)) + ok += 1; + } + if (ok == n) + paths.add(path); + } + + return paths; + } + + public List<Vector<Node>> possiblePaths(Pawn pawn, int col0, int row0, int col1, int row1) + { + clearPossiblePaths(); Node from = getNode(col0, row0); Node to = getNode(col1, row1); |