Random Prim method to create random maze (C # implementation)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.