summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/engine/SearchBoard.java53
1 files changed, 25 insertions, 28 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java
index a782cb5..7e03153 100644
--- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java
+++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java
@@ -35,7 +35,7 @@ public class SearchBoard
private ArrayDeque<Node> roadMarch;
private ArrayDeque<Node> path = new ArrayDeque<Node>(20);
- private List<ArrayDeque<Node>> possiblePaths = new LinkedList<ArrayDeque<Node>>();
+ private List<Vector<Node>> possiblePaths = new LinkedList<Vector<Node>>();
private List<Node> moves;
private List<Node> targets;
@@ -487,7 +487,7 @@ public class SearchBoard
return los;
}
- public List<ArrayDeque<Node>> possiblePaths(Pawn pawn, int col0, int row0, int col1, int row1)
+ public List<Vector<Node>> possiblePaths(Pawn pawn, int col0, int row0, int col1, int row1)
{
path.clear();
possiblePaths.clear();
@@ -495,43 +495,40 @@ public class SearchBoard
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);
+ findAllPaths(pawn, from, to, pawn.getMovementPoints(), true, pawn.getMovementPoints());
return possiblePaths;
}
- private void findAllPaths(Pawn pawn, Node from, Node to)
+ private void findAllPaths(Pawn pawn, Node from, Node to, int mvtLeft, boolean roadMarch, int roadMarchBonus)
{
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();
- }
+ if (next == null) continue;
+
+ Tile t = board.getTile(next.col, next.row);
+ boolean road = t.road(sides[i]);
+ int cost = t.costFrom(pawn, sides[i], road);
+ int r = (mvtLeft - cost);
+ roadMarch = roadMarch & road;
+ if (roadMarch) r += roadMarchBonus;
+
+ if ((r >= 0) && (distance(next, to) <= r)) {
+ if (next == to) {
+ Vector<Node> temp = new Vector<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, (mvtLeft - cost), roadMarch, roadMarchBonus);
+ path.pop();
}
}
}