diff --git a/src/main/kotlin/BFSPathFinder.kt b/src/main/kotlin/BFSPathFinder.kt new file mode 100644 index 0000000..dc55235 --- /dev/null +++ b/src/main/kotlin/BFSPathFinder.kt @@ -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() + + } + +} \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 9dd4b5c..6db3a2b 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -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) { - 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") diff --git a/src/main/kotlin/World.kt b/src/main/kotlin/World.kt index 3d357b0..97a08df 100644 --- a/src/main/kotlin/World.kt +++ b/src/main/kotlin/World.kt @@ -20,7 +20,7 @@ import technology.zim.data.Directions.* object World { //Default size should be 10 val tiles = WorldData(ArrayList>()) - var sizeX = 10 + var sizeX = 10 //Default size var sizeY = 10 const val ANSI_RESET = "\u001B[0m" const val ANSI_BLACK = "\u001B[30m" diff --git a/src/main/kotlin/data/Directions.kt b/src/main/kotlin/data/Directions.kt index 9c20db7..ae2c07e 100644 --- a/src/main/kotlin/data/Directions.kt +++ b/src/main/kotlin/data/Directions.kt @@ -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 { diff --git a/src/main/kotlin/data/WorldData.kt b/src/main/kotlin/data/WorldData.kt index b5ea5e0..f16be4e 100644 --- a/src/main/kotlin/data/WorldData.kt +++ b/src/main/kotlin/data/WorldData.kt @@ -5,6 +5,20 @@ package technology.zim.data @JvmInline value class WorldData(val value: ArrayList>) { + + //Accepts a list of directions, removes those directions from every TileProperties in WorldData + fun scrubDirections(rem: List) { + 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)