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?
Share
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
2*k+1gridmark all cells with 2 odd coordinates (
(2*p+1, 2*q+1); p,q < k) as blocks.the modifications are:
i.e. you ‘jump’ over a brick.
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