Ver Mensaje Individual
  #10 (permalink)  
Antiguo 28/03/2007, 16:22
Avatar de Falhor
Falhor
 
Fecha de Ingreso: diciembre-2005
Ubicación: Buenos Aires
Mensajes: 425
Antigüedad: 18 años, 5 meses
Puntos: 5
Re: Soluciones para el Desafío del Laberinto

Bueno, yo lo posteo acá... Obvié la parte del array para el laberinto:

Código PHP:
function dibujartodo(&$array,$p NULL){
    for(
$i=0;$i 24;$i++){
        echo(
'<br />');
        for(
$n=0;$n 24$n++){
            if(
$array[$i][$n] == 0){
                echo(
'<img src="0.jpg" width="8" height="8" alt="'.$i.' - '.$n.'" title="'.$i.' - '.$n.'">');
            }elseif(
$array[$i][$n] == 1){
                echo(
'<img src="1.jpg" width="8" height="8" alt="'.$i.' - '.$n.'" title="'.$i.' - '.$n.'">');
            }elseif(
$array[$i][$n] == 2){
                echo(
'<img src="2.jpg" width="8" height="8" alt="'.$i.' - '.$n.'" title="'.$i.' - '.$n.'">');
            }elseif(
$array[$i][$n] == 3){
                echo(
'<img src="3.JPG" width="8" height="8" alt="'.$i.' - '.$n.'" title="'.$i.' - '.$n.'">');
            }elseif(
$array[$i][$n] == 4){
                echo(
'<img src="4.jpg" width="8" height="8" alt="'.$i.' - '.$n.'" title="'.$i.' - '.$n.'">');
            }
        }
    }
}
function 
queso(&$array,$p NULL)
{
     
// Ingresar Queso al Laberinto
     
$d=count($array);
     
$t[0]=rand(0,($d-1));
     
$t[1]=rand(0,($d-1));
    if ( 
$array[$t[0]][$t[1]] == )
    {
         
// Posicion Vacia
         // Guardamos Queso
         
$array[$t[0]][$t[1]] = 2;
         global 
$quesox;
         
$quesox $t[0];
         global 
$quesoy;
         
$quesoy $t[1];
         echo(
"Posición del queso: " $t[0] . " - " $t[1] . "<br />");
         return 
TRUE;
    }      
     else
     {
        return ( 
queso($array) );
    }
}
queso($array);
function 
raton(&$array,$p NULL)
{
     
// Ingresar Raton al Laberinto
     
$d=count($array);
     
$t[0]=rand(0,($d-1));
     
$t[1]=rand(0,($d-1));
    if ( 
$array[$t[0]][$t[1]] == )
    {
         
// Posicion Vacia
         // Guardamos Raton
         
$array[$t[0]][$t[1]] = 3;
         global 
$ratonx;
         
$ratonx $t[0];
         global 
$ratony;
         
$ratony $t[1];
         echo(
"Posición inicial del ratón: " $t[0] . " - " $t[1] . "<br />");
         return 
TRUE;
    }      
     else
     {
        return ( 
raton($array) );
    }
}
raton($array);
dibujartodo($array);
echo(
"<br />");

//ESTA ES LA FUNCION QUE HACE TODO EL TRABAJO PARA ENCONTRAR EL QUESO

function mover(&$array$ratonx$ratony)
{
    for(
$i 1;$i 0;$i++){
        
$mover rand(0,3); //0 = ARRIBA, 1 = ABAJO, 2 = IZQUIERDA, 3 = DERECHA
        
if($mover == 0){
            if(
$array[$ratonx 1][$ratony] == || $array[$ratonx 1][$ratony] == 4){
                
$array[$ratonx 1][$ratony] = 4;
                
$ratonx -= 1;
            }elseif(
$array[$ratonx 1][$ratony] == 2){
                echo(
'Bien! Conseguimos el queso! A comerlo!');
                
$i = -1;
            }elseif(
$array[$ratonx 1][$ratony] == 3){
                
$ratonx -= 1;
            }
        }
        if(
$mover == 1){
            if(
$array[$ratonx 1][$ratony] == || $array[$ratonx 1][$ratony] == 4){
                
$array[$ratonx 1][$ratony] = 4;
                
$ratonx += 1;
            }elseif(
$array[$ratonx 1][$ratony] == 2){
                echo(
'Bien! Conseguimos el queso! A comerlo!');
                
$i = -1;
            }elseif(
$array[$ratonx 1][$ratony] == 3){
                
$ratonx += 1;
            }
        }
        if(
$mover == 2){
            if(
$array[$ratonx][$ratony 1] == || $array[$ratonx][$ratony 1] == 4){
                
$array[$ratonx][$ratony 1] = 4;
                
$ratony -= 1;
            }elseif(
$array[$ratonx][$ratony 1] == 2){
                echo(
'Bien! Conseguimos el queso! A comerlo!');
                
$i = -1;
            }elseif(
$array[$ratonx][$ratony 1] == 3){
                
$ratony -= 1;
            }
        }
        if(
$mover == 3){
            if(
$array[$ratonx][$ratony 1] == || $array[$ratonx][$ratony 1] == 4){
                
$array[$ratonx][$ratony 1] = 4;
                
$ratony += 1;
            }elseif(
$array[$ratonx][$ratony 1] == 2){
                echo(
'Bien! Conseguimos el queso! A comerlo!');
                
$i = -1;
            }elseif(
$array[$ratonx][$ratony 1] == 3){
                
$ratony += 1;
            }
        }
    }
}
mover($array,$ratonx,$ratony);
dibujartodo($array);
?>