diff options
Diffstat (limited to 'core/src/ch/asynk')
3 files changed, 41 insertions, 16 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java index f96c06f..3bd057b 100644 --- a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java +++ b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java @@ -151,6 +151,44 @@ public class PathBuilder implements Disposable return 1; } + public int chooseExit(Orientation o) + { + List<Path> ps = getPaths(); + + Path good = ps.get(0); + int mvt = pawn.getMovementPoints(); + int cost = to.exitCost(); + int rBonus = (to.road(o) ? pawn.getRoadMarchBonus() : 0); + + if (ps.size() > 1) { + good = null; + for (Path p : getPaths()) { + if (pathCanExit(p, mvt, cost, rBonus)) { + if (good != null) { + if ( (p.fitness > good.fitness) || ((p.fitness == good.fitness) && (p.cost < good.cost))) + good = p; + } else { + good = p; + } + } + } + + keepOnly(good); + } + + if (!pathCanExit(good, mvt, cost, rBonus)) + throw new RuntimeException("chosen path can't exit"); + + orientation = o; + if (from != to) { + good.cost += 1; + good.tiles.add(to); + } + to = board.getAdjTileAt(to, o); + + return 1; + } + private void keepOnly(Path path) { getPaths().remove(path); @@ -293,17 +331,6 @@ public class PathBuilder implements Disposable return filteredPaths.get(i); } - public void setExit(Orientation o) - { - orientation = o; - Path path = getPath(0); - if (from != to) { - path.cost += 1; - path.tiles.add(to); - } - to = board.getAdjTileAt(to, o); - } - private void printToErr(String what, List<Path> paths) { System.err.println(what + " " + paths.size() + " - " + from + " -> " + to); diff --git a/core/src/ch/asynk/rustanddust/game/map/Map2Moves.java b/core/src/ch/asynk/rustanddust/game/map/Map2Moves.java index 411e2c9..738de2b 100644 --- a/core/src/ch/asynk/rustanddust/game/map/Map2Moves.java +++ b/core/src/ch/asynk/rustanddust/game/map/Map2Moves.java @@ -72,10 +72,10 @@ public abstract class Map2Moves extends Map1Units public void pathsSetOrientation(Orientation o) { paths.orientation = o; } public boolean pathsIsSet() { return paths.isSet(); } public boolean pathsCanExit(Orientation o) { return paths.canExit(o); } - public void pathsSetExit(Orientation o) { paths.setExit(o); } public boolean pathsContains(Hex hex) { return paths.contains(hex); } public int pathsChooseBest() { return paths.chooseBest(); } public int pathsChooseShortest() { return paths.chooseShortest(); } + public int pathsChooseExit(Orientation o) { return paths.chooseExit(o); } public int pathsToggleHex(Hex hex) { boolean enable = !hex.isOverlayEnabled(Hex.MOVE); diff --git a/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java b/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java index a759e51..12bb3c4 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java @@ -43,14 +43,12 @@ public class StateWithdraw extends StateCommon if (map.pathsTo() == null) map.pathsBuild(hex); - if (map.pathsSize() > 1) - RustAndDust.debug("ERROR: Withdraw pathsSize() == " + map.pathsSize()); - Hex exitHex = (Hex) map.pathsTo(); if (!exitZone.contains(exitHex)) throw new RuntimeException(String.format("%s not in exitZone", exitHex)); - map.pathsSetExit(exitZone.orientation); + if (map.pathsChooseExit(exitZone.orientation) > 1) + RustAndDust.debug("ERROR: Withdraw pathsSize() == " + map.pathsSize()); unit.hideActiveable(); if (to != null) |