\ No newline at end of file
diff --git a/src/main/kotlin/Mazefinder.kt b/src/main/kotlin/Mazefinder.kt
new file mode 100644
index 0000000..2e8b910
--- /dev/null
+++ b/src/main/kotlin/Mazefinder.kt
@@ -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 {
+
+
+}
\ No newline at end of file
diff --git a/src/main/kotlin/Pathfinder.kt b/src/main/kotlin/Pathfinder.kt
index 4b69348..4bf5256 100644
--- a/src/main/kotlin/Pathfinder.kt
+++ b/src/main/kotlin/Pathfinder.kt
@@ -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 {
}
\ No newline at end of file
diff --git a/src/main/kotlin/Tile.kt b/src/main/kotlin/Tile.kt
deleted file mode 100644
index fe55f73..0000000
--- a/src/main/kotlin/Tile.kt
+++ /dev/null
@@ -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) {
-
-}
diff --git a/src/main/kotlin/Walls.kt b/src/main/kotlin/Walls.kt
deleted file mode 100644
index ee9b88a..0000000
--- a/src/main/kotlin/Walls.kt
+++ /dev/null
@@ -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)
-}
diff --git a/src/main/kotlin/World.kt b/src/main/kotlin/World.kt
index 77979ed..ed91f7b 100644
--- a/src/main/kotlin/World.kt
+++ b/src/main/kotlin/World.kt
@@ -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,
-class World(val tiles: ArrayList> ) {
- //TODO: Implement world generation algorithm
- fun generate(seed: Int) {
+ constructor(xmin: Int, ymin: Int) : this(WorldData(xmin, ymin))
+ //Returns a coordinate pair
+ fun getRandomLocation(): Pair {
+ return Pair((0..tiles.data.size).random(), (0..tiles.data[0].size).random())
}
- //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) {
+ //Get the properties of the tile at the given coordinates
+ fun tile(coords: Pair): TileProperties {
+ return tiles.data.elementAt(coords.first).elementAt(coords.second)
+ }
+
+ //TODO: Add function for creating connections
+ //fun addConnection(at: Pair, 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): Set> {
+ val listTiles = ArrayList>()
+ for (dir: Directions in tile(at).connections) {
+ //Use the ghost of linear algebra to identify potential neighbor tiles
+ val candidateTile = Pair(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()
}
}
\ No newline at end of file
diff --git a/src/main/kotlin/data/Directions.kt b/src/main/kotlin/data/Directions.kt
new file mode 100644
index 0000000..2cee81a
--- /dev/null
+++ b/src/main/kotlin/data/Directions.kt
@@ -0,0 +1,5 @@
+package technology.zim.data
+
+enum class Directions(val dif: Pair) {
+ NORTH(Pair(0, 1)), SOUTH(Pair(0, -1)), EAST(Pair(1, 0)), WEST(Pair(-1, 0))
+}
\ No newline at end of file
diff --git a/src/main/kotlin/data/TileProperties.kt b/src/main/kotlin/data/TileProperties.kt
new file mode 100644
index 0000000..f910a81
--- /dev/null
+++ b/src/main/kotlin/data/TileProperties.kt
@@ -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 = mutableSetOf()) {
+}
diff --git a/src/main/kotlin/data/WorldData.kt b/src/main/kotlin/data/WorldData.kt
new file mode 100644
index 0000000..139a805
--- /dev/null
+++ b/src/main/kotlin/data/WorldData.kt
@@ -0,0 +1,21 @@
+package technology.zim.data
+
+//Data structure wrapper for more easily readable code
+
+
+@JvmInline
+value class WorldData constructor(val data: ArrayList>) {
+ constructor(xmin : Int, ymin : Int) : this(ArrayList>()) {
+ with(data) {
+ this.ensureCapacity(xmin)
+ this.fill(ArrayList())
+ }
+
+ for(y in data) {
+ with(y) {
+ this.ensureCapacity((ymin))
+ this.fill(TileProperties())
+ }
+ }
+ }
+}