# Thread: Help solving a maze!

1. ## Help solving a maze!

Hi, i have a question i need to create a program that creates a maze which i can design my self i used this design:
@@@@@@
@S@xxxx@
@x@xxxx@ @=walls
@xxxxxxx@ S=Start
@xxxxxxE@ E=End
@@@@@@ x=emptyspace or ' ' in matrix

and i have all those values on a matrix, but can anyone give me an insight on how can i solve this maze, i mean how should the north.south,east,west, functions be more less, because really i have no idea. thank you very much in advance! hope someone can help

2. Look up the A* (A star) algorithm on Google.

3. ## What i have so far

It just goes around in a square, any idea how to make it move all around the maze?

Code:
```#include <stdio.h>
#include <string.h>

#define COLMAX 8
#define RENMAX 8

void Laberinto(char Lab[COLMAX][RENMAX]);
void BuscarEntrada(char Lab[COLMAX][RENMAX], int PosE[1][1]);
void BuscarSalida(char Lab[COLMAX][RENMAX], int PosE[1][1]);

main()
{
char Lab[COLMAX][RENMAX];
int PosE[1][1];
Laberinto(Lab);
BuscarEntrada(Lab, PosE);
BuscarSalida(Lab, PosE);
}

void Laberinto(char Lab[COLMAX][RENMAX])
{
int i,j;
for (i=0,j=0; j<8; j++)
Lab[i][j]='@';
Lab[1][0]='@';
Lab[1][1]='E';
Lab[1][2]=' ';
Lab[1][3]=' ';
Lab[1][4]=' ';
Lab[1][5]=' ';
Lab[1][6]=' ';
Lab[1][7]='@';
Lab[2][0]='@';
Lab[2][1]=' ';
Lab[2][2]=' ';
Lab[2][3]=' ';
Lab[2][4]=' ';
Lab[2][5]=' ';
Lab[2][6]=' ';
Lab[2][7]='@';
Lab[3][0]='@';
Lab[3][1]=' ';
Lab[3][2]='@';
Lab[3][3]='@';
Lab[3][4]='@';
Lab[3][5]=' ';
Lab[3][6]=' ';
Lab[3][7]='@';
Lab[4][0]='@';
Lab[4][1]=' ';
Lab[4][2]=' ';
Lab[4][3]=' ';
Lab[4][4]=' ';
Lab[4][5]=' ';
Lab[4][6]=' ';
Lab[4][7]='@';
Lab[5][0]='@';
Lab[5][1]=' ';
Lab[5][2]=' ';
Lab[5][3]=' ';
Lab[5][4]=' ';
Lab[5][5]=' ';
Lab[5][6]=' ';
Lab[5][7]='@';
Lab[6][0]='@';
Lab[6][1]=' ';
Lab[6][2]=' ';
Lab[6][3]=' ';
Lab[6][4]=' ';
Lab[6][5]=' ';
Lab[6][6]=' ';
Lab[6][7]='@';
for (i=7,j=0; j<8; j++)
Lab[i][j]='@';
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
printf("%c",Lab[i][j]);
}
printf("\n");
}
}

void BuscarEntrada(char Lab[COLMAX][RENMAX], int PosE[1][1])
{
int i,j;
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
if (Lab[i][j]=='E') {
PosE[0][0]=i;
PosE[1][0]=j;
}
}
}
}

void BuscarSalida(char Lab[COLMAX][RENMAX], int PosE[1][1])
{
while (Lab[PosE[0][0]][PosE[1][0]]!='@') {
PosE[1][0]++;
printf("%d",PosE[1][0]);
if(Lab[PosE[0][0]][PosE[1][0]]=='S')
printf("Ganaste");
}
PosE[1][0]--;
while (Lab[PosE[0][0]][PosE[1][0]]!='@') {
PosE[0][0]++;
printf("%d",PosE[0][0]);
if(Lab[PosE[0][0]][PosE[1][0]]=='S')
printf("Ganaste");
}
PosE[0][0]--;
while (Lab[PosE[0][0]][PosE[1][0]]!='@') {
PosE[1][0]--;
printf("%d",PosE[1][0]);
if(Lab[PosE[0][0]][PosE[1][0]]=='S')
printf("Ganaste");
}
}```

Popular pages Recent additions