Depth-first-search maze generation algorithm with blocks instead of walls
Asked Answered
H

1

6

I am trying to implement the depth first search algorithm into my game. I have been studying this web page: http://www.mazeworks.com/mazegen/mazetut/index.htm , only to find that I wouldn't be able to use it with blocks instead of Walls. What I mean by blocks is a square that covers the whole cell, instead of just the edges. I thought that it would be easier to do it this way, but now I am not so sure. Has anyone done this? If so, how? (psuedocode is fine). Or, should I just go with the walls method, if it is easier?

Handtohand answered 21/5, 2011 at 16:40 Comment(3)
Isn't a block just a cell that has all four walls?Ion
maybe, but what if I could only delete the whole block, and not just one of its walls... good question though.Handtohand
Without more information about your particular application, it's tough to say whether you can apply that depth first maze generation algorithm. As you say, it's designed to work with cells that have individual walls rather than "blocked" cells.Ion
O
4

depending on what you actually wish to achieve i've two solutions for you. they are both basically the algorithm presented on the website you've referenced.

1.) there are blocks at predefined positions in your maze

  • you run the algorithm on a 2*k+1 grid
  • assume the numbering of your cells starts top left with (0,0). mark all cells with 2 odd coordinates ( (2*p+1, 2*q+1); p,q < k ) as blocks.
  • you run the modified algorithm from your source on the remaining cells ('even cells'). the modifications are:
    • start with an even cell picked at random
    • a 'neighbour cell' is the second but next cell in any grid direction; i.e. you 'jump' over a brick.
    • instead of knocking down the wall between cells, you turn the block into an accesible cell. however, this cell will not be considered by the selection and backtracking

2.) instead of walls separating cells you want blocks.

before starting the algorithm mark any number of cells as blocks. proceed as outlined in your source but never consider any of the block cells. you will have to take special precautions if you want want to guarantee complete accessibility in your maze. a simple scheme would be to never mark a cell as a block that has more than 1 blocks as neighbours.

hope these ideas suit your needs,

best regards, carsten

Oriental answered 26/5, 2011 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.