From 450918a377a01e523221a40df58aab1a88251c77 Mon Sep 17 00:00:00 2001 From: Bryson Zimmerman Date: Thu, 7 Nov 2024 14:29:44 -0500 Subject: [PATCH] Added ability for tile to return its connections --- src/main/kotlin/data/Tile.kt | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/data/Tile.kt b/src/main/kotlin/data/Tile.kt index a9c7670..eb158bf 100644 --- a/src/main/kotlin/data/Tile.kt +++ b/src/main/kotlin/data/Tile.kt @@ -114,21 +114,21 @@ value class Tile(private val value: ULong) { return "<" + x() + ", " + y() + ">" } - //TODO: Consider pushing getAdjacent and getUnexplored to their call locations to avoid allocating sets? - fun getUnexploredTiles(map: HashMap):Set { - val adj = mutableSetOf() - val dirs = Directions.ALL - - dirs.forEach { dir -> - val candidateTile = this + dir - //Ensure that the tile is within bounds - if(candidateTile.isInBounds() && !map.containsKey(candidateTile)) - { - //println("$this+$dir --> $candidateTile") - adj.add(candidateTile) - } + fun getConnections(): Set { + val connections = mutableSetOf() + val properties = getProperties() + val north = Directions.UP.dir + if(properties.connections and(Directions.UP.dir) != 0) { + connections.add(this + Directions.NORTH) } - return adj + if(properties.connections and(Directions.LEFT.dir) != 0) + connections.add(this + Directions.WEST) + if(properties.connections and(Directions.RIGHT.dir) != 0) + connections.add(this + Directions.EAST) + if(properties.connections and(Directions.DOWN.dir) != 0) + connections.add(this + Directions.SOUTH) + + return connections } companion object {