Replaced bugged connect code with a reference to the actual, tested, connect code

main
Bryson Zimmerman 12 months ago
parent f051b907f7
commit 0bc2192e4a

@ -23,7 +23,7 @@ object MazeFinder {
var startingTile = World.getRandomLocation() var startingTile = World.getRandomLocation()
val randGen = XoRoShiRo128PlusRandom() val randGen = XoRoShiRo128PlusRandom()
val tempInGraph = ArrayList<Pair<Tile, TileProperties>>() val tempInGraph = ArrayList<Tile>()
fun primsAlgorithm() { fun primsAlgorithm() {
cleanUp() cleanUp()
@ -36,6 +36,8 @@ object MazeFinder {
startingTile = World.getRandomLocation() startingTile = World.getRandomLocation()
val tmpIndex = randGen.nextInt(Directions.ALL.size) val tmpIndex = randGen.nextInt(Directions.ALL.size)
startingTile.connect(Directions.ALL.get(tmpIndex)) startingTile.connect(Directions.ALL.get(tmpIndex))
tempInGraph.add(startingTile)
tempInGraph.add(startingTile + Directions.ALL.get(tmpIndex))
//Choose an arbitrary vertex from G (the graph), and add it to some (initially empty) set V. //Choose an arbitrary vertex from G (the graph), and add it to some (initially empty) set V.
frontier.addAll(startingTile.getAdjacentTiles(false)) frontier.addAll(startingTile.getAdjacentTiles(false))
frontier.addAll((startingTile + Directions.ALL.get(tmpIndex)).getAdjacentTiles(false)) frontier.addAll((startingTile + Directions.ALL.get(tmpIndex)).getAdjacentTiles(false))
@ -47,7 +49,6 @@ object MazeFinder {
//Grab a random tile from the frontier, mark it as visited //Grab a random tile from the frontier, mark it as visited
val random = randGen.nextInt(frontier.size()) val random = randGen.nextInt(frontier.size())
current = frontier.data.get(random) current = frontier.data.get(random)
current.getProperties().visited()
frontier.removeAt(random) frontier.removeAt(random)
@ -55,13 +56,18 @@ object MazeFinder {
adjacentExplored = current.getAdjacentTiles(true) adjacentExplored = current.getAdjacentTiles(true)
if(adjacentExplored.isEmpty()) if(adjacentExplored.isEmpty())
println("No explored adjacent tiles found") println("")
if(adjacentExplored.isEmpty()) {
val world = World.tiles
println ("No explored adjacent tiles found")
}
//Select a random tile from possibleTiles //Select a random tile from possibleTiles
inGraph = adjacentExplored.elementAt(randGen.nextInt(adjacentExplored.size)) inGraph = adjacentExplored.elementAt(randGen.nextInt(adjacentExplored.size))
//Connect the frontier tile to the graph //Connect the frontier tile to the graph
current.connect(Directions.convertModifier(current.value - inGraph.value)) current.connect(inGraph)
tempInGraph.add(current)
//Add current's unexplored tiles to the frontier, if not already in frontier //Add current's unexplored tiles to the frontier, if not already in frontier
frontier.addAll(current.getAdjacentTiles(false)) frontier.addAll(current.getAdjacentTiles(false))
@ -73,7 +79,6 @@ object MazeFinder {
println("prim") println("prim")
} }
fun cleanUp() { fun cleanUp() {
//Clean up the frontier //Clean up the frontier
frontier.clear() frontier.clear()

@ -15,7 +15,7 @@ class MazeFinderTest {
} }
@Test @Test
fun topRowConnectedSouth() { fun topRowOutOfBoundsCheck() {
var southExists = false var southExists = false
World.tiles.value.forEach { World.tiles.value.forEach {
col -> col ->
@ -26,7 +26,7 @@ class MazeFinderTest {
} }
@Test @Test
fun bottomRowConnectedSouth() { fun bottomRowOutOfBoundsCheck() {
var southNotExists = true var southNotExists = true
World.tiles.value.forEach { World.tiles.value.forEach {
col -> col ->

Loading…
Cancel
Save