• Viernes 3 de Mayo de 2024, 07:20

Autor Tema:  Laberinto nunca termina ciclo porfavor leer codigo T_T  (Leído 1553 veces)

punketo666

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Laberinto nunca termina ciclo porfavor leer codigo T_T
« en: Lunes 13 de Diciembre de 2010, 02:11 »
0
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++
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4.  
  5. int main()
  6. {
  7.     int i,j,tablero[50][50],mov,der,izq,c;
  8.    
  9.     //RELLENAR EL TABLERO DE MUROS//
  10.     for(i=0;i<10;i++)
  11.     {
  12.                      for(j=0;j<10;j++)
  13.                      {
  14.                                       tablero[i][j]=1;//MUROS=1..............ESPACIO=2//
  15.                      }
  16.     }
  17.     tablero[0][0]=3;
  18.     tablero[9][9]=4;
  19.    
  20.    
  21.     i=0;
  22.     j=0;
  23.     der=0;
  24.     izq=0;
  25.     c=0;
  26.    
  27.     while(c==0)
  28.     {
  29.            mov=rand()%3+1;
  30.            if((mov==1 && tablero[i][j+1]==1) && (tablero[i][j-1]==1) && tablero[i+1][j]==1)//abajo
  31.            {
  32.                      if(i+1<=8)
  33.                      {
  34.                             tablero[i+1][j]=2;
  35.                             i=i+1;
  36.                             der=0;
  37.                             izq=0;
  38.                      }
  39.            }
  40.            if(mov==2 && tablero[i][j+1]==1 && tablero[i][j-1]==1 && tablero[i+1][j]==1)//izquierda
  41.            {
  42.                      if(j-1>=0)
  43.                      {
  44.                                tablero[i][j-1]=2;
  45.                                j=j-1;
  46.                                der=1;
  47.                                izq=1;
  48.                      }
  49.            }
  50.            if(mov==3 && tablero[i][j+1]==1 && tablero[i][j-1]==1 && tablero[i+1][j]==1)//derecha
  51.            {
  52.                        if(j+1<=8)
  53.                        {
  54.                                  tablero[i][j+1]=2;
  55.                                  j=j+1;
  56.                                  der=1;
  57.                                  izq=1;
  58.                        }
  59.            }
  60.            
  61.            if(tablero[9][8]==2 || tablero[8][9]==2)
  62.            {
  63.                                c=c+1;
  64.            }
  65.     }
  66.                      
  67.    
  68.    
  69.     for(i=0;i<10;i++)
  70.     {
  71.                      for(j=0;j<10;j++)
  72.                      {
  73.                                       if(tablero[i][j]==2)
  74.                                       {
  75.                                                           printf(" ");
  76.                                       }
  77.                                       if(tablero[i][j]==3)
  78.                                       {
  79.                                                           printf("E");
  80.                                       }
  81.                                       if(tablero[i][j]==4)
  82.                                       {
  83.                                                           printf("S");
  84.                                       }
  85.                                       if(tablero[i][j]==1)
  86.                                       {
  87.                                                           printf("*");
  88.                                       }
  89.                      }
  90.                      printf("n");
  91.     }
  92.    
  93.     system ("pause");
  94.     return 0;
  95.     }
  96.  
« última modificación: Lunes 13 de Diciembre de 2010, 16:42 por punketo666 »

m0skit0

  • Miembro de PLATA
  • *****
  • Mensajes: 2337
  • Nacionalidad: ma
    • Ver Perfil
    • http://fr33kk0mpu73r.blogspot.com/
Re: Laberinto nunca termina ciclo porfavor leer codigo T_T
« Respuesta #1 en: Lunes 13 de Diciembre de 2010, 09:00 »
0
Formatea tu código y ponle las etiquetas de código si pretendes que alguien lo lea, por favor.