Cleanup and switch number formatting to NumberFormat to automatically conform to number standards

main
Bryson Zimmerman 11 months ago
parent 7d1ec41f06
commit 3370f6215e

@ -12,7 +12,6 @@ import kotlin.math.abs
//and https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Comparator.html
object ArrayBackedPathfinder {
//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)
//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

@ -1,6 +1,7 @@
package technology.zim
import technology.zim.data.Tile
import java.text.NumberFormat
import java.util.Locale
import kotlin.time.measureTime
@ -40,14 +41,13 @@ class HierarchicalPathfinding {
MapBackedPathfinder.generatePath(Tile(0, 0), Tile(n - 1, (n - 1)))
}
val numberFormat = NumberFormat.getInstance(Locale.US)
println(World.toString())
print("Tiles in Maze: ")
println(String.format(Locale.US, "%,d", n*n))
println("Maze build time: ${String.format(Locale.US, "%,d",buildMazeTime.inWholeMilliseconds)} ms")
println("BFS Pathfinder time: ${String.format(Locale.US, "%,d",bfsPathfinderTime.inWholeMilliseconds)}ms")
println("Array-Backed A* Pathfinder time: ${String.format(Locale.US, "%,d",arrayBackedPathfinderTime.inWholeMilliseconds)}ms")
println("HashMap-Backed A* Pathfinder time: ${String.format(Locale.US, "%,d",mapBackedPathfinderTime.inWholeMilliseconds)}ms")
println(numberFormat.format(n*n))
println("Maze build time: ${numberFormat.format(buildMazeTime.inWholeMilliseconds)} ms")
println("BFS Pathfinder time: ${numberFormat.format(bfsPathfinderTime.inWholeMilliseconds)}ms")
println("Array-Backed Pathfinder time: ${numberFormat.format(arrayBackedPathfinderTime.inWholeMilliseconds)}ms")
println("HashMap-Backed Pathfinder time: ${numberFormat.format(mapBackedPathfinderTime.inWholeMilliseconds)}ms")
}
fun buildMaze(n: Int) {

@ -3,8 +3,6 @@ package technology.zim
import technology.zim.data.Directions
import technology.zim.data.Tile
import technology.zim.data.TileProperties
import technology.zim.data.WorldData
import java.util.*
import technology.zim.data.Directions.*
import technology.zim.data.TileNavigatedArray
@ -19,6 +17,7 @@ import technology.zim.data.TileNavigatedArray
//Each element contains a TileProperties
// Which currently only contains the edges of the "graph", stored as directions
@Suppress("unused")
object World {
//Default size should be 10
val tiles = TileNavigatedArray<TileProperties>()
@ -57,17 +56,6 @@ object World {
tiles.resize(x, y)
}
//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()
tiles.forEachIndexed {
index, tile ->
tiles[index] = TileProperties((tile?:TileProperties(0)).connections and(mask))
}
}
override fun toString(): String {
val str = StringBuilder()
@ -97,6 +85,7 @@ object World {
return str.toString()
}
@Suppress("unused")
fun getTileShape(tile: TileProperties): Char {
return when(tile.connections and(UP.dir+DOWN.dir+LEFT.dir+RIGHT.dir )) {
UP.dir+DOWN.dir+LEFT.dir+RIGHT.dir -> '╋'

@ -5,8 +5,6 @@ import technology.zim.World
//Tile is a ULong that represents the X,Y coordinates of a Tile
//Contains functions necessary for accessing and manipulating Tiles
//TODO: Untangle visited maths
@JvmInline
value class Tile(private val value: ULong) {
@ -85,7 +83,7 @@ value class Tile(private val value: ULong) {
//Debug function to print the coordinates of this Tile
@SuppressWarnings
@Suppress("unused")
fun getCoordinates(): Pair<Int, Int> {
return Pair(x(), y())
}

@ -1,16 +1,12 @@
package technology.zim.data
import java.util.HashMap
import kotlin.math.abs
//Translated code from CS222 MaxHeap homework
//Cannot use index 0 due to Integer limitations
//TODO: Consider better options than passing in the information this thing needs
class TileHeap(val end: Tile, val fValue:(Tile, Tile) -> Int) {
val dat = ArrayList<Tile>()
init {
//Shove some data into the zero slot
if(dat.isEmpty)
if(dat.isEmpty())
dat.add(Tile(0, 0))
}

@ -9,8 +9,6 @@ import technology.zim.data.Directions.*
//For now, a simple inline class to mitigate memory usage
@JvmInline
value class TileProperties(val connections: Int) {
@ -19,7 +17,7 @@ value class TileProperties(val connections: Int) {
}
//Remove a direction from the list of connections
@SuppressWarnings
@Suppress("unused") //Debug function, leaving in
fun remove(dir: Directions): TileProperties {
return TileProperties(connections and(dir.dir.inv()))
}

Loading…
Cancel
Save