diff options
Diffstat (limited to 'core/src/ch/asynk/rustanddust/engine')
-rw-r--r-- | core/src/ch/asynk/rustanddust/engine/PathBuilder.java | 49 |
1 files changed, 38 insertions, 11 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); |