new specs for stupidAI
This commit is contained in:
parent
94b2791f9e
commit
978d9ce2a8
|
@ -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])){
|
||||
//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;
|
||||
}
|
||||
|
||||
$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($_GET[$case]==""){
|
||||
$freeCases[]=$case;
|
||||
if($message['board'][$key] == ""){
|
||||
$freeCells[] = $key;
|
||||
}
|
||||
}
|
||||
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é";
|
||||
|
||||
if (count($freeCells) == 0){
|
||||
echo "error. Board is full i can't play";
|
||||
die;
|
||||
}
|
||||
shuffle($freeCases);
|
||||
echo $freeCases[0];
|
||||
//Stupid IA, juste random
|
||||
shuffle($freeCells);
|
||||
echo '{"play":"'.$freeCells[0].'"}';
|
||||
|
|
Loading…
Reference in New Issue
Block a user