Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 views
in Technique[技术] by (71.8m points)

algorithm - Binary Maze Generator

enter image description hereI'm trying to make a simple maze generator using the simplest algorithm I know of. This is what my code looks like right now but there is almost never a path from start to finish and I don't know what I'm doing wrong. Here is the algorithm page

function generateMaze() {
  let cells = []

  for (var i=0;i<nodes.length;i++){
    let cell = new Cell(nodes[i].x, nodes[i].y)

    cells.push(cell)
    //obstacles.push([nodes[i].x, nodes[i].y])


  }


  
  for (var i=0;i<cells.length;i++){
    if (i % 2 == 0){
    if (round(random(1, 2)) == 1){
      obstacles.push([cells[i].x, cells[i].y-base])
    }
    else{
      obstacles.push([cells[i].x-base, cells[i].y])
    }
  }
}


}


class Cell{
  constructor(x, y){
    this.x = x
    this.y = y
    this.has_visited = false
    this.neigbors = []
  }
}

Obstacles is just an empty array to hold the walls and base is how big each block is.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...