By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,420 Members | 1,130 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,420 IT Pros & Developers. It's quick & easy.

Problem writing in the trail of matrix of maze program

P: 1
Hi
im an IT student.I have registered as a member of this site recently.I have a question about the solution of maze program. I want to write maze program in c++ .I want to solve the maze class includes two methods: 1)makeMaze & 2)runMaze.
I write the method of makeMaze in a way that fulls a n*n matrix.
one of my problem is about the writing the code of dynamic 2D array allocation .
an another is about the writing the method of runMaze in a way that finds the path for movment and then print this in a trail of matrix and as we know the "main" is necessary to write it.
I saw the maze program that you have written in the part of "c++ maze program"
but the code of that post dosent follow the path of movment in a trail of matrix.
here is the code:


#include<iostream.h>
#include<conio.h>
#include<stdlib.h>

class maze {
int a[100][100];
public:
void makeMaze();
void runMaze(int row, int col);
};
//************************************************** *
void maze :: makeMaze()
{
clrscr();
srand(time(0));
int maze[10][10]={0};
int i,j=0;
for( i=0;i<10;i++)
for(j=0;j<10;j++)
maze[i][j] =random(2);
for( i=0;i<10;i++){
for(j=0;j<10;j++)
cout<<maze[i][j]<<"\t";
cout<<endl<<endl;
}
}
//************************************************** ***
void maze :: runMaze(int row, int col)
{
// int col = 1;
// int row = 2;

if( (row>0 && row<10) && (col>0 && col<10)) {
if( a[row][col] == 'W' ) return;

if( a[row][col] == ' ') {
a[row][col]='*';

runMaze(row, col+1);
runMaze(row, col-1);
runMaze(row-1, col);
runMaze(row+1, col);
}
}
}
//************************************************** *****
int main()
{
clrscr();
maze m;
m.makeMaze();
m.runMaze(1, 2);
getch();
return 0;
}
Im in a hurry.
please help me to solve this qustion very soon.
thank you
Jun 4 '07 #1
Share this Question
Share on Google+
1 Reply


DeMan
100+
P: 1,806
Hi Daneshjo,

Welcome to thescripts. As this question is c/c++ related, I will now move it to the appropriate forum. While you will still be able to find this question from the link here, any future posts can be made directly to the technical forums (which can be found from the links on the blue bar near the top of your screen).

I hope the c/c++ experts can help you with your enquiry!!
Jun 4 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.