diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-14 16:53:07 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-14 16:53:07 +0100 |
commit | 14223fe9fd30832ddfc2798ad6f287a5888592ea (patch) | |
tree | 905bef4906e131d3f1dbf3cf2565f300c5a63dbc /core/src/ch/asynk/tankontank | |
parent | 944d1d2729b898f92083c4981a919116e6d0baa9 (diff) | |
download | RustAndDust-14223fe9fd30832ddfc2798ad6f287a5888592ea.zip RustAndDust-14223fe9fd30832ddfc2798ad6f287a5888592ea.tar.gz |
PossiblePaths: support rotation has moves of distance 0 and cost 0
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/PossiblePaths.java | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java index 0e10d81..2cf45eb 100644 --- a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java +++ b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java @@ -87,7 +87,7 @@ public class PossiblePaths implements Iterable<Vector3> clear(); this.to = to; // from and to are not part of the path - if (board.distance(from, to) == 1) { + if (board.distance(from, to) < 2) { ArrayList<Tile> temp = new ArrayList<Tile>(0); // temp.add(from); // temp.add(to); @@ -187,23 +187,26 @@ public class PossiblePaths implements Iterable<Vector3> boolean roadMarch = true; Tile prev = from; - for (Tile next : paths.get(i)) { - Orientation o = Orientation.fromMove(next.col, next.row, prev.col, prev.row); - cost += next.costFrom(pawn, o); - roadMarch &= next.road(o); - prev = next; - } - Orientation o = Orientation.fromMove(to.col, to.row, prev.col, prev.row); - cost += to.costFrom(pawn, o); + pawn.movement.distance = board.distance(from, to); + + if (pawn.movement.distance > 0) { + for (Tile next : paths.get(i)) { + Orientation o = Orientation.fromMove(next.col, next.row, prev.col, prev.row); + cost += next.costFrom(pawn, o); + roadMarch &= next.road(o); + prev = next; + } + Orientation o = Orientation.fromMove(to.col, to.row, prev.col, prev.row); + cost += to.costFrom(pawn, o); - if (roadMarch) - cost -= pawn.getRoadMarchBonus(); - if (cost < 1) - cost = 1; + if (roadMarch) + cost -= pawn.getRoadMarchBonus(); + if (cost < 1) + cost = 1; + } pawn.movement.cost = cost; pawn.movement.roadMarch = roadMarch; - pawn.movement.distance = (1 + paths.get(i).size()); return cost; } |