fixes
This commit is contained in:
parent
3b49573988
commit
7939a6a911
|
@ -1 +1 @@
|
|||
1703
|
||||
1716
|
57
src/arenas/tron/ScoreLap.php
Normal file
57
src/arenas/tron/ScoreLap.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
class ScoreLap
|
||||
{
|
||||
private $playersIdsByOrder; //array containing id's of alive players at the beginning of the match, Put only alive bots in!
|
||||
private $looserList; //only containing theirs orders
|
||||
|
||||
public function addBotOnLap($order,$id){
|
||||
$this->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();
|
||||
|
||||
}
|
||||
}
|
|
@ -21,11 +21,14 @@ class TronGame
|
|||
}
|
||||
|
||||
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){
|
||||
|
@ -149,12 +154,9 @@ class TronGame
|
|||
$this->bots[$botCount]->loose();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//loosers list (in order to pass their id)
|
||||
$loosersList = array();
|
||||
foreach($loosers as $looser){
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,3 +142,10 @@ Les champs qui différent sont:
|
|||
</p>
|
||||
<p>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).</p>
|
||||
<p>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.</p>
|
||||
<h2>Scoring</h2>
|
||||
<p>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":</p>
|
||||
<ul>
|
||||
<li>Lors de la défaite d'un bot, l'arène enregistre un match nul contre tous les autres bots qui ont aussi perdu au même tour de jeu.</li>
|
||||
<li>Elle enregistre aussi une défaite des bots morts contre tous les bots encore en course à la fin du tour.</li>
|
||||
</ul>
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue
Block a user