diff --git a/countBattles.txt b/countBattles.txt index f6e16be..ae6f116 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1496 \ No newline at end of file +1507 \ No newline at end of file diff --git a/src/arenas/tron/class.TronGame.php b/src/arenas/tron/class.TronGame.php index eccd144..46657db 100644 --- a/src/arenas/tron/class.TronGame.php +++ b/src/arenas/tron/class.TronGame.php @@ -40,12 +40,21 @@ class TronGame $a = $arr[0]; array_shift($arr); foreach($arr as $bot){ - save_battle('tron',$a,$bot,0); + save_battle('tron',$a,$bot,0,'id'); } $this->save_draw_bots($arr); } } + private function save_losers_winers($arrLoosers,$arrWiners){ + foreach($arrWiners as $winner){ + foreach($arrLoosers as $loser){ + save_battle('tron',$winer,$loser,1,'id'); + } + } + + } + private function get_multi_IAS_Responses($iasUrls, $postParams){ //same as the get_IAS_Responses function // but more than one bot requested parallely @@ -149,20 +158,25 @@ class TronGame } $responses = $this->get_multi_IAS_Responses($urls,$paramsToSend); - + //print_r($responses); $targetsList = array(); $busyCells = $this->getBusyCells(); + $busyCellsStr = array(); + foreach ($busyCells as $bs){ + $busyCellsStr[] = $bs[0].",".$bs[1]; //as string for use in in_array + } 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']); + $target = $this->bots[$botCount]->grow($responses[$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 (in_array($target,$busyCellsStr)) OR ($x < 0) OR ($x > 999) OR ($y < 0) OR ($y > 999) ){ + $this->bots[$botCount]->loose(); //he loses $loosers[] = $botCount; } @@ -177,6 +191,7 @@ class TronGame && ($botCount <> $botCount2) && ($hashTargetsList[$botCount] == $hashTargetsList[$botCount2]) ){ + $this->bots[$botCount]->loose(); //they loose $loosers[] = $botCount; $loosers[] = $botCount2; @@ -185,10 +200,21 @@ class TronGame } } - //save_draw_bots + + if(count($loosers > 0)){ + + //save_draw_bots + save_draw_bots($loosers); + $winners = array(); + for ($botCount = 0; $botCount < $nbeBots; $botCount++){ + if ($this->bots[$botCount]->getStatus()){ + $winners[] = $this->bots[$botCount]->getId(); + } + } + } - print_r($responses); + //sauver les relations winers loosers } @@ -224,7 +250,7 @@ class TronGame private function getBusyCells(){ $arr=array(); foreach($this->bots as $bot){ - $arr = array_merge($arr,$bot->getTail); + $arr = array_merge($arr,$bot->getTail()); } return $arr; } diff --git a/src/arenas/tron/class.TronPlayer.php b/src/arenas/tron/class.TronPlayer.php index 3aa3d1b..c90462c 100644 --- a/src/arenas/tron/class.TronPlayer.php +++ b/src/arenas/tron/class.TronPlayer.php @@ -1,6 +1,7 @@ name; } + public function getId(){ + return $this->id; + } private function set_direction($newDir){ //can't be the opposite of the previous direction if( @@ -76,6 +80,7 @@ class TronPlayer{ "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->id = $id; $this->name = $r[0]; $this->url = $r[1]; $this->tail = array(array($initialX,$initialY)); diff --git a/src/functions.php b/src/functions.php index 3e9e3b1..8fd041a 100644 --- a/src/functions.php +++ b/src/functions.php @@ -229,18 +229,24 @@ function ELO_get_new_ranks($elo1,$elo2,$score){ $elo2 + ELO_get_k($elo2) * (1 - $score - (1/ (1 + pow(10,(($elo1 - $elo2) / 400))))) ); } -function save_battle($game,$bot1,$bot2,$resultat){ + +function save_battle($game,$bot1,$bot2,$resultat,$nameOrIds = 'name'){ + //$bots1 and $bots2 are bots'names //resultat: 0 match nul, 1 bot1 gagne 2 bot 2 gagne global $lnMysql; - $game=substr($game,0,8); //limit 8 char for limitting mysql index size - - //chercher les id de bot 1 et bot2 - $rs=mysqli_query($lnMysql,"SELECT name,id,ELO FROM bots - WHERE name='".mysqli_real_escape_string($lnMysql,$bot1)."' - OR name='".mysqli_real_escape_string($lnMysql,$bot2)."'"); + if($nameOrIds == "name"){ + //chercher les id de bot 1 et bot2 + $rs=mysqli_query($lnMysql,"SELECT name,id,ELO FROM bots + WHERE name='".mysqli_real_escape_string($lnMysql,$bot1)."' + OR name='".mysqli_real_escape_string($lnMysql,$bot2)."'"); + }else{ + $rs = mysqli_query($lnMysql, "SELECT name,id,ELO FROM bots + WHERE id='".mysqli_real_escape_string($lnMysql,$bot1)."' + OR id='".mysqli_real_escape_string($lnMysql,$bot2)."'"); + } while($r=mysqli_fetch_row($rs)){ $bots[$r[0]]=$r[1]; $actualELO[$r[0]]=$r[2];