summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/engine
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-01-04 23:46:33 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-01-04 23:46:33 +0100
commit9b760a3cfee8964620f8faed051159fd1ee4ba42 (patch)
treeb57cf231a36a2f8f245a94afa98c2e8bdc40a5d9 /core/src/ch/asynk/rustanddust/engine
parent79054924a90058a4cf700ca441a7f5009bd652e3 (diff)
downloadRustAndDust-9b760a3cfee8964620f8faed051159fd1ee4ba42.zip
RustAndDust-9b760a3cfee8964620f8faed051159fd1ee4ba42.tar.gz
PathBuilder: replace setExit(Orientation) with chooseExit(Orientation)
Diffstat (limited to 'core/src/ch/asynk/rustanddust/engine')
-rw-r--r--core/src/ch/asynk/rustanddust/engine/PathBuilder.java49
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);