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
//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-Methods: GET, POST');
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");
//remplir l'array
$freeCases=array();
foreach($cases as $case){
if (!isset($_GET[$case])){
echo "wrong parameters ".$case; die;
}
if($_GET[$case]==""){
$freeCases[]=$case;
}
}
if(!isset($_GET['you'])){
echo "wrong parameters 2"; die;
}
//have all parameters lets play the game
//Stupid IA, juste random
if (count($freeCases)==0){
echo "error. la grille est déjà pleine enfoiré";
//get the query onto $message
$message=json_decode(file_get_contents('php://input'), TRUE);
if($message['action'] == "init"){
//It's the init message
echo '{"name":"stupidAI"}';
die;
}
shuffle($freeCases);
echo $freeCases[0];
$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;
}
if($message['board'][$key] == ""){
$freeCells[] = $key;
}
}
if (count($freeCells) == 0){
echo "error. Board is full i can't play";
die;
}
//Stupid IA, juste random
shuffle($freeCells);
echo '{"play":"'.$freeCells[0].'"}';