G
G
Gebrauchsanweis2014-04-11 06:44:38
Algorithms
Gebrauchsanweis, 2014-04-11 06:44:38

Eller's algorithm for generating mazes generates loops

I'm trying to write a labyrinth generator in java using the Eller algorithm, I looked at the algorithm here: habrahabr.ru/post/176671
Based on the fact that I met another site where the maze is built normally using this algorithm, it means my cant, but there is code in java script and I didn’t understand anything :(
here are the pieces that I get wrong:
(I mark empty spaces with dots, otherwise the spaces collapse)
the first:
__ __ __
|__ .... ....|
|.... .... ....|
those. in this case, in the first row, the sets are 1 1 1, and in the second, when creating the row 4 1 1, after which, with the "adding the right wall" item, it turns out that at first the wall may not be placed if the chance does not proc and the sets become 4 4 ​​1, and as a result, when comparing 4 1, the wall will not be placed, although in theory it should be placed there, because. otherwise, a loop is obtained.
second:
__ __ __
|__ .... ....|
|__ ....|....|
|....|.... ....|
in this piece in the first row of the set again 1 1 1, in the second 4 4 1, i.e. the sets are separated, but in the third line they are combined again (5 4 4), resulting in a loop.
Can you please tell me what condition I missed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Deerenaros, 2014-04-11
@Deerenaros

I read about Eller's algorithm, and did not understand its beauty. IMHO, it's much better to use a depth -first search and use a spanning tree as a maze . You can see it in code here (sorry for the terrible code).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question