fix
This commit is contained in:
parent
697395fe60
commit
3b4c14d782
|
@ -14,17 +14,33 @@ switch($params['action']){
|
||||||
echo '{"name":"Stupid AI"}';
|
echo '{"name":"Stupid AI"}';
|
||||||
break;
|
break;
|
||||||
case "play-turn":
|
case "play-turn":
|
||||||
//to do
|
|
||||||
//{"game-id":"","action":"play-turn","game":"tron","board":[[[619,240]],[[329,353]]],"player-index":0,"players":2}
|
//Input JSON exemple:
|
||||||
|
/*{
|
||||||
|
"game-id":"1647",
|
||||||
|
"action":"play-turn",
|
||||||
|
"game":"tron",
|
||||||
|
"board":[
|
||||||
|
[
|
||||||
|
[425,763],[424,763],[423,763],[422,763],[421,763],[420,763],[419,763]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[858,501],[857,501],[856,501],[855,501],[854,501],[853,501],[852,501]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"player-index":0,
|
||||||
|
"players":2}
|
||||||
|
*/
|
||||||
|
|
||||||
//put all non empty coords on array
|
//put all non empty coords on array
|
||||||
$busyCells = array();
|
$busyCells = array();
|
||||||
|
|
||||||
foreach($params['board'] as $tails){
|
foreach($params['board'] as $tail){
|
||||||
foreach($tails as $coords){
|
foreach($tail as $coord){
|
||||||
$busyCells[] = $coords;
|
$busyCells[] = $coord[0].",".$coord[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//get my head coords
|
//get my head coords
|
||||||
$myCoords = end($params['board'][$params['player-index']]);
|
$myCoords = end($params['board'][$params['player-index']]);
|
||||||
|
|
||||||
|
@ -32,18 +48,18 @@ switch($params['action']){
|
||||||
$y = $myCoords[1];
|
$y = $myCoords[1];
|
||||||
|
|
||||||
$availablesDirs = array();
|
$availablesDirs = array();
|
||||||
if (in_array(($x + 1).",".$y, $busyCells)){
|
if (!in_array(($x + 1).",".$y, $busyCells)){
|
||||||
$availablesDirs[] = "x+";
|
|
||||||
}
|
|
||||||
if (in_array(($x -1 ).",".$y, $busyCells)){
|
|
||||||
$availablesDirs[] = "x-";
|
$availablesDirs[] = "x-";
|
||||||
}
|
}
|
||||||
if (in_array($x.",".($y + 1), $busyCells)){
|
if (!in_array(($x -1 ).",".$y, $busyCells)){
|
||||||
$availablesDirs[] = "y+";
|
$availablesDirs[] = "x+";
|
||||||
}
|
}
|
||||||
if (in_array($x.",".($y - 1), $busyCells)){
|
if (!in_array($x.",".($y + 1), $busyCells)){
|
||||||
$availablesDirs[] = "y-";
|
$availablesDirs[] = "y-";
|
||||||
}
|
}
|
||||||
|
if (!in_array($x.",".($y - 1), $busyCells)){
|
||||||
|
$availablesDirs[] = "y+";
|
||||||
|
}
|
||||||
|
|
||||||
if(count($availablesDirs) == 0){
|
if(count($availablesDirs) == 0){
|
||||||
echo '{"play":"x+","comment":"I Loose"}';
|
echo '{"play":"x+","comment":"I Loose"}';
|
||||||
|
@ -51,8 +67,8 @@ switch($params['action']){
|
||||||
shuffle($availablesDirs);
|
shuffle($availablesDirs);
|
||||||
echo '{"play":"'.$availablesDirs[0].'"}';
|
echo '{"play":"'.$availablesDirs[0].'"}';
|
||||||
}
|
}
|
||||||
|
//error_log(json_encode($availablesDirs));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user