some fixes

This commit is contained in:
Gnieark 2016-07-22 18:45:17 +02:00
parent b6060449e7
commit 8f093f6966
3 changed files with 15 additions and 11 deletions

View File

@ -1 +1 @@
1549 1559

View File

@ -75,6 +75,7 @@ class TronGame
foreach($this->bots as $bot){ foreach($this->bots as $bot){
$trailsArr[] = $bot->trail; $trailsArr[] = $bot->trail;
} }
//echo json_encode($trailsArr);
return json_encode($trailsArr); return json_encode($trailsArr);
} }
public function new_lap(){ public function new_lap(){
@ -83,14 +84,14 @@ class TronGame
$nbeBots = count($this->bots); $nbeBots = count($this->bots);
$urls = array(); $urls = array();
$paramToSend = array(); $paramToSend = array();
$board = $this->getBoard(); $board = $this->get_trails();
$loosers = array(); $loosers = array();
$lastsCells = array(); $lastsCells = array();
for ($botCount = 0; $botCount < $nbeBots; $botCount++){ for ($botCount = 0; $botCount < $nbeBots; $botCount++){
if ($this->bots[$botCount]->getStatus()){ if ($this->bots[$botCount]->isAlive){
$urls[$botCount] = $this->bots[$botCount]->getURL(); $urls[$botCount] = $this->bots[$botCount]->url;
$paramsToSend[$botCount] = array( $paramsToSend[$botCount] = array(
'game-id' => "".$this->gameId, 'game-id' => "".$this->gameId,
@ -105,16 +106,20 @@ class TronGame
$responses = $this->get_multi_IAS_Responses($urls,$paramsToSend); $responses = $this->get_multi_IAS_Responses($urls,$paramsToSend);
print_r($responses);
//grow bots'tails //grow bots'tails
for ($botCount = 0; $botCount < $nbeBots; $botCount++){ for ($botCount = 0; $botCount < $nbeBots; $botCount++){
if ($this->bots[$botCount]->getStatus()){ if ($this->bots[$botCount]->isAlive){
$lastsCells[$botCount] = $this->bots[$botCount]->grow($responses[$botCount]['responseArr']['play']); $dir = Direction::make($responses[$botCount]['responseArr']['play']);
$lastsCells[$botCount] = $this->bots[$botCount]->grow($dir);
} }
} }
//test if loose //test if loose
for ($botCount = 0; $botCount < $nbeBots; $botCount++){ for ($botCount = 0; $botCount < $nbeBots; $botCount++){
if ($this->bots[$botCount]->getStatus()){ if ($this->bots[$botCount]->isAlive){
foreach($this->bots as $otherBot){ foreach($this->bots as $otherBot){
if($otherBot->trail->contains($lastsCells($botCount))) if($otherBot->trail->contains($lastsCells($botCount)))
$loosers[] = $botCount; $loosers[] = $botCount;
@ -248,5 +253,4 @@ class TronGame
} }
return $err; return $err;
} }
} }

View File

@ -61,7 +61,7 @@ switch ($_POST['act']){
$game = unserialize($_SESSION['game']); $game = unserialize($_SESSION['game']);
if($game->getGameId() <> $_POST['gameId']){ if($game->gameId <> $_POST['gameId']){
//sometimes if an ajax callback is applied after init an other game //sometimes if an ajax callback is applied after init an other game
echo '{"status":"error"}'; echo '{"status":"error"}';
die; die;
@ -73,7 +73,7 @@ switch ($_POST['act']){
$continue = 0; $continue = 0;
} }
echo json_encode(array( echo json_encode(array(
'gameId' => $game->getGameId(), 'gameId' => $game->gameId,
'continue' => $continue, 'continue' => $continue,
'lap' => $lap 'lap' => $lap
)); ));