#### Archived

This topic is now archived and is closed to further replies.

# Random Maze Algorithms

This topic is 5382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m currently trying to create a simple 2D maze game. I have gotten it all to work with a preset level and I am currently in the process of trying to make the levels randomize on their own. I''ve started with this code: for (loop1=0; loop1<10; loop1++) { for (loop2=0; loop2<10; loop2++) { field[loop1][loop2]=rand()%2; } } pos1=rand()%10; pos2=rand()%10; field[pos1][pos2]=3; field[0][0]=2; while (field[pos1][pos2] == field[0][0]) { pos1=rand()%10; pos2=rand()%10; field[pos1][pos2]=3; } I have a 10x10 playing field. If a square is a path, it''s 0. If it''s a wall, it''s 1. You start on the square that is 2, and you end on the square that is 3. What the above code does is just randomly place squares all around the board. The only problem is, obvously, this isn''t very efficient. There will never be a path from start to finish (well, 99.9% of the time at least). I need to somehow create checks that will make sure that there is at least one path from start to finish and that is what I''m having problems with. If anyone has any ideas as to how I could do this, please feel free to reply. Thanks a lot! -Alexis

##### Share on other sites
Hey there,

There are many good maze algorithms floating around the internet, mostly because it is a very common programming assignment in colleges. I would just google for it, and you will find a bunch of good algorithms.

-stilltjack