Filled out World class necessities, created appropriate data holders. Should be ready for Mazefinder

main
Bryson Zimmerman 12 months ago
parent 8fa4825f9d
commit 50f2951f00

@ -4,14 +4,16 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="741ceb24-e493-47c1-9f25-1dbd8b151381" name="Changes" comment="Added intellij files... for better or for worse">
<change afterPath="$PROJECT_DIR$/src/main/kotlin/Pathfinder.kt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/kotlin/Tile.kt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/kotlin/Walls.kt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/kotlin/World.kt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/kotlin/TestingClassTest.kt" afterDir="false" />
<list default="true" id="741ceb24-e493-47c1-9f25-1dbd8b151381" name="Changes" comment="Initial work on data structures. Saving for move to another computer.">
<change afterPath="$PROJECT_DIR$/src/main/kotlin/Mazefinder.kt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/kotlin/data/Directions.kt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/kotlin/data/TileProperties.kt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/kotlin/data/WorldData.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/Main.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/Main.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/Pathfinder.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/Pathfinder.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/Tile.kt" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/Walls.kt" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/World.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/World.kt" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -27,9 +29,9 @@
<option name="RECENT_TEMPLATES">
<list>
<option value="JUnit5 Test Class" />
<option value="Kotlin Enum" />
<option value="Kotlin Class" />
<option value="Kotlin Data Class" />
<option value="Kotlin Enum" />
</list>
</option>
</component>
@ -55,7 +57,11 @@
&quot;com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary&quot;: &quot;JUnit5&quot;,
&quot;com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrarySuperClass.JUnit5&quot;: &quot;&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;project.structure.last.edited&quot;: &quot;Modules&quot;,
&quot;project.structure.proportion&quot;: &quot;0.15&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;reference.settingsdialog.project.gradle&quot;
}
}</component>
@ -66,6 +72,9 @@
<key name="CreateTestDialog.RecentsKey">
<recent name="" />
</key>
<key name="K2MoveDeclarationsDialog.RECENT_PACKAGE_KEY">
<recent name="technology.zim.data" />
</key>
</component>
<component name="RunManager" selected="Gradle.TestingClassTest.basic">
<configuration name="TestingClassTest.basic" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
@ -154,7 +163,15 @@
<option name="project" value="LOCAL" />
<updated>1728575379269</updated>
</task>
<option name="localTasksCounter" value="4" />
<task id="LOCAL-00004" summary="Initial work on data structures. Saving for move to another computer.">
<option name="closed" value="true" />
<created>1728930163649</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1728930163649</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -197,6 +214,7 @@
<MESSAGE value="Project Setup" />
<MESSAGE value="Project Setup 2" />
<MESSAGE value="Added intellij files... for better or for worse" />
<option name="LAST_COMMIT_MESSAGE" value="Added intellij files... for better or for worse" />
<MESSAGE value="Initial work on data structures. Saving for move to another computer." />
<option name="LAST_COMMIT_MESSAGE" value="Initial work on data structures. Saving for move to another computer." />
</component>
</project>

@ -0,0 +1,20 @@
package technology.zim
//Build the maze
//Options:
//DFS - Long corridors
//Prim's - Solid maze
//Wall-builder?
//https://emmilco.github.io/path_finder/
//Needs https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/PriorityQueue.html
//and https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Comparator.html
//http://weblog.jamisbuck.org/2011/1/10/maze-generation-prim-s-algorithm
//http://weblog.jamisbuck.org/2011/1/3/maze-generation-kruskal-s-algorithm
class Mazefinder {
}

@ -1,5 +1,10 @@
package technology.zim
//A* to be upgraded with hierarchies
//Needs https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/PriorityQueue.html
//and https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Comparator.html
class Pathfinder {
}

@ -1,13 +0,0 @@
package technology.zim
//Data holder to encapsulate a particular location
//Might not be necessary, might add unnecessary memory usage
//Tile could use a simple int or long to combine both coordinates
//Retrieve X or Y with bitwise operations
//Removes boxing while allowing access. Still doesn't add walls.
@JvmInline
value class Tile(val coords: Int) {
}

@ -1,7 +0,0 @@
package technology.zim
//Should change things around so an inline class holds the data and functions for wall checks
enum class Walls(val dirs: Int) {
NORTH(1), EAST(2), SOUTH(4), WEST(8)
}

@ -1,23 +1,53 @@
package technology.zim
import technology.zim.data.Directions
import technology.zim.data.TileProperties
import technology.zim.data.WorldData
import java.util.*
//For now, keep it small with uncompresed tile representation
//In the future, this could be stored in a gzipped file and memory mapped
//Location in array is the tile's coordinates
//Value of int is barriers, bitwise operation
//Each element contains a TileProperties
// Which currently only contains the edges of the "graph", stored as directions
class World(private val tiles: WorldData) {
//TODO: Constructor that calls Mazefinder algorithm with given dimensions,
constructor(xmin: Int, ymin: Int) : this(WorldData(xmin, ymin))
class World(val tiles: ArrayList<ArrayList<Walls>> ) {
//TODO: Implement world generation algorithm
fun generate(seed: Int) {
//Returns a coordinate pair
fun getRandomLocation(): Pair<Int, Int> {
return Pair((0..tiles.data.size).random(), (0..tiles.data[0].size).random())
}
//Get the properties of the tile at the given coordinates
fun tile(coords: Pair<Int, Int>): TileProperties {
return tiles.data.elementAt(coords.first).elementAt(coords.second)
}
//Determine whether moving from one tile to another is valid
//Should limit to adjacent tiles
//Should detect walls and refuse movement if one exists in the desired direction
//Or maybe this should be delegated to another class
fun canPass(x: Int, y: Int, fromX: Int, fromY: Int) {
//TODO: Add function for creating connections
//fun addConnection(at: Pair<Int, Int>, dir: Directions)
//Sort out what cells are connected. Induces some CPU overhead compared to storing a simple list
//Benefit is smaller memory footprint by using references to singleton enums
fun getConnections(at: Pair<Int, Int>): Set<Pair<Int, Int>> {
val listTiles = ArrayList<Pair<Int, Int>>()
for (dir: Directions in tile(at).connections) {
//Use the ghost of linear algebra to identify potential neighbor tiles
val candidateTile = Pair<Int, Int>(at.first + dir.dif.first, at.second + dir.dif.second)
//Ensure that the tile is within bounds
if(candidateTile.first > 0 &&
candidateTile.second > 0 &&
candidateTile.first < tiles.data.size &&
candidateTile.second < tiles.data[candidateTile.first].size) {
listTiles.add(candidateTile)
}
}
return listTiles.toSet()
}
}

@ -0,0 +1,5 @@
package technology.zim.data
enum class Directions(val dif: Pair<Int, Int>) {
NORTH(Pair(0, 1)), SOUTH(Pair(0, -1)), EAST(Pair(1, 0)), WEST(Pair(-1, 0))
}

@ -0,0 +1,11 @@
package technology.zim.data
//Data holder for a Tile
//Should contain a mutable set of connected directions
//Later, can hold jumps to other locations other such fancy features
//For now, a simple inline class to mitigate memory usage
@JvmInline
value class TileProperties(val connections:MutableSet<Directions> = mutableSetOf<Directions>()) {
}

@ -0,0 +1,21 @@
package technology.zim.data
//Data structure wrapper for more easily readable code
@JvmInline
value class WorldData constructor(val data: ArrayList<ArrayList<TileProperties>>) {
constructor(xmin : Int, ymin : Int) : this(ArrayList<ArrayList<TileProperties>>()) {
with(data) {
this.ensureCapacity(xmin)
this.fill(ArrayList<TileProperties>())
}
for(y in data) {
with(y) {
this.ensureCapacity((ymin))
this.fill(TileProperties())
}
}
}
}
Loading…
Cancel
Save