Hi.. i am totally lost with this random 20x70 maze generator i have to create.
can some one give me some insight on how im supposed to start this?
i know i use 2 for loops but my question is.. how do i create the actual blank space maze pattern.

Hi,
Just to get you started, have a look at this, i coded this in 10 mins so it is not complete at all but if you think for few mins, you can create maze using it.
Run this program and you will see what I am trying to say

#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main()
{
  char MAZE[20][70];

  int i,j,k,R_Num[3];

  /* Simple "srand()" seed: just use "time()" */
  unsigned int iseed = (unsigned int)time(NULL);
  srand (iseed);

 


  for(i=0;i<20;i++)
  {
		for (k=0; k<3; k++)
		{
		    R_Num[k] = 1 + (int)( 70.0 * rand() / ( RAND_MAX + 1.0) );
		} 
	  
		
		for(j=0;j<70;j++)
		{
	        if(j==R_Num[0]||j==R_Num[1]||j==R_Num[2])
			{
			     cout<<" ";
			
			}
		
			else
			{
			     cout<<"_";
			
			}
	  
		}
          cout<<"\n";
  }


return 0;
}

thanx software guy..u were alot of help... i came up with this here.

now. i wanna create a recursive function 2 find a path through the maze
i know its going to b using the x y coordinates of the array to find the position of the path but how do i write that in code?


any insight?

#include <iostream>
#include <ctime>
using namespace std;


void path(char array[20][70, int, int, int, int );

int main()
{
	srand( (unsigned)time( NULL ) );

	char maze[20][70];
	
	for (int i =0; i<20; i++)
	{
		for(int j =0; j<70; j++)
		{
			int x=rand()%2;
				
			if (x==0)
			
				maze[i][j]=' ';
			
			else
			
				maze[i][j]='#';
			
		
	cout<<maze[i][j];


		}
	}
	cout<<endl;

void path(

ok guys... finished the actual code but im getting a problem ... tell me what you think i should do to fix

//Program to generate a random 20x70 maze and find a path through it.

#include <iostream>
#include <ctime>
using namespace std;


void startfinish( char array[][70], int startx, int starty, int finshx , int finishy ); //start finish function prototype 
void path(char paths[][70], int sx, int sy, int fx , int fy); //path recursion prototype

int main()// begin program
{
	srand( (unsigned)time( NULL ) );// seed generator

	char maze[20][70]={}; // declare and initiliaze 20x70 maze array
	

	int col=20; //column variable initilized to 20 
	int row=70; //row variable initilized to 70
	int xstart; //variable to hold path start x coordinate
	int xfinish;// variable to hold path finish x coordinate
	int ystart; //variable to hold path start y coordinate
	int yfinish; //variable to hold path finish y coordinate

	int i; //i counter
	int j; //j counter


	for (i= 0; i<col; i++) //column for loop
	{
		cout<<endl;
		for( j =0; j<row; j++) //row for loop
		{
			int x=rand()%2; //random number generator devided by 2 and remainder passed to x
				
			if (x==0) //if remainder = 0
			
				maze[i][j]=' '; //pass blank charater to current position in array
			
			else
			
				maze[i][j]='#'; //else pass hash charater to current position in array
				
				cout<<maze[i][j]; //display maze to screen

		
			
		}
		
	}
	
	cout<<endl;
	cout<<"------------------------------------------------------------------\n";
	
	
	
	cout<<"Enter path starting and finishing points x and y:"<<endl; //enter paths begining and end
	cout<<"Starting Coloumn (down): "<<endl; 
	cin>>xstart; //get start point x from user
	
	cout<<endl;
	
	cout<<"Starting Row (accros): "<<endl;
	cin>>ystart; // get start point y from user
	
	cout<<endl;
	
	cout<<"Finish Column: "<<endl;
	cin>>xfinish; // get finish point x from user
	
	cout<<endl;
	
	cout<<"Finish Row: "<<endl;
	cin>>yfinish; // get finish point y from user
	cout<<endl;
	
			
	startfinish(maze,xstart,ystart,xfinish,yfinish); //call start finish function holding array and start and finish coordinates
		
	cout<<endl;
	
	return 0;

}// end program


void startfinish( char array[][70], int startx, int starty, int finishx , int finishy ) //start finish fucntion
{
	
	if (array[startx][starty]==' ' && array[finishx][finishy]==' ') //if start and finish = blanck charater
	{
		array[startx][starty]='B'; //let start hold B
		array[finishx][finishy]='E'; // let finish hold E
		path(array,startx,starty,finishx,finishy); //call path function holding array and coordiantes

	}
	else (array[startx][starty]=='#' && array[finishx][finishy]=='#'); //if start and finish = #
	{
		
		cout<<"Error no start point found please rerun program to try again"<<endl; //exit 
	
	}	
	
	return ;
	

}	// end function



void path(char paths[][70], int sx, int sy, int fx , int fy) //recursive path function 
{
	if ((sx==fx)&&(sy==fy)) //if start == finish
	{
		for(int i=0; i<20; i++)
		{
			cout<<endl;
			for(int j=0;j<70; j++)
			{
				cout<<paths[i][j]; // display maze with path
			}
		}
	else 
	{
		if (paths[sx+1][sy]==' ') //if path is blank charater move up once space
			paths[sx+1][sy]='+'; //mark position
			path( paths,sx+1,sy,fx,fy ); // call path function
	

		if (paths[sx][sy+1]==' ') //if path is blank charater move one space to the left
			paths[sx][sy+1]='+'; //mark position
			path( paths,sx,sy+1,fx,fy ); // call path function
	

		if (paths[sx-1][sy]==' ') //if path is blank charater move down space to the left
			paths[sx-1][sy]='+'; //mark position
			path( paths,sx-1,sy,fx,fy ); // call path function
	

		if (paths[sx][sy-1]==' ') //if path is blank charater move one space to the right
			paths[sx][sy-1]='+'; //mark position
			path( paths,sx,sy-1,fx,fy ); // call path function


	}

	
} //end function
This article has been dead for over six months. Start a new discussion instead.