Because these two days want to participate in a competition, so on the Internet to find material, just see the maze generated, decided to take this surgery.
The original address of the reference is (source page)
The source address is used as the implementation of, did not learn as, so directly will not run, so they are based on the concept of the original model (Chao) imitation (xi).
The crap is over, now let's talk about the principle of the stochastic prim method:
1. Create two arrays, one for storing the map's two-dimensional array α, and the other for storing the array β for the wall to be processed.
2. Initialize all squares of α to the wall.
3. Select the starting point and turn the wall of the position into a path, placing the four blocks around it into the beta array (the direct sieve out of bounds is not said).
4. When the beta array is not empty, loop the following steps
1) Randomly select a piece from the beta array and call him a.
2) walk around the block and select one of the blocks for the road, and call him B.
3) Judging relative to a, the square C on the opposite side of B is a wall (if B is on the left side of a, it will determine the square on the right of A, b above a, a block under a; ), if it is a wall, then:
① both A and C are the roads.
② all squares around C that are walls, placed in a beta array.
4) Remove a from the beta array.
After execution, the maze is created.
At present, I still only completed the goal of 10% less than the target, now this version can only generate a maze, and the code is not enough optimization. Follow up slowly (without prejudice to the competition) until the entire project is finished.
Source Address:
http://pan.baidu.com/share/link?shareid=4019441680&uk=756504557
Random Prim method to create random maze (C # implementation)