I need to solve the mouse come out from the maze.This is my coding..Can anyone help me solve the problem??

moon5896

Estimable
Nov 10, 2014
2
0
4,510
0
C++:
#include<conio.h>
#include<stdio.h>
#define SIZE 15
#include<stdlib.h>
void main()
{
	int maze[SIZE][SIZE],mark[SIZE][SIZE],stack[SIZE][3];
	static int move[8][2]={-1,0,-1,1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
	int i,j,m,n,top,mov,g,h;
	system("cls");
	printf("enter size");
	scanf("%d%d",&m,&n);
	for(i=1;i<=m;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf("%d",&maze[i][j]);
		}
	}
	for(i=0;i<=n+1;i++)
	{
		maze[0][i]=1;
	}
	
	for(i=0;i<=n+1;i++)
	{
		maze[m+1][i]=1;
	}
	for(i=0;i<=m+1;i++)
	{
		maze[i][0]=1;
	}
	for(i=0;i<=m+1;i++)
	{
		maze[i][n+1]=1;
	}
	for(i=1;i<=m;i++)
	{
		for(j=1;j<=n;j++)
		{
			mark[i][j]=0;
		}
	}
mark[1][1]=1;
stack[0][0]=1;
stack[0][1]=1;
stack[0][2]=2;
top=1;
while(top!=0)
{
i=stack[0][0];
j=stack[0][1];
mov=stack[0][2];
top=top-1;
while(mov<=7)
{
g=i+move[mov][0];
h=j+move[mov][1];

if(mark[g][h]==0&&maze[g][h]==0)
{
mark[g][h]=1;
top++;
stack[top][0]=i;
stack[top][1]=j;
mov=-1;
i=g;j=h;
}
mov=mov+1;
if(g==m&&h==n)
{
printf("path made by the rat is");
for(i=1;i<=top;i++)
printf("%d %d",stack[i][0],stack[i][1]);
printf("%d %d",m,n);
getch();
exit(0);
}
}
}
}
C++:
 
It seems to be "a solution" for classic maze problem, implemented with local stack instead of recursively. I see following problems with it:
- there is no check that maze' sizes (m, n) are valid (positive, less than SIZE);
- there is no check that there is still free space in the stack when storing next move;
- entering initial data would be a nightmare
 
It seems to be "a solution" for classic maze problem, implemented with local stack instead of recursively. I see following problems with it:
- there is no check that maze' sizes (m, n) are valid (positive, less than SIZE);
- there is no check that there is still free space in the stack when storing next move;
- entering initial data would be a nightmare
 
Thread starter Similar threads Forum Replies Date
S Apps General Discussion 2
P Apps General Discussion 1
K Apps General Discussion 2
G Apps General Discussion 1
D Apps General Discussion 1
Rafael Mestdag Apps General Discussion 2
P Apps General Discussion 1
B Apps General Discussion 1
D Apps General Discussion 1
K Apps General Discussion 1
deramatic351 Apps General Discussion 6
K Apps General Discussion 1
L Apps General Discussion 1
L Apps General Discussion 1
tech-wreck Apps General Discussion 5
My Life Is Tech Apps General Discussion 4
drapacioli Apps General Discussion 1
delellod123 Apps General Discussion 2
P Apps General Discussion 4
nate vongrimm Apps General Discussion 2

ASK THE COMMUNITY