From 480b3f753cc68799db7ec0d440d8c995730e23c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 4 Jan 2016 20:51:24 +0100 Subject: PathBuilder: add chooseShortest() --- core/src/ch/asynk/rustanddust/engine/PathBuilder.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java index 2846928..ca25535 100644 --- a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java +++ b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java @@ -140,6 +140,25 @@ public class PathBuilder implements Disposable return 1; } + public int chooseShortest() + { + if (paths.size() > 1) { + Path good = paths.get(0); + for (Path path : paths) { + if (path.tiles.size() < good.tiles.size()) + good = path; + } + + paths.remove(good); + clearPaths(); + paths.add(good); + for (Tile tile : good.tiles) + tiles.add(tile); + } + + return 1; + } + private void findAllPaths(Tile from, int mvtLeft, int fitness, boolean roadMarch) { Tile moves[] = new Tile[6]; -- cgit v1.1-2-g2b99