Programación General > C/C++
Laberinto nunca termina ciclo porfavor leer codigo T_T
(1/1)
punketo666:
Buenas pues he intentado hacer un laberinto pero no he podido, se supone que con la funcion random hago que nunca sea el mismo pero no he podido porfavor si ven algun error
estoy trabajando con dev c
--- Código: C++ ---#include <stdlib.h>#include <stdio.h> int main(){ int i,j,tablero[50][50],mov,der,izq,c; //RELLENAR EL TABLERO DE MUROS// for(i=0;i<10;i++) { for(j=0;j<10;j++) { tablero[i][j]=1;//MUROS=1..............ESPACIO=2// } } tablero[0][0]=3; tablero[9][9]=4; i=0; j=0; der=0; izq=0; c=0; while(c==0) { mov=rand()%3+1; if((mov==1 && tablero[i][j+1]==1) && (tablero[i][j-1]==1) && tablero[i+1][j]==1)//abajo { if(i+1<=8) { tablero[i+1][j]=2; i=i+1; der=0; izq=0; } } if(mov==2 && tablero[i][j+1]==1 && tablero[i][j-1]==1 && tablero[i+1][j]==1)//izquierda { if(j-1>=0) { tablero[i][j-1]=2; j=j-1; der=1; izq=1; } } if(mov==3 && tablero[i][j+1]==1 && tablero[i][j-1]==1 && tablero[i+1][j]==1)//derecha { if(j+1<=8) { tablero[i][j+1]=2; j=j+1; der=1; izq=1; } } if(tablero[9][8]==2 || tablero[8][9]==2) { c=c+1; } } for(i=0;i<10;i++) { for(j=0;j<10;j++) { if(tablero[i][j]==2) { printf(" "); } if(tablero[i][j]==3) { printf("E"); } if(tablero[i][j]==4) { printf("S"); } if(tablero[i][j]==1) { printf("*"); } } printf("n"); } system ("pause"); return 0; }
m0skit0:
Formatea tu código y ponle las etiquetas de código si pretendes que alguien lo lea, por favor.
Navegación
Ir a la versión completa