Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aldous-Broder Maze Algorithm #6

Open
wadez opened this issue Aug 15, 2021 · 0 comments
Open

Aldous-Broder Maze Algorithm #6

wadez opened this issue Aug 15, 2021 · 0 comments

Comments

@wadez
Copy link

wadez commented Aug 15, 2021

Hello,

I stumbled across this repo in search of maze algorithm implementations. I tried translating your code to Lua but I could not get the algorithm to work. For whatever reason, the algorithm would only generate zigzag patterns with a few joining cells...

Since then, I stumbled across the Aldous-Broder algorithm which you may find useful. The algorithm is the following:

// semi-pseudocode (translating from Lua to JS-like)

var visited = new Set();
function visit(cell) {
    cell.isVisited = true
    visited.add(cell)
}

function hasUnvisitedCells() {
    return visited.size < numberOfColumns * numberOfRows
}

function generate() {
    var cell = this.getRandomCell()
    visit(cell)
    while (this.hasUnvisitedCells()) {
        var neighbor = cell.neighbors.shuffle().first()
        if (!neighbor.isVisited) {
            cell.connect(neighbor)
            this.visit(neighbor)
        }
        cell = neighbor
   }
}

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant