diff --git a/countBattles.txt b/countBattles.txt index d081bc1..645efcf 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1836 \ No newline at end of file +1865 \ No newline at end of file diff --git a/html/index.php b/html/index.php index a5b940b..76fd88f 100755 --- a/html/index.php +++ b/html/index.php @@ -13,9 +13,11 @@ @session_start(); require_once("../src/functions.php"); +//load classes +require_once ("../src/ARENAS.php"); +require_once ("../src/BOTS.php"); + $lnMysql=conn_bdd(); -$arenas=get_arenas_list(); -$lang=get_language_array(); //check type of page //$_GET['arena'] -> an arena @@ -24,6 +26,66 @@ $lang=get_language_array(); //$_GET['page'] -> a simple page like about page, legals etc... //Nothing -> home page + +if(isset($_GET['arena'])){ + $arenaId = $_GET['arena']; +}elseif(isset($_GET['doc'])){ + $arenaId = $_GET['doc']; +}elseif(isset($_GET['scores'])){ + $arenaId = $_GET['scores']; +}else{ + $arenaId = ""; +} + +//hydrate +require_once ("../src/arenas_lists.php"); +$exists = false; +foreach($arenas as $arena){ + + if($arenaId == "") break; + + if($arena['id'] == $arenaId){ + $currentArena = new ARENA($arenaId); + $currentArena->hydrate($arena); + //add Bots on arena + $rs=mysqli_query($lnMysql, + "SELECT id,name,url,description,ELO + FROM bots + WHERE game='".mysqli_real_escape_string($lnMysql,$currentArena->get_id())."' + AND active='1';" + ); + while($r=mysqli_fetch_array($rs)){ + $bot = new BOT("plop"); + $bot->hydrate($r); + $currentArena->addBot($bot); + } + $exists = true; + break; + } +} +if((!$exists)&& ($arenaId <> ""))error(404,"Page not found ".$arenaId); //l'arene passée en url n'existe pass + + + +if($arenaId == ""){ + echo "accueil"; +}else{ + foreach($currentArena->bots as $bot){ + echo $bot->name."\n"; + } +} + +die(); +//**********************rewriting this file! *************** + +//**********OLD code from here ************************************ + + + + + + + $permitIndex=true; //will be set to false for pages that google or other bot must not index if(isset($_GET['arena'])){ diff --git a/html/testBotScripts/tron.html b/html/testBotScripts/tron.html new file mode 100755 index 0000000..978ab3b --- /dev/null +++ b/html/testBotScripts/tron.html @@ -0,0 +1,131 @@ + + + + + + + + Trons's Ludus + + + + + +
+

Tron's Ludus

+
+
+

Here you can test and fix your bot, against himself, against human or against any other bot if you know the URL. +
No scoring here, it's a Ludus (gladiators training center).

+ + +
+
+
+ + + diff --git a/src/ARENAS.php b/src/ARENAS.php new file mode 100644 index 0000000..edda28e --- /dev/null +++ b/src/ARENAS.php @@ -0,0 +1,77 @@ + "tictactoe", + 'url' => "/tictactoe", + 'title' => "Tic Tac Toe", + 'metaDescription' => 'Affrontements de bots au TicTacToe, morpion', + 'jsFile'=> "js.js", + 'cssFile'=> "style.css", + 'ludusUrl' => "/testBotScripts/tictactoe.html" + */ + public function get_id(){ + return $this->id; + } + public function get_css_code(){ + return file_get_contents($this->path.$this->cssFile); + } + public function get_js_code(){ + return file_get_contents($this->path.$this->jsFile); + } + public function get_title(){ + return $this->title; + } + public function get_meta_description(){ + return $this->metaDescription; + } + public function get_ludus_url(){ + return $this->ludusUrl; + } + public function get_doc($lang){ + if(file_exists($this->path."doc-".$lang.".html")) return file_get_contents($this->path."doc-".$lang.".html"); + if(file_exists($this->path."doc-fr.html")) return file_get_contents($this->path."doc-fr.html"); + return ""; + } + + + public function __construct($name){ + $this->name = $name; + $this->path = __DIR__."/arenas/".$name."/"; + + if(!is_dir($this->path)){ + throw new InvalidArenaException("No path containing arena ".$name." found ".__DIR__."/".$name."/"); + } + + $this->bots = new SplStack(); + + } + + public function hydrate($arr){ + foreach ($arr as $key => $value){ + if (property_exists($this,$key)){ + $this->$key = $value; + }else{ + throw new InvalidArenaException("incorrect array key"); + } + } + } + public function addBot(BOT $bot){ + $this->bots->push($bot); + } +} \ No newline at end of file diff --git a/src/BOTS.php b/src/BOTS.php new file mode 100644 index 0000000..bf930e9 --- /dev/null +++ b/src/BOTS.php @@ -0,0 +1,46 @@ +name = $name; + } + public function hydrate ($arr){ + foreach ($arr as $key => $value){ + if (property_exists($this,$key)){ + $this->$key = $value; + }elseif(is_numeric($key)){ + //rien, on accepte mais prends pas en compte + }else{ + throw new InvalidArenaException("incorrect array key".$key); + } + } + } +} \ No newline at end of file diff --git a/src/DUEL.php b/src/DUEL.php index 0b158c5..ca00537 100644 --- a/src/DUEL.php +++ b/src/DUEL.php @@ -31,16 +31,6 @@ class DUEL{ } } - - - - - - - - - - class ELO { public $rank = 1500; //default rank diff --git a/src/arenas/tron/Direction.php b/src/arenas/tron/Direction.php index 69105e2..8cadfed 100755 --- a/src/arenas/tron/Direction.php +++ b/src/arenas/tron/Direction.php @@ -1,6 +1,6 @@