From 7939a6a91119c2905109cad5b13f77a36b14f56c Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 14 Oct 2016 21:24:55 +0200 Subject: [PATCH] fixes --- countBattles.txt | 2 +- src/arenas/tron/ScoreLap.php | 57 ++++++++++++++++++++++++++++++++++++ src/arenas/tron/TronGame.php | 18 +++++++----- src/arenas/tron/act.php | 5 ++-- src/arenas/tron/doc-fr.html | 7 +++++ src/functions.php | 1 + 6 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 src/arenas/tron/ScoreLap.php diff --git a/countBattles.txt b/countBattles.txt index 9b21444..f754216 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1703 \ No newline at end of file +1716 \ No newline at end of file diff --git a/src/arenas/tron/ScoreLap.php b/src/arenas/tron/ScoreLap.php new file mode 100644 index 0000000..9c42848 --- /dev/null +++ b/src/arenas/tron/ScoreLap.php @@ -0,0 +1,57 @@ +playersIdsByOrder[$order] = $id; + } + + public function addLoser($order){ + $this->looserList[] = $order; + } + public function __construct() { + $this->playersIdsByOrder = array(); + $this->looserList = array(); + } + public function make($botsList){ + //$botsList must be like array[{botOrder:BotId},{botOrder:BotId}] + $this->looserList = $botsList; + } + + private function ApplyDraws(){ + //apply draw match to all losers + if(count($this->looserList) > 1){ //no draw if only 0 or one user at this lap + foreach($looserList as $looser1){ + foreach($looserList as $looser2){ + save_battle('tron', + $this->playersIdsByOrder[$looser1], + $this->playersIdsByOrder[$looser2], + 0, + 'id'); + } + } + } + } + private function ApplyWins(){ + foreach($this->looserList as $looser){ + foreach($playersIdsByOrder as $order=>$player){ + if(!in_array($order,$this->looserList)){ + save_battle('tron', + $this->playersIdsByOrder[$looser], + $player, + 2, + 'id'); + } + } + } + + } + public function ApplyScores(){ + $this-> ApplyDraws(); + $this-> ApplyWins(); + + } +} \ No newline at end of file diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index 4d6a949..6288e0c 100755 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -20,12 +20,15 @@ class TronGame } } - private function apply_looses($loosersArr){ + private function apply_looses($loosersArr){ + //$loosersArr est construit comme ça: [{"order":1,"id":54"},{"order":3,"id":54"}] + //save draws if( count($loosersArr) > 0 ){ $loosersById = array(); foreach($loosersArr as $bot){ - $loosersById[] = $this->bots[$bot]->id; + //error_log('apply lose '.$bot['id']); + $loosersById[] = $bot['id']; } } @@ -96,9 +99,13 @@ class TronGame $loosers = array(); $lastsCells = array(); + $scoring = new ScoreLap(); + + for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ + $scoreLap->addBotOnLap($botCount,$this->bots[$botCount]->id); $urls[$botCount] = $this->bots[$botCount]->url; $paramsToSend[$botCount] = array( @@ -134,8 +141,6 @@ class TronGame } } } - - //test if loose for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ @@ -148,13 +153,10 @@ class TronGame $loosers[] = $botCount; $this->bots[$botCount]->loose(); break; - } - + } } - } } - //loosers list (in order to pass their id) $loosersList = array(); foreach($loosers as $looser){ diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index 3a4714b..d88e0ee 100755 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -17,6 +17,7 @@ require_once ("TronPlayer.php"); require_once ("Direction.php"); require_once ("Trail.php"); require_once ("Coords.php"); +require_once ("ScoreLap.php"); switch ($_POST['act']){ case "initGame": @@ -28,12 +29,12 @@ switch ($_POST['act']){ $botsArrayTemp = json_decode($_POST['bots']); - error_log($botsArrayTemp); + //error_log($_POST['bots']); $botsInfos = array(); foreach($botsArrayTemp as $id){ //tester si le bot existe dans la bdd - if(isset($botsFullArr[$id])){ + if((isset($botsFullArr[$id])) && ($id > 0)){ $botsInfos[] = $botsFullArr[$id]; } } diff --git a/src/arenas/tron/doc-fr.html b/src/arenas/tron/doc-fr.html index 2231cfb..1170785 100755 --- a/src/arenas/tron/doc-fr.html +++ b/src/arenas/tron/doc-fr.html @@ -142,3 +142,10 @@ Les champs qui différent sont:

L'ordre des "queues" des serpents dans ce tableau correspond à l'ordre des joueurs. Donc votre serpent est representée par la queue correspondant à player-index (le décompte de player-index commence par 0).

L'ordre des couples de coordonnées de chaque bot, est dans le sens queue vers la tête. Les bots grandissent à chaque tour en déplaçant leur tête.

+

Scoring

+

Le scorring (classement EHLO) reste sur une logique de duels, bien que ce jeu puisse contenir plus de deux bots par match. Le score est modifié au fur et à mesure de la partie à chaque fois qu'un bot "décède":

+ + diff --git a/src/functions.php b/src/functions.php index 8fd041a..3c44b40 100755 --- a/src/functions.php +++ b/src/functions.php @@ -114,6 +114,7 @@ function get_language_array(){ return $lang; } function error($code,$message){ + error_log($code." ".$message); switch($code){ case 404: header("HTTP/1.0 404 Not Found");