From 79054924a90058a4cf700ca441a7f5009bd652e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 4 Jan 2016 23:29:34 +0100 Subject: PathBuilder: factorise keepOnly(Path) out of choosBest() and chooseShortest() --- .../ch/asynk/rustanddust/engine/PathBuilder.java | 23 +++++++++++----------- 1 file 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]; -- cgit v1.1-2-g2b99