.
This commit is contained in:
parent
63480be4c5
commit
df29fb61cc
|
@ -94,6 +94,9 @@ switch($message['action']){
|
|||
}
|
||||
$$key=$message['board'][$key];
|
||||
}
|
||||
if(!preg_match('/^[0-9]+-(1|2)$/',$match_id)){
|
||||
echo "parametre incorrect"; die;
|
||||
}
|
||||
|
||||
if(!is_it_possible_to_place_ships_on_grid($width,$height,$ship1,$ship2,$ship3,$ship4,$ship5,$ship6)){
|
||||
echo "I don't want play this game";
|
||||
|
@ -207,12 +210,12 @@ switch($message['action']){
|
|||
}
|
||||
|
||||
|
||||
echo json_encode(array("name" => "gnieark", "boats" => $shipsCoords));
|
||||
echo json_encode(array("name" => "gnieark", "boats" => $shipsCoords);
|
||||
break;
|
||||
case "play-turn":
|
||||
case "fight":
|
||||
//for debog arena
|
||||
|
||||
echo '{"play":"'.rand(0,$message['board']['width'] -1).",".rand(0,$message['board']['height'] -1).'"}';
|
||||
echo rand(0,$_POST['width'] -1).",".rand(0,$_POST['height'] -1);
|
||||
|
||||
|
||||
die;
|
||||
|
|
|
@ -147,11 +147,13 @@ function analize($line,$me,$opponent,$isVertical,$decalageX){
|
|||
static $colForNoLose1 = array();
|
||||
static $canWinDepth1 = array();
|
||||
|
||||
global $params;
|
||||
|
||||
if(count(can_win($line,$me,0)) > 0){
|
||||
if($isVertical){
|
||||
echo '{"play":'.$decalageX.'}';
|
||||
play($params['board'],$decalageX,$me,$opponent,$params['game-id'],$params['player-index']);
|
||||
}else{
|
||||
echo '{"play":'.(can_win($line,$me,0)[0] + $decalageX).'}';
|
||||
play($params['board'],(can_win($line,$me,0)[0] + $decalageX),$me,$opponent,$params['game-id'],$params['player-index']);
|
||||
}
|
||||
die;
|
||||
|
||||
|
@ -382,12 +384,12 @@ switch($params['action']){
|
|||
$intersection = array_intersect($choice['colForNoLose'],$colAvailable);
|
||||
if(count($intersection) > 0){
|
||||
shuffle($intersection);
|
||||
echo '{"play":'.$intersection[0].'}';
|
||||
play($params['board'],$intersection[0],$params['you'],$opponent,$params['game-id'],$params['player-index']);
|
||||
die;
|
||||
}else{
|
||||
//on pourra perdre au prochain tour, tant pis
|
||||
shuffle($choice['colForNoLose']);
|
||||
echo '{"play":'.$choice['colForNoLose'][0].'}';
|
||||
play($params['board'],$choice['colForNoLose'][0],$params['you'],$opponent,$params['game-id'],$params['player-index']);
|
||||
die;
|
||||
}
|
||||
|
||||
|
@ -399,28 +401,28 @@ switch($params['action']){
|
|||
$intersection = array_intersect($colForNoLose1,$colAvailable,$canWinDepth1);
|
||||
if(count($intersection) > 0){
|
||||
shuffle($intersection);
|
||||
echo '{"play":'.$intersection[0].'}';
|
||||
play($params['board'],$intersection[0],$params['you'],$opponent,$params['game-id'],$params['player-index']);
|
||||
die;
|
||||
}
|
||||
|
||||
$intersection = array_intersect($colForNoLose1,$colAvailable);
|
||||
if(count($intersection) > 0){
|
||||
shuffle($intersection);
|
||||
echo '{"play":'.$intersection[0].'}';
|
||||
play($params['board'],$intersection[0],$params['you'],$opponent,$params['game-id'],$params['player-index']);
|
||||
die;
|
||||
}
|
||||
|
||||
$intersection = array_intersect($colForNoLose1,$canWinDepth1);
|
||||
if(count($intersection) > 0){
|
||||
shuffle($intersection);
|
||||
echo '{"play":'.$intersection[0].'}';
|
||||
play($params['board'],$intersection[0],$params['you'],$opponent,$params['game-id'],$params['player-index']);
|
||||
die;
|
||||
}
|
||||
|
||||
//still there? random
|
||||
|
||||
shuffle($colAvailable);
|
||||
echo '{"play":'.$colAvailable[0].'}';
|
||||
play($params['board'],$colAvailable[0],$params['you'],$opponent,$params['game-id'],$params['player-index']);
|
||||
|
||||
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue
Block a user