More refactoring

main
Bryson Zimmerman 11 months ago
parent 7fbaea08da
commit 7786a0789f

@ -7,7 +7,7 @@ class HierarchicalPathfinding {
companion object { companion object {
@JvmStatic @JvmStatic
fun main(args: Array<String>) { fun main(args: Array<String>) {
val n = 50 val n = 500
buildMaze(n) buildMaze(n)
val startTime = System.currentTimeMillis() val startTime = System.currentTimeMillis()
PathFinder.generatePath(Tile(0, 0), Tile(n-1, (n-1))) PathFinder.generatePath(Tile(0, 0), Tile(n-1, (n-1)))

@ -56,7 +56,7 @@ object MazeFinder {
current.connect(inGraph) current.connect(inGraph)
//Look around the frontier tile for unexplored tiles, add them to the frontier //Look around the frontier tile for unexplored tiles, add them to the frontier
manifestDestiny(current) addToManifest(current)
//print(World.toString()) //print(World.toString())
//println("--------------------------------------------") //println("--------------------------------------------")
@ -65,7 +65,7 @@ object MazeFinder {
println("prim") println("prim")
} }
private fun manifestDestiny(current: Tile) { private fun addToManifest(current: Tile) {
current.getAdjacentTiles(false).forEach { current.getAdjacentTiles(false).forEach {
tile -> tile ->
val tileprops = World.get(tile) val tileprops = World.get(tile)

@ -54,7 +54,7 @@ object PathFinder {
//Otherwise, the tile has been reached and this path is not better, so carry on //Otherwise, the tile has been reached and this path is not better, so carry on
gVals.put(candidateTile, currentG + 1) gVals.put(candidateTile, currentG + 1)
frontier.insert(candidateTile) frontier.insert(candidateTile)
World.update(candidateTile, candidateTile.getProperties() +Directions.FRONTIERIFIED) World.update(candidateTile, candidateTile.getProperties() +Directions.FRONTIER)
} }
} }
} }

@ -64,7 +64,7 @@ object World {
for (x in 0..tiles.value[0].size - 1) { for (x in 0..tiles.value[0].size - 1) {
if(World.get(Tile(x, y)).connections and(INPATH.dir) != 0) if(World.get(Tile(x, y)).connections and(INPATH.dir) != 0)
inPath = true inPath = true
else if (World.get(Tile(x, y)).connections and(FRONTIERIFIED.dir) != 0) else if (World.get(Tile(x, y)).connections and(FRONTIER.dir) != 0)
checked = true checked = true
if(inPath) if(inPath)
str.append(ANSI_GREEN) str.append(ANSI_GREEN)
@ -103,7 +103,7 @@ object World {
} }
} }
fun getTileShapeDoubles(tile: TileProperties): Char { fun getTileShapeDoubles(tile: TileProperties): Char {
return when(tile.connections and(MANIFEST.inv()) and(INPATH.inv()) and(FRONTIERIFIED.inv())) { return when(tile.connections and(MANIFEST.inv()) and(INPATH.inv()) and(FRONTIER.inv())) {
UP.dir+DOWN.dir+LEFT.dir+RIGHT.dir -> '╬' UP.dir+DOWN.dir+LEFT.dir+RIGHT.dir -> '╬'
UP.dir+DOWN.dir+LEFT.dir -> '╣' UP.dir+DOWN.dir+LEFT.dir -> '╣'
UP.dir+DOWN.dir+RIGHT.dir -> '╠' UP.dir+DOWN.dir+RIGHT.dir -> '╠'

@ -6,8 +6,8 @@ enum class Directions(val dir: Int) {
DOWN(2), DOWN(2),
LEFT(4), LEFT(4),
RIGHT(8), RIGHT(8),
MANIFEST(16),//Checked by MazeFinder, the imperialist way MANIFEST(16),//Was added to MazeFinder's frontier, but the pathfinder has a frontier so this is named something other than frontier
FRONTIERIFIED(32), //Added to the pathfinder's frontier FRONTIER(32), //Added to the pathfinder's frontier
INPATH(64), //Chosen by the pathfinder INPATH(64), //Chosen by the pathfinder
; ;

Loading…
Cancel
Save