0

I am attempting to create a maze using a premade Disjoint set class. I have created a Cell class that contains a boolean variable for each of the four walls. The problem is, how do I create a disjoint set of cell objects? That way I can union the cells and change the boolean variables accordingly.

http://users.cis.fiu.edu/~weiss/dsaajava3/code/DisjSets.java

That is the code for the disjoint set

fluteman24
  • 33
  • 1
  • 5
  • May we see this Disjoint set class you're using? Does it use Generics? – Norsk Apr 14 '16 at 20:49
  • edited question to include the code – fluteman24 Apr 14 '16 at 20:55
  • Are you allowed to change the class at all? If not, then you'll need to Union the different rooms (identified as integers) and design your own logic for how a player navigates through the cells. This isn't trivial and if you want to use that DisjSets class you're going to have to put a fair bit of planning into the logic of it – Norsk Apr 14 '16 at 21:15

1 Answers1

0

A disjoint set data-structure is not suited for this particular problem.

Attempting to force your solution to use it is just going to give you poor code and a bad design.

Not to mention that there is a much simpler, more elegant solution.

In order to generate a perfect (one unique path between any two points) maze:

  1. create an array of N by M cells, keeping track of each wall in each cell
  2. choose a cell at random
  3. from your current cell (A), select a non-visited neighbour (B), if there are no such neighbours, go back to your previously visited cell and start from step (3)
  4. break down the wall between A and B
  5. mark B as the current cell (or push it in a list or similar datastructure)
  6. if all cells have been visited, end. else go back to step (3)

All you need is a grid, and a list.

Joris Schellekens
  • 8,483
  • 2
  • 23
  • 54