loop for the two players
This commit is contained in:
parent
0c4e3396e8
commit
5349d192a8
|
@ -62,15 +62,21 @@ switch ($_POST['act']){
|
|||
$_SESSION['matchId']=get_unique_id();
|
||||
|
||||
|
||||
for($player = 1; $player <= 2; $player++){
|
||||
|
||||
// get_IA_Response($iaUrl,$postParams)
|
||||
//array à envoyer au bot 1
|
||||
if($player==1){
|
||||
$opponentName=$bot2['name'];
|
||||
$currentBot=$bot1;
|
||||
}else{
|
||||
$opponentName=$bot1['name'];
|
||||
$currentBot=$bot2;
|
||||
}
|
||||
|
||||
$bot1ParamsToSend=array(
|
||||
$botParamsToSend=array(
|
||||
'game' => 'Battleship',
|
||||
'match_id' => $_SESSION['matchId']."-1",
|
||||
'act' => 'init',
|
||||
'opponent' => $bot2['name'],
|
||||
'opponent' => $opponentName,
|
||||
'width' => $postValues['gridWidth'],
|
||||
'height' => $postValues['gridHeight'],
|
||||
'ship1' => $postValues['nbShip1'],
|
||||
|
@ -81,18 +87,22 @@ switch ($_POST['act']){
|
|||
'ship6' => $postValues['nbShip6']
|
||||
|
||||
);
|
||||
$anwserPlayer1=get_IA_Response($bot1['url'],$bot1ParamsToSend);
|
||||
$boatsPlayer1 = json_decode( html_entity_decode($anwserPlayer1));
|
||||
if(!$boatsPlayer1){
|
||||
echo $bot1['name']." a fait une réponse non conforme, il perd.".$anwserPlayer1;
|
||||
$anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend);
|
||||
$boatsPlayer = json_decode( html_entity_decode($anwserPlayer));
|
||||
if(!$boatsPlayer){
|
||||
echo $currentBot['name']." a fait une réponse non conforme, il perd.";
|
||||
if($player==1){
|
||||
save_battle('Battleship',$bot1['name'],$bot2['name'],2);
|
||||
}else{
|
||||
save_battle('Battleship',$bot1['name'],$bot2['name'],1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//vérifier si'il y a le bon nombre de bateaux
|
||||
$nbBoatsIwant=array(0,$postValues['nbShip1'],$postValues['nbShip2'],$postValues['nbShip3'],
|
||||
$postValues['nbShip4'],$postValues['nbShip5'],$postValues['nbShip6']);
|
||||
foreach($boatsPlayer1 as $boat){
|
||||
foreach($boatsPlayer as $boat){
|
||||
list($startCoord,$endCoord) = explode("-",$boat);
|
||||
list($xStart,$yStart)=explode(",",$startCoord);
|
||||
list($xEnd,$yEnd)=explode(",",$endCoord);
|
||||
|
@ -105,8 +115,13 @@ switch ($_POST['act']){
|
|||
}
|
||||
foreach($nbBoatsIwant as $nb){
|
||||
if($nb <> 0){
|
||||
echo $bot1['name']." n'a pas placé correctement ses bateaux. Il perd";
|
||||
echo $currentBot['name']." n'a pas placé correctement ses bateaux. Il perd";
|
||||
if($player==1){
|
||||
save_battle('Battleship',$bot1['name'],$bot2['name'],2);
|
||||
}else{
|
||||
save_battle('Battleship',$bot1['name'],$bot2['name'],1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user