mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
Simplified BFS.getPathTo()
This commit is contained in:
parent
d9942aec7c
commit
0fe3de0d50
@ -39,11 +39,11 @@ class BFS(val startingPoint: TileInfo, val predicate : (TileInfo) -> Boolean){
|
||||
val path = ArrayList<TileInfo>()
|
||||
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user