Skip to content

Commit

Permalink
make Kruskal work for 8-neighbor grids
Browse files Browse the repository at this point in the history
  • Loading branch information
armin-reichert committed Mar 4, 2020
1 parent af5cb6d commit a545cee
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import de.amr.datastruct.Partition;
import de.amr.graph.core.api.TraversalState;
import de.amr.graph.grid.api.GridGraph2D;
import de.amr.graph.grid.impl.Grid4Topology;
import de.amr.maze.alg.core.MazeGenerator;

/**
* Maze generator derived from Kruskal's minimum spanning tree algorithm.
*
* @author Armin Reichert
*
* @see <a href="https://en.wikipedia.org/wiki/Kruskal%27s_algorithm">Kruskal's Algorithm -
* Wikipedia</a>
* @see <a href="https://en.wikipedia.org/wiki/Kruskal%27s_algorithm">Kruskal's
* Algorithm - Wikipedia</a>
*
* @see <a href="http://weblog.jamisbuck.org/2011/1/3/maze-generation-kruskal-s-algorithm.html">Maze
* @see <a href=
* "http://weblog.jamisbuck.org/2011/1/3/maze-generation-kruskal-s-algorithm.html">Maze
* Generation: Kruskal's Algorithm</a>
*/
public class KruskalMST extends MazeGenerator {
Expand All @@ -31,7 +31,7 @@ public KruskalMST(GridGraph2D<TraversalState, Integer> grid) {
@Override
public void createMaze(int x, int y) {
Partition<Integer> forest = new Partition<>();
GridGraph2D<?, ?> fullGrid = fullGrid(grid.numCols(), grid.numRows(), Grid4Topology.get(), UNVISITED, 0);
GridGraph2D<?, ?> fullGrid = fullGrid(grid.numCols(), grid.numRows(), grid.getTopology(), UNVISITED, 0);
permute(fullGrid.edges()).forEach(edge -> {
int u = edge.either(), v = edge.other();
if (forest.find(u) != forest.find(v)) {
Expand Down

0 comments on commit a545cee

Please sign in to comment.