Maze

so the code blow generates a random maze based on a size input by the user, now my question is: how do i make sure it has at least ONE path to win it?. It might have more then one path or no path at all, so how do i ensure that? any ideas?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include<ctime>
#include<cstdlib>
using namespace std;

int main()
{
	srand(time(NULL));
	
	char obj[3]={'|','_',' '};
	int n;
	cout<<"Enter the size of the maze (nxn): ";
	cin>>n;
	
	char maze[n][n];
	
	system("cls");
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			int r=rand()%3;
			maze[i][j]=obj[r];
		}
	}
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		cout<<maze[i][j];
		
		cout<<endl;
	}
	
}
http://en.wikipedia.org/wiki/Maze_generation_algorithm
Here are some maze generation algorithms.
Topic archived. No new replies allowed.