+ + + + '.$bot['name'].''; + } + ?> + + VS + + '.$bot['name'].''; + } + ?> + + + view the full logs + + +
+ @@ -34,5 +34,5 @@ $bots=get_Bots_Array('tron'); view the full logs - + \ No newline at end of file From f34ce0722615758b1d092311a39144b3d5d86fad Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 11:48:12 +0200 Subject: [PATCH 013/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 349dcd5..5f88a7a 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -13,8 +13,7 @@ function tron(bot1,bot2,xdcheck){ var mapImg = createElem('svg',{'alt' : 'map','width':'200','height':'200'}); // "circle" may be any tag name - mapImg.innerHTML = ''; - + mapImg.innerHTML = ' '; document.getElementById('mainArticle').appendChild(mapImg); } From 0577612b2dd301f8e4ea946ff56665744423cea1 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 11:52:08 +0200 Subject: [PATCH 014/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 5f88a7a..e411bdd 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -8,10 +8,7 @@ function createElem(type,attributes){ function tron(bot1,bot2,xdcheck){ - //empty - - - var mapImg = createElem('svg',{'alt' : 'map','width':'200','height':'200'}); + var mapImg = createElem('svg',{'alt' : 'map','width':'200px','height':'200px','xmlns':'http://www.w3.org/2000/svg'}); // "circle" may be any tag name mapImg.innerHTML = ' '; document.getElementById('mainArticle').appendChild(mapImg); From b6c95f797974041d662fcaab5a9faa3d69139df0 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 11:59:47 +0200 Subject: [PATCH 015/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index e411bdd..847dd67 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -8,7 +8,7 @@ function createElem(type,attributes){ function tron(bot1,bot2,xdcheck){ - var mapImg = createElem('svg',{'alt' : 'map','width':'200px','height':'200px','xmlns':'http://www.w3.org/2000/svg'}); + var mapImg = createElem('svg',{'alt' : 'map','width':'200','height':'200','xmlns':'http://www.w3.org/2000/svg','viewBox':'0 0 20 20'}); // "circle" may be any tag name mapImg.innerHTML = ' '; document.getElementById('mainArticle').appendChild(mapImg); From 289e1eac2d836bf8b22ea7568c7a23eb2efade45 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 12:04:49 +0200 Subject: [PATCH 016/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- src/arenas/tron/public.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 847dd67..dd03c32 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -8,7 +8,7 @@ function createElem(type,attributes){ function tron(bot1,bot2,xdcheck){ - var mapImg = createElem('svg',{'alt' : 'map','width':'200','height':'200','xmlns':'http://www.w3.org/2000/svg','viewBox':'0 0 20 20'}); + var mapImg = createElem('svg',{'version':'1.1','alt' : 'map','width':'200','height':'200','xmlns':'http://www.w3.org/2000/svg','viewBox':'0 0 20 20'}); // "circle" may be any tag name mapImg.innerHTML = ' '; document.getElementById('mainArticle').appendChild(mapImg); diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index b50ddb6..02ea46c 100644 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -34,5 +34,7 @@ $bots=get_Bots_Array('tron'); view the full logs - + + +
- - - '.$bot['name'].''; - } - ?> - - VS - - '.$bot['name'].''; - } - ?> - - + + + + + + view the full logs From 35fc852ee953732381313ded71679a1a5ae877b5 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 17:21:46 +0200 Subject: [PATCH 045/126] try to draw 1000*1000 svg grig --- src/arenas/tron/public.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index 3d446c0..d5a4302 100644 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -23,7 +23,7 @@ foreach($bots as $bot){ From 561d76001b5a7b1d35346a3844ffa51ed1c7320c Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 29 Jun 2016 23:08:43 +0200 Subject: [PATCH 046/126] js --- src/arenas/tron/js.js | 16 ++++++++++++++++ src/arenas/tron/public.php | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 4f5d245..d96a5d2 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -11,6 +11,22 @@ function createElemNS(type,attributes){ {elem.setAttributeNS(null,i,attributes[i]);} return elem; } +function show_bot_panel(number){ + //configurePlayers + var fieldset = createElem('fieldset',{'class':'botFormulaire'}); + var p=createElem('p'); + var select = createElem('select',{'id':'selectBot' + number, 'onchange':'changeSelect(this.value);'}); + for each (var bot in botsAvailable){ + var option = createElem('option',{'value':bot['id']}); + option.innerHTML = bot['name']; + select.appendChild(option); + } + p.appendChild(select); + fieldset.appendChild(p); + + + document.getElementById('configurePlayers').appendChild(fieldset); +} function applyInitMessage(req){ //callback function when init game request diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index d5a4302..3dfa844 100644 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -19,9 +19,9 @@ foreach($bots as $bot){ ?> - + + - - - view the full logs + view the full logs - \ No newline at end of file From 8f093f6966fd9e4286df75dc0d59aeea1465a75a Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 22 Jul 2016 18:45:17 +0200 Subject: [PATCH 122/126] some fixes --- countBattles.txt | 2 +- src/arenas/tron/TronGame.php | 20 ++++++++++++-------- src/arenas/tron/act.php | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index d10f97d..7e4fd5e 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1549 \ No newline at end of file +1559 \ No newline at end of file diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index 57f5de8..9a10f67 100644 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -75,6 +75,7 @@ class TronGame foreach($this->bots as $bot){ $trailsArr[] = $bot->trail; } + //echo json_encode($trailsArr); return json_encode($trailsArr); } public function new_lap(){ @@ -83,14 +84,14 @@ class TronGame $nbeBots = count($this->bots); $urls = array(); $paramToSend = array(); - $board = $this->getBoard(); + $board = $this->get_trails(); $loosers = array(); $lastsCells = array(); 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( 'game-id' => "".$this->gameId, @@ -105,16 +106,20 @@ class TronGame $responses = $this->get_multi_IAS_Responses($urls,$paramsToSend); + print_r($responses); + //grow bots'tails for ($botCount = 0; $botCount < $nbeBots; $botCount++){ - if ($this->bots[$botCount]->getStatus()){ - $lastsCells[$botCount] = $this->bots[$botCount]->grow($responses[$botCount]['responseArr']['play']); + if ($this->bots[$botCount]->isAlive){ + $dir = Direction::make($responses[$botCount]['responseArr']['play']); + $lastsCells[$botCount] = $this->bots[$botCount]->grow($dir); } } + //test if loose for ($botCount = 0; $botCount < $nbeBots; $botCount++){ - if ($this->bots[$botCount]->getStatus()){ + if ($this->bots[$botCount]->isAlive){ foreach($this->bots as $otherBot){ if($otherBot->trail->contains($lastsCells($botCount))) $loosers[] = $botCount; @@ -248,5 +253,4 @@ class TronGame } return $err; } - -} +} \ No newline at end of file diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index 2bec0ac..c7df199 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -61,7 +61,7 @@ switch ($_POST['act']){ $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 echo '{"status":"error"}'; die; @@ -73,7 +73,7 @@ switch ($_POST['act']){ $continue = 0; } echo json_encode(array( - 'gameId' => $game->getGameId(), + 'gameId' => $game->gameId, 'continue' => $continue, 'lap' => $lap )); From aced31b12c38ca8d349f129712cccd66db9f7dfa Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 25 Jul 2016 18:38:48 +0200 Subject: [PATCH 123/126] some fixes --- countBattles.txt | 2 +- src/arenas/tron/Trail.php | 17 +++++++++-------- src/arenas/tron/TronGame.php | 7 +++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 7e4fd5e..7157ddd 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1559 \ No newline at end of file +1579 \ No newline at end of file diff --git a/src/arenas/tron/Trail.php b/src/arenas/tron/Trail.php index c740b36..8150eb2 100644 --- a/src/arenas/tron/Trail.php +++ b/src/arenas/tron/Trail.php @@ -34,20 +34,21 @@ class Trail { $this->trail->push($value); } public function __toString(){ - $arr = ""; - foreach($this->trail as $value) { - $arr[] = $value; + return json_encode($this->getTrailAsArray()); + } + public function getTrailAsArray(){ + $arr = array(); + foreach($this->trail as $coord) { + $arr[] = array($coord->x,$coord->y); } - return json_encode($arr); - - + return $arr; } public function contains($searchedValue) { foreach($this->trail as $value) { - if($value == $searchedValue) return TRUE; + if($value == $searchedValue) return true; } - return FALSE; + return false; } public static function kind($var) { diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index 9a10f67..e186945 100644 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -73,9 +73,8 @@ class TronGame //return all trails for draw svg $trailsArr = array(); foreach($this->bots as $bot){ - $trailsArr[] = $bot->trail; + $trailsArr[] = $bot->trail->getTrailAsArray(); } - //echo json_encode($trailsArr); return json_encode($trailsArr); } public function new_lap(){ @@ -105,13 +104,13 @@ class TronGame } $responses = $this->get_multi_IAS_Responses($urls,$paramsToSend); - print_r($responses); - //grow bots'tails for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ + $dir = Direction::make($responses[$botCount]['responseArr']['play']); + $lastsCells[$botCount] = $this->bots[$botCount]->grow($dir); } } From 60c95835a4202aeaabfd4750fe3ca85f0a64dc3b Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 25 Jul 2016 19:01:38 +0200 Subject: [PATCH 124/126] some fixes --- countBattles.txt | 2 +- src/arenas/tron/TronGame.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 7157ddd..46547e5 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1579 \ No newline at end of file +1591 \ No newline at end of file diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index e186945..d484315 100644 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -75,7 +75,7 @@ class TronGame foreach($this->bots as $bot){ $trailsArr[] = $bot->trail->getTrailAsArray(); } - return json_encode($trailsArr); + return $trailsArr; } public function new_lap(){ // for all alive bots @@ -104,7 +104,7 @@ class TronGame } $responses = $this->get_multi_IAS_Responses($urls,$paramsToSend); - print_r($responses); + //print_r($responses); //grow bots'tails for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ @@ -120,7 +120,7 @@ class TronGame for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ foreach($this->bots as $otherBot){ - if($otherBot->trail->contains($lastsCells($botCount))) + if($otherBot->trail->contains($lastsCells[$botCount])) $loosers[] = $botCount; $this->bots[$botCount]->loose(); break; From 5935b750d0334817b38d0370bbb3df1154bee331 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 25 Jul 2016 22:01:58 +0200 Subject: [PATCH 125/126] . --- countBattles.txt | 2 +- src/arenas/tron/TronGame.php | 9 +++++++-- src/arenas/tron/TronPlayer.php | 3 --- src/arenas/tron/js.js | 4 ++++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 46547e5..30ab544 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1591 \ No newline at end of file +1593 \ No newline at end of file diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index d484315..86c210d 100644 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -119,12 +119,17 @@ class TronGame //test if loose for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ - foreach($this->bots as $otherBot){ - if($otherBot->trail->contains($lastsCells[$botCount])) + for( $botCount2 = 0; $botCount2 < $nbeBots; $botCount2++){ + + if(($botCount <> $botCount2) + && ($this->bots[$botCount2]->trail->contains($lastsCells[$botCount])) + ){ $loosers[] = $botCount; $this->bots[$botCount]->loose(); break; } + + } } } diff --git a/src/arenas/tron/TronPlayer.php b/src/arenas/tron/TronPlayer.php index ba8c357..60115f8 100644 --- a/src/arenas/tron/TronPlayer.php +++ b/src/arenas/tron/TronPlayer.php @@ -5,14 +5,12 @@ class TronPlayer{ public $name; public $trail; private $direction; - public $isAlive = true; public function grow(Direction $dir){ $this->trail->add($this->trail->last()->addDirection($dir)); return $this->trail->last(); } - public function loose(){ $this->isAlive = false; $this->trail->emptyTrail(); @@ -29,5 +27,4 @@ class TronPlayer{ public function __construct(){ $this->state = false; } - } \ No newline at end of file diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 9f01129..c189820 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -104,6 +104,10 @@ function play(gameId,xd_check){ if(req.status == 200) { addLog(req.responseText); var reponse = JSON.parse(req.responseText); + + growTails(reponse['lap']); + play(gameId,xd_check); + }else{ } From 1d5624462f07c40f032adb6898ae6b7b177179e8 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 26 Jul 2016 19:55:40 +0200 Subject: [PATCH 126/126] it draws the tail --- countBattles.txt | 2 +- src/arenas/tron/act.php | 1 + src/arenas/tron/js.js | 29 ++++++++++++++++++++++++----- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 30ab544..f84ccb2 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1593 \ No newline at end of file +1617 \ No newline at end of file diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index c7df199..5cc1d81 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -77,6 +77,7 @@ switch ($_POST['act']){ 'continue' => $continue, 'lap' => $lap )); + $_SESSION['game'] = serialize($game); die; break; diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index c189820..1223cbf 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -43,9 +43,9 @@ function changeSelect(number,botId){ return; }else{ show_bot_panel(next); - } + } if(number > 0){ - document.getElementById('fightButton').disabled = false; + document.getElementById('fightButton').disabled = false; } } } @@ -96,6 +96,22 @@ function applyInitMessage(req,xd_check){ } } } + + +function drawMap(map){ + console.log(map); + var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue']; + + for (var botId in map){ + for(var coordsI in map[botId]){ + coords = map[botId][coordsI]; + //draw the point + var rect=createElemNS('rect',{'x':coords[0],'y':coords[1],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'}); + document.getElementById('map').appendChild(rect); + } + } +} + function play(gameId,xd_check){ var req = new XMLHttpRequest(); @@ -105,8 +121,12 @@ function play(gameId,xd_check){ addLog(req.responseText); var reponse = JSON.parse(req.responseText); - growTails(reponse['lap']); - play(gameId,xd_check); + + + drawMap(reponse['lap']); + if(reponse['continue'] == '1'){ + play(gameId,xd_check); + } }else{ @@ -116,7 +136,6 @@ function play(gameId,xd_check){ req.open("POST", '/tron', true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send('act=play&xd_check=' + xd_check + '&gameId=' + gameId + '&fullLogs=' + document.getElementById("fullLogs").checked); - } function tron(xd_check){ //empty