diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 5 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/SearchBoard.java | 25 |
2 files changed, 30 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 9015394..8423fc4 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -387,6 +387,11 @@ public abstract class Board implements Disposable points.clear(); } + protected int getPathCost(Pawn pawn, int i) + { + return searchBoard.pathCost(pawn, paths.get(i)); + } + protected int getCoordinatePath(Pawn pawn, int idx, ArrayList<Vector3> path, Orientation finalOrientation) { clearCoordinateVector(path); diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java index 77ffe4c..d7e0208 100644 --- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java +++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java @@ -596,4 +596,29 @@ public class SearchBoard } } } + + public int pathCost(Pawn pawn, List<Node> path) + { + int cost = 0; + boolean roadMarch = true; + Node prev = null; + + for (Node next : path) { + if (prev != null) { + Orientation o = Orientation.fromMove(next.col, next.row, prev.col, prev.row); + Tile t = board.getTile(next.col, next.row); + boolean road = t.road(o); + cost += t.costFrom(pawn, o, road); + roadMarch &= road; + } + prev = next; + } + + if (roadMarch) + cost -= pawn.getRoadMarchBonus(); + if (cost < 1) + cost = 1; + + return cost; + } } |