summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
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
parent79054924a90058a4cf700ca441a7f5009bd652e3 (diff)
downloadRustAndDust-9b760a3cfee8964620f8faed051159fd1ee4ba42.zip
RustAndDust-9b760a3cfee8964620f8faed051159fd1ee4ba42.tar.gz
PathBuilder: replace setExit(Orientation) with chooseExit(Orientation)
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/rustanddust/engine/PathBuilder.java49
-rw-r--r--core/src/ch/asynk/rustanddust/game/map/Map2Moves.java2
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java6
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)