Naming updates

main
Bryson Zimmerman 11 months ago
parent 6b31dfabb8
commit 9900e8d476

@ -4,7 +4,7 @@ import technology.zim.data.Directions
import technology.zim.data.Tile
import technology.zim.data.TileNavigatedArray
object BFSPathFinder {
object BFSPathfinder {
//In this particular situation, only a single outcome is likely. Thus, BFS always finds the perfect (and only) path
//Skipping the Heap data structure allows better utilization of on-die cache
var gVals:TileNavigatedArray<Int> = TileNavigatedArray<Int>()
@ -30,7 +30,7 @@ object BFSPathFinder {
while (frontier.isNotEmpty()) {
//Grab the next tile and its gValue
current = frontier.removeFirst()
val currentG = gVals.get(current)?:Int.MAX_VALUE-1.also{throw IndexOutOfBoundsException("Couldn't get gValue in BFS")}
val currentG = gVals.get(current) ?: (Int.MAX_VALUE - 1).also{throw IndexOutOfBoundsException("Couldn't get gValue in BFS")}
// add its unexplored neighbors and update their gVals
current.getConnections().forEach {

@ -1,6 +1,5 @@
package technology.zim
import technology.zim.data.Directions
import technology.zim.data.Tile
import kotlin.time.measureTime
@ -17,16 +16,16 @@ class HierarchicalPathfinding {
println("Pathfinding")
val BFSPathFinderTime = measureTime {
BFSPathFinder.generatePath(Tile(0, 0), Tile(n-1, n-1))
val bfsPathfinderTime = measureTime {
BFSPathfinder.generatePath(Tile(0, 0), Tile(n-1, n-1))
}
val ArrayBackedPathfinderTime = measureTime {
val arrayBackedPathfinderTime = measureTime {
ArrayBackedPathfinder.generatePath(Tile(0, 0), Tile(n - 1, (n - 1)))
}
val MapBackedPathfinderTime = measureTime {
val mapBackedPathfinderTime = measureTime {
MapBackedPathfinder.generatePath(Tile(0, 0), Tile(n - 1, (n - 1)))
}
@ -34,14 +33,9 @@ class HierarchicalPathfinding {
println(World.toString())
println(n*n)
println("Maze build time: ${buildMazeTime.inWholeMilliseconds} ms")
println("BFS Pathfinder time: ${BFSPathFinderTime.inWholeMilliseconds}ms")
println("Array-Backed Pathfinder time: ${ArrayBackedPathfinderTime.inWholeMilliseconds}ms")
println("HashMap-Backed Pathfinder time: ${MapBackedPathfinderTime.inWholeMilliseconds}ms")
}
//Clear the maze of pathfinding markers before running another pathfinding algorithm
fun clearMaze() {
World.scrubDirections(listOf(Directions.FRONTIER, Directions.INPATH))
println("BFS Pathfinder time: ${bfsPathfinderTime.inWholeMilliseconds}ms")
println("Array-Backed Pathfinder time: ${arrayBackedPathfinderTime.inWholeMilliseconds}ms")
println("HashMap-Backed Pathfinder time: ${mapBackedPathfinderTime.inWholeMilliseconds}ms")
}
fun buildMaze(n: Int) {

Loading…
Cancel
Save