This commit is contained in:
gnieark 2016-06-18 00:56:46 +02:00
parent 73f5dd4e37
commit 2892d62519
2 changed files with 327 additions and 299 deletions

View File

@ -51,6 +51,16 @@ switch ($_POST['act']){
}
$postValues[$p[0]]=$value;
}
if(($_POST['fullLogs'] <> 'true') && ($_POST['fullLogs'] <> 'false')){
error(500, 'wrong POST parameters');
die;
}
if($_POST['fullLogs'] == 'true'){
$fullLogs = true;
}else{
$fullLogs = false;
}
//check if bots exists
$bot1Exists = false;
$bot2Exists = false;
@ -74,11 +84,15 @@ switch ($_POST['act']){
error (500,"missing parameter 2");
}
if(!is_it_possible_to_place_ships_on_grid($postValues['gridWidth'],$postValues['gridHeight'],$postValues['nbShip1'],$postValues['nbShip2'],$postValues['nbShip3'],$postValues['nbShip4'],$postValues['nbShip5'],$postValues['nbShip6'])){
if(!is_it_possible_to_place_ships_on_grid($postValues['gridWidth'],$postValues['gridHeight'],
$postValues['nbShip1'],$postValues['nbShip2'],$postValues['nbShip3'],
$postValues['nbShip4'],$postValues['nbShip5'],$postValues['nbShip6']))
{
error (404,"grid is too little for these ships");
}
//vars checked, lets init the initGame
//******vars checked, lets init the initGame *******
$_SESSION['matchId']=get_unique_id();
@ -94,9 +108,12 @@ switch ($_POST['act']){
}
$botParamsToSend=array(
'game' => 'Battleship',
'match_id' => $_SESSION['matchId']."-1",
'act' => 'init',
'game-id' => $_SESSION['matchId'],
'game' => 'battleship',
'action' => 'init',
'players' => 2
'player-index' => $player -1,
'board' => array(
'opponent' => $opponentName,
'width' => $postValues['gridWidth'],
'height' => $postValues['gridHeight'],
@ -106,9 +123,20 @@ switch ($_POST['act']){
'ship4' => $postValues['nbShip4'],
'ship5' => $postValues['nbShip5'],
'ship6' => $postValues['nbShip6']
)
);
$anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend);
$anwserPlayerJson=get_IA_Response($currentBot['url'],$botParamsToSend);
if($fulLLogs){
$fullLogs='Arena send to '.$currentBot['name'].'<em>'.htmlentities($anwserPlayerJson['messageSend']).'</em><br/>
HTTP status: <em>'.htmlentities($anwserPlayerJson['httpStatus']).'</em><br/>
Bot anwser: <em>'.htmlentities($anwserPlayerJson['response']).'</em><br/>';
}else{
$fullLogs="";
}
$boatsPlayer = json_decode( html_entity_decode($anwserPlayer));
if(!$boatsPlayer){
echo $currentBot['name']." a fait une réponse non conforme, il perd.".$anwserPlayer;

View File

@ -37,7 +37,7 @@
<li><em>players</em> Int indicating the number of players in the game, still 2 on connect Four.</li>
<li><em>board</em> The map, i'll explain it at next chapter</li>
<li><em>you</em> String, Your bot's character on the grid</li>
<li><em>player-index</em> Int The order of your bot in turns. The first player is 0, second is 2.</li>
<li><em>player-index</em> Int The order of your bot in turns. The first player is 0, second is 1.</li>
</ul>
<h4>The map</h4>
<p> It is represented by a sub-array, on the "board" parameter.<br/>Exemple:</p>