loop for the two players

This commit is contained in:
Gnieark 2015-12-14 22:30:10 +01:00
parent 0c4e3396e8
commit 5349d192a8

View File

@ -62,51 +62,66 @@ switch ($_POST['act']){
$_SESSION['matchId']=get_unique_id(); $_SESSION['matchId']=get_unique_id();
for($player = 1; $player <= 2; $player++){
// get_IA_Response($iaUrl,$postParams) if($player==1){
//array à envoyer au bot 1 $opponentName=$bot2['name'];
$currentBot=$bot1;
}else{
$opponentName=$bot1['name'];
$currentBot=$bot2;
}
$bot1ParamsToSend=array( $botParamsToSend=array(
'game' => 'Battleship', 'game' => 'Battleship',
'match_id' => $_SESSION['matchId']."-1", 'match_id' => $_SESSION['matchId']."-1",
'act' => 'init', 'act' => 'init',
'opponent' => $bot2['name'], 'opponent' => $opponentName,
'width' => $postValues['gridWidth'], 'width' => $postValues['gridWidth'],
'height' => $postValues['gridHeight'], 'height' => $postValues['gridHeight'],
'ship1' => $postValues['nbShip1'], 'ship1' => $postValues['nbShip1'],
'ship2' => $postValues['nbShip2'], 'ship2' => $postValues['nbShip2'],
'ship3' => $postValues['nbShip3'], 'ship3' => $postValues['nbShip3'],
'ship4' => $postValues['nbShip4'], 'ship4' => $postValues['nbShip4'],
'ship5' => $postValues['nbShip5'], 'ship5' => $postValues['nbShip5'],
'ship6' => $postValues['nbShip6'] 'ship6' => $postValues['nbShip6']
); );
$anwserPlayer1=get_IA_Response($bot1['url'],$bot1ParamsToSend); $anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend);
$boatsPlayer1 = json_decode( html_entity_decode($anwserPlayer1)); $boatsPlayer = json_decode( html_entity_decode($anwserPlayer));
if(!$boatsPlayer1){ if(!$boatsPlayer){
echo $bot1['name']." a fait une réponse non conforme, il perd.".$anwserPlayer1; echo $currentBot['name']." a fait une réponse non conforme, il perd.";
save_battle('Battleship',$bot1['name'],$bot2['name'],2); if($player==1){
} save_battle('Battleship',$bot1['name'],$bot2['name'],2);
//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){
list($startCoord,$endCoord) = explode("-",$boat);
list($xStart,$yStart)=explode(",",$startCoord);
list($xEnd,$yEnd)=explode(",",$endCoord);
if($xStart == $xEnd){
$long=abs($yStart - $yEnd);
}else{ }else{
$long=abs($xStart - $xEnd); 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($boatsPlayer as $boat){
list($startCoord,$endCoord) = explode("-",$boat);
list($xStart,$yStart)=explode(",",$startCoord);
list($xEnd,$yEnd)=explode(",",$endCoord);
if($xStart == $xEnd){
$long=abs($yStart - $yEnd);
}else{
$long=abs($xStart - $xEnd);
}
$nbBoatsIwant[$long]-=1;
}
foreach($nbBoatsIwant as $nb){
if($nb <> 0){
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);
}
} }
$nbBoatsIwant[$long]-=1;
}
foreach($nbBoatsIwant as $nb){
if($nb <> 0){
echo $bot1['name']." n'a pas placé correctement ses bateaux. Il perd";
save_battle('Battleship',$bot1['name'],$bot2['name'],2);
} }
} }