switch ($_POST['act']) { case "init": file_put_contents(__DIR__ . "/log.txt", print_r($_POST, true)); $wantedVars = array('match_id' => false, 'opponent' => false, 'width' => true, 'height' => true, 'ship1' => true, 'ship2' => true, 'ship3' => true, 'ship4' => true, 'ship5' => true, 'ship6' => true); foreach ($wantedVars as $key => $shouldBeInteger) { if ($shouldBeInteger && !is_numeric($_POST[$key])) { echo "var is not numeric"; die; } ${$key} = $_POST[$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"; die; } a: $map = array(); //construire une grille for ($i = 0; $i < $width; $i++) { for ($j = 0; $j < $height; $j++) { $map[$j][$i] = 0; } } $shipsCoords = array(); //pour toutes les tailles de bateau for ($shipWidth = 6; $shipWidth > 0; $shipWidth--) { //nombre de bateau à placer de cette taille
$_SESSION['bot1'] = $bot; $bot1Exists = true; } if ($bot['id'] == $_POST['bot2']) { $bot2 = $bot; $_SESSION['bot2'] = $bot; $bot2Exists = true; } if ($bot1Exists && $bot2Exists) { break; } } if (!$bot1Exists or !$bot2Exists) { 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'])) { error(404, "grid is too little for these ships"); } //vars checked, lets init the initGame $_SESSION['matchId'] = get_unique_id(); for ($player = 1; $player <= 2; $player++) { if ($player == 1) { $opponentName = $bot2['name']; $currentBot = $bot1; } else { $opponentName = $bot1['name']; $currentBot = $bot2; } $botParamsToSend = array('game' => 'Battleship', 'match_id' => $_SESSION['matchId'] . "-1", 'act' => 'init', 'opponent' => $opponentName, 'width' => $postValues['gridWidth'], 'height' => $postValues['gridHeight'], 'ship1' => $postValues['nbShip1'], 'ship2' => $postValues['nbShip2'], 'ship3' => $postValues['nbShip3'], 'ship4' => $postValues['nbShip4'], 'ship5' => $postValues['nbShip5'], 'ship6' => $postValues['nbShip6']); $anwserPlayer = get_IA_Response($currentBot['url'], $botParamsToSend); $boatsPlayer = json_decode(html_entity_decode($anwserPlayer));