diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 79eec21..64da3ec 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,16 +4,11 @@
-
-
-
-
-
+
+
-
-
-
+
@@ -30,8 +25,8 @@
-
+
@@ -171,7 +166,15 @@
1728930163649
-
+
+
+ 1729358883715
+
+
+
+ 1729358883715
+
+
@@ -215,6 +218,7 @@
-
+
+
\ No newline at end of file
diff --git a/src/main/kotlin/World.kt b/src/main/kotlin/World.kt
index ed91f7b..5f4ff48 100644
--- a/src/main/kotlin/World.kt
+++ b/src/main/kotlin/World.kt
@@ -1,6 +1,7 @@
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.*
@@ -13,38 +14,35 @@ import java.util.*
//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))
+object World {
+ val tiles = WorldData(ArrayList>())
//Returns a coordinate pair
- fun getRandomLocation(): Pair {
- return Pair((0..tiles.data.size).random(), (0..tiles.data[0].size).random())
+ fun getRandomLocation(): Tile {
+ return Tile(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): TileProperties {
- return tiles.data.elementAt(coords.first).elementAt(coords.second)
+ fun getProperties(tile: Tile): TileProperties {
+ return tiles.data.elementAt(tile.loc.first).elementAt(tile.loc.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) {
+ fun getConnections(at: Tile): Set {
+ val listTiles = ArrayList()
+ for (dir: Directions in getProperties(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)
+ val candidateTile = Tile(Pair(at.loc.first + dir.dif.first, at.loc.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) {
+ if(candidateTile.loc.first > 0 &&
+ candidateTile.loc.second > 0 &&
+ candidateTile.loc.first < tiles.data.size &&
+ candidateTile.loc.second < tiles.data[candidateTile.loc.first].size) {
listTiles.add(candidateTile)
}
}
diff --git a/src/main/kotlin/data/Tile.kt b/src/main/kotlin/data/Tile.kt
new file mode 100644
index 0000000..b47fb32
--- /dev/null
+++ b/src/main/kotlin/data/Tile.kt
@@ -0,0 +1,7 @@
+package technology.zim.data
+
+@JvmInline
+value class Tile(val loc: Pair) {
+ //Todo: Function for cell to add a connection
+ //Todo: Refactor so Tiles know how to get their connections, not the world
+}
\ No newline at end of file
diff --git a/src/main/kotlin/data/WorldData.kt b/src/main/kotlin/data/WorldData.kt
index 139a805..1e31c35 100644
--- a/src/main/kotlin/data/WorldData.kt
+++ b/src/main/kotlin/data/WorldData.kt
@@ -5,7 +5,7 @@ package technology.zim.data
@JvmInline
value class WorldData constructor(val data: ArrayList>) {
- constructor(xmin : Int, ymin : Int) : this(ArrayList>()) {
+ fun setSize(xmin : Int, ymin : Int) {
with(data) {
this.ensureCapacity(xmin)
this.fill(ArrayList())