From 0fb60e7cf444d5181e67692dd9aad46a88dd0b97 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 30 Sep 2016 18:36:24 +0200 Subject: [PATCH] fixes --- countBattles.txt | 2 +- src/arenas/tron/Direction.php | 5 ++++- src/arenas/tron/Trail.php | 7 +++--- src/arenas/tron/TronGame.php | 40 ++++++++++++++++++++++----------- src/arenas/tron/act.php | 2 ++ src/arenas/tron/js.js | 42 +++++++++-------------------------- 6 files changed, 48 insertions(+), 50 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 5b208ae..377ce3c 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1622 \ No newline at end of file +1660 \ No newline at end of file diff --git a/src/arenas/tron/Direction.php b/src/arenas/tron/Direction.php index 4f1396f..69105e2 100755 --- a/src/arenas/tron/Direction.php +++ b/src/arenas/tron/Direction.php @@ -73,7 +73,10 @@ class Direction $dir->setValue(Direction::$bottom); break; default: - throw new InvalidDirectionException("expected 'x+', 'x-', 'y+' or 'y-'". (string)$str."received."); + //error_log("expected 'x+', 'x-', 'y+' or 'y-'". (string)$str."received."); + return false; + //throw new InvalidDirectionException("expected 'x+', 'x-', 'y+' or 'y-'". (string)$str."received."); + break; } return $dir; } diff --git a/src/arenas/tron/Trail.php b/src/arenas/tron/Trail.php index 195a692..dca329b 100755 --- a/src/arenas/tron/Trail.php +++ b/src/arenas/tron/Trail.php @@ -25,9 +25,10 @@ class Trail { } if($this->contains($value)) { - throw new AlreadyBeenAddedException( - 'value has already been added to the trail' - ); + //throw new AlreadyBeenAddedException( + // 'value has already been added to the trail'.$value.'|'.$this->__toString() + //); + return false; } } diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index f790989..afd17d2 100755 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -92,6 +92,7 @@ class TronGame $urls = array(); $paramToSend = array(); $board = $this->get_trails(); + //$board = $this->get_lasts_trails(); $loosers = array(); $lastsCells = array(); @@ -108,27 +109,40 @@ class TronGame 'player-index' => $botCount, // To do: verifier que ça restera le même à chaque tour 'players' => $nbeBots ); + //!!!!!!!!!!!!! To debug + //error_log(json_encode($paramsToSend[$botCount])); } } $responses = $this->get_multi_IAS_Responses($urls,$paramsToSend); - //print_r($responses); - //grow bots'tails + + //grow bots'tails for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ - $dir = Direction::make($responses[$botCount]['responseArr']['play']); + if(!$dir = Direction::make($responses[$botCount]['responseArr']['play'])){ + //he loses , non conform response + $loosers[] = $botCount; + $this->bots[$botCount]->loose(); + }else{ - $lastsCells[$botCount] = $this->bots[$botCount]->grow($dir); + $lastsCells[$botCount] = $this->bots[$botCount]->grow($dir); + if($lastsCells[$botCount] === false){ + $loosers[] = $botCount; + $this->bots[$botCount]->loose(); + } + + } } } //test if loose - for ($botCount = 0; $botCount < $nbeBots; $botCount++){ + for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ - for( $botCount2 = 0; $botCount2 < $nbeBots; $botCount2++){ - + + //tester si collusion avec les cases actuelles + for( $botCount2 = 0; $botCount2 < $nbeBots; $botCount2++){ if(($botCount <> $botCount2) && ($this->bots[$botCount2]->trail->contains($lastsCells[$botCount])) ){ @@ -137,13 +151,13 @@ class TronGame break; } - } + } + } } return $this->get_lasts_trails(); - - + } @@ -218,11 +232,11 @@ class TronGame $nbeBots = count($this->bots); for ($botCount = 0; $botCount < $nbeBots; $botCount++){ $messageArr = array( - 'game-id' => "".$this->gameId, - 'action' => 'init', + 'game-id' => "".$this->gameId, + 'action' => 'init', 'game' => 'tron', 'board' => '', - 'players' => $nbeBots, + 'players' => $nbeBots, 'player-index' => $botCount ); diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index c8dcde0..f527950 100755 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -10,6 +10,8 @@ # # -- END LICENSE BLOCK ----------------------------------------- +//error_log(json_encode($_SESSION,true)."\n\n"); + require_once ("TronGame.php"); require_once ("TronPlayer.php"); require_once ("Direction.php"); diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 969d8e3..5e44b37 100755 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -12,24 +12,7 @@ function addLog(message){ divLogs.scrollTop = divLogs.scrollHeight; } -/* -function growTails(newPointsByPlayer){ - var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue']; - //document.getElementById('map'); - for (var botId in newPointsByPlayer){ - - var tail = newPointsByPlayer[botId]['tail']; - for(var coordsIx in tail){ - - coords = tail[coordsIx]; - //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 createElemNS(type,attributes){ //same as createElem but with ns for svg file var elem=document.createElementNS("http://www.w3.org/2000/svg",type); @@ -92,7 +75,7 @@ function applyInitMessage(req,xd_check){ } }else{ - alert ('error ' + req.status); + alert ('error ' + req.status + req.responseText ); document.getElementById('fightButton').disabled=false; return; } @@ -108,15 +91,6 @@ function drawMap(map){ //draw the point var rect=createElemNS('rect',{'x':map[botId]['x'],'y':map[botId]['y'],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'}); document.getElementById('map').appendChild(rect); - /* - 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); - } - */ } } @@ -127,13 +101,17 @@ function play(gameId,xd_check){ if(req.readyState == 4){ if(req.status == 200) { addLog(req.responseText); - var reponse = JSON.parse(req.responseText); - - - + var reponse = JSON.parse(req.responseText); drawMap(reponse['lap']); if(reponse['continue'] == '1'){ - play(gameId,xd_check); + + setTimeout(function(){ + play(gameId,xd_check); + } ,500); + + + + }else{ alert ('game ended'); }