|
|
@ -13,11 +13,10 @@ import kotlin.math.abs
|
|
|
|
|
|
|
|
|
|
|
|
object ArrayBackedPathfinder {
|
|
|
|
object ArrayBackedPathfinder {
|
|
|
|
//TODO: Replace with array for coordinate lookups for speed, do it in a separate pathfinder class to demonstrate the difference
|
|
|
|
//TODO: Replace with array for coordinate lookups for speed, do it in a separate pathfinder class to demonstrate the difference
|
|
|
|
val gVals = TileNavigatedArray<Int>(World.sizeX, World.sizeY, false)
|
|
|
|
val gVals = TileNavigatedArray<Int>()
|
|
|
|
//work along the path, marking tiles with VISITED along the way
|
|
|
|
//work along the path, marking tiles with VISITED along the way
|
|
|
|
//if marking with visited is too expensive, just make the path and finalize it
|
|
|
|
//if marking with visited is too expensive, just make the path and finalize it
|
|
|
|
fun generatePath(start: Tile, end: Tile) {
|
|
|
|
fun generatePath(start: Tile, end: Tile) {
|
|
|
|
|
|
|
|
|
|
|
|
if(!start.isInBounds() || !end.isInBounds()) {
|
|
|
|
if(!start.isInBounds() || !end.isInBounds()) {
|
|
|
|
throw IndexOutOfBoundsException("Cannot generate a path to or from an out of bounds tile")
|
|
|
|
throw IndexOutOfBoundsException("Cannot generate a path to or from an out of bounds tile")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -55,7 +54,6 @@ object ArrayBackedPathfinder {
|
|
|
|
} while( current != end)
|
|
|
|
} while( current != end)
|
|
|
|
|
|
|
|
|
|
|
|
//At this point, a path is found
|
|
|
|
//At this point, a path is found
|
|
|
|
markPath(start, end)
|
|
|
|
|
|
|
|
println("Path found!")
|
|
|
|
println("Path found!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -79,7 +77,7 @@ object ArrayBackedPathfinder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun fValue(prospect: Tile, end: Tile): Int {
|
|
|
|
private fun fValue(prospect: Tile, end: Tile): Int {
|
|
|
|
return hValue(prospect, end).plus(gVals.get(prospect) ?: 0)
|
|
|
|
return hValue(prospect, end).plus(MapBackedPathfinder.gVals.get(prospect) ?: 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun hValue(prospect: Tile, end:Tile): Int {
|
|
|
|
private fun hValue(prospect: Tile, end:Tile): Int {
|
|
|
|