Prep work for BFS implementation

main
Bryson Zimmerman 11 months ago
parent 96faabcf9a
commit 9da4bb2c24

@ -0,0 +1,24 @@
package technology.zim
import technology.zim.data.Tile
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
fun generatePath(start: Tile, end: Tile) {
if (!start.isInBounds() || !end.isInBounds()) {
throw IndexOutOfBoundsException("Cannot generate a path to or from an out of bounds tile")
}
if (start == end) {
println("Ouroboros detected")
return
}
//Queue for tiles to be checked
val frontier = ArrayDeque<Tile>()
}
}

@ -1,5 +1,6 @@
package technology.zim
import technology.zim.data.Directions
import technology.zim.data.Tile
class HierarchicalPathfinding {
@ -7,16 +8,25 @@ class HierarchicalPathfinding {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val n = 500
val n = 1000
buildMaze(n)
val startTime = System.currentTimeMillis()
var startTime = System.currentTimeMillis()
PathFinder.generatePath(Tile(0, 0), Tile(n-1, (n-1)))
val endTime = System.currentTimeMillis()
var endTime = System.currentTimeMillis()
val aStarMs = endTime - startTime
println(World.toString())
println(n*n)
println((endTime - startTime).toString() + "ms")
}
//Clear the maze of pathfinding markers before running another pathfinding algorithm
fun clearMaze() {
World.tiles.scrubDirections(listOf(Directions.FRONTIER, Directions.INPATH))
}
fun buildMaze(n: Int) {
println("Building world")

@ -20,7 +20,7 @@ import technology.zim.data.Directions.*
object World {
//Default size should be 10
val tiles = WorldData(ArrayList<ArrayList<TileProperties>>())
var sizeX = 10
var sizeX = 10 //Default size
var sizeY = 10
const val ANSI_RESET = "\u001B[0m"
const val ANSI_BLACK = "\u001B[30m"

@ -9,6 +9,7 @@ enum class Directions(val dir: Int) {
MANIFEST(16),//Was added to MazeFinder's frontier, but the pathfinder has a frontier so this is named something other than frontier
FRONTIER(32), //Added to the pathfinder's frontier
INPATH(64), //Chosen by the pathfinder
NOPATH(128) //Tile is not a viable path
;
companion object {

@ -5,6 +5,20 @@ package technology.zim.data
@JvmInline
value class WorldData(val value: ArrayList<ArrayList<TileProperties>>) {
//Accepts a list of directions, removes those directions from every TileProperties in WorldData
fun scrubDirections(rem: List<Directions>) {
var mask = rem.fold(0) { sum, element -> sum + element.dir}
mask = mask.inv()
value.forEachIndexed {
x, row ->
row.forEachIndexed {
y, tile ->
value[x][y] = TileProperties(tile.connections and(mask))
}
}
}
fun setSize(xmin : Int, ymin : Int) {
val emptyTile = TileProperties(0)
//println("WorldData setting to: " + xmin + ", " + ymin)

Loading…
Cancel
Save