From ebf6583d56a50898893ce0c4fd649f577acaedd2 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 19:44:04 +0100 Subject: [PATCH 01/35] php debug output --- src/arenas/Battleship/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 2416726..18dace2 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -132,7 +132,7 @@ switch ($_POST['act']){ } foreach($nbBoatsIwant as $nb){ if($nb <> 0){ - echo $currentBot['name']." n'a pas placé correctement ses bateaux. Il perd"; + echo $currentBot['name']." n'a pas placé correctement ses bateaux. Il perd. sa réponse:
'.$anwserPlayer.'
"; if($player==1){ save_battle('Battleship',$bot1['name'],$bot2['name'],2); }else{ From 0b511cd931d3bb093d7e93c1b95969aee7e4aa4a Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 19:45:28 +0100 Subject: [PATCH 02/35] php debug output --- src/arenas/Battleship/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 18dace2..550be0f 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -121,7 +121,7 @@ switch ($_POST['act']){ $nbBoatsIwant[$long]-=1; $grid[$player]=place_ship_on_map($xStart,$yStart,$xEnd,$yEnd,$grid[$player]); if(!$grid[$player]){ - echo $currentBot['name']." n'a pas placé correctement ses bateaux. Certains se chevauchent. Il perd"; + echo $currentBot['name']." n'a pas placé correctement ses bateaux. Certains se chevauchent. Il perd
'.$anwserPlayer.'
"; if($player==1){ save_battle('Battleship',$bot1['name'],$bot2['name'],2); }else{ From f45994ebdacf7ccbe7034952aebe751093621232 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 19:46:46 +0100 Subject: [PATCH 03/35] php debug output --- src/arenas/Battleship/act.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 550be0f..9989c51 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -121,7 +121,7 @@ switch ($_POST['act']){ $nbBoatsIwant[$long]-=1; $grid[$player]=place_ship_on_map($xStart,$yStart,$xEnd,$yEnd,$grid[$player]); if(!$grid[$player]){ - echo $currentBot['name']." n'a pas placé correctement ses bateaux. Certains se chevauchent. Il perd
'.$anwserPlayer.'
"; + echo $currentBot['name']." n'a pas placé correctement ses bateaux. Certains se chevauchent. Il perd
".$anwserPlayer."
"; if($player==1){ save_battle('Battleship',$bot1['name'],$bot2['name'],2); }else{ @@ -132,7 +132,7 @@ switch ($_POST['act']){ } foreach($nbBoatsIwant as $nb){ if($nb <> 0){ - echo $currentBot['name']." n'a pas placé correctement ses bateaux. Il perd. sa réponse:
'.$anwserPlayer.'
"; + echo $currentBot['name']." n'a pas placé correctement ses bateaux. Il perd. sa réponse:
".$anwserPlayer."
"; if($player==1){ save_battle('Battleship',$bot1['name'],$bot2['name'],2); }else{ From 145ab319f5d342d6ac478d2ca96ab58c5d919bda Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 20:47:25 +0100 Subject: [PATCH 04/35] js debug output --- src/arenas/Battleship/js.js | 156 ++++++++++++++++++------------------ 1 file changed, 80 insertions(+), 76 deletions(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 3986ac8..eb9c0ed 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -21,81 +21,85 @@ function createElem(type,attributes) } 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":"tbl1","class":"battleshipGrid"}); - var tableMe=createElem("table",{"id":"tbl2","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":"bot1-" + i +"-" + j,"class": "empty"}); - var tdMe=createElem("td",{"id":"bot2-" + 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) { - //debug - //alert(xhr.responseText); - try{ - var grids = JSON.parse(xhr.responseText); - for( var player=1; player <= 2 ; player ++){ - for (var y=0; y < grids[player].length ; y++){ - for (var x=0; x < grids[player][y].length ; x++){ - if (grids[player][y][x] == 1){ - document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; - } - } - } - } - + var bot1IdName = bot1.split("-"); + var bot2IdName = bot2.split("-"); + document.getElementById('fightResult').innerHTML = ''; + //dessiner les deux grilles + var tableAdv=createElem("table",{"id":"tbl1","class":"battleshipGrid"}); + var tableMe=createElem("table",{"id":"tbl2","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":"bot1-" + i +"-" + j,"class": "empty"}); + var tdMe=createElem("td",{"id":"bot2-" + i +"-" + j,"class": "empty"}); + trAdv.appendChild(tdAdv); + trMe.appendChild(tdMe); + } + tableAdv.appendChild(trAdv); + tableMe.appendChild(trMe); } - catch(e){ - document.getElementById('logs').innerHTML = xhr.responseText; - - } - } - }}; - xhr.open("POST", '/Battleship', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send( - 'act=initGame&bot1=' + bot1IdName[0] - + '&bot2=' + bot2IdName[0] - + '&gridWidth=' + gridWidth - + '&gridHeight=' + gridHeight - + '&nbShip1=' + nbShip1 - + '&nbShip2=' + nbShip2 - + '&nbShip3=' + nbShip3 - + '&nbShip4=' + nbShip4 - + '&nbShip5=' + nbShip5 - + '&nbShip6=' + nbShip6 - + '&xd_check=' + xd_check - ); - + 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) { + //debug + //alert(xhr.responseText); + try{ + var grids = JSON.parse(xhr.responseText); + for( var player=1; player <= 2 ; player ++){ + var p=createElem("p"); + p.innerHTML='Reponse joueurs:'xhr.responseText; + document.getElementById('logs').appendChild(p); + + for (var y=0; y < grids[player].length ; y++){ + for (var x=0; x < grids[player][y].length ; x++){ + if (grids[player][y][x] == 1){ + document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; + } + } + } + } + + } + catch(e){ + document.getElementById('logs').innerHTML = xhr.responseText; + + } + } + }}; + xhr.open("POST", '/Battleship', true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send( + 'act=initGame&bot1=' + bot1IdName[0] + + '&bot2=' + bot2IdName[0] + + '&gridWidth=' + gridWidth + + '&gridHeight=' + gridHeight + + '&nbShip1=' + nbShip1 + + '&nbShip2=' + nbShip2 + + '&nbShip3=' + nbShip3 + + '&nbShip4=' + nbShip4 + + '&nbShip5=' + nbShip5 + + '&nbShip6=' + nbShip6 + + '&xd_check=' + xd_check + ); + } \ No newline at end of file From d34d9f90f21358b111a199533f9a6fa5418bea3f Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 20:48:22 +0100 Subject: [PATCH 05/35] js debug output --- src/arenas/Battleship/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index eb9c0ed..506d445 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -67,7 +67,7 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi var grids = JSON.parse(xhr.responseText); for( var player=1; player <= 2 ; player ++){ var p=createElem("p"); - p.innerHTML='Reponse joueurs:'xhr.responseText; + p.innerHTML='Reponse joueurs:' + xhr.responseText; document.getElementById('logs').appendChild(p); for (var y=0; y < grids[player].length ; y++){ From eb2f475b596776191a1b58d46da8c28bd12609f1 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 22:40:46 +0100 Subject: [PATCH 06/35] =?UTF-8?q?5-2=3D3,=20mais=20[2=C3=A05]=3D=204=20cas?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/StupidIABattleship.php | 37 +++++++++++++++++------------------ src/arenas/Battleship/act.php | 4 ++-- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index 7701e49..e3ee4d4 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -68,25 +68,24 @@ switch($_POST['act']){ $shipsCoords=array(); //pour toutes les tailles de bateau - for($shipWidth = 6; $shipWidth > 0; $shipWidth--){ + for($shipWidth = 6; $shipWidth > 0; $shipWidth--){pl //nombre de bateau à placer de cette taille $dynVar='ship'.$shipWidth; $shipCount=$$dynVar; // #trollface - for( $sh = 0; $sh < $shipCount; $sh++){ + for( $sh = 0; $sh < $shipCount; $sh++){ //loop for all boats witch size is $shipWidth $directions=array(); while( count($directions) == 0){ - do{ $xtest=rand(0,$width -1); $ytest=rand(0,$height -1); }while($map[$ytest][$xtest] == 1); //Y a t'il la place pour le bateau vers le haut? - if($ytest < $shipWidth){ + if($ytest < $shipWidth -1){ $top=false; }else{ $top=true; - for($i = $ytest; $i > $ytest - $shipWidth; $i--){ + for($i = $ytest; $i > $ytest - $shipWidth + 1; $i--){ if($map[$i][$xtest] == 1){ $top=false; break; @@ -95,11 +94,11 @@ switch($_POST['act']){ } //vers le bas - if($ytest + $shipWidth > $height){ + if($ytest + $shipWidth -1 > $height){ $bottom=false; }else{ $bottom=true; - for($y=$ytest; $i < $ytest + $shipWidth; $i++){ + for($y=$ytest; $i < $ytest + $shipWidth -1; $i++){ if($map[$i][$xtest] == 1){ $bottom=false; break; @@ -108,11 +107,11 @@ switch($_POST['act']){ } //droite - if($xtest + $shipWidth > $width){ + if($xtest + $shipWidth -1 > $width){ $right=false; }else{ $right=true; - for($i = $xtest; $i < $xtest + $shipWidth; $i++){ + for($i = $xtest; $i < $xtest + $shipWidth -1; $i++){ if($map[$ytest][$i] == 1){ $right= false; break; @@ -121,11 +120,11 @@ switch($_POST['act']){ } //gauche - if($xtest < $shipWidth){ + if($xtest < $shipWidth +1){ $left=false; }else{ $left=true; - for($i = $xtest; $i > $xtest - $shipWidth; $i--){ + for($i = $xtest; $i > $xtest - $shipWidth + 1; $i--){ if($map[$ytest][$i] == 1){ $left= false; break; @@ -152,20 +151,20 @@ switch($_POST['act']){ shuffle($directions); switch($directions[0]){ case 'top': - $shipsCoords[]=$xtest.",".$ytest."-".$xtest.",".($ytest - $shipWidth); - $map= place_ship_on_map($xtest,$ytest,$xtest,$ytest - $shipWidth,$map); + $shipsCoords[]=$xtest.",".$ytest."-".$xtest.",".($ytest - $shipWidth + 1); + $map= place_ship_on_map($xtest,$ytest,$xtest,$ytest - $shipWidth + 1,$map); break; case 'bottom': - $shipsCoords[]=$xtest.",".$ytest."-".$xtest.",".($ytest + $shipWidth); - $map= place_ship_on_map($xtest,$ytest,$xtest,$ytest + $shipWidth,$map); + $shipsCoords[]=$xtest.",".$ytest."-".$xtest.",".($ytest + $shipWidth - 1); + $map= place_ship_on_map($xtest,$ytest,$xtest,$ytest + $shipWidth -1 ,$map); break; case 'left': - $shipsCoords[]=$xtest.",".$ytest."-".($xtest - $shipWidth).",".$ytest; - $map= place_ship_on_map($xtest,$ytest,$xtest - $shipWidth ,$ytest,$map); + $shipsCoords[]=$xtest.",".$ytest."-".($xtest - $shipWidth + 1).",".$ytest; + $map= place_ship_on_map($xtest,$ytest,$xtest - $shipWidth + 1 ,$ytest,$map); break; case 'right': - $shipsCoords[]=$xtest.",".$ytest."-".($xtest + $shipWidth).",".$ytest; - $map= place_ship_on_map($xtest,$ytest,$xtest + $shipWidth ,$ytest,$map); + $shipsCoords[]=$xtest.",".$ytest."-".($xtest + $shipWidth - 1 ).",".$ytest; + $map= place_ship_on_map($xtest,$ytest,$xtest + $shipWidth -1 ,$ytest,$map); break; } diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 9989c51..518cf59 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -114,9 +114,9 @@ switch ($_POST['act']){ list($xStart,$yStart)=explode(",",$startCoord); list($xEnd,$yEnd)=explode(",",$endCoord); if($xStart == $xEnd){ - $long=abs($yStart - $yEnd); + $long=abs($yStart - $yEnd +1); }else{ - $long=abs($xStart - $xEnd); + $long=abs($xStart - $xEnd +1); } $nbBoatsIwant[$long]-=1; $grid[$player]=place_ship_on_map($xStart,$yStart,$xEnd,$yEnd,$grid[$player]); From f6212a89479e6a93fcb33c5a8b4083b92bc3e1f0 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 22:41:57 +0100 Subject: [PATCH 07/35] debug php --- src/arenas/Battleship/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 518cf59..d255b0e 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -90,7 +90,7 @@ switch ($_POST['act']){ $anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend); $boatsPlayer = json_decode( html_entity_decode($anwserPlayer)); if(!$boatsPlayer){ - echo $currentBot['name']." a fait une réponse non conforme, il perd."; + echo $currentBot['name']." a fait une réponse non conforme, il perd.".$anwserPlayer; if($player==1){ save_battle('Battleship',$bot1['name'],$bot2['name'],2); }else{ From 6ded637d78fdaf49eb8c6095e73fdb71fee55685 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 22:43:06 +0100 Subject: [PATCH 08/35] debug php --- html/StupidIABattleship.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index e3ee4d4..2a51294 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -68,7 +68,7 @@ switch($_POST['act']){ $shipsCoords=array(); //pour toutes les tailles de bateau - for($shipWidth = 6; $shipWidth > 0; $shipWidth--){pl + for($shipWidth = 6; $shipWidth > 0; $shipWidth--){ //nombre de bateau à placer de cette taille $dynVar='ship'.$shipWidth; $shipCount=$$dynVar; // #trollface From d7c4688a5293fb2aa022b3f40dab7ebe2fc4de21 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 23:15:53 +0100 Subject: [PATCH 09/35] debug php --- html/StupidIABattleship.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index 2a51294..3000f37 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -85,7 +85,7 @@ switch($_POST['act']){ $top=false; }else{ $top=true; - for($i = $ytest; $i > $ytest - $shipWidth + 1; $i--){ + for($i = $ytest; $i >= $ytest - $shipWidth + 1; $i--){ if($map[$i][$xtest] == 1){ $top=false; break; @@ -124,7 +124,7 @@ switch($_POST['act']){ $left=false; }else{ $left=true; - for($i = $xtest; $i > $xtest - $shipWidth + 1; $i--){ + for($i = $xtest; $i >= $xtest - $shipWidth + 1; $i--){ if($map[$ytest][$i] == 1){ $left= false; break; From 5c1eb66577b7c9bc009814e518825e3fb2286043 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 23:27:44 +0100 Subject: [PATCH 10/35] fix ship superposition tests --- html/StupidIABattleship.php | 67 +++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index 3000f37..ffc725e 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -81,58 +81,51 @@ switch($_POST['act']){ }while($map[$ytest][$xtest] == 1); //Y a t'il la place pour le bateau vers le haut? - if($ytest < $shipWidth -1){ - $top=false; - }else{ - $top=true; - for($i = $ytest; $i >= $ytest - $shipWidth + 1; $i--){ - if($map[$i][$xtest] == 1){ - $top=false; - break; - } + + //haut + $top=true; + for($i = $ytest; $i >= $ytest - $shipWidth + 1; $i--){ + if ((!isset($map[$i][$xtest]) + OR ($map[$i][$xtest] == 1)){ + $top=false; + break; } } //vers le bas - if($ytest + $shipWidth -1 > $height){ - $bottom=false; - }else{ - $bottom=true; - for($y=$ytest; $i < $ytest + $shipWidth -1; $i++){ - if($map[$i][$xtest] == 1){ - $bottom=false; - break; - } + $bottom=true; + for($y=$ytest; $i < $ytest + $shipWidth -1; $i++){ + if ((!isset($map[$i][$xtest]) + OR ($map[$i][$xtest] == 1)){ + $bottom=false; + break; } } //droite - if($xtest + $shipWidth -1 > $width){ - $right=false; - }else{ - $right=true; - for($i = $xtest; $i < $xtest + $shipWidth -1; $i++){ - if($map[$ytest][$i] == 1){ - $right= false; - break; - } + $right=true; + for($i = $xtest; $i < $xtest + $shipWidth -1; $i++){ + if((!isset($map[$ytest][$i])) + OR($map[$ytest][$i] == 1)){ + $right= false; + break; } } + //gauche - if($xtest < $shipWidth +1){ - $left=false; - }else{ - $left=true; - for($i = $xtest; $i >= $xtest - $shipWidth + 1; $i--){ - if($map[$ytest][$i] == 1){ - $left= false; - break; - } - } + + $left=true; + for($i = $xtest; $i >= $xtest - $shipWidth + 1; $i--){ + if((!isset($map[$ytest][$i])) + OR($map[$ytest][$i] == 1)){ + $left= false; + break; + } } + $directions=array(); if($top){ $directions[]='top'; From 3c2afc38d22d90c66aec2b84fe6927ec32b0cd18 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 23:29:01 +0100 Subject: [PATCH 11/35] fix php parse --- html/StupidIABattleship.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index ffc725e..05941e0 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -85,7 +85,7 @@ switch($_POST['act']){ //haut $top=true; for($i = $ytest; $i >= $ytest - $shipWidth + 1; $i--){ - if ((!isset($map[$i][$xtest]) + if ((!isset($map[$i][$xtest])) OR ($map[$i][$xtest] == 1)){ $top=false; break; @@ -95,7 +95,7 @@ switch($_POST['act']){ //vers le bas $bottom=true; for($y=$ytest; $i < $ytest + $shipWidth -1; $i++){ - if ((!isset($map[$i][$xtest]) + if ((!isset($map[$i][$xtest])) OR ($map[$i][$xtest] == 1)){ $bottom=false; break; From 957f5e9edb75012925ae4611d12da9f14bf863cd Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 23:41:31 +0100 Subject: [PATCH 12/35] fix php parse --- src/arenas/Battleship/act.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index d255b0e..c086022 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -109,6 +109,7 @@ switch ($_POST['act']){ //vérifier si'il y a le bon nombre de bateaux et les placer $nbBoatsIwant=array(0,$postValues['nbShip1'],$postValues['nbShip2'],$postValues['nbShip3'], $postValues['nbShip4'],$postValues['nbShip5'],$postValues['nbShip6']); + print_r($nbBoatsIwant); foreach($boatsPlayer as $boat){ list($startCoord,$endCoord) = explode("-",$boat); list($xStart,$yStart)=explode(",",$startCoord); From ad27848ef8638f87a665feabb4d80f2e87863e5c Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 23:45:53 +0100 Subject: [PATCH 13/35] debug --- src/arenas/Battleship/act.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index c086022..8dbcd9f 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -109,7 +109,7 @@ switch ($_POST['act']){ //vérifier si'il y a le bon nombre de bateaux et les placer $nbBoatsIwant=array(0,$postValues['nbShip1'],$postValues['nbShip2'],$postValues['nbShip3'], $postValues['nbShip4'],$postValues['nbShip5'],$postValues['nbShip6']); - print_r($nbBoatsIwant); + foreach($boatsPlayer as $boat){ list($startCoord,$endCoord) = explode("-",$boat); list($xStart,$yStart)=explode(",",$startCoord); @@ -122,7 +122,7 @@ switch ($_POST['act']){ $nbBoatsIwant[$long]-=1; $grid[$player]=place_ship_on_map($xStart,$yStart,$xEnd,$yEnd,$grid[$player]); if(!$grid[$player]){ - echo $currentBot['name']." n'a pas placé correctement ses bateaux. Certains se chevauchent. Il perd
".$anwserPlayer."
"; + echo $currentBot['name']." n'a pas placé correctement ses bateaux. Certains se chevauchent. Il perd
".$anwserPlayer." ".$xStart.$yStart.$xEnd.$yEnd."
"; if($player==1){ save_battle('Battleship',$bot1['name'],$bot2['name'],2); }else{ From 297f74c9fc435d9be768a9741f8aa90f38fc9cb4 Mon Sep 17 00:00:00 2001 From: gnieark Date: Tue, 15 Dec 2015 23:55:24 +0100 Subject: [PATCH 14/35] grrrr --- html/StupidIABattleship.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index 05941e0..f5221a7 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -94,7 +94,7 @@ switch($_POST['act']){ //vers le bas $bottom=true; - for($y=$ytest; $i < $ytest + $shipWidth -1; $i++){ + for($i=$ytest; $i < $ytest + $shipWidth -1; $i++){ if ((!isset($map[$i][$xtest])) OR ($map[$i][$xtest] == 1)){ $bottom=false; From ec06d2c2cface837dace01f283d23b0e8955c39a Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 16 Dec 2015 00:06:35 +0100 Subject: [PATCH 15/35] grrrr --- html/StupidIABattleship.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index f5221a7..a464951 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -61,7 +61,7 @@ switch($_POST['act']){ //construire une grille for($i=0; $i < $width; $i++){ for($j=0; $j < $height; $j++){ - $map[$i][$j]=0; + $map[$j][$i]=0; } } @@ -94,7 +94,7 @@ switch($_POST['act']){ //vers le bas $bottom=true; - for($i=$ytest; $i < $ytest + $shipWidth -1; $i++){ + for($i = $ytest; $i < $ytest + $shipWidth -1; $i++){ if ((!isset($map[$i][$xtest])) OR ($map[$i][$xtest] == 1)){ $bottom=false; @@ -112,9 +112,7 @@ switch($_POST['act']){ } } - //gauche - $left=true; for($i = $xtest; $i >= $xtest - $shipWidth + 1; $i--){ if((!isset($map[$ytest][$i])) From 9e910f01578be2038a0e7d0b71c5cc7d3d17833f Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 16 Dec 2015 00:12:48 +0100 Subject: [PATCH 16/35] grrrr --- html/StupidIABattleship.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index a464951..ba9af2d 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -1,8 +1,11 @@ $x2) && ($y1 <> $y2)){ - return false; + if ((($x1 <> $x2) && ($y1 <> $y2)) + OR (!isset($map[$y1][$x1])) + OR (!isset($map[$y2][$x2]))){ + return false; } + if($x1 == $x2){ //horizontal ship @@ -14,7 +17,11 @@ function place_ship_on_map($x1,$y1,$x2,$y2,$map){ $end=$y1; } for($i = $start; $i <= $end; $i++){ - $map[$i][$x1]=1; + if($map[$i][$x1]==0){ + $map[$i][$x1]=1; + }else{ + return false; + } } return $map; } @@ -28,11 +35,14 @@ function place_ship_on_map($x1,$y1,$x2,$y2,$map){ $end=$x1; } for( $i = $start; $i <= $end; $i++){ - $map[$y1][$i]=1; + if( $map[$y1][$i] == 0){ + $map[$y1][$i]=1; + }else{ + return false; + } } return $map; } - } switch($_POST['act']){ case "init": @@ -57,7 +67,7 @@ switch($_POST['act']){ if(!preg_match('/^[0-9]+-(1|2)$/',$match_id)){ echo "parametre incorrect"; die; } - + $map=array(); //construire une grille for($i=0; $i < $width; $i++){ for($j=0; $j < $height; $j++){ @@ -162,7 +172,7 @@ switch($_POST['act']){ } } - + print_r($map); echo json_encode($shipsCoords); break; default: From 518f2b409ae9f65d448cc11e190cddd73ef675c0 Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 16 Dec 2015 00:20:59 +0100 Subject: [PATCH 17/35] put stupid IA off before sleep, it can load 100% CPU --- html/StupidIABattleship.php | 1 + 1 file changed, 1 insertion(+) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index ba9af2d..66b75e1 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -1,4 +1,5 @@ $x2) && ($y1 <> $y2)) OR (!isset($map[$y1][$x1])) From 5bdff50f37efabbb5c806ed6bc0e08be192f2d96 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 16 Dec 2015 10:10:31 +0100 Subject: [PATCH 18/35] add css file to doc page && battle ship specs --- html/index.php | 3 +++ src/arenas/Battleship/doc-fr.html | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/html/index.php b/html/index.php index 1e1393e..2ff7447 100644 --- a/html/index.php +++ b/html/index.php @@ -90,6 +90,9 @@ if(isset($_GET['arena'])){ $mainSectionScript="../src/arenas/".$currentArenaArr['id']."/doc-".$lang['lang'].".html"; $asideSectionContent=''; //to do $cssAdditionalScript=""; + if(isset($currentArenaArr['cssFile'])){ + $cssAdditionalScript.='"; + } $jsAdditionalScript=""; }elseif(isset($_GET['page'])){ diff --git a/src/arenas/Battleship/doc-fr.html b/src/arenas/Battleship/doc-fr.html index 5933375..520b101 100644 --- a/src/arenas/Battleship/doc-fr.html +++ b/src/arenas/Battleship/doc-fr.html @@ -40,4 +40,19 @@

integer, compris entre 0 et 10, bornes incluses, Vous indique le nombre de bateaux de longeur 6 cases à placer.

Ce que doit retourner votre bot

Il doit retourner la position des navires. +Vous retournez un tableau JSON ayant autant d'enregistrement que de navires. +Chaque navire est défini par les coordonnées de ses extrémités. + + + + + + + + + + + + +
0123456789
0
1
2
3
4
5
6
7
8
9
From 160017eaed3a4befd8435379240e4f45450f15c7 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 16 Dec 2015 10:13:00 +0100 Subject: [PATCH 19/35] style --- src/arenas/Battleship/doc-fr.html | 2 +- src/arenas/Battleship/style.css | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/arenas/Battleship/doc-fr.html b/src/arenas/Battleship/doc-fr.html index 520b101..b750669 100644 --- a/src/arenas/Battleship/doc-fr.html +++ b/src/arenas/Battleship/doc-fr.html @@ -43,7 +43,7 @@ Il doit retourner la position des navires. Vous retournez un tableau JSON ayant autant d'enregistrement que de navires. Chaque navire est défini par les coordonnées de ses extrémités. - +
diff --git a/src/arenas/Battleship/style.css b/src/arenas/Battleship/style.css index 3f7b941..062c39d 100644 --- a/src/arenas/Battleship/style.css +++ b/src/arenas/Battleship/style.css @@ -3,6 +3,7 @@ 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;} +.nofloat{float: none;} .battleshipGrid tr{} .battleshipGrid tr td{border: 1px dashed green;} .battleshipGrid tr th{text-align: center;} From f680b6234f56e332d531e8620d3a8857f9d58618 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 16 Dec 2015 10:14:47 +0100 Subject: [PATCH 20/35] style --- src/arenas/Battleship/doc-fr.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/arenas/Battleship/doc-fr.html b/src/arenas/Battleship/doc-fr.html index b750669..06e7bff 100644 --- a/src/arenas/Battleship/doc-fr.html +++ b/src/arenas/Battleship/doc-fr.html @@ -45,13 +45,13 @@ Chaque navire est défini par les coordonnées de ses extrémités.
0123456789
0
1
- - - - - + + + + + - + From 4e0d4c6f4fc7e988e2399f85255d96d01cb272a5 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 16 Dec 2015 10:22:07 +0100 Subject: [PATCH 21/35] specs --- src/arenas/Battleship/doc-fr.html | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/arenas/Battleship/doc-fr.html b/src/arenas/Battleship/doc-fr.html index 06e7bff..bf9d54c 100644 --- a/src/arenas/Battleship/doc-fr.html +++ b/src/arenas/Battleship/doc-fr.html @@ -39,10 +39,10 @@

"ship6"

integer, compris entre 0 et 10, bornes incluses, Vous indique le nombre de bateaux de longeur 6 cases à placer.

Ce que doit retourner votre bot

-Il doit retourner la position des navires. -Vous retournez un tableau JSON ayant autant d'enregistrement que de navires. -Chaque navire est défini par les coordonnées de ses extrémités. - +

Il doit retourner la position des navires.

+

Vous retournez un tableau JSON ayant autant d'enregistrement que de navires. +Chaque navire est défini par les coordonnées de ses extrémités.

+

Exemple;

0123456789
0
1
2
3
4
0
1
2
3
4
5
6
6
7
8
9
@@ -56,3 +56,9 @@ Chaque navire est défini par les coordonnées de ses extrémités.
0123456789
0
8
9
+

largeur; 10, hauteur 10; 3 bateaux:

+
    +
  • Bateau de 4 cases ayant pour extrémités 1,0 et 1,3. sera noté "1,0-1,3" ou "1,3-1,0"
  • +
  • Bateau de 2 cases ayant pour extrémités 2,4 et 3,4. sera noté "2,4-3,4" ou "3,4-2,4"
  • +
  • Bateau de 3 cases ayant pour extrémités 3,6 et 5,6. sera noté "3,6-5,6" ou "5,6-3,6"
  • +
From 9abbe799199205c874df40b155afd32ba9a0ec99 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 16 Dec 2015 10:32:58 +0100 Subject: [PATCH 22/35] specs --- src/arenas/Battleship/doc-fr.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/arenas/Battleship/doc-fr.html b/src/arenas/Battleship/doc-fr.html index bf9d54c..8d1f100 100644 --- a/src/arenas/Battleship/doc-fr.html +++ b/src/arenas/Battleship/doc-fr.html @@ -42,6 +42,11 @@

Il doit retourner la position des navires.

Vous retournez un tableau JSON ayant autant d'enregistrement que de navires. Chaque navire est défini par les coordonnées de ses extrémités.

+
    +
  • La grille commence au point 0,0.
  • +
  • Les entiers; ordonnée et abscisses définissant un point sont séparés d'une virgule.
  • +
  • Les deux points définissant les extrémités d'un navire sont séparés par un tiret -
  • +

Exemple;

@@ -62,3 +67,8 @@ Chaque navire est défini par les coordonnées de ses extrémités.

  • Bateau de 2 cases ayant pour extrémités 2,4 et 3,4. sera noté "2,4-3,4" ou "3,4-2,4"
  • Bateau de 3 cases ayant pour extrémités 3,6 et 5,6. sera noté "3,6-5,6" ou "5,6-3,6"
  • + +

    Pour placer ces 3 bateaux, vous devez retourner au format JSON le tableau suivant:

    +
    +["1,0-1,3","2,4-3,4","3,6-5,6"]
    +
    From 6f10822e22acf4c1aa8c8d6b1c39967fb2fa9773 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 16 Dec 2015 10:33:53 +0100 Subject: [PATCH 23/35] specs --- src/arenas/Battleship/doc-fr.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arenas/Battleship/doc-fr.html b/src/arenas/Battleship/doc-fr.html index 8d1f100..d47c454 100644 --- a/src/arenas/Battleship/doc-fr.html +++ b/src/arenas/Battleship/doc-fr.html @@ -44,10 +44,10 @@ Chaque navire est défini par les coordonnées de ses extrémités.

    • La grille commence au point 0,0.
    • -
    • Les entiers; ordonnée et abscisses définissant un point sont séparés d'une virgule.
    • -
    • Les deux points définissant les extrémités d'un navire sont séparés par un tiret -
    • +
    • Les entiers; ordonnée et abscisses définissant un point sont séparés d'une virgule ",".
    • +
    • Les deux points définissant les extrémités d'un navire sont séparés par un tiret "-".
    -

    Exemple;

    +

    Exemple:

    0123456789
    From c70c34ac97540f697c629d8fb910e393831d1499 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 16 Dec 2015 10:40:51 +0100 Subject: [PATCH 24/35] specs --- src/arenas/Battleship/functions.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/arenas/Battleship/functions.php b/src/arenas/Battleship/functions.php index deca0ce..35ef95f 100644 --- a/src/arenas/Battleship/functions.php +++ b/src/arenas/Battleship/functions.php @@ -53,6 +53,12 @@ function get_IA_Response($iaUrl,$postParams){ curl_close($ch); return htmlentities($output); } +function is_it_possible_to_place_ships_on_grid($gridWidth,$gridHeight,$nbShipsSize1,$nbShipsSize2,$nbShipsSize3,$nbShipsSize4,$nbShipsSize5,$nbShipsSize6){ + //return false or true + + +} + function place_ship_on_map($x1,$y1,$x2,$y2,$map){ if ((($x1 <> $x2) && ($y1 <> $y2)) OR (!isset($map[$y1][$x1])) From 5666d4d10cff187aba46c4fe768009c3d2c44772 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 16 Dec 2015 10:42:21 +0100 Subject: [PATCH 25/35] specs --- src/arenas/Battleship/functions.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/arenas/Battleship/functions.php b/src/arenas/Battleship/functions.php index 35ef95f..63f1244 100644 --- a/src/arenas/Battleship/functions.php +++ b/src/arenas/Battleship/functions.php @@ -1,4 +1,9 @@ $x2) && ($y1 <> $y2)) OR (!isset($map[$y1][$x1])) From f16807d8a87d289259987f932af8daaa3811780e Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 16 Dec 2015 18:31:13 +0100 Subject: [PATCH 26/35] place ships function --- src/arenas/Battleship/functions.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/arenas/Battleship/functions.php b/src/arenas/Battleship/functions.php index 63f1244..723c8b8 100644 --- a/src/arenas/Battleship/functions.php +++ b/src/arenas/Battleship/functions.php @@ -1,10 +1,26 @@ 0; $i--){ + $var='nbShipsSize'.$i; + if($$var > 0){ + $longestShip=$$var; + break; + } + } + if( (!isset($longestShip)) + OR(($longestShip > $gridWidth) && ($longestShip > $gridHeight)) + ){ + return false: + } } -function get_Post_Params($botsCount){ +function get_Post_Params($ccbotsCount){ $keysBots=array('bot1','bot2'); foreach($keysBots as $botKey){ if(!isset($_POST[$botKey])){ From b717a85e53a4bfae4d66c9c6fe2e213f40ced78e Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 16 Dec 2015 18:32:48 +0100 Subject: [PATCH 27/35] place ships function --- src/arenas/Battleship/functions.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/arenas/Battleship/functions.php b/src/arenas/Battleship/functions.php index 723c8b8..9079a2e 100644 --- a/src/arenas/Battleship/functions.php +++ b/src/arenas/Battleship/functions.php @@ -17,8 +17,9 @@ function is_it_possible_to_place_ships_on_grid($gridWidth,$gridHeight,$nbShipsSi if( (!isset($longestShip)) OR(($longestShip > $gridWidth) && ($longestShip > $gridHeight)) ){ - return false: + return false; } + return true; } function get_Post_Params($ccbotsCount){ $keysBots=array('bot1','bot2'); From 30cd1bc199673df12c92a4c3e85729a91ef2d10b Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 17 Dec 2015 16:09:28 +0100 Subject: [PATCH 28/35] =?UTF-8?q?coh=C3=A9rance=20taill=20grille=20et=20no?= =?UTF-8?q?mbre/taille=20des=20navires?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/arenas/Battleship/act.php | 4 + src/arenas/Battleship/js.js | 168 +++++++++++++++++++--------------- 2 files changed, 99 insertions(+), 73 deletions(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 8dbcd9f..6a62660 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -57,6 +57,10 @@ switch ($_POST['act']){ error (500,"missing parameter 2"); } + if(!is_it_possible_to_place_ships_on_grid($postValues['gridWidth'],$postValues['gridHeight'],$postValues['nbShip1'],$posValues['nbship2'],$postValues['nbship3'],$postValues['nbship4'],$postValues['nbship5'],$postvalues['nbship6'])){ + error (404,"grid is too little for these sips"); + } + //vars checked, lets init the initGame $_SESSION['matchId']=get_unique_id(); diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 506d445..a5caf5d 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -21,85 +21,107 @@ function createElem(type,attributes) } 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":"tbl1","class":"battleshipGrid"}); - var tableMe=createElem("table",{"id":"tbl2","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); + + var shipsArea=nbShip1 + 2 * nbShip2 + 3 * nbShip3 + 4 * nbShip4 + 5 * nbShip5 + 6 * nbShip6; + if(shipsArea > gridWidth * gridHeight / 2 ){ + alert("Map is too small. Sum of ships areas must be under 50% of the map."); + return; + } + var ships= [0,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6]; + var longestShip=0; + for(var i = 6; i > 0; i--){ + if(ships[i] > 0){ + longestShip=ships[i]; + break; + } + } + if((longestShip==0) + ||((longestShip > gridWidth) && (longestShip > gridHeight)) + ){ + alert ("Map is too small. Grow it or reduce ships"); + break; + } + + + var bot1IdName = bot1.split("-"); + var bot2IdName = bot2.split("-"); + document.getElementById('fightResult').innerHTML = ''; + //dessiner les deux grilles + var tableAdv=createElem("table",{"id":"tbl1","class":"battleshipGrid"}); + var tableMe=createElem("table",{"id":"tbl2","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":"bot1-" + i +"-" + j,"class": "empty"}); - var tdMe=createElem("td",{"id":"bot2-" + 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); + 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":"bot1-" + i +"-" + j,"class": "empty"}); + var tdMe=createElem("td",{"id":"bot2-" + 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) { - //debug - //alert(xhr.responseText); - try{ - var grids = JSON.parse(xhr.responseText); - for( var player=1; player <= 2 ; player ++){ - var p=createElem("p"); - p.innerHTML='Reponse joueurs:' + xhr.responseText; - document.getElementById('logs').appendChild(p); + var xhr = Ajx(); + xhr.onreadystatechange = function(){if(xhr.readyState == 4){ + if(xhr.status == 200) { + //debug + //alert(xhr.responseText); + try{ + var grids = JSON.parse(xhr.responseText); + for( var player=1; player <= 2 ; player ++){ + var p=createElem("p"); + p.innerHTML='Reponse joueurs:' + xhr.responseText; + document.getElementById('logs').appendChild(p); - for (var y=0; y < grids[player].length ; y++){ - for (var x=0; x < grids[player][y].length ; x++){ - if (grids[player][y][x] == 1){ - document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; - } - } - } - } + for (var y=0; y < grids[player].length ; y++){ + for (var x=0; x < grids[player][y].length ; x++){ + if (grids[player][y][x] == 1){ + document.getElementById( 'bot' + player + '-' + y + '-' + x).className="shipOn"; + } + } + } + } - } - catch(e){ - document.getElementById('logs').innerHTML = xhr.responseText; + } + catch(e){ + document.getElementById('logs').innerHTML = xhr.responseText; - } - } - }}; - xhr.open("POST", '/Battleship', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send( - 'act=initGame&bot1=' + bot1IdName[0] - + '&bot2=' + bot2IdName[0] - + '&gridWidth=' + gridWidth - + '&gridHeight=' + gridHeight - + '&nbShip1=' + nbShip1 - + '&nbShip2=' + nbShip2 - + '&nbShip3=' + nbShip3 - + '&nbShip4=' + nbShip4 - + '&nbShip5=' + nbShip5 - + '&nbShip6=' + nbShip6 - + '&xd_check=' + xd_check - ); + } + } + }}; + xhr.open("POST", '/Battleship', true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send( + 'act=initGame&bot1=' + bot1IdName[0] + + '&bot2=' + bot2IdName[0] + + '&gridWidth=' + gridWidth + + '&gridHeight=' + gridHeight + + '&nbShip1=' + nbShip1 + + '&nbShip2=' + nbShip2 + + '&nbShip3=' + nbShip3 + + '&nbShip4=' + nbShip4 + + '&nbShip5=' + nbShip5 + + '&nbShip6=' + nbShip6 + + '&xd_check=' + xd_check + ); } \ No newline at end of file From 7366926906dc0926f2f92261d8933044b81b58f9 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 17 Dec 2015 16:13:08 +0100 Subject: [PATCH 29/35] fix js$ --- src/arenas/Battleship/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index a5caf5d..7447d11 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -39,7 +39,7 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi ||((longestShip > gridWidth) && (longestShip > gridHeight)) ){ alert ("Map is too small. Grow it or reduce ships"); - break; + return; } From 0b90324a310e3534330a3d987bea225113998b3b Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 17 Dec 2015 16:14:29 +0100 Subject: [PATCH 30/35] fix js$ --- src/arenas/Battleship/js.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 7447d11..e7eb204 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -22,9 +22,9 @@ function createElem(type,attributes) function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6,xd_check){ - var shipsArea=nbShip1 + 2 * nbShip2 + 3 * nbShip3 + 4 * nbShip4 + 5 * nbShip5 + 6 * nbShip6; + var shipsArea= nbShip1 + 2 * nbShip2 + 3 * nbShip3 + 4 * nbShip4 + 5 * nbShip5 + 6 * nbShip6; if(shipsArea > gridWidth * gridHeight / 2 ){ - alert("Map is too small. Sum of ships areas must be under 50% of the map."); + alert("Map is too small. Sum of ships areas must be under 50% of the map." + shipsArea); return; } var ships= [0,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6]; From 797472f8552b16f6f830de09127622d7790ba417 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 17 Dec 2015 16:15:59 +0100 Subject: [PATCH 31/35] fix js$ --- src/arenas/Battleship/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index e7eb204..98a62fb 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -23,7 +23,7 @@ function createElem(type,attributes) function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6,xd_check){ var shipsArea= nbShip1 + 2 * nbShip2 + 3 * nbShip3 + 4 * nbShip4 + 5 * nbShip5 + 6 * nbShip6; - if(shipsArea > gridWidth * gridHeight / 2 ){ + if(shipsArea > parseInt(gridWidth * gridHeight / 2) ){ alert("Map is too small. Sum of ships areas must be under 50% of the map." + shipsArea); return; } From afe83a5f6e5e349ae2de1f25e5572acfe508efd3 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 17 Dec 2015 16:16:41 +0100 Subject: [PATCH 32/35] fix js$ --- src/arenas/Battleship/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 98a62fb..6d52143 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -24,7 +24,7 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi var shipsArea= nbShip1 + 2 * nbShip2 + 3 * nbShip3 + 4 * nbShip4 + 5 * nbShip5 + 6 * nbShip6; if(shipsArea > parseInt(gridWidth * gridHeight / 2) ){ - alert("Map is too small. Sum of ships areas must be under 50% of the map." + shipsArea); + alert("Map is too small. Sum of ships areas must be under 50% of the map." + shipsArea + " " + parseInt(gridWidth * gridHeight / 2)); return; } var ships= [0,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6]; From 0190c7b124c7266ffc5ed5cd5e08dfdabc2c482c Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 17 Dec 2015 16:18:48 +0100 Subject: [PATCH 33/35] fix js$ --- src/arenas/Battleship/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 6d52143..57a85b3 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -22,7 +22,7 @@ function createElem(type,attributes) function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6,xd_check){ - var shipsArea= nbShip1 + 2 * nbShip2 + 3 * nbShip3 + 4 * nbShip4 + 5 * nbShip5 + 6 * nbShip6; + var shipsArea= nbShip1 + (2 * nbShip2) + (3 * nbShip3) + (4 * nbShip4) + (5 * nbShip5) + (6 * nbShip6); if(shipsArea > parseInt(gridWidth * gridHeight / 2) ){ alert("Map is too small. Sum of ships areas must be under 50% of the map." + shipsArea + " " + parseInt(gridWidth * gridHeight / 2)); return; From f256805864dcd8dc1e12937630d101baecd12d7a Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 17 Dec 2015 16:21:15 +0100 Subject: [PATCH 34/35] fix js --- src/arenas/Battleship/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 57a85b3..aecd784 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -22,7 +22,7 @@ function createElem(type,attributes) function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6,xd_check){ - var shipsArea= nbShip1 + (2 * nbShip2) + (3 * nbShip3) + (4 * nbShip4) + (5 * nbShip5) + (6 * nbShip6); + var shipsArea= parseInt(nbShip1) + 2 * parseInt(nbShip2) + 3 * parseInt(nbShip3) + 4 * parseInt(nbShip4) + 5 * parseInt(nbShip5) + 6 * parseInt(nbShip6); if(shipsArea > parseInt(gridWidth * gridHeight / 2) ){ alert("Map is too small. Sum of ships areas must be under 50% of the map." + shipsArea + " " + parseInt(gridWidth * gridHeight / 2)); return; From ae1dc89119af04eed4bdc10950bf74af2950b46e Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 17 Dec 2015 16:22:26 +0100 Subject: [PATCH 35/35] fix js --- src/arenas/Battleship/js.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index aecd784..dfaa90a 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -24,10 +24,10 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi var shipsArea= parseInt(nbShip1) + 2 * parseInt(nbShip2) + 3 * parseInt(nbShip3) + 4 * parseInt(nbShip4) + 5 * parseInt(nbShip5) + 6 * parseInt(nbShip6); if(shipsArea > parseInt(gridWidth * gridHeight / 2) ){ - alert("Map is too small. Sum of ships areas must be under 50% of the map." + shipsArea + " " + parseInt(gridWidth * gridHeight / 2)); + alert("Map is too small. Sum of ships areas must be under 50% of the map." + shipsArea + " "); return; } - var ships= [0,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6]; + var ships= [0,parseInt(nbShip1),parseInt(nbShip2),parseInt(nbShip3),parseInt(nbShip4),parseInt(nbShip5),parseInt(nbShip6)]; var longestShip=0; for(var i = 6; i > 0; i--){ if(ships[i] > 0){
    0123456789
    0