开发者

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

I am trying to impleme开发者_如何学编程nt 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜