summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-01 12:03:16 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-01 12:03:16 +0200
commit8f1bc29230f1af76fe50fd9a3e533a06b7aec33e (patch)
treed3c6204bcd8361c5a2c8504d9b3349fc9c50fb2b /core
parent9c400931626e575c1aaef1201a19b607985b8f4a (diff)
downloadRustAndDust-8f1bc29230f1af76fe50fd9a3e533a06b7aec33e.zip
RustAndDust-8f1bc29230f1af76fe50fd9a3e533a06b7aec33e.tar.gz
SearchBoard: add possiblePaths(...) TODO roadMarch support
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/engine/SearchBoard.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java
index 1ac52bc..a782cb5 100644
--- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java
+++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java
@@ -34,6 +34,9 @@ public class SearchBoard
private LinkedList<Node> queue;
private ArrayDeque<Node> roadMarch;
+ private ArrayDeque<Node> path = new ArrayDeque<Node>(20);
+ private List<ArrayDeque<Node>> possiblePaths = new LinkedList<ArrayDeque<Node>>();
+
private List<Node> moves;
private List<Node> targets;
private List<Node> los;
@@ -483,4 +486,54 @@ public class SearchBoard
return los;
}
+
+ public List<ArrayDeque<Node>> possiblePaths(Pawn pawn, int col0, int row0, int col1, int row1)
+ {
+ path.clear();
+ possiblePaths.clear();
+
+ Node from = getNode(col0, row0);
+ Node to = getNode(col1, row1);
+
+ searchCount += 1;
+ // TODO : search
+ from.search = searchCount;
+ from.remaining = pawn.getMovementPoints();
+ // TODO : roadMarch
+ from.roadMarch = true;
+
+ path.add(from);
+ findAllPaths(pawn, from, to);
+
+ return possiblePaths;
+ }
+
+ private void findAllPaths(Pawn pawn, Node from, Node to)
+ {
+ Node moves[] = new Node[6];
+ adjacentMoves(from, moves);
+
+ for(int i = 0; i < 6; i++) {
+ Node next = moves[i];
+ if (next != null) {
+ Tile t = board.getTile(next.col, next.row);
+ boolean road = t.road(sides[i]);
+ int r = (from.remaining - t.costFrom(pawn, sides[i], road));
+ if ((r >= 0) && (distance(next, to) <= r)) {
+ if (next == to) {
+ ArrayDeque<Node> temp = new ArrayDeque<Node>(path.size() + 1);
+ temp.add(next);
+ for (Node n: path)
+ temp.add(n);
+ possiblePaths.add(temp);
+ } else {
+ next.remaining = r;
+ path.push(next);
+ findAllPaths(pawn, next, to);
+ path.pop();
+ }
+ }
+ }
+ }
+ }
}