I'm trying to determine if the characters in the maze can escape, the characters are labeled by their initials except for D which is the door here is the input data:
11 13
7 10
XXXXXXXXXXXXX
X JX AX X
XXXX XXXXBX X
X X SX X X
X XXXX XXX X
X X X X
X XXXXXXXXX X
X X X
XXXXXX XXXX X
XL X
XXXXXXXDXXXXX
this is the input but the spacing is off some of the X's should be up against the right hand side the top two numbers are the size of the maze and the next two are the location of the door. I'm having a problem with my runMaze function, because it keeps returning true when really the character should not be able to escape such as in J's case where he is surrounded by X's. It keeps returning true and I have a feeling it's not checking against the X's correctly or leaving * in the worng spot and going back to the same spot????
#include <stdio.h>
void load(char x[][1000], int collum, int row, char ln );
bool runMaze(char x[][1000],int row, int collum, const int MAXR, const int MAXC);
int main()
{
int row = 0;
int collum = 0;
int doorx;
int doory;
char ln;
int jcordx, Acordx, Bcordx, Scordx, Alcordx;
int jcordy, Acordy, Bcordy, Scordy, Alcordy;
bool escapeJ = false;
bool escapeA = false;
scanf("%d", &row);
scanf("%d", &collum);
scanf("%c",ln);
scanf("%d", &doorx);
scanf("%d", &doory);
scanf("%c", &ln);
const int MAXR = row;
const int MAXC = collum;
char maze[collum][1000];
load(maze, collum, row, ln);
for (int i = 0; i < row + 1; i++ )
{
for(int j = 0; j < collum; j++ )
{
if(maze[i][j] == 'J')
{
jcordx = j;
jcordy = i;
escapeJ = runMaze(maze, collum, row, MAXR, MAXC);
}
if(maze[i][j] == 'A')
{
Acordx = j;
Acordy = i;
escapeA = runMaze(maze, collum, row, MAXR, MAXC);
}
if(maze[i][j] == 'A')
{
Acordx = j;
Acordy = i;
escapeA = runMaze(maze, collum, row, MAXR, MAXC);
}
if(maze[i][j] == 'S')
{
Scordx = j;
Scordy = i;
}
if(maze[i][j] == 'L')
{
Alcordx = j;
Alcordy = i;
}
if(maze[i][j] == 'B')
{
Bcordx = j;
Bcordy = i;
}
}
}
if(escapeJ == true)
printf("Jamie - Position(%d,%d): Escape\n", jcordx,jcordy);
else
printf("Jamie - Position(%d,%d): No Escape\n", jcordx,jcordy);
if(escapeA == true)
printf("Adam - Position(%d,%d): Escape\n", Acordx,Acordy);
else
printf("Adam - Position(%d,%d): No Escape\n", Acordx,Acordy);
printf("Sam - Position(%d,%d):\n", Scordx,Scordy);
printf("Al - Position(%d,%d):\n", Alcordx,Alcordy);
printf("Buster - Position(%d,%d):\n", Bcordx,Bcordy);
}
bool runMaze(char x[][1000],int row, int collum, const int MAXR, const int MAXC)
{
x[collum][row];
if( (row>0 && row<MAXR) && (collum>0 && collum< MAXC))
{
if( x[row][collum] == 'D' ) return true;
{
if( x[row][collum] == ' ')
if( x[row][collum] == ' ')
{
x[row][collum]='*';
runMaze(x,row, collum+1, MAXR, MAXC);
runMaze(x,row, collum-1, MAXR, MAXC);
runMaze(x,row-1, collum, MAXR, MAXC);
runMaze(x,row+1, collum, MAXR, MAXC);
}
}
}
}
void load(char x[][1000], int collum, int row, char ln)
{
x[collum][row];
for(int i = 0; i < row + 1; i++ )
{
for( int j = 0; j < collum; j++)
{
scanf("%c",&x[i][j]);
}
scanf("%c",&ln);
}
}