From 27cdeb549c66226dff6c620a6f1b1752a15b2b63 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 24 Nov 2016 19:31:32 +0100 Subject: [PATCH 1/4] start rewriting core --- countBattles.txt | 2 +- html/index.php | 66 ++++++++++++++++- html/testBotScripts/tron.html | 131 ++++++++++++++++++++++++++++++++++ src/ARENAS.php | 77 ++++++++++++++++++++ src/BOTS.php | 46 ++++++++++++ src/DUEL.php | 10 --- src/arenas/tron/Direction.php | 2 +- 7 files changed, 320 insertions(+), 14 deletions(-) create mode 100755 html/testBotScripts/tron.html create mode 100644 src/ARENAS.php create mode 100644 src/BOTS.php 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 @@ Date: Tue, 29 Nov 2016 18:33:39 +0100 Subject: [PATCH 2/4] back --- countBattles.txt | 2 +- html/index.php | 66 ++--------------------------------- src/DUEL.php | 10 ++++++ src/arenas/tron/Direction.php | 2 +- 4 files changed, 14 insertions(+), 66 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 645efcf..d081bc1 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1865 \ No newline at end of file +1836 \ No newline at end of file diff --git a/html/index.php b/html/index.php index 76fd88f..a5b940b 100755 --- a/html/index.php +++ b/html/index.php @@ -13,11 +13,9 @@ @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 @@ -26,66 +24,6 @@ $lnMysql=conn_bdd(); //$_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/src/DUEL.php b/src/DUEL.php index ca00537..0b158c5 100644 --- a/src/DUEL.php +++ b/src/DUEL.php @@ -31,6 +31,16 @@ class DUEL{ } } + + + + + + + + + + class ELO { public $rank = 1500; //default rank diff --git a/src/arenas/tron/Direction.php b/src/arenas/tron/Direction.php index 8cadfed..69105e2 100755 --- a/src/arenas/tron/Direction.php +++ b/src/arenas/tron/Direction.php @@ -1,6 +1,6 @@ Date: Tue, 29 Nov 2016 18:39:38 +0100 Subject: [PATCH 3/4] back2 --- src/ARENAS.php | 77 -------------------------------------------------- src/BOTS.php | 46 ------------------------------ 2 files changed, 123 deletions(-) delete mode 100644 src/ARENAS.php delete mode 100644 src/BOTS.php diff --git a/src/ARENAS.php b/src/ARENAS.php deleted file mode 100644 index edda28e..0000000 --- a/src/ARENAS.php +++ /dev/null @@ -1,77 +0,0 @@ - "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 deleted file mode 100644 index bf930e9..0000000 --- a/src/BOTS.php +++ /dev/null @@ -1,46 +0,0 @@ -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 From 8355a75c9931c10787d8f048775be7e225608c29 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 29 Nov 2016 18:51:32 +0100 Subject: [PATCH 4/4] Tron down to 100X100, My CPU is happy --- src/arenas/tron/Coords.php | 2 +- src/arenas/tron/TronGame.php | 4 ++-- src/arenas/tron/doc-en.html | 4 ++-- src/arenas/tron/doc-fr.html | 4 ++-- src/arenas/tron/js.js | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/arenas/tron/Coords.php b/src/arenas/tron/Coords.php index 9fdb5e4..dbb8c29 100755 --- a/src/arenas/tron/Coords.php +++ b/src/arenas/tron/Coords.php @@ -1,7 +1,7 @@ The game ends when there are less than two snakes left

Grid

Communications between the arena and the bots

diff --git a/src/arenas/tron/doc-fr.html b/src/arenas/tron/doc-fr.html index eeeabe5..cf700d8 100755 --- a/src/arenas/tron/doc-fr.html +++ b/src/arenas/tron/doc-fr.html @@ -34,8 +34,8 @@

Le jeu prend fin lorsqu'il reste moins de deux serpents.

La grille

Communications entre l'arène et les bots

diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 54f52e1..7ce82c5 100755 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -90,7 +90,7 @@ function drawMap(map){ for (var botId in map){ if(typeof(map[botId]['x']) != 'undefined'){ //don't draw deads bots //draw the point - var rect=createElemNS('rect',{'x':map[botId]['x'],'y':map[botId]['y'],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'}); + var rect=createElemNS('rect',{'x':map[botId]['x'],'y':map[botId]['y'],'width':'1','height':'1','style':'fill:' + botsColor[botId] + ';'}); document.getElementById('map').appendChild(rect); } } @@ -159,7 +159,7 @@ function tron(xd_check){ document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); } // draw border; - var svg = createElemNS('svg',{'id':'map','width':'500','height':'500','viewBox':'0 0 1000 1000'}); + var svg = createElemNS('svg',{'id':'map','width':'500','height':'500','viewBox':'0 0 100 100'}); var rect=createElemNS('rect',{'x':'0','y':'0','width':'1000','height':'1000','style':'stroke:#000000; fill:none;'}); svg.appendChild(rect); document.getElementById("fightResult").appendChild(svg);