diff --git a/countBattles.txt b/countBattles.txt
index 3559f24..ce4798b 100644
--- a/countBattles.txt
+++ b/countBattles.txt
@@ -1 +1 @@
-1477
\ No newline at end of file
+1483
\ No newline at end of file
diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php
index 5cf7176..1bb4b4c 100644
--- a/src/arenas/tron/act.php
+++ b/src/arenas/tron/act.php
@@ -55,7 +55,7 @@ switch ($_POST['act']){
echo '{"status":"error"}';
die;
}
-
+ $game()->newLap();
//make the board array
for ($botCount = 0; $botCount < count($bots); $botCount ++){
diff --git a/src/arenas/tron/class.TronGame.php b/src/arenas/tron/class.TronGame.php
new file mode 100644
index 0000000..b756986
--- /dev/null
+++ b/src/arenas/tron/class.TronGame.php
@@ -0,0 +1,95 @@
+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;
+ }
+ public function get_continue(){
+ //count bots alive. if less than 1, game is ended
+ $count = 0;
+ foreach($this->bots as $bot){
+ if( $bot->getStatus() == true){
+ $count++;
+ }
+ }
+ if($count > 1){
+ return true;
+ }else{
+ return false;
+ }
+ }
+ public function init_game(){
+ //send init messages to bots
+ $logs = "";
+ $nbeBots = count($this->bots);
+ for ($botCount = 0; $botCount < $nbeBots; $botCount++){
+ $messageArr = array(
+ 'game-id' => "".$this->gameId,
+ 'action' => 'init',
+ 'game' => 'tron',
+ 'board' => '',
+ 'players' => $nbeBots,
+ 'player-index' => $botCount
+ );
+
+ $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 ".$this->bots[$botCount]->getName()."
";
+ }
+ }
+
+ return $logs;
+ }
+ private function getBusyCells(){
+ $arr=array();
+ foreach($this->bots as $bot){
+ $arr = array_merge($arr,$bot->getTail);
+ }
+ return $arr;
+ }
+ public function __construct($botsIds){
+
+ $this->gameId = get_unique_id();
+ $this->bots = array();
+ $positions = array();
+ $botCount = 0;
+ $err = "";
+ foreach($botsIds as $botId){
+ //find a random start position
+ do{
+ $x = rand(1,999);
+ $y = rand(1,999);
+ }while(in_array($x.",".$y,$positions));
+
+ $positions[] = $x.",".$y;
+ $this->bots[$botCount] = new TronPlayer($botId,$x,$y,'y+');
+
+ if ($this->bots[$botCount]->getStatus() === false){
+
+ $err = "Something went wrong for ".$this->bots[$botCount]->getName()."
";
+ }else{
+ $botCount++;
+ }
+ }
+ return $err;
+ }
+}
+?>
\ No newline at end of file
diff --git a/src/arenas/tron/class.TronPlayer.php b/src/arenas/tron/class.TronPlayer.php
new file mode 100644
index 0000000..d2dbbf1
--- /dev/null
+++ b/src/arenas/tron/class.TronPlayer.php
@@ -0,0 +1,87 @@
+tail;
+ }
+ public function getStatus(){
+ return $this->state;
+ }
+ public function getURL(){
+ return $this->url;
+ }
+ public function getName(){
+ return $this->name;
+ }
+ private function set_direction($newDir){
+ //can't be the opposite of the previous direction
+ if(
+ (($newDir == "x+") && ($this->direction == "x-"))
+ || (($newDir == "x-") && ($this->direction == "x+"))
+ || (($newDir == "y+") && ($this->direction == "y-"))
+ || (($newDir == "y-") && ($this->direction == "y+"))
+ ){
+ return false;
+ }
+ $this->direction = $newDir;
+ return true;
+ }
+ public function getTargetCell($dir){
+
+ if($dir == ""){
+ $dir = $this->direction;
+ }
+ if(!$this->set_direction($dir)){
+ return false;
+ }
+ $headCoords = end($this->tail);
+
+ switch ($dir){
+ case "y+":
+ return array($headCoords[0],$headCoords[1]++);
+ break;
+ case "y-":
+ return array($headCoords[0],$headCoords[1]--);
+ break;
+ case "x+":
+ return array($headCoords[0]++,$headCoords[1]);
+ break;
+ case "x-":
+ return array($headCoords[0]--,$headCoords[1]);
+ break;
+ default:
+ return false;
+ }
+
+
+ }
+
+ public function grow($dir=""){
+ $this->tail[] = $this->getTargetCell($dir);
+ }
+ public function loose(){
+ $this->state = false;
+ $this->tail = array();
+ return false;
+ }
+ public function __construct($id,$initialX,$initialY,$initialDirection){
+ $lnBdd = conn_bdd();
+ $rs = mysqli_query($lnBdd,
+ "SELECT name,url FROM bots WHERE game='tron' AND id='".mysqli_real_escape_string($lnBdd, $id)."';"
+ );
+ if(($r=mysqli_fetch_row($rs)) && in_array($initialDirection,array('x-','x+','y-','y+'))){
+ $this->name = $r[0];
+ $this->url = $r[1];
+ $this->tail = array(array($initialX,$initialY));
+ $this->direction = $initialDirection;
+ $this->state= true;
+ }else{
+ $this->state = false;
+ }
+ }
+}
+?>
\ No newline at end of file
diff --git a/src/arenas/tron/functions.php b/src/arenas/tron/functions.php
index 0edb411..d36c912 100644
--- a/src/arenas/tron/functions.php
+++ b/src/arenas/tron/functions.php
@@ -1,6 +1,6 @@
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;
- }
- public function get_continue(){
- //count bots alive. if less than 1, game is ended
- $count = 0;
- foreach($this->bots as $bot){
- if( $bot->getStatus() == true){
- $count++;
- }
- }
- if($count > 1){
- return true;
- }else{
- return false;
- }
- }
- public function init_game(){
- //send init messages to bots
- $logs = "";
- $nbeBots = count($this->bots);
- for ($botCount = 0; $botCount < $nbeBots; $botCount++){
- $messageArr = array(
- 'game-id' => "".$this->gameId,
- 'action' => 'init',
- 'game' => 'tron',
- 'board' => '',
- 'players' => $nbeBots,
- 'player-index' => $botCount
- );
-
- $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 ".$this->bots[$botCount]->getName()."
";
- }
- }
-
- return $logs;
- }
- private function getBusyCells(){
- $arr=array();
- foreach($this->bots as $bot){
- $arr = array_merge($arr,$bot->getTail);
- }
- return $arr;
- }
- public function __construct($botsIds){
-
- $this->gameId = get_unique_id();
- $this->bots = array();
- $positions = array();
- $botCount = 0;
- $err = "";
- foreach($botsIds as $botId){
- //find a random start position
- do{
- $x = rand(1,999);
- $y = rand(1,999);
- }while(in_array($x.",".$y,$positions));
-
- $positions[] = $x.",".$y;
- $this->bots[$botCount] = new TronPlayer($botId,$x,$y,'y+');
-
- if ($this->bots[$botCount]->getStatus() === false){
-
- $err = "Something went wrong for ".$this->bots[$botCount]->getName()."
";
- }else{
- $botCount++;
- }
- }
- return $err;
- }
-}
-class TronPlayer{
- private $url;
- private $name;
- private $tail = array();
- private $direction;
- private $state;
- public function getTail(){
- return $this->tail;
- }
- public function getStatus(){
- return $this->state;
- }
- public function getURL(){
- return $this->url;
- }
- public function getName(){
- return $this->name;
- }
- private function set_direction($newDir){
- //can't be the opposite of the previous direction
- if(
- (($newDir == "x+") && ($this->direction == "x-"))
- || (($newDir == "x-") && ($this->direction == "x+"))
- || (($newDir == "y+") && ($this->direction == "y-"))
- || (($newDir == "y-") && ($this->direction == "y+"))
- ){
- return false;
- }
- $this->direction = $newDir;
- return true;
- }
- public function getTargetCell($dir){
-
- if($dir == ""){
- $dir = $this->direction;
- }
- if(!$this->set_direction($dir)){
- return false;
- }
- $headCoords = end($this->tail);
-
- switch ($dir){
- case "y+":
- return array($headCoords[0],$headCoords[1]++);
- break;
- case "y-":
- return array($headCoords[0],$headCoords[1]--);
- break;
- case "x+":
- return array($headCoords[0]++,$headCoords[1]);
- break;
- case "x-":
- return array($headCoords[0]--,$headCoords[1]);
- break;
- default:
- return false;
- }
-
-
- }
-
- public function grow($dir=""){
- $this->tail[] = $this->getTargetCell($dir);
- }
- public function loose(){
- $this->state = false;
- $this->tail = array();
- return false;
- }
- public function __construct($id,$initialX,$initialY,$initialDirection){
- $lnBdd = conn_bdd();
- $rs = mysqli_query($lnBdd,
- "SELECT name,url FROM bots WHERE game='tron' AND id='".mysqli_real_escape_string($lnBdd, $id)."';"
- );
- if(($r=mysqli_fetch_row($rs)) && in_array($initialDirection,array('x-','x+','y-','y+'))){
- $this->name = $r[0];
- $this->url = $r[1];
- $this->tail = array(array($initialX,$initialY));
- $this->direction = $initialDirection;
- $this->state= true;
- }else{
- $this->state = false;
- }
- }
-}
\ No newline at end of file
+
diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js
index 765f386..412587c 100644
--- a/src/arenas/tron/js.js
+++ b/src/arenas/tron/js.js
@@ -86,7 +86,7 @@ function applyInitMessage(req,xd_check){
addLog(ret['logs']);
if(ret['status'] == true){
growTails(ret['botsPosition']);
- //play(ret['gameId'],xd_check);
+ play(ret['gameId'],xd_check);
}
}else{