summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-01-04 23:29:34 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-01-04 23:29:34 +0100
commit79054924a90058a4cf700ca441a7f5009bd652e3 (patch)
treeb79280caea5d652506d7900ed9e120683af27713 /core/src/ch
parent20ab618a929c5911b472781b5db47f39544a087b (diff)
downloadRustAndDust-79054924a90058a4cf700ca441a7f5009bd652e3.zip
RustAndDust-79054924a90058a4cf700ca441a7f5009bd652e3.tar.gz
PathBuilder: factorise keepOnly(Path) out of choosBest() and chooseShortest()
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/rustanddust/engine/PathBuilder.java23
1 files changed, 11 insertions, 12 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java
index 0017c43..f96c06f 100644
--- a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java
+++ b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java
@@ -129,12 +129,7 @@ public class PathBuilder implements Disposable
if ( (path.fitness > good.fitness) || ((path.fitness == good.fitness) && (path.cost < good.cost)))
good = path;
}
-
- ps.remove(good);
- clearPaths();
- paths.add(good);
- for (Tile tile : good.tiles)
- tiles.add(tile);
+ keepOnly(good);
}
return 1;
@@ -150,17 +145,21 @@ public class PathBuilder implements Disposable
if (path.tiles.size() < good.tiles.size())
good = path;
}
-
- ps.remove(good);
- clearPaths();
- paths.add(good);
- for (Tile tile : good.tiles)
- tiles.add(tile);
+ keepOnly(good);
}
return 1;
}
+ private void keepOnly(Path path)
+ {
+ getPaths().remove(path);
+ clearPaths();
+ paths.add(path);
+ for (Tile tile : path.tiles)
+ tiles.add(tile);
+ }
+
private void findAllPaths(Tile from, int mvtLeft, int fitness, boolean roadMarch)
{
Tile moves[] = new Tile[6];