diff --git a/countBattles.txt b/countBattles.txt index ac3f740..85b0c4b 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1456 \ No newline at end of file +1462 \ No newline at end of file diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index 902dc41..b4db349 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -21,9 +21,10 @@ switch ($_POST['act']){ $logs = $game->init_game(); echo json_encode(array( - 'status' => $game->getStatus();, - 'logs' => $logs - 'gameId' => $game->getGameId(); + 'status' => $game->get_continue(), + 'logs' => $logs, + 'gameId' => $game->getGameId(), + 'botsPosition' => $game->getBotsPositions() )); $_SESSION['game'] = serialize($game); @@ -34,12 +35,21 @@ switch ($_POST['act']){ case "play": $logs = ""; //check for correct game ID - if($_POST['gameId'] <> $_SESSION['gameId']){ + + if(!isset($_SESSION['game'])){ echo '{"status":"error"}'; - die; + die; } - $bots = unserialize($_SESSION['bots']); - $board= array(); + + $game= unserialize($_SESSION['game']); + + if($game->getGameId() <> $_POST['gameId']){ + //sometimes if an ajax callback is applied after init an other game + echo '{"status":"error"}'; + die; + } + + //make the board array for ($botCount = 0; $botCount < count($bots); $botCount ++){ $board[$botCount] = $bots[$botCount]->getTail(); diff --git a/src/arenas/tron/functions.php b/src/arenas/tron/functions.php index 95dd157..6b1fef9 100644 --- a/src/arenas/tron/functions.php +++ b/src/arenas/tron/functions.php @@ -20,6 +20,18 @@ function save_draw_bots($arr){ class TronGame{ private $bots; private $gameId; + public function getBotsPositions(){ + $nbeBots = count($this->bots); + $arr = array(); + for ($botCount = 0; $botCount < $nbeBots; $botCount++){ + $arr[$botCount] = array( + "name" => $this->bots[$botCount]->getName(), + "tail" => $this->bots[$botCount]->getTail() + + ); + } + return $arr; + } public function getGameId(){ return $this->gameId; } @@ -39,7 +51,7 @@ class TronGame{ } public function init_game(){ //send init messages to bots - + $logs = ""; $nbeBots = count($this->bots); for ($botCount = 0; $botCount < $nbeBots; $botCount++){ $messageArr = array( @@ -51,25 +63,15 @@ class TronGame{ 'player-index' => $botCount ); - $resp = get_IA_Response($bots[$botCount]->getURL(),$messageArr); + $resp = get_IA_Response($this->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()."
"; - } - - //check response - if( - ($resp['httpStatus'] <> 200) - OR (!pregmatch('^[0-9]*,[0-9]*$', $resp['responseArr'])) - ){ - $this->bots[$botCount]->loose(); - $logs.= $this->bots[$botCount]->getName." Made a non conform response
"; - } - + $logs.="Init message send to ".$this->bots[$botCount]->getName()."
"; + } } return $logs;