From 0fe3de0d50f5a4ede3c0d61ba156ae072020fb38 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 12 Jul 2019 15:40:03 +0300 Subject: [PATCH] Simplified BFS.getPathTo() --- core/src/com/unciv/logic/map/BFS.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/com/unciv/logic/map/BFS.kt b/core/src/com/unciv/logic/map/BFS.kt index f087559196..70de98776d 100644 --- a/core/src/com/unciv/logic/map/BFS.kt +++ b/core/src/com/unciv/logic/map/BFS.kt @@ -39,11 +39,11 @@ class BFS(val startingPoint: TileInfo, val predicate : (TileInfo) -> Boolean){ val path = ArrayList() path.add(destination) var currentNode = destination - while(currentNode != startingPoint){ - tilesReached[currentNode]?.let { - currentNode = it - path.add(currentNode) - } ?: return ArrayList() // destination is not in our path + while(currentNode != startingPoint) { + val parent = tilesReached[currentNode] + if (parent == null) return ArrayList()// destination is not in our path + currentNode = parent + path.add(currentNode) } return path }