I have difficulties solving this program, so I'll be very happy if someone h
elps me.
Thanks in advance!

Find a way in a maze

Write a program that finds way between two points in certain maze.
The maze is rectangular matrix which consists of cells. Each cell is from on
e of the following 4 types and it can be represented with one positive numbe
r.
1.Void (blank space) – This cell is empty and you can go through it. Repres
ented by 0 (zero).
2.Wall – in this cell there is a wall and you can’t go through it. Represen
ted by 100.
3.Key – this cell contains a key with given number. You can go through it,
and when you do that a “door with corresponding number to the key opens. Re
presented by the numbers from 1 to 20. Key number 1, 2, ………20.
4.Door – this cell is a wall. You can walk through it only if you walked on
key which is corresponding to this wall. Represented by the numbers from 10
1 to 120, respectively for wall number 101, 102, 103, ……….120.
In the maze there can not be more than 20 walls, and 20 keys.

Information for the maze can be written in text file according to this forma
t:
On the first line there are 2 positive integer numbers N(3 < N < 10)- the wi
dth of the maze and M(3 < M < 10)- length of the maze. Followed by 4 numbers

SX(0 < SX < N) , SY(0 < SY < M) , TX(0 < TX < N) , TY(0 < TY < M),
which are the start position (SX, SY) and the final position (TX, TY) in the
maze. These are the two positions between you have to find a way.
Then there is M in number of lines with N in numbers of numbers on each line
. They describe the contents of each cell of the maze as it is described in
1(void), 2(wall), 3(key), 4(door).

Recommended Answers

All 4 Replies

You should try it yourself first.
First write the steps you would take, if you were to do it in real life. You can do it in a spoken language you are familar with.
After writing it, then try to convert it to C/C++.
If you try it yourself, and find you are stuck somewhere, post your attempts, and we will help if we are convinced that you deserve help.

I don't understand very much of programming. I have this and I still can't do the program. The bold places are tips for what I have to do but I can't. It's a project for school and I really need help.

bool LabPath(  int [][] maze, int[][] Path, int xpos, int ypos )
{
	int [][] TempMaze = maze[][];
	int [][] TempPath = Path[][];	

	if (  xpos == xend and ypos == yend   )
	{
		[B]You add maze[xpos][ypos] to TempPath[][][/B]
		solution[][] = TempPath[][];
		return true;
	}
	
	if ( TempMaze[xpos][ypos] >= 100 and TempMaze[xpos][ypos] <= 120 )
		return False;

	if (  TempMaze [xpos][ypos] >= 1 and TempMaze[xpos][ypos] <= 20 )
	{
		[B]in TempMaze[][] you find the cell with value = ( TempMaze [xpos][ypos] +100 ) and you give it a value = 0
		the door is open
		for( i ... )
			for(  j ... )[/B]
				if ( TempMaze [i][j] == ( TempMaze [xpos][ypos] +100 ))
					 TempMaze [i][j] = 0;
	
	}
	// the visited cells in the maze we mark with 40
	if ( TempMaze [xpos][ypos] == 40 )
		return False;
	else
	{
		TempMaze[xpos][ypos] = 40;
		[B]add [xpoa, ypos] to TempPath[][]; [/B] 
		return 	LabPath(  TempMaze, TempPath,  xpos + 1,  ypos ) or
			LabPath(  TempMaze, TempPath,  xpos  - 1,  ypos  ) or
			LabPath(  TempMaze, TempPath,  xpos,  ypos +1 ) or
			LabPath(  TempMaze, TempPath,  xpos,  ypos -  1 ) 

	
	}

}

	// global variables
	int lab[][];
	int lab1[][];
	int path1[][] =[];
	int solution[][] = [];
	int xbegin, xend, ybegin, yend; 

main( argc, argv )
{
  	
	[B]Open fail in.txt for reading
	lab[M][N] = data for the maze
	xbegin, ybegin = start position
	xend, yend = end position
	
you create lab1[M+2][N+2] array and you copy the whole lab[m][n] in it from position (1, 1) to (M,N), and the points on the walls of the new array lab1[][] you mark them as walls. They are = 100(you surround the array with wall, it is needed so that the function can work)[/B]

	LabPath( lab1, path1, xbegin, ybegin );

	if ( solution[][] = [] )
		Nosolution
	else
	{
		[B]You open out.txt

		Write down the found way from solution[][], and this solution is for lab1 array, it is with bigger size then the needed array so, you must take out 1 from the coordinates of the found solution on the axis X and Y[/B]
	}
}

I read it and I still can't do it myself. I'm sorry but not everyone understands this kind of stuff. I just need help, if someone needs help ypu held him/her don't attack them, so if you can't help don't attack me with, read your textbook or do it yourself because if I can do it myself i won't ask for help.

Can anyone give any suggestions on how to find your way through a maze by using

commented: Nope -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.