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;
$bot1ParamsToSend=array( }else{
'game' => 'Battleship', $opponentName=$bot1['name'];
'match_id' => $_SESSION['matchId']."-1", $currentBot=$bot2;
'act' => 'init', }
'opponent' => $bot2['name'],
'width' => $postValues['gridWidth'], $botParamsToSend=array(
'height' => $postValues['gridHeight'], 'game' => 'Battleship',
'ship1' => $postValues['nbShip1'], 'match_id' => $_SESSION['matchId']."-1",
'ship2' => $postValues['nbShip2'], 'act' => 'init',
'ship3' => $postValues['nbShip3'], 'opponent' => $opponentName,
'ship4' => $postValues['nbShip4'], 'width' => $postValues['gridWidth'],
'ship5' => $postValues['nbShip5'], 'height' => $postValues['gridHeight'],
'ship6' => $postValues['nbShip6'] 'ship1' => $postValues['nbShip1'],
'ship2' => $postValues['nbShip2'],
); 'ship3' => $postValues['nbShip3'],
$anwserPlayer1=get_IA_Response($bot1['url'],$bot1ParamsToSend); 'ship4' => $postValues['nbShip4'],
$boatsPlayer1 = json_decode( html_entity_decode($anwserPlayer1)); 'ship5' => $postValues['nbShip5'],
if(!$boatsPlayer1){ 'ship6' => $postValues['nbShip6']
echo $bot1['name']." a fait une réponse non conforme, il perd.".$anwserPlayer1;
save_battle('Battleship',$bot1['name'],$bot2['name'],2); );
} $anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend);
$boatsPlayer = json_decode( html_entity_decode($anwserPlayer));
if(!$boatsPlayer){
//vérifier si'il y a le bon nombre de bateaux echo $currentBot['name']." a fait une réponse non conforme, il perd.";
$nbBoatsIwant=array(0,$postValues['nbShip1'],$postValues['nbShip2'],$postValues['nbShip3'], if($player==1){
$postValues['nbShip4'],$postValues['nbShip5'],$postValues['nbShip6']); save_battle('Battleship',$bot1['name'],$bot2['name'],2);
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);
} }
} }