Added ability for tile to return its connections

main
Bryson Zimmerman 11 months ago
parent 437f8e3699
commit 450918a377

@ -114,21 +114,21 @@ value class Tile(private val value: ULong) {
return "<" + x() + ", " + y() + ">" return "<" + x() + ", " + y() + ">"
} }
//TODO: Consider pushing getAdjacent and getUnexplored to their call locations to avoid allocating sets? fun getConnections(): Set<Tile> {
fun getUnexploredTiles(map: HashMap<Tile, Int>):Set<Tile> { val connections = mutableSetOf<Tile>()
val adj = mutableSetOf<Tile>() val properties = getProperties()
val dirs = Directions.ALL val north = Directions.UP.dir
if(properties.connections and(Directions.UP.dir) != 0) {
dirs.forEach { dir -> connections.add(this + Directions.NORTH)
val candidateTile = this + dir
//Ensure that the tile is within bounds
if(candidateTile.isInBounds() && !map.containsKey(candidateTile))
{
//println("$this+$dir --> $candidateTile")
adj.add(candidateTile)
}
} }
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 { companion object {

Loading…
Cancel
Save