connectfour jjson

This commit is contained in:
gnieark 2016-06-07 22:58:14 +02:00
parent 86b1f9bd8f
commit c2d3a1d8c2
2 changed files with 19 additions and 10 deletions

BIN
.tictactoe.php.kate-swp Normal file

Binary file not shown.

View File

@ -9,15 +9,24 @@ header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Ac
*/
$in=file_get_contents('php://input');
$params=json_decode($in, TRUE);
switch($params['action']){
case "init":
echo "{'name':'Stupid AI'}";
break;
case "play-turn":
$grid=$params['grid'];
$colAvailable=array();
//dont play on full colomns
for($i=0;$i<7;$i++){
if($grid[5][$i] == ""){
$colAvailable[]=$i;
}
}
//ia am stupid, just random
shuffle($colAvailable);
echo $colAvailable[0];
die;
echo '{"play":"'.$colAvailable[0].'"};
break;
default:
break;
}