IAS/StupidIAconnectFour.php

33 lines
725 B
PHP
Raw Normal View History

2016-05-31 13:10:01 +02:00
<?php
2016-06-02 23:29:30 +02:00
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
2016-06-02 23:35:23 +02:00
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
2016-06-02 23:29:30 +02:00
2016-05-31 13:10:01 +02:00
/*
* stupid IA for battle ship
* choose by random a free column
*/
$in=file_get_contents('php://input');
$params=json_decode($in, TRUE);
2016-06-07 22:58:14 +02:00
switch($params['action']){
case "init":
echo "{'name':'Stupid AI'}";
break;
case "play-turn":
2016-05-31 13:10:01 +02:00
2016-06-08 16:37:28 +02:00
$grid=$params['board'];
2016-06-07 22:58:14 +02:00
$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);
2016-06-11 01:23:16 +02:00
echo '{"play":'.$colAvailable[0].'}';
2016-06-07 22:58:14 +02:00
break;
default:
break;
2016-05-31 13:10:01 +02:00
}