UNA DUDA

ORNI
30 de Abril del 2004
Tengo que hacer un laberinto en el que para hacer los caminos, tengo que meter una matrix en un fichero con unos y ceros. El1 es un camino válido y un 0 no me deja pasar. Pero, cómo puedo hacer para que me reconozca eso?


natha
30 de Abril del 2004
tengo un laverinto que te podria prestar

noel solw
30 de Abril del 2004
A continuacion que hace lo que pides. (y un poco mas).

// program k7c3 - page 135.
// recursive labyrinth.
// c++ exercices book - dr. gershon kagan - first edition : 2001
// written in Borland CPP ver 3.1

#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <dos.h>

#define M 12
#define N 10
#define B (80-3*N)/2
#define H (24-M)/2

const char *sym[] = {"²²²"," ù "," þ "};
const color[] = {LIGHTBLUE,YELLOW,LIGHTRED,LIGHTMAGENTA};

void ShowLabyrinth(char a[M+2][N+2])
{
gotoxy(B+10,3);
textcolor(color[3]);
cprintf("Labyrinth Maze");
textcolor(color[0]);
for(int i = 0; i < M+2; i++)
{
gotoxy(B,H+i);
for(int j = 0; j < N+2; j++)
cprintf(sym[a[i][j]]);
cout << endl;
}
cout << endl;
} // SHOW LABYRINTH

int OutSide(int i,int j)
{
return (i == 0) || (i == M+1) || (j == 0) || (j == N+1);
} // OUTSIDE

void Show(int i,int j,int sw)
{
gotoxy(B+j*3,H+i);
textcolor(color[sw]);
cprintf(sym[sw]);
delay(150);
} // SHOW

void Write(int i,int j)
{
static int y = 1,
x = 2;
gotoxy(x,y++);
if(y > 23)
{
x += 8;
y = 1;
}
textcolor(LIGHTGRAY);
cprintf("(%d,%d)",i+1,j+1);
}

int Process(char a[M+2][N+2],int i,int j)
{
if(!a[i][j])
return 0;
Show(i,j,1);
if(!i || !j || i == M+1 || j == N+1)
{
Show(i,j,2);
Write(i,j);
return 1;
}
a[i][j] = 0;
int ret = Process(a,i-1,j) || Process(a,i+1,j) ||
Process(a,i,j+1) || Process(a,i,j-1);
if(ret)
{
Show(i,j,2);
Write(i,j);
}
return ret;
} // PROCESS

void main()
{
char a[M+2][N+2] = {{1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,0,0,1,1,1,1,1,1},
{1,0,0,1,0,1,1,0,0,1,0,1},
{1,0,0,1,0,0,1,0,0,0,0,1},
{1,0,0,1,0,1,1,1,1,1,0,1},
{1,0,1,1,0,0,1,0,0,1,0,1},
{1,0,1,0,0,0,1,0,0,1,0,1},
{1,0,1,1,1,1,1,0,0,1,0,1},
{1,0,0,0,1,0,1,1,1,1,0,1},
{1,0,1,0,1,0,1,0,0,0,0,1},
{1,0,1,1,1,0,1,1,1,1,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1}};
clrscr();
_setcursortype(_NOCURSOR);
ShowLabyrinth(a);
Show(2,0,1);
a[2][0] = 0;
if (Process(a,2,1))
{
Show(2,0,2);
Write(2,0);
}
else
{
gotoxy(B+10,21);
textcolor(color[3]);
cprintf("path not found");
}
gotoxy(B+3,23);
textcolor(color[3]);
cprintf("end of program - good bye ! ! !n");
getch();
_setcursortype(_NORMALCURSOR);
textcolor(WHITE);
} // MAIN