.
This commit is contained in:
parent
adf5d14c35
commit
0d79e871de
|
@ -1 +1 @@
|
||||||
1456
|
1462
|
|
@ -21,9 +21,10 @@ switch ($_POST['act']){
|
||||||
$logs = $game->init_game();
|
$logs = $game->init_game();
|
||||||
|
|
||||||
echo json_encode(array(
|
echo json_encode(array(
|
||||||
'status' => $game->getStatus();,
|
'status' => $game->get_continue(),
|
||||||
'logs' => $logs
|
'logs' => $logs,
|
||||||
'gameId' => $game->getGameId();
|
'gameId' => $game->getGameId(),
|
||||||
|
'botsPosition' => $game->getBotsPositions()
|
||||||
));
|
));
|
||||||
|
|
||||||
$_SESSION['game'] = serialize($game);
|
$_SESSION['game'] = serialize($game);
|
||||||
|
@ -34,12 +35,21 @@ switch ($_POST['act']){
|
||||||
case "play":
|
case "play":
|
||||||
$logs = "";
|
$logs = "";
|
||||||
//check for correct game ID
|
//check for correct game ID
|
||||||
if($_POST['gameId'] <> $_SESSION['gameId']){
|
|
||||||
|
if(!isset($_SESSION['game'])){
|
||||||
echo '{"status":"error"}';
|
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
|
//make the board array
|
||||||
for ($botCount = 0; $botCount < count($bots); $botCount ++){
|
for ($botCount = 0; $botCount < count($bots); $botCount ++){
|
||||||
$board[$botCount] = $bots[$botCount]->getTail();
|
$board[$botCount] = $bots[$botCount]->getTail();
|
||||||
|
|
|
@ -20,6 +20,18 @@ function save_draw_bots($arr){
|
||||||
class TronGame{
|
class TronGame{
|
||||||
private $bots;
|
private $bots;
|
||||||
private $gameId;
|
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(){
|
public function getGameId(){
|
||||||
return $this->gameId;
|
return $this->gameId;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +51,7 @@ class TronGame{
|
||||||
}
|
}
|
||||||
public function init_game(){
|
public function init_game(){
|
||||||
//send init messages to bots
|
//send init messages to bots
|
||||||
|
$logs = "";
|
||||||
$nbeBots = count($this->bots);
|
$nbeBots = count($this->bots);
|
||||||
for ($botCount = 0; $botCount < $nbeBots; $botCount++){
|
for ($botCount = 0; $botCount < $nbeBots; $botCount++){
|
||||||
$messageArr = array(
|
$messageArr = array(
|
||||||
|
@ -51,25 +63,15 @@ class TronGame{
|
||||||
'player-index' => $botCount
|
'player-index' => $botCount
|
||||||
);
|
);
|
||||||
|
|
||||||
$resp = get_IA_Response($bots[$botCount]->getURL(),$messageArr);
|
$resp = get_IA_Response($this->bots[$botCount]->getURL(),$messageArr);
|
||||||
|
|
||||||
if($_POST['fullLogs'] == "true"){
|
if($_POST['fullLogs'] == "true"){
|
||||||
$logs.='Arena send to '.$bots[$botCount]->getName().'<em>'.htmlentities($resp['messageSend']).'</em><br/>
|
$logs.='Arena send to '.$bots[$botCount]->getName().'<em>'.htmlentities($resp['messageSend']).'</em><br/>
|
||||||
HTTP status: <em>'.htmlentities($resp['httpStatus']).'</em><br/>
|
HTTP status: <em>'.htmlentities($resp['httpStatus']).'</em><br/>
|
||||||
Bot anwser: <em>'.htmlentities($resp['response']).'</em><br/>';
|
Bot anwser: <em>'.htmlentities($resp['response']).'</em><br/>';
|
||||||
}else{
|
}else{
|
||||||
$logs.="Init message send to ".$bots[$botCount]->getName()."<br/>";
|
$logs.="Init message send to ".$this->bots[$botCount]->getName()."<br/>";
|
||||||
}
|
}
|
||||||
|
|
||||||
//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 <br/>";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $logs;
|
return $logs;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user