コード例 #1
0
ファイル: act.php プロジェクト: CamTosh/botsArena
 switch ($playerPlayingNow) {
     case 1:
         $playerURL = $bots[$bot1]['url'];
         $playerCHAR = 'X';
         $playerName = $bots[$bot1]['name'];
         break;
     case 2:
         $playerURL = $bots[$bot2]['url'];
         $playerCHAR = 'O';
         $playerName = $bots[$bot2]['name'];
         break;
     default:
         error(500, "oups");
         die;
 }
 $playerResponse = get_IA_Response($playerCHAR, $playerURL, $map);
 //tester la validité de la réponse
 if (isset($map[$playerResponse]) && $map[$playerResponse] == "") {
     //reponse conforme
     echo "<p>" . $playerName . " joue en " . $playerResponse . " la nouvelle grille est <br/>";
     $map[$playerResponse] = $playerCHAR;
     echo "<table>";
     for ($j = 0; $j < 3; $j++) {
         echo "<tr>";
         for ($i = 0; $i < 3; $i++) {
             echo '<td class="cellj' . $j . ' celli' . $i . '">' . $map[$j . '-' . $i] . '</td>';
         }
         echo "</tr>";
     }
     echo "</table>";
     //tester si trois caracteres allignés
コード例 #2
0
ファイル: act.php プロジェクト: jcolfej/botsArena
 case "fight":
     if (count($_SESSION['strikes'][1]) == count($_SESSION['strikes'][2])) {
         //player 1 has to fight
         $currentPlayer = 1;
         $currentBot = $_SESSION['bot1'];
         $opponent = 2;
         $opponentName = $_SESSION['bot2']['name'];
     } else {
         //it's player2
         $currentPlayer = 2;
         $currentBot = $_SESSION['bot2'];
         $opponentName = $_SESSION['bot1']['name'];
         $opponent = 1;
     }
     $botParamsToSend = array('game' => 'Battleship', 'match_id' => $_SESSION['matchId'] . "-" . $currentPlayer, 'act' => 'fight', 'opponent' => $opponentName, 'width' => $_SESSION['width'], 'height' => $_SESSION['height'], 'ship1' => $_SESSION['ship1'], 'ship2' => $_SESSION['ship2'], 'ship3' => $_SESSION['ship3'], 'ship4' => $_SESSION['ship4'], 'ship5' => $_SESSION['ship5'], 'ship6' => $_SESSION['ship6'], 'your_strikes' => json_encode($_SESSION['strikes'][$currentPlayer]), 'his_strikes' => json_encode($_SESSION['strikes'][$opponent]));
     $anwserPlayer = get_IA_Response($currentBot['url'], $botParamsToSend);
     if (!preg_match('/^[0-9]+,[0-9]+$/', $anwserPlayer)) {
         echo json_encode(array('target' => '', 'log' => $currentBot['name'] . " a fait une réponse non conforme, il perd." . $anwserPlayer));
         save_battle('Battleship', $_SESSION['bot1']['name'], $_SESSION['bot2']['name'], $opponent);
         die;
     }
     list($x, $y) = explode(",", $anwserPlayer);
     //check if shot is under map's limits
     if ($x >= $_SESSION['width'] or $y >= $_SESSION['height']) {
         echo json_encode(array('target' => '', 'log' => $currentBot['name'] . " a fait un tir en dehors des limites de la carte. " . $x . "," . $y . " C'est interdit par les conventions de Geneve. Il perd"));
         save_battle('Battleship', $_SESSION['bot1']['name'], $_SESSION['bot2']['name'], $opponent);
         die;
     }
     //put previous strikes in a one dimmension array ;
     $previousStrikes = array();
     foreach ($_SESSION['strikes'][$currentPlayer] as $strikes) {