Good, I am faced with a recursive problem to find the exit of a labyrinth in a bidimensional matrix. The legend of this labyrinth is:
'E' = entrada
'S' = salida
'#' = pared
' ' = camino
The idea is that the program marks a path that goes from the entrance to the exit and marks it with the character 'O'. The labyrinth of the matrix is perfectly generated and takes without problem the position of the entrance and the exit in the same I had thought about implementing it using backtracking but I can not apply it correctly because I can not figure out how I can execute it to work correctly. Any idea how to implement it?
Struct:
typedef struct{
char Laberinto[FIL][COL];
}Tablero;
Recursive subprogram to exit
void salir (int x,int y,int *resultado_x,int *resultado_y , Tablero *tab)
{
x = entrx; //Coordenada x de la entrada
y = entry; //Coordenada y de la entrada
if(tab->Laberinto[x][y]==' ') //camino libre { tab->Laberinto[x][y]=3;
salir(x+1,y,resultado_x,resultado_y, &*tab);
salir(x-1,y,resultado_x,resultado_y ,&*tab);
salir(x,y+1,resultado_x,resultado_y ,&*tab);
salir(x,y-1,resultado_x,resultado_y ,&*tab); }
if(tab->Laberinto[x][y]=='#') //pared
{ return; }
if(tab->Laberinto[x][y]=='o') //ya estuve aqui
{ return; }
if(tab->Laberinto[x][y]=='S') //encontre la salida {
*resultado_x=x;
*resultado_y=y; return; }
}
Subprogram that the board generates me and finds me the coordinates of the entry
void EncontrarEntradas(Tablero *tab) {
int i , j , x , y;
int entrada = 0
int entrx = 0, entry = 0;
int resultado_x = 0 , resultado_y = 0;
for(i = 0; i < FIL-1; i++)
{
for (j = 0; j < COL; j++ )
{
printf("%c",tab->Laberinto[i][j]);
if (tab->Laberinto[i][j] == 'S')
{
salx = j;
saly = i;
salida = 1;
}
if (tab->Laberinto[i][j] == 'E')
{
x = j;
y = i;
entrada = 1;
}
}
}
salir(x,y,&resultado_x,&resultado_y , &tab);
}