elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Re: juego del caballo en: 4 Noviembre 2016, 21:11 pm
Prueba con esta función.

Código:
void Caballo(int tab[][N], int i, int pos_x, int pos_y, int *q) {

 int k,u,v;
 k=0;
 *q=0;
 
 do {
     u=pos_x + ejex[k];  v=pos_y + ejey[k];
     if(u>=0 && u<N && v>=0 && v< N)  {
        if (tab[u][v]==0) {
           tab[u][v]=i;
           if(i< N*N)  {
              Caballo(tab,i+1,u,v,q);
              if(!(*q)) tab[u][v]=0;
             }
           else *q=1;
         }
      }
    k++;
   } while(!(*q) && k<8);
}

también ->

Código:
void Caballo(int tab[][N], int i, int pos_x, int pos_y)  {
     int k,u,v;
     k=0;
  do{
     u=pos_x + ejex[k];  v=pos_y + ejey[k];
     if(u>=0 && u<N && v>=0 && v< N)
      {
        if (tab[u][v]==0)
         {
           tab[u][v]=i;
           if(i< N*N)
             Caballo (tab, i+1 ,u ,v);
           else
              ImprimeSol(tab);
           tab[u][v]=0;
        }
     }
     k++;
   } while(k<8);
}
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines