getStatus() === false){ unset($bots[$botCount]); }else{ $botCount++; } } $_SESSION['players'] = $botCount; if ($botCount < 2){ error (500,"missing bots"); } $logs=""; //send init message $gameId = get_unique_id(); $responses = array(); for ($botCount = 0; $botCount < count($bots); $botCount ++){ $messageArr = array( 'game-id' => "".$gameId, 'action' => 'init', 'game' => 'tron', 'board' => '', 'players' => $_SESSION['players'], 'player-index' => $botCount ); $resp = get_IA_Response($bots[$botCount]->getURL(),$messageArr); if($_POST['fullLogs'] == "true"){ $logs.='Arena send to '.$bots[$botCount]->getName().''.htmlentities($resp['messageSend']).'
HTTP status: '.htmlentities($resp['httpStatus']).'
Bot anwser: '.htmlentities($resp['response']).'
'; }else{ $logs.="Init message send to ".$bots[$botCount]->getName()."
"; } } //save bots on session var $_SESSION['bots'] = serialize($bots); $_SESSION['gameId'] = $gameId; echo json_encode(array( 'status' => 'OK', 'logs' => $logs, 'gameId' => $gameId )); die; break; case "play": //check for correct game ID if($_POST['gameId'] !=== $_SESSION['gameId']){ echo '{"status":"error"}'; die; } $bots = unserialize($_SESSION['bots']); $board= array(); //make the board array for ($botCount = 0; $botCount < count($bots); $botCount ++){ $board[$botCount] = $bots[$botCount]->getTail(); } $responses = array(); for ($botCount = 0; $botCount < count($bots); $botCount ++){ $messageArr = array( 'game-id' => '', 'action' => 'play-turn', 'game' => 'tron', 'board' => $board, 'player-index' => $botCount, // To do: verifier que ça restera le même à chaque tour 'players' => $_SESSION['players'] ); $responses[$botCount] = get_IA_Response($bots[$botCount]->getURL(),$messageArr); } print_r($responses); die; break; default: break; }