From 7558b7d38d450a80a5bcb7bc91831a6393a50624 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 8 Jul 2016 08:05:29 +0200 Subject: [PATCH] . --- countBattles.txt | 2 +- src/arenas/tron/class.TronGame.php | 62 ++++++++++++++++++++++++++-- src/arenas/tron/class.TronPlayer.php | 6 ++- src/arenas/tron/functions.php | 17 +------- 4 files changed, 65 insertions(+), 22 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index bcddd5d..f6e16be 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1494 \ No newline at end of file +1496 \ No newline at end of file diff --git a/src/arenas/tron/class.TronGame.php b/src/arenas/tron/class.TronGame.php index c62b215..eccd144 100644 --- a/src/arenas/tron/class.TronGame.php +++ b/src/arenas/tron/class.TronGame.php @@ -29,6 +29,23 @@ class TronGame return $board; } + private function save_draw_bots($arr){ + /* + * Recursive function who save all combionaisons of draw matches + */ + + if(count($arr) < 2){ + return; + }else{ + $a = $arr[0]; + array_shift($arr); + foreach($arr as $bot){ + save_battle('tron',$a,$bot,0); + } + $this->save_draw_bots($arr); + } + } + private function get_multi_IAS_Responses($iasUrls, $postParams){ //same as the get_IAS_Responses function // but more than one bot requested parallely @@ -114,7 +131,8 @@ class TronGame $nbeBots = count($this->bots); $urls = array(); $paramToSend = array(); - + $board = $this->getBoard(); + $loosers = array(); for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->getStatus()){ @@ -123,15 +141,53 @@ class TronGame 'game-id' => "".$this->gameId, 'action' => 'play-turn', 'game' => 'tron', - 'board' => $this->getBoard(), + 'board' => $board, 'player-index' => $botCount, // To do: verifier que ça restera le même à chaque tour 'players' => $nbeBots ); - } } $responses = $this->get_multi_IAS_Responses($urls,$paramsToSend); + + $targetsList = array(); + $busyCells = $this->getBusyCells(); + for ($botCount = 0; $botCount < $nbeBots; $botCount++){ + if ($this->bots[$botCount]->getStatus()){ + //tester si sa réponse n'est pas sur une case déjà occupée. + $target = $this->bot[$botCount]->grow($response[$botCount]['responseArr']['play']); + $x = $target[0]; + $y = $target[1]; + $hashTargetsList[$botCount] = $x * 1000 + $y; //wil be easyest to compare than if it was arrays + if(($target === false) + OR (in_array($target,$busyCells)) + OR ($x < 0) OR ($x > 999) OR ($y < 0) OR ($y > 999) + ){ + //he loses + $loosers[] = $botCount; + } + } + } + + //did some bots have played on the same cell? + for ($botCount = 0; $botCount < $nbeBots; $botCount++){ + if ($this->bots[$botCount]->getStatus()){ + for ($botCount2 = 0; $botCount2 < $nbeBots; $botCount2++){ + if (($this->bots[$botCount2]->getStatus()) + && ($botCount <> $botCount2) + && ($hashTargetsList[$botCount] == $hashTargetsList[$botCount2]) + ){ + //they loose + $loosers[] = $botCount; + $loosers[] = $botCount2; + } + } + } + } + + //save_draw_bots + + print_r($responses); diff --git a/src/arenas/tron/class.TronPlayer.php b/src/arenas/tron/class.TronPlayer.php index d2dbbf1..3aa3d1b 100644 --- a/src/arenas/tron/class.TronPlayer.php +++ b/src/arenas/tron/class.TronPlayer.php @@ -30,7 +30,7 @@ class TronPlayer{ $this->direction = $newDir; return true; } - public function getTargetCell($dir){ + private function getTargetCell($dir){ if($dir == ""){ $dir = $this->direction; @@ -61,7 +61,9 @@ class TronPlayer{ } public function grow($dir=""){ - $this->tail[] = $this->getTargetCell($dir); + $targetCell = $this->getTargetCell($dir); + $this->tail[] = $targetCell; + return $targetCell; } public function loose(){ $this->state = false; diff --git a/src/arenas/tron/functions.php b/src/arenas/tron/functions.php index 9285281..0705b1d 100644 --- a/src/arenas/tron/functions.php +++ b/src/arenas/tron/functions.php @@ -1,20 +1,5 @@