connectfour jjson
This commit is contained in:
parent
86b1f9bd8f
commit
c2d3a1d8c2
BIN
.tictactoe.php.kate-swp
Normal file
BIN
.tictactoe.php.kate-swp
Normal file
Binary file not shown.
|
@ -9,15 +9,24 @@ header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Ac
|
||||||
*/
|
*/
|
||||||
$in=file_get_contents('php://input');
|
$in=file_get_contents('php://input');
|
||||||
$params=json_decode($in, TRUE);
|
$params=json_decode($in, TRUE);
|
||||||
$grid=$params['grid'];
|
switch($params['action']){
|
||||||
$colAvailable=array();
|
case "init":
|
||||||
|
echo "{'name':'Stupid AI'}";
|
||||||
|
break;
|
||||||
|
case "play-turn":
|
||||||
|
|
||||||
for($i=0;$i<7;$i++){
|
$grid=$params['grid'];
|
||||||
if($grid[5][$i] == ""){
|
$colAvailable=array();
|
||||||
$colAvailable[]=$i;
|
//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 '{"play":"'.$colAvailable[0].'"};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
shuffle($colAvailable);
|
|
||||||
echo $colAvailable[0];
|
|
||||||
die;
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user