diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-09 14:05:17 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-09 14:05:17 +0200 |
commit | a275df92aab52735105561fcc930d3ffbc8b4f6b (patch) | |
tree | 77e4900df03737a679db545bee1f22dea212b3ec | |
parent | be380f190b0fc73256dda71444021e51b0f61de9 (diff) | |
download | RustAndDust-a275df92aab52735105561fcc930d3ffbc8b4f6b.zip RustAndDust-a275df92aab52735105561fcc930d3ffbc8b4f6b.tar.gz |
SearchBoard,Board: implement pathCost(Pawn, List<Node>)
-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; + } } |