new specs for stupidAI
This commit is contained in:
parent
94b2791f9e
commit
978d9ce2a8
|
@ -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 "wrong parameters ".$case; die;
|
echo '{"name":"stupidAI"}';
|
||||||
}
|
|
||||||
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é";
|
|
||||||
die;
|
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].'"}';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user