diff --git a/.gitignore b/.gitignore index 38942cb..149ba46 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ src/config.php +src/countBattles.txt \ No newline at end of file diff --git a/html/index.php b/html/index.php index 1ea7818..1e1393e 100644 --- a/html/index.php +++ b/html/index.php @@ -44,7 +44,7 @@ if(isset($_GET['arena'])){ $hist=get_battles_history($currentArena); - $siteTitle=$currentArenaArr['title']." - bots Arena"; + $siteTitle=$currentArenaArr['title']; $siteDescription=$currentArenaArr['metaDescription']; $mainSectionScript="../src/arenas/".$currentArena."/public.php"; $asideSectionContent='

infos:

'.$lang['DEV-YOUR-OWN-BOT'].'
'.$lang['DOC_SPECS_LINKS'].'

@@ -85,7 +85,7 @@ if(isset($_GET['arena'])){ error(404,"Wrong parameter"); die; } - $siteTitle="Specifications ".$currentArenaArr['title']." - bots Arena"; + $siteTitle="Specifications ".$currentArenaArr['title']; $siteDescription="documentation, faites votre propre bot pour ".$currentArenaArr['metaDescription']; $mainSectionScript="../src/arenas/".$currentArenaArr['id']."/doc-".$lang['lang'].".html"; $asideSectionContent=''; //to do @@ -104,7 +104,7 @@ if(isset($_GET['arena'])){ $jsAdditionalScript=""; break; case "About": - $siteTitle="About - bots Arena"; + $siteTitle="About"; $siteDescription="bots arena about page"; $mainSectionScript="../src/about.html"; $asideSectionContent=''; //to do or not to do @@ -112,7 +112,7 @@ if(isset($_GET['arena'])){ $jsAdditionalScript=""; break; case "addBot": - $siteTitle="Valider l'ajout d'une IA - bots Arena"; + $siteTitle="Valider l'ajout d'une IA"; $siteDescription="bots arena about page"; $permitIndex=false; $mainSectionScript="../src/addBot.php"; diff --git a/html/style.css b/html/style.css index 9fb8c07..62ece79 100644 --- a/html/style.css +++ b/html/style.css @@ -1,18 +1,12 @@ -html { - height: 100%; -} body{ width:100%; font-size:100%; - top: 0px; line-height:140%; word-wrap:break-word; text-rendering:optimizelegibility; margin:0 auto; font-family : "lucida grande", "gill sans", arial, sans-serif; left:auto; -top:auto; - min-height:100%; } header{ background-color:#A60800; @@ -24,10 +18,9 @@ header h1{ display: block; font-size:300%; color:#FFF;float: left; - width: 45%; margin-left: 5%;} - header nav{ +header nav{ display: block; width: 45%; color:#FFF; @@ -82,7 +75,6 @@ footer a { section{ margin: 0 auto; width: 90%; - padding-bottom: 40px; } article{ float: right; @@ -91,7 +83,7 @@ article{ aside{ float:left; width: 28%; - border-right: + border-right: 1px dashed green; } form textarea, form input, form select {width:40%;} diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php new file mode 100644 index 0000000..0a69db6 --- /dev/null +++ b/src/arenas/Battleship/act.php @@ -0,0 +1,68 @@ + $p[2]) + ) + { + error(500,'wrong parameters'); + die; + } + $postValues[$p[0]]=$value; + + } + //check if bots exists + $bot1Exists = false; + $bot2Exists = false; + foreach($bots as $bot){ + if($bot['id'] == $_POST['bot1']){ + $bot1 = $bot; + $bot1Exists =true; + } + if($bot['id'] == $_POST['bot2']){ + $bot2 = $bot; + $bot2Exists =true; + } + if ($bot1Exists && $bot2Exists){ + break; + } + } + if ((!$bot1Exists) OR (!$bot2Exists)){ + error (500,"missing parameter"; + } + + //vars checked, lets init the initGame + + $_SESSION['matchId']=get_unique_id(); + + + break; + default: + break; +} \ No newline at end of file diff --git a/src/arenas/Battleship/doc-fr.html b/src/arenas/Battleship/doc-fr.html new file mode 100644 index 0000000..cd2f505 --- /dev/null +++ b/src/arenas/Battleship/doc-fr.html @@ -0,0 +1,7 @@ +

Initialisation de la partie

+

Pour démarrer la partie, l'arène va envoyer une requette http(s) à votre programme contenant les paramètres POST suivants:

+ \ No newline at end of file diff --git a/src/arenas/Battleship/functions.php b/src/arenas/Battleship/functions.php new file mode 100644 index 0000000..f57cd56 --- /dev/null +++ b/src/arenas/Battleship/functions.php @@ -0,0 +1,44 @@ + $botsCount)){ + error(400,"wrong parameters"); + die; + } + } + return array('bot1' => $_POST['bot1'],'bot2' => $_POST['bot2']); +} + +function generate_numeric_select($start,$end,$selected,$name,$id){ + $out="'.$i.''; + } + }else{ + for($i=$start; $i < $selected; $i++ ){ + $out.=''; + } + $out.=''; + for($i=$selected + 1; $i <= $end; $i++ ){ + $out.=''; + } + } + return $out.""; + +} \ No newline at end of file diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js new file mode 100644 index 0000000..e5d752b --- /dev/null +++ b/src/arenas/Battleship/js.js @@ -0,0 +1,83 @@ +function Ajx(){ + var request = false; + try {request = new ActiveXObject('Msxml2.XMLHTTP');} + catch (err2) { + try {request = new ActiveXObject('Microsoft.XMLHTTP');} + catch (err3) { + try { request = new XMLHttpRequest();} + catch (err1) { + request = false; + } + } + } + return request; +} +function createElem(type,attributes) +{ + var elem=document.createElement(type); + for (var i in attributes) + {elem.setAttribute(i,attributes[i]);} + return elem; +} + +function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6,xd_check){ + var bot1IdName = bot1.split("-"); + var bot2IdName = bot2.split("-"); + document.getElementById('fightResult').innerHTML = ''; + //dessiner les deux grilles + var tableAdv=createElem("table",{"id":"tblAdv","class":"battleshipGrid"}); + var tableMe=createElem("table",{"id":"tblAdv","class":"battleshipGrid"}); + //ligne de titre + var trTitre1=createElem("tr"); + var trTitre2=createElem("tr"); + var tdTitre1=createElem("th",{"colspan":gridWidth}); + var tdTitre2=createElem("th",{"colspan":gridWidth}); + tdTitre1.innerHTML = bot1IdName[1]; + tdTitre2.innerHTML = bot2IdName[1]; + trTitre1.appendChild(tdTitre1); + tableAdv.appendChild(trTitre1); + trTitre2.appendChild(tdTitre2); + tableMe.appendChild(trTitre2); + + for (var i=0; i < gridHeight ; i++){ + var trAdv=createElem("tr"); + var trMe=createElem("tr"); + for (var j=0; j < gridWidth ; j++){ + var tdAdv=createElem("td",{"id":"adv" + i +"-" + j,"class": "empty"}); + var tdMe=createElem("td",{"id":"me" + i +"-" + j,"class": "empty"}); + trAdv.appendChild(tdAdv); + trMe.appendChild(tdMe); + } + tableAdv.appendChild(trAdv); + tableMe.appendChild(trMe); + } + document.getElementById('fightResult').appendChild(tableAdv); + document.getElementById('fightResult').appendChild(tableMe); + var divLogs=createElem("div",{"id":"logs"}); + document.getElementById('fightResult').appendChild(divLogs); + + + + var xhr = Ajx(); + xhr.onreadystatechange = function(){if(xhr.readyState == 4){ + if(xhr.status == 200) { + //document.getElementById('fightResult').innerHTML = xhr.responseText; + } + }}; + xhr.open("POST", '/Battleship', true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send( + 'act=initGame&bot1=' + bot1 + + '&bot2=' + bot2 + + '&gridWidth=' + gridWidth + + '&gridHeight=' + gridHeight + + '&nbShip1=' + nbShip1 + + '&nbShip1=' + nbShip2 + + '&nbShip3=' + nbShip3 + + '&nbShip4=' + nbShip4 + + '&nbShip5=' + nbShip5 + + '&nbShip6=' + nbShip6 + + '&xd_check=' + xd_check + ); + +} \ No newline at end of file diff --git a/src/arenas/Battleship/public.php b/src/arenas/Battleship/public.php index 61aa218..f62943a 100644 --- a/src/arenas/Battleship/public.php +++ b/src/arenas/Battleship/public.php @@ -1 +1,55 @@ -

Battle ship

\ No newline at end of file + +
+

+

+

+

+

+

+

+

+

+

+ +  VS  + +

+ +

+
+
\ No newline at end of file diff --git a/src/arenas/Battleship/style.css b/src/arenas/Battleship/style.css new file mode 100644 index 0000000..4c97286 --- /dev/null +++ b/src/arenas/Battleship/style.css @@ -0,0 +1,8 @@ +article p {width: 100%;} +article p label {float:left; text-align:right; width:60%} +article p select {} +td{min-width: 15px; height: 15px;} +.battleshipGrid{float: left; border-collapse:collapse; margin: 20px 20px 20px 20px;} +.battleshipGrid tr{} +.battleshipGrid tr td{border: 1px dashed green;} +.battleshipGrid tr th{text-align: center;} \ No newline at end of file diff --git a/src/arenas/tictactoe/doc-fr.html b/src/arenas/tictactoe/doc-fr.html index de5151a..2e5feff 100644 --- a/src/arenas/tictactoe/doc-fr.html +++ b/src/arenas/tictactoe/doc-fr.html @@ -32,4 +32,4 @@ avec les coordonnées d'une case déjà jouée perd la partie.

Publier votre programme pour le tester puis le lâcher dans l'arène

-

Ce n'est pas encore possible. L'interface est en cours de developpement. Mais vous pouvez toujours me contacter, @gnieark sur twitter, je mettrai à la main votre bot dans l'arène.

\ No newline at end of file +

le formulaire est sur la page d'accueil du site

\ No newline at end of file diff --git a/src/arenas/tictactoe/public.php b/src/arenas/tictactoe/public.php index 106542c..8ed983d 100644 --- a/src/arenas/tictactoe/public.php +++ b/src/arenas/tictactoe/public.php @@ -41,5 +41,5 @@ if(!$postParams){

- -
\ No newline at end of file +
+ diff --git a/src/arenas_lists.php b/src/arenas_lists.php index 70cda3c..2770c6f 100644 --- a/src/arenas_lists.php +++ b/src/arenas_lists.php @@ -12,7 +12,9 @@ $arenas=array( 'id' => "Battleship", 'url' => "/Battleship", 'title' => "bataille Navale", - 'metaDescription' => 'Affrontements de bots à la battaille navale' + 'metaDescription' => 'Affrontements de bots à la battaille navale', + 'jsFile'=> "js.js", + 'cssFile'=> "style.css" ) ); \ No newline at end of file diff --git a/src/functions.php b/src/functions.php index 1e09187..fb776da 100644 --- a/src/functions.php +++ b/src/functions.php @@ -213,3 +213,16 @@ function save_battle($game,$bot1,$bot2,$resultat){ '1') ON DUPLICATE KEY UPDATE ".$field." = ".$field." + 1;"); } +function get_unique_id(){ + $fp = fopen(__DIR__.'countBattles.txt', 'c+'); + flock($fp, LOCK_EX); + + $count = (int)fread($fp, filesize('count.txt')); + ftruncate($fp, 0); + fseek($fp, 0); + fwrite($fp, $count + 1); + + flock($fp, LOCK_UN); + fclose($fp); + return $count; +}