Okram, yo con mi Script para Competencias, que en general es bien basico, tengo problema al competir mi Script con el Tuyo, aunque cuando realizo DeeR vs DeeR , o Okram vs Okram , funcion bien.
Mira Primera Peticion Tablero Limpio
Código:
CP1:http://fdw.myokram.com.ar/gato/index.php?op=3&ob=2&tablero=a:3:{i:0;a:3:{i:0;i:0;i:1;i:0;i:2;i:0;}i:1;a:3:{i:0;i:0;i:1;i:0;i:2;i:0;}i:2;a:3:{i:0;i:0;i:1;i:0;i:2;i:0;}}
El Resultado se lo Mando a mi Tablero
Código:
CP2:http://deerme.org/gato/index.php?op=3&ob=1&tablero=a:3:{i:0;a:3:{i:0;i:0;i:1;i:0;i:2;i:2;}i:1;a:3:{i:0;i:0;i:1;i:0;i:2;i:0;}i:2;a:3:{i:0;i:0;i:1;i:0;i:2;i:0;}}
La Respuesta se la Mando al tuyo
Código:
CP1:http://fdw.myokram.com.ar/gato/index.php?op=3&ob=2&tablero=a:3:{i:0;a:3:{i:0;i:0;i:1;i:0;i:2;i:2;}i:1;a:3:{i:0;i:0;i:1;s:1:"1";i:2;i:0;}i:2;a:3:{i:0;i:0;i:1;i:0;i:2;i:0;}}
y aqui me devuelve un Tablero Vacio con tu Jugada
Código:
a:3:{i:0;a:3:{i:0;i:0;i:1;i:0;i:2;i:0;}i:1;a:3:{i:0;i:0;i:1;i:0;i:2;i:0;}i:2;a:3:{i:0;i:0;i:1;i:0;i:2;i:2;}}
Aunque con tu propio Script, hacer competir el mio contra el tuyo, funciona bien.
Pego Parte de mi Script de Server
Código PHP:
<?
// Desafio N°2 : Implementando el Script Albitro "Tres en Raya" FDW
// Autor : DeeRme
// http://deerme.org
// Variables de Entrada $_REQUEST;
// Iniciamos Session
// Implementando el Script Albitro
include('class/class.myactiverecord.php');
define('MYACTIVERECORD_CONNECTION_STR', 'mysql://user:pwpwpw@deerme/gato');
define('USUARIO', 'user');
define('PASSWORD', 'pwpwpw');
define('SERVIDOR', 'localhost');
define('BASE_DE_DATOS', 'gato');
class resultado extends MyActiveRecord
{
}
class gato
{
// Definimos Variables de la Entidad Juego
var $tablero = array (
0 => array(
0 => 0,
1 => 0,
2 => 0,
),
1 => array(
0 => 0,
1 => 0,
2 => 0,
),
2 => array(
0 => 0,
1 => 0,
2 => 0,
)
);
// Metodos
function win($quiengano)
{
// Debemos Buscar si Existe una Linea
for($ob = 1 ; $ob<3 ; $ob++)
{
// Lados
if ( $this->tablero[0][0] == $ob AND $this->tablero[0][1] == $ob AND $this->tablero[0][2] == $ob)
{
$quiengano=$ob; return TRUE;
}
if ( $this->tablero[1][0] == $ob AND $this->tablero[1][1] == $ob AND $this->tablero[1][2] == $ob)
{
$quiengano=$ob; return TRUE;
}
if ( $this->tablero[2][0] == $ob AND $this->tablero[2][1] == $ob AND $this->tablero[2][2] == $ob)
{
$quiengano=$ob; return TRUE;
}
// Abajo
if ( $this->tablero[0][0] == $ob AND $this->tablero[1][0] == $ob AND $this->tablero[2][0] == $ob)
{
$quiengano=$ob; return TRUE;
}
if ( $this->tablero[0][1] == $ob AND $this->tablero[1][1] == $ob AND $this->tablero[2][1] == $ob)
{
$quiengano=$ob; return TRUE;
}
if ( $this->tablero[0][2] == $ob AND $this->tablero[1][2] == $ob AND $this->tablero[2][2] == $ob)
{
$quiengano=$ob; return TRUE;
}
// Diagonal
if ( $this->tablero[0][0] == $ob AND $this->tablero[1][1] == $ob AND $this->tablero[2][2] == $ob)
{
$quiengano=$ob; return TRUE;
}
if ( $this->tablero[2][0] == $ob AND $this->tablero[1][1] == $ob AND $this->tablero[0][2] == $ob)
{
$quiengano=$ob; return TRUE;
}
}
// ¿ Empate ?
if ( !$this->buscar(&$this->tablero,0) )
{
// Empate
$quiengano=0;
return TRUE;
}
return 0;
}
function buscar($array,$dato)
{
foreach($array as $valor)
{
foreach ( $valor as $digito )
{
if ( $dato == $digito )
{
return TRUE;
}
}
}
return FALSE;
}
}
function generartabla($array)
{
echo '<br><table width="150" border="0" cellspacing="0" cellpadding="0" style="border:1px solid #999999">';
for($i=0;$i<3;$i++)
{
echo '<tr>';
for($j=0;$j<3;$j++)
{
echo '<td style="border:1px solid #999999">';
if ( $array[$i][$j] == 0 )
echo '<img src="img/disponible.gif" width="50" height="50" />';
elseif ( $array[$i][$j] == 1 )
echo '<img src="img/o.gif" width="50" height="50" />';
elseif ( $array[$i][$j] == 2 )
echo '<img src="img/x.gif" width="50" height="50" />';
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
}
for ($i=0;$i<5;$i++)
{
// Comenzamos el Juego
$gatito = new Gato;
$CPU1 = "http://fdw.myokram.com.ar/gato/index.php?op=3&";
$CPU2 = "http://deerme.org/gato/index.php?op=3&";
// Mientras no Exista Ganador
do {
// Entregamos Tablero a la CPU1
$url = $CPU1.'ob=2&tablero='.(serialize($gatito->tablero)).'';
$array = file_get_contents($url);
echo "CP1:".$url."<br>";
//$array = urldecode($array);
$array = unserialize($array);
$gatito->tablero = $array;
// Todo Bien hasta Aqui
generartabla(&$gatito->tablero);
// ¿ Es Posible que Gano ? Preguntamos
if ( $gatito->win(&$gano) )
break;
// Entregamos Tablero a la CPU2
$url = $CPU2.'ob=1&tablero='.(serialize($gatito->tablero)).'';
echo "CPU2:".$url."<br>";
$array = file_get_contents($url);
//$array = urldecode($array);
$array = unserialize($array);
$gatito->tablero = $array;
generartabla(&$gatito->tablero);
// Todo Bien hasta Aqui
// !$gatito->win($gano)
} while ( !$gatito->win(&$gano) );
echo '<br><br>';
switch ($gano):
case 1:
echo " Gano 1 $CPU1 V0.999";
// Gano CPU1
echo $html;
$r = new resultado;
$r->win1++;
$r->save();
break;
case 2:
echo " Gano 2 $CPU2 V0.5";
// Gano CPU2
echo $html;
$r = new resultado;
$r->win2++;
$r->save();
break;
case 0:
echo " Empate";
// Empate
$r = new resultado;
$r->emp++;
$r->save();
break;
endswitch;
// Eliminamos el Gato
unset($gatito);
}
?>
Aunq con mi Script de Albitro, funcione bien mi gato contra mi gato, o tu gato contra tu gato, q sera??
mas q nada okram revisa el paso de pasos que puse al principio de este post, las URL paso a paso, pero al final tu script me responde un tablero vacio con su jugada.
Saludos