From 376e767449f060341cec38f4574c93149611be5c Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 18 Dec 2015 13:18:14 +0100 Subject: [PATCH 01/40] log --- src/arenas/Battleship/act.php | 37 ++++++++++++++++++++++++++++++++++- src/arenas/Battleship/js.js | 19 +++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 49a266b..ece3efc 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -43,10 +43,12 @@ switch ($_POST['act']){ if($bot['id'] == $_POST['bot1']){ $bot1 = $bot; + $_SESSION['bot1']=$bot; $bot1Exists =true; } if($bot['id'] == $_POST['bot2']){ $bot2 = $bot; + $_SESSION['bot2']=$bot; $bot2Exists =true; } if ($bot1Exists && $bot2Exists){ @@ -134,6 +136,33 @@ switch ($_POST['act']){ } die; } + //remember each cases of each boats + $boatListOfCases=array(); + if($xStart == $xEnd){ + if($yStart <= $yEnd ){ + $start=$yStart; + $end=$yEnd; + }else{ + $start=$yEnd; + $end=$yStart; + } + for($i = $start; $i <= $end; $i++){ + $boatListOfCases[]=$xStart.",".$i; + } + }else{ + if($xStart <= $xEnd ){ + $start=$xStart; + $end=$xEnd; + }else{ + $start=$xEnd; + $end=$xStart; + } + for($i = $start; $i <= $end; $i++){ + $boatListOfCases[]=$i.",".$yStart; + } + + } + $_SESSION['ships'][$player][]=$boatListOfCases; } foreach($nbBoatsIwant as $nb){ if($nb <> 0){ @@ -148,11 +177,17 @@ switch ($_POST['act']){ } } - //$_SESSION['grids']=$grid; + $_SESSION['shots'][1]=array(); + $_SESSION['shots'][2]=array(); + $_SESSION['width']=$postValues['gridWidth']; + $_SESSION['height']=$postValues['gridHeight']; echo json_encode($grid); die; die; + break; + case "fight"; + print_r($_SESSION); break; default: break; diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index fd7d108..bc2b6f9 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -19,6 +19,23 @@ function createElem(type,attributes) {elem.setAttribute(i,attributes[i]);} return elem; } +function fight(xd_check){ + var xhr = Ajx(); + xhr.onreadystatechange = function(){if(xhr.readyState == 4){ + if(xhr.status == 200) { + var p=createElem("p"); + p.innerHTML=xhr.responseText; + document.getElementById('logs').appendChild(p); + fight(xd_check); + + } + + }}; + xhr.open("POST", '/Battleship', true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send('act=fight&xd_check=' + xd_check); + +} function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6,xd_check){ @@ -104,7 +121,7 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi var p=createElem("p"); p.innerHTML='players placed theirs ships'; document.getElementById('logs').appendChild(p); - + fight(xd_check); } }}; From 7d8d7e962e915db9d59938dce8de49e66fa26588 Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 18 Dec 2015 13:20:38 +0100 Subject: [PATCH 02/40] die php die --- src/arenas/Battleship/act.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index ece3efc..be199bc 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -187,7 +187,9 @@ switch ($_POST['act']){ break; case "fight"; + print_r($_SESSION); + die; break; default: break; From 6bc55e26684b231442a35fd68f1284eee47af692 Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 18 Dec 2015 13:21:21 +0100 Subject: [PATCH 03/40] die php die --- 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 bc2b6f9..00bc526 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -26,7 +26,7 @@ function fight(xd_check){ var p=createElem("p"); p.innerHTML=xhr.responseText; document.getElementById('logs').appendChild(p); - fight(xd_check); + //fight(xd_check); } From 77ef41d5b8f2ea20fea93247b0a5051d85535f3f Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 18 Dec 2015 13:32:37 +0100 Subject: [PATCH 04/40] session vars --- src/arenas/Battleship/act.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index be199bc..4b9d30f 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -4,6 +4,11 @@ $bots=get_Bots_Array('Battleship'); switch ($_POST['act']){ case "initGame": + //remove $_SESSION less xd_check + $xd=$_SESSION['xd_check']; + session_unset(); + $_SESSION['xd_check']=$xd; + //verifier parametres POST $postParamsWanted=array( // key,min,max @@ -188,7 +193,22 @@ switch ($_POST['act']){ break; case "fight"; - print_r($_SESSION); + /* + print_r($_SESSION); + Array ( [xd_check] => VSlWXLQVbYL2sCBwqetQdorR9 [bot1] => Array ( [id] => 10 [name] => stupidIA [url] => http://botsArena.tinad.fr/StupidIABattleship.php [description] => ) [bot2] => Array ( [id] => 10 [name] => stupidIA [url] => http://botsArena.tinad.fr/StupidIABattleship.php [description] => ) [matchId] => 702 [ships] => Array ( [1] => Array ( [0] => Array ( [0] => 3,0 [1] => 3,1 [2] => 3,2 [3] => 3,3 [4] => 3,4 ) [1] => Array ( [0] => 1,5 [1] => 2,5 [2] => 3,5 [3] => 4,5 ) [2] => Array ( [0] => 7,5 [1] => 8,5 [2] => 9,5 ) [3] => Array ( [0] => 0,0 [1] => 1,0 [2] => 2,0 ) [4] => Array ( [0] => 4,4 [1] => 5,4 ) [5] => Array ( [0] => 5,3 [1] => 6,3 [2] => 7,3 [3] => 8,3 [4] => 9,3 ) [6] => Array ( [0] => 2,7 [1] => 3,7 [2] => 4,7 [3] => 5,7 ) [7] => Array ( [0] => 1,9 [1] => 2,9 [2] => 3,9 ) [8] => Array ( [0] => 7,4 [1] => 8,4 [2] => 9,4 ) [9] => Array ( [0] => 0,2 [1] => 0,3 ) [10] => Array ( [0] => 3,9 [1] => 4,9 [2] => 5,9 [3] => 6,9 [4] => 7,9 ) [11] => Array ( [0] => 2,2 [1] => 2,3 [2] => 2,4 [3] => 2,5 ) [12] => Array ( [0] => 0,8 [1] => 1,8 [2] => 2,8 ) [13] => Array ( [0] => 7,7 [1] => 8,7 [2] => 9,7 ) [14] => Array ( [0] => 8,3 [1] => 9,3 ) [15] => Array ( [0] => 4,5 [1] => 5,5 [2] => 6,5 [3] => 7,5 [4] => 8,5 ) [16] => Array ( [0] => 3,2 [1] => 4,2 [2] => 5,2 [3] => 6,2 ) [17] => Array ( [0] => 0,7 [1] => 1,7 [2] => 2,7 ) [18] => Array ( [0] => 6,1 [1] => 7,1 [2] => 8,1 ) [19] => Array ( [0] => 2,3 [1] => 3,3 ) ) [2] => Array ( [0] => Array ( [0] => 0,9 [1] => 1,9 [2] => 2,9 [3] => 3,9 [4] => 4,9 ) [1] => Array ( [0] => 1,4 [1] => 1,5 [2] => 1,6 [3] => 1,7 ) [2] => Array ( [0] => 3,0 [1] => 4,0 [2] => 5,0 ) [3] => Array ( [0] => 0,0 [1] => 1,0 [2] => 2,0 ) [4] => Array ( [0] => 5,2 [1] => 6,2 ) [5] => Array ( [0] => 2,0 [1] => 3,0 [2] => 4,0 [3] => 5,0 [4] => 6,0 ) [6] => Array ( [0] => 2,1 [1] => 3,1 [2] => 4,1 [3] => 5,1 ) [7] => Array ( [0] => 7,3 [1] => 8,3 [2] => 9,3 ) [8] => Array ( [0] => 0,2 [1] => 1,2 [2] => 2,2 ) [9] => Array ( [0] => 5,3 [1] => 5,4 ) [10] => Array ( [0] => 5,3 [1] => 6,3 [2] => 7,3 [3] => 8,3 [4] => 9,3 ) [11] => Array ( [0] => 0,2 [1] => 0,3 [2] => 0,4 [3] => 0,5 ) [12] => Array ( [0] => 7,2 [1] => 8,2 [2] => 9,2 ) [13] => Array ( [0] => 0,1 [1] => 1,1 [2] => 2,1 ) [14] => Array ( [0] => 7,7 [1] => 7,8 ) [15] => Array ( [0] => 4,1 [1] => 4,2 [2] => 4,3 [3] => 4,4 [4] => 4,5 ) [16] => Array ( [0] => 3,9 [1] => 4,9 [2] => 5,9 [3] => 6,9 ) [17] => Array ( [0] => 7,3 [1] => 8,3 [2] => 9,3 ) [18] => Array ( [0] => 6,8 [1] => 7,8 [2] => 8,8 ) [19] => Array ( [0] => 0,5 [1] => 0,6 ) ) ) [shots] => Array ( [1] => Array ( ) [2] => Array ( ) ) [width] => 10 [height] => 10 ) + */ + if(count($_SESSION['shots'][1]) == count($_SESSION['shots'][1])){ + //player 1 has to fight + $currentPlayer=1; + + }else{ + //it's player2 + $currentPlayer=2; + } + + + + die; break; default: From 44b5e4eb342e18bcb27ec565e49568024ca3bd46 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:23:52 +0100 Subject: [PATCH 05/40] communication phase 2 --- html/StupidIABattleship.php | 4 ++++ src/arenas/Battleship/act.php | 42 +++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index fdbba96..47b507c 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -206,6 +206,10 @@ switch($_POST['act']){ //print_r($map); echo json_encode($shipsCoords); break; + case "fight": + print_r($_POST); + die; + break; default: break; diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 4b9d30f..0d28506 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -181,9 +181,14 @@ switch ($_POST['act']){ } } } - - $_SESSION['shots'][1]=array(); - $_SESSION['shots'][2]=array(); + $_SESSION['ship1']=$postValues['nbShip1']; + $_SESSION['ship2']=$postValues['nbShip2']; + $_SESSION['ship3']=$postValues['nbShip3']; + $_SESSION['ship4']=$postValues['nbShip4']; + $_SESSION['ship5']=$postValues['nbShip5']; + $_SESSION['ship6']=$postValues['nbShip6']; + $_SESSION['hits'][1]=array(); + $_SESSION['hits'][2]=array(); $_SESSION['width']=$postValues['gridWidth']; $_SESSION['height']=$postValues['gridHeight']; echo json_encode($grid); die; @@ -197,16 +202,39 @@ switch ($_POST['act']){ print_r($_SESSION); Array ( [xd_check] => VSlWXLQVbYL2sCBwqetQdorR9 [bot1] => Array ( [id] => 10 [name] => stupidIA [url] => http://botsArena.tinad.fr/StupidIABattleship.php [description] => ) [bot2] => Array ( [id] => 10 [name] => stupidIA [url] => http://botsArena.tinad.fr/StupidIABattleship.php [description] => ) [matchId] => 702 [ships] => Array ( [1] => Array ( [0] => Array ( [0] => 3,0 [1] => 3,1 [2] => 3,2 [3] => 3,3 [4] => 3,4 ) [1] => Array ( [0] => 1,5 [1] => 2,5 [2] => 3,5 [3] => 4,5 ) [2] => Array ( [0] => 7,5 [1] => 8,5 [2] => 9,5 ) [3] => Array ( [0] => 0,0 [1] => 1,0 [2] => 2,0 ) [4] => Array ( [0] => 4,4 [1] => 5,4 ) [5] => Array ( [0] => 5,3 [1] => 6,3 [2] => 7,3 [3] => 8,3 [4] => 9,3 ) [6] => Array ( [0] => 2,7 [1] => 3,7 [2] => 4,7 [3] => 5,7 ) [7] => Array ( [0] => 1,9 [1] => 2,9 [2] => 3,9 ) [8] => Array ( [0] => 7,4 [1] => 8,4 [2] => 9,4 ) [9] => Array ( [0] => 0,2 [1] => 0,3 ) [10] => Array ( [0] => 3,9 [1] => 4,9 [2] => 5,9 [3] => 6,9 [4] => 7,9 ) [11] => Array ( [0] => 2,2 [1] => 2,3 [2] => 2,4 [3] => 2,5 ) [12] => Array ( [0] => 0,8 [1] => 1,8 [2] => 2,8 ) [13] => Array ( [0] => 7,7 [1] => 8,7 [2] => 9,7 ) [14] => Array ( [0] => 8,3 [1] => 9,3 ) [15] => Array ( [0] => 4,5 [1] => 5,5 [2] => 6,5 [3] => 7,5 [4] => 8,5 ) [16] => Array ( [0] => 3,2 [1] => 4,2 [2] => 5,2 [3] => 6,2 ) [17] => Array ( [0] => 0,7 [1] => 1,7 [2] => 2,7 ) [18] => Array ( [0] => 6,1 [1] => 7,1 [2] => 8,1 ) [19] => Array ( [0] => 2,3 [1] => 3,3 ) ) [2] => Array ( [0] => Array ( [0] => 0,9 [1] => 1,9 [2] => 2,9 [3] => 3,9 [4] => 4,9 ) [1] => Array ( [0] => 1,4 [1] => 1,5 [2] => 1,6 [3] => 1,7 ) [2] => Array ( [0] => 3,0 [1] => 4,0 [2] => 5,0 ) [3] => Array ( [0] => 0,0 [1] => 1,0 [2] => 2,0 ) [4] => Array ( [0] => 5,2 [1] => 6,2 ) [5] => Array ( [0] => 2,0 [1] => 3,0 [2] => 4,0 [3] => 5,0 [4] => 6,0 ) [6] => Array ( [0] => 2,1 [1] => 3,1 [2] => 4,1 [3] => 5,1 ) [7] => Array ( [0] => 7,3 [1] => 8,3 [2] => 9,3 ) [8] => Array ( [0] => 0,2 [1] => 1,2 [2] => 2,2 ) [9] => Array ( [0] => 5,3 [1] => 5,4 ) [10] => Array ( [0] => 5,3 [1] => 6,3 [2] => 7,3 [3] => 8,3 [4] => 9,3 ) [11] => Array ( [0] => 0,2 [1] => 0,3 [2] => 0,4 [3] => 0,5 ) [12] => Array ( [0] => 7,2 [1] => 8,2 [2] => 9,2 ) [13] => Array ( [0] => 0,1 [1] => 1,1 [2] => 2,1 ) [14] => Array ( [0] => 7,7 [1] => 7,8 ) [15] => Array ( [0] => 4,1 [1] => 4,2 [2] => 4,3 [3] => 4,4 [4] => 4,5 ) [16] => Array ( [0] => 3,9 [1] => 4,9 [2] => 5,9 [3] => 6,9 ) [17] => Array ( [0] => 7,3 [1] => 8,3 [2] => 9,3 ) [18] => Array ( [0] => 6,8 [1] => 7,8 [2] => 8,8 ) [19] => Array ( [0] => 0,5 [1] => 0,6 ) ) ) [shots] => Array ( [1] => Array ( ) [2] => Array ( ) ) [width] => 10 [height] => 10 ) */ - if(count($_SESSION['shots'][1]) == count($_SESSION['shots'][1])){ + if(count($_SESSION['shots'][1]) == count($_SESSION['shots'][2])){ //player 1 has to fight $currentPlayer=1; - + $currentBot=$_SESSION['bot1']; + $opennent=2; + $opponentName=$_SESSION['bot2']['name']; }else{ //it's player2 $currentPlayer=2; + $currentBot=$_SESSION['bot2']; + $opponentName=$_SESSION['bot1']['name']; + $opponent=2; } - - + + $botParamsToSend=array( + 'game' => 'Battleship', + 'match_id' => $_SESSION['matchId']."-".$currentPlayer; + 'act' => 'fight', + 'opponent' => $opponentName, + 'width' => $_SESSION['width'], + 'height' => $_SESSION['height'], + 'ship1' => $postValues['nbShip1'], + 'ship2' => $postValues['nbShip2'], + 'ship3' => $postValues['nbShip3'], + 'ship4' => $postValues['nbShip4'], + 'ship5' => $postValues['nbShip5'], + 'ship6' => $postValues['nbShip6'] + 'your_hits' => json_encode($_SESSION['hits'][$player]), + 'his_hits' => json_encode($_SESSION['hits'][$opponent]), + + ); + $anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend); + echo $anwserPlayer; die; From 9d4a266eb40d9336eef0a506563177eb31d27317 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:25:29 +0100 Subject: [PATCH 06/40] fix php parse error --- src/arenas/Battleship/act.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 0d28506..d23bca6 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -218,7 +218,7 @@ switch ($_POST['act']){ $botParamsToSend=array( 'game' => 'Battleship', - 'match_id' => $_SESSION['matchId']."-".$currentPlayer; + 'match_id' => $_SESSION['matchId']."-".$currentPlayer, 'act' => 'fight', 'opponent' => $opponentName, 'width' => $_SESSION['width'], @@ -228,9 +228,9 @@ switch ($_POST['act']){ 'ship3' => $postValues['nbShip3'], 'ship4' => $postValues['nbShip4'], 'ship5' => $postValues['nbShip5'], - 'ship6' => $postValues['nbShip6'] + 'ship6' => $postValues['nbShip6'], 'your_hits' => json_encode($_SESSION['hits'][$player]), - 'his_hits' => json_encode($_SESSION['hits'][$opponent]), + 'his_hits' => json_encode($_SESSION['hits'][$opponent]) ); $anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend); From 4cc05812432d9d8bb10f802cd1ceb860dd312ed2 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:26:27 +0100 Subject: [PATCH 07/40] fix php parse error --- 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 d23bca6..1fc28b6 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -202,7 +202,7 @@ switch ($_POST['act']){ print_r($_SESSION); Array ( [xd_check] => VSlWXLQVbYL2sCBwqetQdorR9 [bot1] => Array ( [id] => 10 [name] => stupidIA [url] => http://botsArena.tinad.fr/StupidIABattleship.php [description] => ) [bot2] => Array ( [id] => 10 [name] => stupidIA [url] => http://botsArena.tinad.fr/StupidIABattleship.php [description] => ) [matchId] => 702 [ships] => Array ( [1] => Array ( [0] => Array ( [0] => 3,0 [1] => 3,1 [2] => 3,2 [3] => 3,3 [4] => 3,4 ) [1] => Array ( [0] => 1,5 [1] => 2,5 [2] => 3,5 [3] => 4,5 ) [2] => Array ( [0] => 7,5 [1] => 8,5 [2] => 9,5 ) [3] => Array ( [0] => 0,0 [1] => 1,0 [2] => 2,0 ) [4] => Array ( [0] => 4,4 [1] => 5,4 ) [5] => Array ( [0] => 5,3 [1] => 6,3 [2] => 7,3 [3] => 8,3 [4] => 9,3 ) [6] => Array ( [0] => 2,7 [1] => 3,7 [2] => 4,7 [3] => 5,7 ) [7] => Array ( [0] => 1,9 [1] => 2,9 [2] => 3,9 ) [8] => Array ( [0] => 7,4 [1] => 8,4 [2] => 9,4 ) [9] => Array ( [0] => 0,2 [1] => 0,3 ) [10] => Array ( [0] => 3,9 [1] => 4,9 [2] => 5,9 [3] => 6,9 [4] => 7,9 ) [11] => Array ( [0] => 2,2 [1] => 2,3 [2] => 2,4 [3] => 2,5 ) [12] => Array ( [0] => 0,8 [1] => 1,8 [2] => 2,8 ) [13] => Array ( [0] => 7,7 [1] => 8,7 [2] => 9,7 ) [14] => Array ( [0] => 8,3 [1] => 9,3 ) [15] => Array ( [0] => 4,5 [1] => 5,5 [2] => 6,5 [3] => 7,5 [4] => 8,5 ) [16] => Array ( [0] => 3,2 [1] => 4,2 [2] => 5,2 [3] => 6,2 ) [17] => Array ( [0] => 0,7 [1] => 1,7 [2] => 2,7 ) [18] => Array ( [0] => 6,1 [1] => 7,1 [2] => 8,1 ) [19] => Array ( [0] => 2,3 [1] => 3,3 ) ) [2] => Array ( [0] => Array ( [0] => 0,9 [1] => 1,9 [2] => 2,9 [3] => 3,9 [4] => 4,9 ) [1] => Array ( [0] => 1,4 [1] => 1,5 [2] => 1,6 [3] => 1,7 ) [2] => Array ( [0] => 3,0 [1] => 4,0 [2] => 5,0 ) [3] => Array ( [0] => 0,0 [1] => 1,0 [2] => 2,0 ) [4] => Array ( [0] => 5,2 [1] => 6,2 ) [5] => Array ( [0] => 2,0 [1] => 3,0 [2] => 4,0 [3] => 5,0 [4] => 6,0 ) [6] => Array ( [0] => 2,1 [1] => 3,1 [2] => 4,1 [3] => 5,1 ) [7] => Array ( [0] => 7,3 [1] => 8,3 [2] => 9,3 ) [8] => Array ( [0] => 0,2 [1] => 1,2 [2] => 2,2 ) [9] => Array ( [0] => 5,3 [1] => 5,4 ) [10] => Array ( [0] => 5,3 [1] => 6,3 [2] => 7,3 [3] => 8,3 [4] => 9,3 ) [11] => Array ( [0] => 0,2 [1] => 0,3 [2] => 0,4 [3] => 0,5 ) [12] => Array ( [0] => 7,2 [1] => 8,2 [2] => 9,2 ) [13] => Array ( [0] => 0,1 [1] => 1,1 [2] => 2,1 ) [14] => Array ( [0] => 7,7 [1] => 7,8 ) [15] => Array ( [0] => 4,1 [1] => 4,2 [2] => 4,3 [3] => 4,4 [4] => 4,5 ) [16] => Array ( [0] => 3,9 [1] => 4,9 [2] => 5,9 [3] => 6,9 ) [17] => Array ( [0] => 7,3 [1] => 8,3 [2] => 9,3 ) [18] => Array ( [0] => 6,8 [1] => 7,8 [2] => 8,8 ) [19] => Array ( [0] => 0,5 [1] => 0,6 ) ) ) [shots] => Array ( [1] => Array ( ) [2] => Array ( ) ) [width] => 10 [height] => 10 ) */ - if(count($_SESSION['shots'][1]) == count($_SESSION['shots'][2])){ + if(count($_SESSION['hits'][1]) == count($_SESSION['hits'][2])){ //player 1 has to fight $currentPlayer=1; $currentBot=$_SESSION['bot1']; From 7b28c14df2bbde5b276181b95d209ca4921f329f Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:27:41 +0100 Subject: [PATCH 08/40] fix php parse error --- src/arenas/Battleship/act.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 1fc28b6..3057bd0 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -223,12 +223,12 @@ switch ($_POST['act']){ 'opponent' => $opponentName, 'width' => $_SESSION['width'], 'height' => $_SESSION['height'], - 'ship1' => $postValues['nbShip1'], - 'ship2' => $postValues['nbShip2'], - 'ship3' => $postValues['nbShip3'], - 'ship4' => $postValues['nbShip4'], - 'ship5' => $postValues['nbShip5'], - 'ship6' => $postValues['nbShip6'], + 'ship1' => $_SESSION['ship1'], + 'ship2' => $_SESSION['ship2'], + 'ship3' => $_SESSION['ship3'], + 'ship4' => $_SESSION['ship4'], + 'ship5' => $_SESSION['ship5'], + 'ship6' => $_SESSION['ship6'], 'your_hits' => json_encode($_SESSION['hits'][$player]), 'his_hits' => json_encode($_SESSION['hits'][$opponent]) From aa7da41d4c0aa25701a6a0e36af2936a2c6ef6ae Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:28:21 +0100 Subject: [PATCH 09/40] fix php parse error --- 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 3057bd0..e586f97 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -229,7 +229,7 @@ switch ($_POST['act']){ 'ship4' => $_SESSION['ship4'], 'ship5' => $_SESSION['ship5'], 'ship6' => $_SESSION['ship6'], - 'your_hits' => json_encode($_SESSION['hits'][$player]), + 'your_hits' => json_encode($_SESSION['hits'][$currentPlayer]), 'his_hits' => json_encode($_SESSION['hits'][$opponent]) ); From 42d50519b3a4edd1fcca281906f701bf5cda2860 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:29:17 +0100 Subject: [PATCH 10/40] fix php parse error --- 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 e586f97..b1026ca 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -206,7 +206,7 @@ switch ($_POST['act']){ //player 1 has to fight $currentPlayer=1; $currentBot=$_SESSION['bot1']; - $opennent=2; + $openent=2; $opponentName=$_SESSION['bot2']['name']; }else{ //it's player2 From 98530a3f4de9d5f01b2b3fc39e74fac5c9658fa8 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:29:42 +0100 Subject: [PATCH 11/40] fix php parse error --- 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 b1026ca..66983e6 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -206,7 +206,7 @@ switch ($_POST['act']){ //player 1 has to fight $currentPlayer=1; $currentBot=$_SESSION['bot1']; - $openent=2; + $opponent=2; $opponentName=$_SESSION['bot2']['name']; }else{ //it's player2 From e1cfeb1e1b8aa901e0a4c69e512e01e808c3d217 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:38:03 +0100 Subject: [PATCH 12/40] stupidIA just rand --- html/StupidIABattleship.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index 47b507c..bd204f5 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -207,7 +207,12 @@ switch($_POST['act']){ echo json_encode($shipsCoords); break; case "fight": - print_r($_POST); + if((is_int($_POST['width'])) && (is_int($_POST['height']))){ + echo rand(0,$_POST['width']).",".$_POST['height']; + die; + } + + die; break; default: From a225f5e17274b99e6a589c4410ac61102b1bc635 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:39:17 +0100 Subject: [PATCH 13/40] stupidIA just rand --- html/StupidIABattleship.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index bd204f5..202cc2e 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -209,7 +209,8 @@ switch($_POST['act']){ case "fight": if((is_int($_POST['width'])) && (is_int($_POST['height']))){ echo rand(0,$_POST['width']).",".$_POST['height']; - die; + }else{ + echo "boaf".$_POST['width']."-".$_POST['height']; } From a6039318cd493b02fad2ad7442a8d82e1f3124f4 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:41:51 +0100 Subject: [PATCH 14/40] cast post var --- html/StupidIABattleship.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index 202cc2e..bf3ecd4 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -207,7 +207,7 @@ switch($_POST['act']){ echo json_encode($shipsCoords); break; case "fight": - if((is_int($_POST['width'])) && (is_int($_POST['height']))){ + if((is_int(settype($_POST['width'],"integer"))) && (is_int(settype($_POST['height']),"integer")){ echo rand(0,$_POST['width']).",".$_POST['height']; }else{ echo "boaf".$_POST['width']."-".$_POST['height']; From 9ea0389e8eac6d750497e2f73e387a66eaca0f64 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:42:32 +0100 Subject: [PATCH 15/40] cast post var --- html/StupidIABattleship.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index bf3ecd4..2dfd9c6 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -207,7 +207,7 @@ switch($_POST['act']){ echo json_encode($shipsCoords); break; case "fight": - if((is_int(settype($_POST['width'],"integer"))) && (is_int(settype($_POST['height']),"integer")){ + if((is_int(settype($_POST['width'],"integer"))) && (is_int(settype($_POST['height'],"integer"))){ echo rand(0,$_POST['width']).",".$_POST['height']; }else{ echo "boaf".$_POST['width']."-".$_POST['height']; From 76d0bfd34271037b3acfa0e4d751cb5acbe36a8a Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:42:54 +0100 Subject: [PATCH 16/40] cast post var --- html/StupidIABattleship.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index 2dfd9c6..fd59d89 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -207,7 +207,7 @@ switch($_POST['act']){ echo json_encode($shipsCoords); break; case "fight": - if((is_int(settype($_POST['width'],"integer"))) && (is_int(settype($_POST['height'],"integer"))){ + if((is_int(settype($_POST['width'],"integer"))) && (is_int(settype($_POST['height'],"integer")))){ echo rand(0,$_POST['width']).",".$_POST['height']; }else{ echo "boaf".$_POST['width']."-".$_POST['height']; From 306413458e9960430596cce3136047f37112116c Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 20:44:02 +0100 Subject: [PATCH 17/40] cast post var --- html/StupidIABattleship.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index fd59d89..8455737 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -207,11 +207,11 @@ switch($_POST['act']){ echo json_encode($shipsCoords); break; case "fight": - if((is_int(settype($_POST['width'],"integer"))) && (is_int(settype($_POST['height'],"integer")))){ +// if((is_int(settype($_POST['width'],"integer"))) && (is_int(settype($_POST['height'],"integer")))){ echo rand(0,$_POST['width']).",".$_POST['height']; - }else{ - echo "boaf".$_POST['width']."-".$_POST['height']; - } +// }else{ +// echo "boaf".$_POST['width']."-".$_POST['height']; +// } die; From 403b9db5de873544461b7f1a0ac539556d0e6775 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:22:43 +0100 Subject: [PATCH 18/40] strikes --- src/arenas/Battleship/act.php | 51 ++++++++++++++++++++++++++++----- src/arenas/Battleship/js.js | 17 ++++++++--- src/arenas/Battleship/style.css | 2 +- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 66983e6..0d3644a 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -187,8 +187,8 @@ switch ($_POST['act']){ $_SESSION['ship4']=$postValues['nbShip4']; $_SESSION['ship5']=$postValues['nbShip5']; $_SESSION['ship6']=$postValues['nbShip6']; - $_SESSION['hits'][1]=array(); - $_SESSION['hits'][2]=array(); + $_SESSION['strikes'][1]=array(); + $_SESSION['strikes'][2]=array(); $_SESSION['width']=$postValues['gridWidth']; $_SESSION['height']=$postValues['gridHeight']; echo json_encode($grid); die; @@ -229,14 +229,51 @@ switch ($_POST['act']){ 'ship4' => $_SESSION['ship4'], 'ship5' => $_SESSION['ship5'], 'ship6' => $_SESSION['ship6'], - 'your_hits' => json_encode($_SESSION['hits'][$currentPlayer]), - 'his_hits' => json_encode($_SESSION['hits'][$opponent]) + 'your_strikes' => json_encode($_SESSION['strikes'][$currentPlayer]), + 'his_strikes' => json_encode($_SESSION['strikes'][$opponent]) ); $anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend); - echo $anwserPlayer; - - + + if(!preg_match('/^[0-9]+,[0-9]$/',$anwserPlayer){ + echo json_encode(array( + 'target' => '', + 'log' => $currentBot['name']." a fait une réponse non conforme, il perd" + )); + save_battle('Battleship',$bot1['name'],$bot2['name'],$opponent); + die; + } + list($x,$y)=explode(",",$anwserPlayer); + + //check if shot is under map's limits + if(($x >= $_SESSION['width']) OR ($y >= $_SESSION['height'])){ + echo json_encode(array( + 'target' => '', + 'log' => $currentBot['name']." a fait un tir en dehors des limites de la carte. C'est interdit par les conventions de Genève. Il perd" + )); + save_battle('Battleship',$bot1['name'],$bot2['name'],$opponent); + } + + //do this shot hit a boat + $result=''; + foreach($_SESSION['ships'][$opponent] as $ennemyBoat{ + if(in_array($x.",".$y, $ennemyBoat)){ + $result='hit'; + break; + } + } + + //save the shot + $_SESSION['strikes'][$currentPlayer][]=array( + 'target' => $x.",".$y, + 'result' => $result + ); + echo json_encode(array( + 'opponent'=> $opponent, + 'target' => $x.",".$y, + 'log' => $currentBot['name']."tire en ".$x.",".$y." ".$result + )); + die; break; default: diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 00bc526..759bbfa 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -23,10 +23,19 @@ function fight(xd_check){ var xhr = Ajx(); xhr.onreadystatechange = function(){if(xhr.readyState == 4){ if(xhr.status == 200) { - var p=createElem("p"); - p.innerHTML=xhr.responseText; - document.getElementById('logs').appendChild(p); - //fight(xd_check); + try{ + var strike = JSON.parse(xhr.responseText); + }catch(e){ + document.getElementById('logs').innerHTML = 'erreur' +xhr.responseText; + return; + } + var coords = strike['target'].split(","); + document.getElementById( 'bot' + strike['opponent'] + '-' + coords[1] + '-' + coords[0]).innerHTML = "X"; + + var p=createElem("p"); + p.innerHTML=strike['log']; + document.getElementById('logs').appendChild(p); + //fight(xd_check); } diff --git a/src/arenas/Battleship/style.css b/src/arenas/Battleship/style.css index 062c39d..00b05b6 100644 --- a/src/arenas/Battleship/style.css +++ b/src/arenas/Battleship/style.css @@ -7,4 +7,4 @@ td{min-width: 15px; height: 15px;} .battleshipGrid tr{} .battleshipGrid tr td{border: 1px dashed green;} .battleshipGrid tr th{text-align: center;} -.shipOn{background-color: black;} \ No newline at end of file +.shipOn{background-color: black; color: #fff;} \ No newline at end of file From 8afa863be40c6e484ae403ad200c86fef93aaa9b Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:23:37 +0100 Subject: [PATCH 19/40] fix php parse error --- 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 0d3644a..91e60c5 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -235,7 +235,7 @@ switch ($_POST['act']){ ); $anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend); - if(!preg_match('/^[0-9]+,[0-9]$/',$anwserPlayer){ + if(!preg_match('/^[0-9]+,[0-9]$/',$anwserPlayer)){ echo json_encode(array( 'target' => '', 'log' => $currentBot['name']." a fait une réponse non conforme, il perd" From 84c80e1e44009ae4a9b9252252b53d8dbc47f9f5 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:24:05 +0100 Subject: [PATCH 20/40] fix php parse error --- 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 91e60c5..145cb89 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -256,7 +256,7 @@ switch ($_POST['act']){ //do this shot hit a boat $result=''; - foreach($_SESSION['ships'][$opponent] as $ennemyBoat{ + foreach($_SESSION['ships'][$opponent] as $ennemyBoat){ if(in_array($x.",".$y, $ennemyBoat)){ $result='hit'; break; From a75645e20327d6cf0b6a06b1b022d78a613b3424 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:25:10 +0100 Subject: [PATCH 21/40] fix php parse error --- 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 145cb89..817d7f7 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -202,7 +202,7 @@ switch ($_POST['act']){ print_r($_SESSION); Array ( [xd_check] => VSlWXLQVbYL2sCBwqetQdorR9 [bot1] => Array ( [id] => 10 [name] => stupidIA [url] => http://botsArena.tinad.fr/StupidIABattleship.php [description] => ) [bot2] => Array ( [id] => 10 [name] => stupidIA [url] => http://botsArena.tinad.fr/StupidIABattleship.php [description] => ) [matchId] => 702 [ships] => Array ( [1] => Array ( [0] => Array ( [0] => 3,0 [1] => 3,1 [2] => 3,2 [3] => 3,3 [4] => 3,4 ) [1] => Array ( [0] => 1,5 [1] => 2,5 [2] => 3,5 [3] => 4,5 ) [2] => Array ( [0] => 7,5 [1] => 8,5 [2] => 9,5 ) [3] => Array ( [0] => 0,0 [1] => 1,0 [2] => 2,0 ) [4] => Array ( [0] => 4,4 [1] => 5,4 ) [5] => Array ( [0] => 5,3 [1] => 6,3 [2] => 7,3 [3] => 8,3 [4] => 9,3 ) [6] => Array ( [0] => 2,7 [1] => 3,7 [2] => 4,7 [3] => 5,7 ) [7] => Array ( [0] => 1,9 [1] => 2,9 [2] => 3,9 ) [8] => Array ( [0] => 7,4 [1] => 8,4 [2] => 9,4 ) [9] => Array ( [0] => 0,2 [1] => 0,3 ) [10] => Array ( [0] => 3,9 [1] => 4,9 [2] => 5,9 [3] => 6,9 [4] => 7,9 ) [11] => Array ( [0] => 2,2 [1] => 2,3 [2] => 2,4 [3] => 2,5 ) [12] => Array ( [0] => 0,8 [1] => 1,8 [2] => 2,8 ) [13] => Array ( [0] => 7,7 [1] => 8,7 [2] => 9,7 ) [14] => Array ( [0] => 8,3 [1] => 9,3 ) [15] => Array ( [0] => 4,5 [1] => 5,5 [2] => 6,5 [3] => 7,5 [4] => 8,5 ) [16] => Array ( [0] => 3,2 [1] => 4,2 [2] => 5,2 [3] => 6,2 ) [17] => Array ( [0] => 0,7 [1] => 1,7 [2] => 2,7 ) [18] => Array ( [0] => 6,1 [1] => 7,1 [2] => 8,1 ) [19] => Array ( [0] => 2,3 [1] => 3,3 ) ) [2] => Array ( [0] => Array ( [0] => 0,9 [1] => 1,9 [2] => 2,9 [3] => 3,9 [4] => 4,9 ) [1] => Array ( [0] => 1,4 [1] => 1,5 [2] => 1,6 [3] => 1,7 ) [2] => Array ( [0] => 3,0 [1] => 4,0 [2] => 5,0 ) [3] => Array ( [0] => 0,0 [1] => 1,0 [2] => 2,0 ) [4] => Array ( [0] => 5,2 [1] => 6,2 ) [5] => Array ( [0] => 2,0 [1] => 3,0 [2] => 4,0 [3] => 5,0 [4] => 6,0 ) [6] => Array ( [0] => 2,1 [1] => 3,1 [2] => 4,1 [3] => 5,1 ) [7] => Array ( [0] => 7,3 [1] => 8,3 [2] => 9,3 ) [8] => Array ( [0] => 0,2 [1] => 1,2 [2] => 2,2 ) [9] => Array ( [0] => 5,3 [1] => 5,4 ) [10] => Array ( [0] => 5,3 [1] => 6,3 [2] => 7,3 [3] => 8,3 [4] => 9,3 ) [11] => Array ( [0] => 0,2 [1] => 0,3 [2] => 0,4 [3] => 0,5 ) [12] => Array ( [0] => 7,2 [1] => 8,2 [2] => 9,2 ) [13] => Array ( [0] => 0,1 [1] => 1,1 [2] => 2,1 ) [14] => Array ( [0] => 7,7 [1] => 7,8 ) [15] => Array ( [0] => 4,1 [1] => 4,2 [2] => 4,3 [3] => 4,4 [4] => 4,5 ) [16] => Array ( [0] => 3,9 [1] => 4,9 [2] => 5,9 [3] => 6,9 ) [17] => Array ( [0] => 7,3 [1] => 8,3 [2] => 9,3 ) [18] => Array ( [0] => 6,8 [1] => 7,8 [2] => 8,8 ) [19] => Array ( [0] => 0,5 [1] => 0,6 ) ) ) [shots] => Array ( [1] => Array ( ) [2] => Array ( ) ) [width] => 10 [height] => 10 ) */ - if(count($_SESSION['hits'][1]) == count($_SESSION['hits'][2])){ + if(count($_SESSION['strikes'][1]) == count($_SESSION['strikes'][2])){ //player 1 has to fight $currentPlayer=1; $currentBot=$_SESSION['bot1']; From 273a49352079b93ad50026754531e4dfedef743b Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:27:04 +0100 Subject: [PATCH 22/40] fix php parse error --- 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 817d7f7..ca4df36 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -240,7 +240,7 @@ switch ($_POST['act']){ 'target' => '', 'log' => $currentBot['name']." a fait une réponse non conforme, il perd" )); - save_battle('Battleship',$bot1['name'],$bot2['name'],$opponent); + save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); die; } list($x,$y)=explode(",",$anwserPlayer); From 5c9c007d4a80a68ddc2a94ba0d59de9977522a6e Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:28:38 +0100 Subject: [PATCH 23/40] strikes --- src/arenas/Battleship/js.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 759bbfa..f68366c 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -29,9 +29,10 @@ function fight(xd_check){ document.getElementById('logs').innerHTML = 'erreur' +xhr.responseText; return; } - var coords = strike['target'].split(","); - document.getElementById( 'bot' + strike['opponent'] + '-' + coords[1] + '-' + coords[0]).innerHTML = "X"; - + if( strike['target'] <> ''){ + var coords = strike['target'].split(","); + document.getElementById( 'bot' + strike['opponent'] + '-' + coords[1] + '-' + coords[0]).innerHTML = "X"; + } var p=createElem("p"); p.innerHTML=strike['log']; document.getElementById('logs').appendChild(p); From d3c1fd970a7f0fb8f51873788ccf2c4570504605 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:30:19 +0100 Subject: [PATCH 24/40] strikes --- 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 f68366c..7f0f8ff 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -29,7 +29,7 @@ function fight(xd_check){ document.getElementById('logs').innerHTML = 'erreur' +xhr.responseText; return; } - if( strike['target'] <> ''){ + if( strike['target'] !== ''){ var coords = strike['target'].split(","); document.getElementById( 'bot' + strike['opponent'] + '-' + coords[1] + '-' + coords[0]).innerHTML = "X"; } From 6ad612de14e1fa5d3957fcebc2563cfe1adf809d Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:31:43 +0100 Subject: [PATCH 25/40] debog 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 ca4df36..547d5d6 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -238,7 +238,7 @@ switch ($_POST['act']){ if(!preg_match('/^[0-9]+,[0-9]$/',$anwserPlayer)){ echo json_encode(array( 'target' => '', - 'log' => $currentBot['name']." a fait une réponse non conforme, il perd" + 'log' => $currentBot['name']." a fait une réponse non conforme, il perd.".$anwserPlayer )); save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); die; From 7b539a959e21509f69c21d342b71d280cce87abc Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:32:52 +0100 Subject: [PATCH 26/40] debog 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 547d5d6..bb28aa0 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -238,7 +238,7 @@ switch ($_POST['act']){ if(!preg_match('/^[0-9]+,[0-9]$/',$anwserPlayer)){ echo json_encode(array( 'target' => '', - 'log' => $currentBot['name']." a fait une réponse non conforme, il perd.".$anwserPlayer + 'log' => $currentBot['name']." a fait une réponse non conforme, il perd.|".nl2br($anwserPlayer)."|"; )); save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); die; From 9b7cde43bdc4fd4b2225990552aefb076725aa8c Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:33:26 +0100 Subject: [PATCH 27/40] debog 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 bb28aa0..391fac2 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -238,7 +238,7 @@ switch ($_POST['act']){ if(!preg_match('/^[0-9]+,[0-9]$/',$anwserPlayer)){ echo json_encode(array( 'target' => '', - 'log' => $currentBot['name']." a fait une réponse non conforme, il perd.|".nl2br($anwserPlayer)."|"; + 'log' => $currentBot['name']." a fait une réponse non conforme, il perd.|".nl2br($anwserPlayer)."|" )); save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); die; From c381411f746747d4a767dab97b0d98aa5789540a Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:35:13 +0100 Subject: [PATCH 28/40] debog 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 391fac2..0935e13 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -235,10 +235,10 @@ switch ($_POST['act']){ ); $anwserPlayer=get_IA_Response($currentBot['url'],$botParamsToSend); - if(!preg_match('/^[0-9]+,[0-9]$/',$anwserPlayer)){ + if(!preg_match('/^[0-9]+,[0-9]+$/',$anwserPlayer)){ echo json_encode(array( 'target' => '', - 'log' => $currentBot['name']." a fait une réponse non conforme, il perd.|".nl2br($anwserPlayer)."|" + 'log' => $currentBot['name']." a fait une réponse non conforme, il perd.".$anwserPlayer )); save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); die; From 825d3c0faf17b79d81a111af2a2b0bf3a7143450 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:36:45 +0100 Subject: [PATCH 29/40] fix php parse error --- 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 0935e13..29c26cd 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -251,7 +251,7 @@ switch ($_POST['act']){ 'target' => '', 'log' => $currentBot['name']." a fait un tir en dehors des limites de la carte. C'est interdit par les conventions de Genève. Il perd" )); - save_battle('Battleship',$bot1['name'],$bot2['name'],$opponent); + save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); } //do this shot hit a boat From 37472adabc653a8d4c16aaa0eb565a229e7ffcf7 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:38:40 +0100 Subject: [PATCH 30/40] fix php parse error --- html/StupidIABattleship.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index 8455737..1540083 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -208,7 +208,7 @@ switch($_POST['act']){ break; case "fight": // if((is_int(settype($_POST['width'],"integer"))) && (is_int(settype($_POST['height'],"integer")))){ - echo rand(0,$_POST['width']).",".$_POST['height']; + echo rand(0,$_POST['width']).",".rand(0,$_POST['height']); // }else{ // echo "boaf".$_POST['width']."-".$_POST['height']; // } From bf79dad577c6e189ac11f3633e879ad5c9d30353 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:40:11 +0100 Subject: [PATCH 31/40] css --- src/arenas/Battleship/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/Battleship/style.css b/src/arenas/Battleship/style.css index 00b05b6..72c9e6b 100644 --- a/src/arenas/Battleship/style.css +++ b/src/arenas/Battleship/style.css @@ -5,6 +5,6 @@ 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 td{border: 1px dashed green; text-align: center; font-weight: bold;} .battleshipGrid tr th{text-align: center;} .shipOn{background-color: black; color: #fff;} \ No newline at end of file From 2346bfa24288565f5fd4d7c7ca96e297d56c6b45 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:45:00 +0100 Subject: [PATCH 32/40] loop --- src/arenas/Battleship/act.php | 8 +++++++- src/arenas/Battleship/js.js | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 29c26cd..c106b98 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -268,10 +268,16 @@ switch ($_POST['act']){ 'target' => $x.",".$y, 'result' => $result ); + if(count( $_SESSION['strikes'][$currentPlayer]) < 10){ + $continue=1; + }else{ + $continue=0; + } echo json_encode(array( 'opponent'=> $opponent, 'target' => $x.",".$y, - 'log' => $currentBot['name']."tire en ".$x.",".$y." ".$result + 'log' => $currentBot['name']."tire en ".$x.",".$y." ".$result, + 'continue' => $continue )); die; diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js index 7f0f8ff..679ff4d 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -36,7 +36,10 @@ function fight(xd_check){ var p=createElem("p"); p.innerHTML=strike['log']; document.getElementById('logs').appendChild(p); - //fight(xd_check); + + if( strike['continue'] == 1){ + fight(xd_check); + } } From 3551bf8a176b9dfdc15bb26ed9be114298710643 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:46:30 +0100 Subject: [PATCH 33/40] . --- 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 c106b98..3a87692 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -213,7 +213,7 @@ switch ($_POST['act']){ $currentPlayer=2; $currentBot=$_SESSION['bot2']; $opponentName=$_SESSION['bot1']['name']; - $opponent=2; + $opponent=1; } $botParamsToSend=array( From b7f157c263c1e7b1578b2fad2bbe8ec36c14c4fa Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:49:25 +0100 Subject: [PATCH 34/40] UTF8 and javascript --- 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 3a87692..8c67996 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -249,7 +249,7 @@ switch ($_POST['act']){ if(($x >= $_SESSION['width']) OR ($y >= $_SESSION['height'])){ echo json_encode(array( 'target' => '', - 'log' => $currentBot['name']." a fait un tir en dehors des limites de la carte. C'est interdit par les conventions de Genève. Il perd" + 'log' => $currentBot['name']." a fait un tir en dehors des limites de la carte. C'est interdit par les conventions de Geneve. Il perd" )); save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); } From 0bdf972eab1382061f4250a2c1a2fba88c0183f0 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:50:17 +0100 Subject: [PATCH 35/40] UTF8 and javascript --- 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 679ff4d..05a6260 100644 --- a/src/arenas/Battleship/js.js +++ b/src/arenas/Battleship/js.js @@ -26,7 +26,7 @@ function fight(xd_check){ try{ var strike = JSON.parse(xhr.responseText); }catch(e){ - document.getElementById('logs').innerHTML = 'erreur' +xhr.responseText; + document.getElementById('logs').innerHTML += 'erreur' +xhr.responseText; return; } if( strike['target'] !== ''){ From 90994a60ee149599df605b68e9552dc263717990 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:51:15 +0100 Subject: [PATCH 36/40] UTF8 and javascript --- 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 8c67996..016dac4 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -249,7 +249,7 @@ switch ($_POST['act']){ if(($x >= $_SESSION['width']) OR ($y >= $_SESSION['height'])){ echo json_encode(array( 'target' => '', - 'log' => $currentBot['name']." a fait un tir en dehors des limites de la carte. C'est interdit par les conventions de Geneve. Il perd" + 'log' => $currentBot['name']." a fait un tir en dehors des limites de la carte. C est interdit par les conventions de Geneve. Il perd" )); save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); } From 14a719b1ae065ba4e79df172a0ba3e72e7c04574 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:52:23 +0100 Subject: [PATCH 37/40] UTF8 and javascript --- src/arenas/Battleship/act.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php index 016dac4..9315759 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -251,7 +251,8 @@ switch ($_POST['act']){ 'target' => '', 'log' => $currentBot['name']." a fait un tir en dehors des limites de la carte. C est interdit par les conventions de Geneve. Il perd" )); - save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); + save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); + die; } //do this shot hit a boat From d424cc35b65e2d55737ee946300414b9ea248ec5 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:53:29 +0100 Subject: [PATCH 38/40] . --- 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 9315759..7cd6437 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -249,7 +249,7 @@ switch ($_POST['act']){ if(($x >= $_SESSION['width']) OR ($y >= $_SESSION['height'])){ echo json_encode(array( 'target' => '', - 'log' => $currentBot['name']." a fait un tir en dehors des limites de la carte. C est interdit par les conventions de Geneve. Il perd" + 'log' => $currentBot['name']." a fait un tir en dehors des limites de la carte. ".$x.",".$y." C'est interdit par les conventions de Geneve. Il perd" )); save_battle('Battleship',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],$opponent); die; From b9da00c608446e6c521bbb8977a20beda9307318 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:54:13 +0100 Subject: [PATCH 39/40] fix maps limits --- html/StupidIABattleship.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/StupidIABattleship.php b/html/StupidIABattleship.php index 1540083..85d17d4 100644 --- a/html/StupidIABattleship.php +++ b/html/StupidIABattleship.php @@ -208,7 +208,7 @@ switch($_POST['act']){ break; case "fight": // if((is_int(settype($_POST['width'],"integer"))) && (is_int(settype($_POST['height'],"integer")))){ - echo rand(0,$_POST['width']).",".rand(0,$_POST['height']); + echo rand(0,$_POST['width'] -1).",".rand(0,$_POST['height'] -1); // }else{ // echo "boaf".$_POST['width']."-".$_POST['height']; // } From c5f23358f56ae633ff41e4f1703d86b036215cf5 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 18 Dec 2015 21:55:45 +0100 Subject: [PATCH 40/40] fix maps limits --- 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 7cd6437..d0c7141 100644 --- a/src/arenas/Battleship/act.php +++ b/src/arenas/Battleship/act.php @@ -277,7 +277,7 @@ switch ($_POST['act']){ echo json_encode(array( 'opponent'=> $opponent, 'target' => $x.",".$y, - 'log' => $currentBot['name']."tire en ".$x.",".$y." ".$result, + 'log' => $currentBot['name']." tire en ".$x.",".$y." ".$result, 'continue' => $continue ));