new specs for stupidAI

This commit is contained in:
Gnieark 2016-06-04 22:58:46 +02:00
parent 94b2791f9e
commit 978d9ce2a8

View File

@ -1,27 +1,37 @@
<?php <?php
//headers for permit CORS,
//This permit me to test this bot, using this web page
//https://botsarena.tinad.fr/testBotScripts/tictactoe.html
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST'); header('Access-Control-Allow-Methods: GET, POST');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
$cases=array("0-0","0-1","0-2","1-0","1-1","1-2","2-0","2-1","2-2"); //get the query onto $message
//remplir l'array $message=json_decode(file_get_contents('php://input'), TRUE);
$freeCases=array();
foreach($cases as $case){ if($message['action'] == "init"){
if (!isset($_GET[$case])){ //It's the init message
echo '{"name":"stupidAI"}';
die;
}
$cellsKeys=array("0-0","0-1","0-2","1-0","1-1","1-2","2-0","2-1","2-2");
//list the free cells
$freeCells=array();
foreach($cellsKeys as $key){
if (!isset($message['board'][$key])){
echo "wrong parameters ".$case; die; echo "wrong parameters ".$case; die;
} }
if($_GET[$case]==""){ if($message['board'][$key] == ""){
$freeCases[]=$case; $freeCells[] = $key;
} }
} }
if(!isset($_GET['you'])){
echo "wrong parameters 2"; die; if (count($freeCells) == 0){
} echo "error. Board is full i can't play";
//have all parameters lets play the game
//Stupid IA, juste random
if (count($freeCases)==0){
echo "error. la grille est déjà pleine enfoiré";
die; die;
} }
shuffle($freeCases); //Stupid IA, juste random
echo $freeCases[0]; shuffle($freeCells);
echo '{"play":"'.$freeCells[0].'"}';