From 49fa966c1b3d90dbd71e6bf64c2edf30ff776694 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 9 May 2016 21:36:41 +0200 Subject: [PATCH 01/87] start dev connect four --- src/arenas/connectFour/js.js | 0 src/arenas/connectFour/public.php | 18 ++++++++++++++++++ src/arenas/connectFour/style.css | 0 src/arenas_lists.php | 8 ++++++++ 4 files changed, 26 insertions(+) create mode 100644 src/arenas/connectFour/js.js create mode 100644 src/arenas/connectFour/public.php create mode 100644 src/arenas/connectFour/style.css diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js new file mode 100644 index 0000000..e69de29 diff --git a/src/arenas/connectFour/public.php b/src/arenas/connectFour/public.php new file mode 100644 index 0000000..de1f375 --- /dev/null +++ b/src/arenas/connectFour/public.php @@ -0,0 +1,18 @@ + +
+

Connect Four +
+

diff --git a/src/arenas/connectFour/style.css b/src/arenas/connectFour/style.css new file mode 100644 index 0000000..e69de29 diff --git a/src/arenas_lists.php b/src/arenas_lists.php index 2770c6f..709e4d9 100644 --- a/src/arenas_lists.php +++ b/src/arenas_lists.php @@ -15,6 +15,14 @@ $arenas=array( 'metaDescription' => 'Affrontements de bots à la battaille navale', 'jsFile'=> "js.js", 'cssFile'=> "style.css" + ), + array( + 'id' => "connectFour", + 'url' => "/connectFour", + 'title' => "Puissance 4", + 'metaDescription' => 'Affrontements de bots puissance 4', + 'jsFile'=> "js.js", + 'cssFile'=> "style.css" ) ); \ No newline at end of file From 82f1e749e10d1d8b3ecde1a0db6265fd562624bc Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 9 May 2016 21:38:20 +0200 Subject: [PATCH 02/87] file missing --- src/arenas/connectFour/functions.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/arenas/connectFour/functions.php diff --git a/src/arenas/connectFour/functions.php b/src/arenas/connectFour/functions.php new file mode 100644 index 0000000..e69de29 From bac2ed4a4547ae04053a4a14e9194f419c9a357c Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 9 May 2016 21:39:53 +0200 Subject: [PATCH 03/87] purge file --- src/arenas/connectFour/public.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/arenas/connectFour/public.php b/src/arenas/connectFour/public.php index de1f375..3f6c6cb 100644 --- a/src/arenas/connectFour/public.php +++ b/src/arenas/connectFour/public.php @@ -2,14 +2,7 @@ require_once(__DIR__."/functions.php"); $bots=get_Bots_Array('connectFour'); -$postParams=get_Post_Params(count($bots)); -if(!$postParams){ - $bot1=""; - $bot2=""; -}else{ - $bot1=$postParams['bot1']; - $bot2=$postParams['bot2']; -} + ?>
From 9735e69552435bcf2ce849297ec60184e2ee34e1 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 9 May 2016 21:47:30 +0200 Subject: [PATCH 04/87] start specifications --- src/arenas/connectFour/doc-fr.html | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/arenas/connectFour/doc-fr.html diff --git a/src/arenas/connectFour/doc-fr.html b/src/arenas/connectFour/doc-fr.html new file mode 100644 index 0000000..fb0cbee --- /dev/null +++ b/src/arenas/connectFour/doc-fr.html @@ -0,0 +1,10 @@ +

Fonctionnement des duels de puisaance 4

+

La grille

+
    +
  • largeur: 7 cases
  • +
  • hauteur: 6 cases
  • +

    + +

    Query générée par l'arène (ce site) vers votre bot

    + +

    Réponse de votre bot

    From 7dddcb5ce45d9dfe24ae80e3318223a823b21273 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 9 May 2016 22:10:46 +0200 Subject: [PATCH 05/87] specifications --- src/arenas/connectFour/doc-fr.html | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/arenas/connectFour/doc-fr.html b/src/arenas/connectFour/doc-fr.html index fb0cbee..1439746 100644 --- a/src/arenas/connectFour/doc-fr.html +++ b/src/arenas/connectFour/doc-fr.html @@ -3,8 +3,32 @@
    • largeur: 7 cases
    • hauteur: 6 cases
    • +

    -

    Query générée par l'arène (ce site) vers votre bot

    +

    Requête générée par l'arène (ce site) vers votre bot

    +L'arène fait une requête http(s) avec les parametres POST suivants vers votre site: + + + + + + + + + + + + + +
    paramètrevaleur
    game + Chaîne de caractères, sera toujours "connectFour".
    + Peut servir si votre url sert à plusieurs jeux. +
    match_id + Chaîne de caractères. Répond à l'expression régulière suivante: ^[0-9]+-(1|2)$
    + Le premier nombre (digits avant le tiret) identifie le match.
    + Le numéro après le tiret vous indique si vous êtes le bot 1 ou le bot 2 dans l'ordre de jeu.
    + Ça vous servira si votre IA fait des statistiques sur les matchs. +
    youvous indique quel est votre symbole dans la grille
    gridtableau au format JSON vous indiquant l'état de la grille

    Réponse de votre bot

    From bf2b0e114de5105f538af3b9387501e93881b5de Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 9 May 2016 22:13:24 +0200 Subject: [PATCH 06/87] bit of css --- src/arenas/connectFour/doc-fr.html | 2 +- src/arenas/connectFour/style.css | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/arenas/connectFour/doc-fr.html b/src/arenas/connectFour/doc-fr.html index 1439746..43464fe 100644 --- a/src/arenas/connectFour/doc-fr.html +++ b/src/arenas/connectFour/doc-fr.html @@ -9,7 +9,7 @@

    Requête générée par l'arène (ce site) vers votre bot

    L'arène fait une requête http(s) avec les parametres POST suivants vers votre site: - +
    diff --git a/src/arenas/connectFour/style.css b/src/arenas/connectFour/style.css index e69de29..6ef9606 100644 --- a/src/arenas/connectFour/style.css +++ b/src/arenas/connectFour/style.css @@ -0,0 +1,2 @@ +.tabledoc{border-collapse:collapse;} +.tabledoc tr td,.tabledoc tr th{border: 1px solid green; padding-left: 5px;} \ No newline at end of file From 48f063f8ef236067412b9a7f06f12cb8bb87af41 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 9 May 2016 22:19:17 +0200 Subject: [PATCH 07/87] specifications --- src/arenas/connectFour/doc-fr.html | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/arenas/connectFour/doc-fr.html b/src/arenas/connectFour/doc-fr.html index 43464fe..b0c7be4 100644 --- a/src/arenas/connectFour/doc-fr.html +++ b/src/arenas/connectFour/doc-fr.html @@ -28,7 +28,18 @@ L'arène fait une requête http(s) avec les parametres POST suivants vers v - +
    paramètrevaleur
    game
    youvous indique quel est votre symbole dans la grille
    gridtableau au format JSON vous indiquant l'état de la grille
    gridtableau à deux dimmensions au format JSON vous indiquant l'état de la grille
    + Exemple:
    +
    +  [{"","","","X","0","",""},
    +   {"","","","X","","",""},
    +   {"","","","","","",""},
    +   {"","","","","","",""},
    +   {"","","","","","",""},
    +   {"","","","","","",""}]
    +  
    + +

    Réponse de votre bot

    From 651371ef27bf9eebb8800c16244c0a4d05716ead Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 9 May 2016 23:38:36 +0200 Subject: [PATCH 08/87] plop --- src/arenas/connectFour/doc-fr.html | 3 ++- src/arenas/connectFour/functions.php | 17 +++++++++++++ src/arenas/connectFour/public.php | 38 ++++++++++++++++++++++++++-- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/arenas/connectFour/doc-fr.html b/src/arenas/connectFour/doc-fr.html index b0c7be4..30c1f48 100644 --- a/src/arenas/connectFour/doc-fr.html +++ b/src/arenas/connectFour/doc-fr.html @@ -1,4 +1,4 @@ -

    Fonctionnement des duels de puisaance 4

    +

    Fonctionnement des duels de puisance 4

    La grille

    • largeur: 7 cases
    • @@ -43,3 +43,4 @@ L'arène fait une requête http(s) avec les parametres POST suivants vers v

      Réponse de votre bot

      +

      Il indique la colonne dans laquelle vous souhaitez jouer 0 à 7

      diff --git a/src/arenas/connectFour/functions.php b/src/arenas/connectFour/functions.php index e69de29..09b1f14 100644 --- a/src/arenas/connectFour/functions.php +++ b/src/arenas/connectFour/functions.php @@ -0,0 +1,17 @@ + $botsCount)){ + error(400,"wrong parameters"); + die; + } + } + return array('bot1' => $_POST['bot1'],'bot2' => $_POST['bot2']); +} \ No newline at end of file diff --git a/src/arenas/connectFour/public.php b/src/arenas/connectFour/public.php index 3f6c6cb..6443536 100644 --- a/src/arenas/connectFour/public.php +++ b/src/arenas/connectFour/public.php @@ -2,10 +2,44 @@ require_once(__DIR__."/functions.php"); $bots=get_Bots_Array('connectFour'); - +$postParams=get_Post_Params(count($bots)); +if(!$postParams){ + $bot1=""; + $bot2=""; +}else{ + $bot1=$postParams['bot1']; + $bot2=$postParams['bot2']; +} ?>
      -

      Connect Four +

      +

      + +  VS  + +

      +

      From e036bd55daed20ab3b013af29362c47e3eb0024d Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 9 May 2016 23:50:07 +0200 Subject: [PATCH 09/87] plop --- src/arenas/connectFour/act.php | 14 ++++++++++++++ src/arenas/connectFour/js.js | 3 +++ src/arenas/connectFour/public.php | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/arenas/connectFour/act.php diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php new file mode 100644 index 0000000..998a7d4 --- /dev/null +++ b/src/arenas/connectFour/act.php @@ -0,0 +1,14 @@ +

      -

      +

From 910142f0d23fb94b02982a3df4385c1f07828261 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 10 May 2016 17:05:09 +0200 Subject: [PATCH 10/87] init map --- src/arenas/connectFour/act.php | 19 +++++++++++++++---- src/arenas/connectFour/functions.php | 1 + src/arenas/connectFour/js.js | 27 +++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 998a7d4..8a4d442 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -3,12 +3,23 @@ require_once(__DIR__."/functions.php"); switch ($_POST['act']){ + case "newfight": + //initialiser la map + $_SESSION['map']=array( + array("","","","","","",""), + array("","","","","","",""), + array("","","","","","",""), + array("","","","","","",""), + array("","","","","","",""), + array("","","","","","",""), + ); + + + echo json_encode($_SESSION['map']); case "fight": - - - break; - + die; + break; default: break; } \ No newline at end of file diff --git a/src/arenas/connectFour/functions.php b/src/arenas/connectFour/functions.php index 09b1f14..1f60e7e 100644 --- a/src/arenas/connectFour/functions.php +++ b/src/arenas/connectFour/functions.php @@ -1,4 +1,5 @@ Please wait...

'; + var xhr = Ajx(); + xhr.onreadystatechange = function(){if(xhr.readyState == 4){ + if(xhr.status == 200) { + document.getElementById('fightResult').innerHTML = xhr.responseText; + } + }}; + xhr.open("POST", '/connectFour', true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send('act=newFight&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check); +} From de33116dae2fd20967443caa1824bef91df0f01b Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 10 May 2016 17:14:20 +0200 Subject: [PATCH 11/87] init map --- src/arenas/connectFour/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 8a4d442..3f810c8 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -15,7 +15,7 @@ switch ($_POST['act']){ ); - echo json_encode($_SESSION['map']); + echo "plop".json_encode($_SESSION['map']); case "fight": die; From 4dd12bf9a0f1d57de02dbbf77f173ab2760bb2d3 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 11 May 2016 09:35:11 +0200 Subject: [PATCH 12/87] erf --- src/arenas/connectFour/act.php | 2 +- src/arenas/connectFour/public.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 3f810c8..284dd92 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -3,7 +3,7 @@ require_once(__DIR__."/functions.php"); switch ($_POST['act']){ - case "newfight": + case "newFight": //initialiser la map $_SESSION['map']=array( array("","","","","","",""), diff --git a/src/arenas/connectFour/public.php b/src/arenas/connectFour/public.php index 8295020..aa5ed1b 100644 --- a/src/arenas/connectFour/public.php +++ b/src/arenas/connectFour/public.php @@ -12,7 +12,7 @@ if(!$postParams){ } ?> -
+

'.$bots[$i]['name'].''; + echo ''; } ?> @@ -32,11 +18,7 @@ if(!$postParams){ From ae48bd4576f7ed561ee4473d98a199363cd9c78d Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 11 May 2016 11:20:02 +0200 Subject: [PATCH 22/87] fix --- src/arenas/connectFour/public.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/arenas/connectFour/public.php b/src/arenas/connectFour/public.php index 0ff01cf..3e3dd95 100644 --- a/src/arenas/connectFour/public.php +++ b/src/arenas/connectFour/public.php @@ -9,16 +9,16 @@ $bots=get_Bots_Array('connectFou');

 VS  From d2ccf4741f4217a2ceaca9b2ea87c87916f0c0c0 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 11 May 2016 11:20:59 +0200 Subject: [PATCH 23/87] fix --- src/arenas/connectFour/act.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 914e32c..036cd50 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -46,13 +46,13 @@ switch ($_POST['act']){ //get a match id $_SESSION['matchId']=get_unique_id(); - $_SESSION['game']="conectFou"; + $_SESSION['game']="connectFou"; //echo "plop".json_encode($_SESSION['map']); case "fight": if($_SESSION['game'] <> "connectFou"){ - erreur(500,"game non found"); + error(500,"game non found"); } //What player has to play? From 72bd49f825f68e262ffa9a7635f16fa1ac2d84eb Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 11 May 2016 11:21:50 +0200 Subject: [PATCH 24/87] fix --- src/arenas/connectFour/act.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 036cd50..d60c5ac 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -71,8 +71,8 @@ switch ($_POST['act']){ //make post datas to send $postDatas=array( - 'game' => 'conectFour', - 'match_id' => $_SESSION['matchId']. $_SESSION['currentPlayer'], + 'game' => 'connectFour', + 'match_id' => $_SESSION['matchId']."-".$_SESSION['currentPlayer'], //'opponent' => $opponentName, 'you' => $you, 'grid' => json_encode( $_SESSION['map']) From f701b8d633f202011308b20d404287fec5d74585 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 11 May 2016 12:20:34 +0200 Subject: [PATCH 25/87] query to bot --- src/arenas/connectFour/act.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index d60c5ac..5f373ef 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -59,12 +59,18 @@ switch ($_POST['act']){ if(!isset($_SESSION['currentPlayer'])){ $_SESSION['currentPlayer']=1; $you="X"; + $opponentName=$_SESSION['bot2']['name']; + $botUrl=$_SESSION['bot1']['url']; }else{ if($_SESSION['currentPlayer']==1){ $_SESSION['currentPlayer']=2; $you="O"; + $opponentName=$_SESSION['bot1']['name']; + $botUrl=$_SESSION['bot2']['url']; }else{ $_SESSION['currentPlayer']=1; + $opponentName=$_SESSION['bot2']['name']; + $botUrl=$_SESSION['bot1']['url']; $you="X"; } } @@ -73,14 +79,14 @@ switch ($_POST['act']){ $postDatas=array( 'game' => 'connectFour', 'match_id' => $_SESSION['matchId']."-".$_SESSION['currentPlayer'], - //'opponent' => $opponentName, + 'opponent' => $opponentName, 'you' => $you, 'grid' => json_encode( $_SESSION['map']) ); - //debug - print_r($postDatas); - print_r($_SESSION['bot1']); + //send query + $anwserPlayer=get_IA_Response($botUrl,$postDatas); + echo "player ".$_SESSION['currentPlayer']." répond ".$anwserPlayer; From 66a119689c5d4b2f490e89064d97488883d64730 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 11 May 2016 12:21:47 +0200 Subject: [PATCH 26/87] query to bot --- src/arenas/connectFour/functions.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/arenas/connectFour/functions.php b/src/arenas/connectFour/functions.php index 1f60e7e..e2633b4 100644 --- a/src/arenas/connectFour/functions.php +++ b/src/arenas/connectFour/functions.php @@ -1,5 +1,14 @@ Date: Wed, 11 May 2016 12:23:19 +0200 Subject: [PATCH 27/87] query to bot --- src/functions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions.php b/src/functions.php index e1af02b..2745efb 100644 --- a/src/functions.php +++ b/src/functions.php @@ -227,6 +227,7 @@ function get_unique_id(){ fclose($fp); return $count; } + function does_arena_exist($string,$arenasArr){ foreach($arenasArr as $arena){ if($string == $arena['id']){ From 9091a4615148b6b8df326abf66f280e5854169c4 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 11 May 2016 14:49:38 +0200 Subject: [PATCH 28/87] stupidIa --- html/StupidIAconnectFour.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/html/StupidIAconnectFour.php b/html/StupidIAconnectFour.php index f96fdd6..aa3f5c2 100644 --- a/html/StupidIAconnectFour.php +++ b/html/StupidIAconnectFour.php @@ -1,3 +1,18 @@ Date: Wed, 11 May 2016 14:50:31 +0200 Subject: [PATCH 29/87] debog stupidIa --- html/StupidIAconnectFour.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/StupidIAconnectFour.php b/html/StupidIAconnectFour.php index aa3f5c2..bd0a3d7 100644 --- a/html/StupidIAconnectFour.php +++ b/html/StupidIAconnectFour.php @@ -5,7 +5,7 @@ */ $grid=json_decode($_POST['grid']); - +print_r($grid); $colAvailable=array(); for($i=0;$i<7;$i++){ From 74d43261678ac283ad0e2426ed689d5b8460a206 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 11 May 2016 14:51:58 +0200 Subject: [PATCH 30/87] debog stupidIa --- html/StupidIAconnectFour.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/StupidIAconnectFour.php b/html/StupidIAconnectFour.php index bd0a3d7..f017083 100644 --- a/html/StupidIAconnectFour.php +++ b/html/StupidIAconnectFour.php @@ -9,7 +9,7 @@ print_r($grid); $colAvailable=array(); for($i=0;$i<7;$i++){ - if($colAvailable[5][$i] == ""){ + if($colAvailable[4][$i] == ""){ $colAvailable[]=$i; } } From 22609cf0b0580bb363736aaea3d386c0f81ca0b1 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 11 May 2016 14:52:26 +0200 Subject: [PATCH 31/87] debog stupidIa --- html/StupidIAconnectFour.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/html/StupidIAconnectFour.php b/html/StupidIAconnectFour.php index f017083..43a9deb 100644 --- a/html/StupidIAconnectFour.php +++ b/html/StupidIAconnectFour.php @@ -5,11 +5,11 @@ */ $grid=json_decode($_POST['grid']); -print_r($grid); + $colAvailable=array(); for($i=0;$i<7;$i++){ - if($colAvailable[4][$i] == ""){ + if($grid[5][$i] == ""){ $colAvailable[]=$i; } } From 5a1636a0fa0e1f58cb5fa606ae6f20320b227f0a Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 11 May 2016 14:53:10 +0200 Subject: [PATCH 32/87] debog stupidIa --- html/StupidIAconnectFour.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/StupidIAconnectFour.php b/html/StupidIAconnectFour.php index 43a9deb..fda1d04 100644 --- a/html/StupidIAconnectFour.php +++ b/html/StupidIAconnectFour.php @@ -14,5 +14,5 @@ for($i=0;$i<7;$i++){ } } shuffle($colAvailable); -echo $i; +echo $colAvailable[0]; die; From 828f1a4492892fbc696eab0e7b89b9ad4305e12a Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 11 May 2016 15:05:33 +0200 Subject: [PATCH 33/87] debog stupidIa --- src/arenas/connectFour/act.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 5f373ef..e73beda 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -86,6 +86,9 @@ switch ($_POST['act']){ ); //send query $anwserPlayer=get_IA_Response($botUrl,$postDatas); + $anwserToJS=array( + + ) echo "player ".$_SESSION['currentPlayer']." répond ".$anwserPlayer; From b85498c1c9798f479294cf7dddb068414fa3ecd6 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 12 May 2016 17:05:44 +0200 Subject: [PATCH 34/87] arbiter --- src/arenas/connectFour/act.php | 84 ++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index e73beda..bdbc3b0 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -59,6 +59,7 @@ switch ($_POST['act']){ if(!isset($_SESSION['currentPlayer'])){ $_SESSION['currentPlayer']=1; $you="X"; + $currentBotName=$_SESSION['bot1']['name']; $opponentName=$_SESSION['bot2']['name']; $botUrl=$_SESSION['bot1']['url']; }else{ @@ -66,10 +67,12 @@ switch ($_POST['act']){ $_SESSION['currentPlayer']=2; $you="O"; $opponentName=$_SESSION['bot1']['name']; + $currentBotName=$_SESSION['bot2']['name']; $botUrl=$_SESSION['bot2']['url']; }else{ $_SESSION['currentPlayer']=1; $opponentName=$_SESSION['bot2']['name']; + $currentBotName=$_SESSION['bot1']['name']; $botUrl=$_SESSION['bot1']['url']; $you="X"; } @@ -86,10 +89,85 @@ switch ($_POST['act']){ ); //send query $anwserPlayer=get_IA_Response($botUrl,$postDatas); - $anwserToJS=array( + + //vérifier la validité de la réponse + + + if(isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == ""){ + //reponse conforme - ) - echo "player ".$_SESSION['currentPlayer']." répond ".$anwserPlayer; + for($y = 0; $_SESSION['map'][$y][$anwserPlayer] <> ""; $y++){ + } + $_SESSION['map'][$y][$anwserPlayer]=$you; + + //does he win? + for($i=0;$i < 7;$i++){ + for($j=0;$j < 6;$j++){ + if($_SESSION['map'][$j][$i]== $you){ + + $wins=false; + //tester si 4 pions allignés vers la droite + if($i<4){ + $wins=true; + for($x = $i+1; $x < $i+4; $x++){ + if($_SESSION['map'][$j][$x] <> $you){ + $wins=false; + break; + } + } + } + + //tester si 4 pions allignés diagonale vers la droite + if((!$wins) && ($i < 4) && ($j < 3)){ + $wins=true; + for($x = $i+1; $y = $j+1; $x < $i+4 ; $x++; $y++){ + if($_SESSION['map'][$j][$x] <> $you){ + $wins=false; + break; + } + } + } + //tester si 4 pions allignés diagonale vers la gauche + if((!$wins) && ($i > 3) && ($j < 3)){ + $wins=true; + for($x = $i-1; $y = $j+1; $x > $i - 4 ; $x++; $y++){ + if($_SESSION['map'][$j][$x] <> $you){ + $wins=false; + break; + } + } + + } + } + } + } + + if($wins){ + $anwserToJS=array( + 'continue' => 0, + 'grid' => $_SESSION['map'], + 'log' => $you." ".$currentBotName." a gagné" + ); + }else{ + $anwserToJS=array( + 'continue' => 1, + 'grid' => $_SESSION['map'], + 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer + ); + + + } + + }else{ + //reponse non conforme + $anwserToJS=array( + 'continue' =>0, + 'grid' => $_SESSION['map'], + 'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd" + ); + } + + echo json_encode($anwserToJS); From 0ccdfd604748441a96c9180014e6d71921888aa8 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 12 May 2016 17:07:06 +0200 Subject: [PATCH 35/87] fix php parse error --- src/arenas/connectFour/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index bdbc3b0..f7007c8 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -93,7 +93,7 @@ switch ($_POST['act']){ //vérifier la validité de la réponse - if(isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == ""){ + if((isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == "")){ //reponse conforme for($y = 0; $_SESSION['map'][$y][$anwserPlayer] <> ""; $y++){ From 2865b4b384448286e622ce4c9eacdf9014683893 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 12 May 2016 17:08:20 +0200 Subject: [PATCH 36/87] fix php parse error --- src/arenas/connectFour/act.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index f7007c8..2be0e44 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -120,7 +120,7 @@ switch ($_POST['act']){ //tester si 4 pions allignés diagonale vers la droite if((!$wins) && ($i < 4) && ($j < 3)){ $wins=true; - for($x = $i+1; $y = $j+1; $x < $i+4 ; $x++; $y++){ + for($x = $i+1, $y = $j+1; $x < $i+4 ; $x++, $y++){ if($_SESSION['map'][$j][$x] <> $you){ $wins=false; break; @@ -130,7 +130,7 @@ switch ($_POST['act']){ //tester si 4 pions allignés diagonale vers la gauche if((!$wins) && ($i > 3) && ($j < 3)){ $wins=true; - for($x = $i-1; $y = $j+1; $x > $i - 4 ; $x++; $y++){ + for($x = $i-1, $y = $j+1; $x > $i - 4 ; $x++, $y++){ if($_SESSION['map'][$j][$x] <> $you){ $wins=false; break; From 73440f63fdd4c19cafdd244bc72da33e6bf17226 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 12 May 2016 19:30:49 +0200 Subject: [PATCH 37/87] test retour js --- src/arenas/connectFour/js.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 0bc5896..b0ed57c 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -17,7 +17,10 @@ function connectFour(bot1,bot2,xd_check){ var xhr = Ajx(); xhr.onreadystatechange = function(){if(xhr.readyState == 4){ if(xhr.status == 200) { - document.getElementById('fightResult').innerHTML = xhr.responseText; + + var reponse = eval(xhr.responseText;); + alert (reponse['continue']); + }else{ alert ('error ' + xhr.status); return; From 4b4f20283aa290793fd66cef26240985b680e024 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 12 May 2016 19:31:49 +0200 Subject: [PATCH 38/87] test retour js --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index b0ed57c..d574c38 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -18,7 +18,7 @@ function connectFour(bot1,bot2,xd_check){ xhr.onreadystatechange = function(){if(xhr.readyState == 4){ if(xhr.status == 200) { - var reponse = eval(xhr.responseText;); + var reponse = eval(xhr.responseText); alert (reponse['continue']); }else{ From 2d0413e5b7592b10776a6c1a150d83b2e50719be Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 12 May 2016 19:33:12 +0200 Subject: [PATCH 39/87] test retour js --- src/arenas/connectFour/js.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index d574c38..0bc5896 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -17,10 +17,7 @@ function connectFour(bot1,bot2,xd_check){ var xhr = Ajx(); xhr.onreadystatechange = function(){if(xhr.readyState == 4){ if(xhr.status == 200) { - - var reponse = eval(xhr.responseText); - alert (reponse['continue']); - + document.getElementById('fightResult').innerHTML = xhr.responseText; }else{ alert ('error ' + xhr.status); return; From 085e89a032a078992fd66554ce69ba0bc23fab31 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 12 May 2016 19:37:18 +0200 Subject: [PATCH 40/87] test retour js --- src/arenas/connectFour/js.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 0bc5896..f0ebcf3 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -17,7 +17,13 @@ function connectFour(bot1,bot2,xd_check){ var xhr = Ajx(); xhr.onreadystatechange = function(){if(xhr.readyState == 4){ if(xhr.status == 200) { - document.getElementById('fightResult').innerHTML = xhr.responseText; + try{ + var reponse = JSON.parse(xhr.responseText); + }catch(e){ + document.getElementById('logs').innerHTML += 'erreur' +xhr.responseText; + return; + } + alert (reponse['continue']); }else{ alert ('error ' + xhr.status); return; From 93a424369b0d9f395e97ee57d285543666f92f7c Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 12 May 2016 19:45:15 +0200 Subject: [PATCH 41/87] draw table --- src/arenas/connectFour/js.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index f0ebcf3..d7faf7d 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -12,8 +12,28 @@ function Ajx(){ } return request; } +function createElem(type,attributes){ + var elem=document.createElement(type); + for (var i in attributes) + {elem.setAttribute(i,attributes[i]);} + return elem; +} function connectFour(bot1,bot2,xd_check){ - document.getElementById('fightResult').innerHTML = '

Please wait...

'; + document.getElementById('fightResult').innerHTML = ''; + //create grid + + var table=createElem('table',{'className':'tabledoc'}); + for (var i=0; i<6; i++){ + var tr=createElem('tr'); + for (var j=0;j<7: j++){ + var td=createElem('td',{'id': 'td' + i + '-' + j}); + tr.appendChild (td); + } + + table.appendChild(tr); + } + document.getElementById('fightResult').appendChild(table); + var xhr = Ajx(); xhr.onreadystatechange = function(){if(xhr.readyState == 4){ if(xhr.status == 200) { @@ -23,7 +43,11 @@ function connectFour(bot1,bot2,xd_check){ document.getElementById('logs').innerHTML += 'erreur' +xhr.responseText; return; } - alert (reponse['continue']); + alert (reponse['continue']); + + + + }else{ alert ('error ' + xhr.status); return; From 0fe79fe8c04d28c7ae155660bde76e5e4be4a518 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 12 May 2016 19:45:49 +0200 Subject: [PATCH 42/87] draw table --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index d7faf7d..f5f0da3 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -25,7 +25,7 @@ function connectFour(bot1,bot2,xd_check){ var table=createElem('table',{'className':'tabledoc'}); for (var i=0; i<6; i++){ var tr=createElem('tr'); - for (var j=0;j<7: j++){ + for (var j=0;j<7; j++){ var td=createElem('td',{'id': 'td' + i + '-' + j}); tr.appendChild (td); } From 5999d87b285b022398f5bc4a5331949bf9eeef95 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 12 May 2016 19:46:33 +0200 Subject: [PATCH 43/87] draw table --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index f5f0da3..02c4f02 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -22,7 +22,7 @@ function connectFour(bot1,bot2,xd_check){ document.getElementById('fightResult').innerHTML = ''; //create grid - var table=createElem('table',{'className':'tabledoc'}); + var table=createElem('table',{'class':'tabledoc'}); for (var i=0; i<6; i++){ var tr=createElem('tr'); for (var j=0;j<7; j++){ From dabb45431009f3db402fdb07460cf94e394f6945 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 12 May 2016 19:49:13 +0200 Subject: [PATCH 44/87] css --- src/arenas/connectFour/js.js | 2 +- src/arenas/connectFour/style.css | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 02c4f02..2501c7b 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -22,7 +22,7 @@ function connectFour(bot1,bot2,xd_check){ document.getElementById('fightResult').innerHTML = ''; //create grid - var table=createElem('table',{'class':'tabledoc'}); + var table=createElem('table',{'class':'battleGrid'}); for (var i=0; i<6; i++){ var tr=createElem('tr'); for (var j=0;j<7; j++){ diff --git a/src/arenas/connectFour/style.css b/src/arenas/connectFour/style.css index 6ef9606..ea33177 100644 --- a/src/arenas/connectFour/style.css +++ b/src/arenas/connectFour/style.css @@ -1,2 +1,7 @@ .tabledoc{border-collapse:collapse;} -.tabledoc tr td,.tabledoc tr th{border: 1px solid green; padding-left: 5px;} \ No newline at end of file +.tabledoc tr td,.tabledoc tr th{border: 1px solid green; padding-left: 5px;} + +.battleGrid{display:table-cell; padding-left:10px; border-collapse:collapse; margin: 20px 20px 20px 20px;} +.nofloat{float: none;} +.battleGrid tr{} +.battleGrid tr td{border: 1px dashed green; text-align: center; font-weight: bold;} \ No newline at end of file From 0b7daa701e508ab5b99b53d3e66db8d713e6cae7 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 12 May 2016 19:51:18 +0200 Subject: [PATCH 45/87] css --- src/arenas/connectFour/style.css | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/arenas/connectFour/style.css b/src/arenas/connectFour/style.css index ea33177..247f3b0 100644 --- a/src/arenas/connectFour/style.css +++ b/src/arenas/connectFour/style.css @@ -2,6 +2,5 @@ .tabledoc tr td,.tabledoc tr th{border: 1px solid green; padding-left: 5px;} .battleGrid{display:table-cell; padding-left:10px; border-collapse:collapse; margin: 20px 20px 20px 20px;} -.nofloat{float: none;} .battleGrid tr{} -.battleGrid tr td{border: 1px dashed green; text-align: center; font-weight: bold;} \ No newline at end of file +.battleGrid tr td{border: 1px dashed green; text-align: center; font-weight: bold;min-width:10px; min-height:10px;} \ No newline at end of file From fcd252297470f214be1541e81cb1710bf0ebe1d4 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 12 May 2016 19:53:06 +0200 Subject: [PATCH 46/87] css --- src/arenas/connectFour/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/style.css b/src/arenas/connectFour/style.css index 247f3b0..8058b46 100644 --- a/src/arenas/connectFour/style.css +++ b/src/arenas/connectFour/style.css @@ -3,4 +3,4 @@ .battleGrid{display:table-cell; padding-left:10px; border-collapse:collapse; margin: 20px 20px 20px 20px;} .battleGrid tr{} -.battleGrid tr td{border: 1px dashed green; text-align: center; font-weight: bold;min-width:10px; min-height:10px;} \ No newline at end of file +.battleGrid tr td{border: 1px dashed green; text-align: center; font-weight: bold;min-width:20px; height:20px;} \ No newline at end of file From fe7905d82c7cfb89812f090413df15df8a69b44f Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 12 May 2016 19:53:51 +0200 Subject: [PATCH 47/87] css --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 2501c7b..2e51274 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -43,7 +43,7 @@ function connectFour(bot1,bot2,xd_check){ document.getElementById('logs').innerHTML += 'erreur' +xhr.responseText; return; } - alert (reponse['continue']); + //alert (reponse['continue']); From 8caa44abab9499dd09a5528d8b14f1ae2b345e68 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 13 May 2016 19:48:41 +0200 Subject: [PATCH 48/87] dont send full map --- src/arenas/connectFour/act.php | 16 +++++++++++----- src/arenas/connectFour/js.js | 8 +++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 2be0e44..73f0a02 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -99,6 +99,8 @@ switch ($_POST['act']){ for($y = 0; $_SESSION['map'][$y][$anwserPlayer] <> ""; $y++){ } $_SESSION['map'][$y][$anwserPlayer]=$you; + $strikeX=$anwserPlayer; + $strikeY=$y; //does he win? for($i=0;$i < 7;$i++){ @@ -145,24 +147,28 @@ switch ($_POST['act']){ if($wins){ $anwserToJS=array( 'continue' => 0, - 'grid' => $_SESSION['map'], + 'strikeX' => $strikeX, + 'strikeY' => $strikeY, + 'strikeSymbol'=> $you, 'log' => $you." ".$currentBotName." a gagné" ); }else{ $anwserToJS=array( 'continue' => 1, - 'grid' => $_SESSION['map'], + 'strikeX' => $strikeX, + 'strikeY' => $strikeY, + 'strikeSymbol'=> $you, 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer ); - - + } }else{ //reponse non conforme $anwserToJS=array( 'continue' =>0, - 'grid' => $_SESSION['map'], + 'strikeX' => -1, + 'strikeY' => -1, 'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd" ); } diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 2e51274..942928d 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -26,7 +26,7 @@ function connectFour(bot1,bot2,xd_check){ for (var i=0; i<6; i++){ var tr=createElem('tr'); for (var j=0;j<7; j++){ - var td=createElem('td',{'id': 'td' + i + '-' + j}); + var td=createElem('td',{'id': 'td' + j + '-' + i}); tr.appendChild (td); } @@ -43,9 +43,11 @@ function connectFour(bot1,bot2,xd_check){ document.getElementById('logs').innerHTML += 'erreur' +xhr.responseText; return; } - //alert (reponse['continue']); - + //fill the grid + if( reponse['strikeX'] > -1){ + document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML=reponse['strikeSymbol']; + } }else{ From 2db615e44e56519bfdf63d91522298dc9e832205 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 13 May 2016 19:50:27 +0200 Subject: [PATCH 49/87] change sense --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 942928d..d456943 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -23,7 +23,7 @@ function connectFour(bot1,bot2,xd_check){ //create grid var table=createElem('table',{'class':'battleGrid'}); - for (var i=0; i<6; i++){ + for (var i=6; i > -1; i--){ var tr=createElem('tr'); for (var j=0;j<7; j++){ var td=createElem('td',{'id': 'td' + j + '-' + i}); From 6b10980a869bb5692305aae845d667deae722f4c Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 22:53:46 +0200 Subject: [PATCH 50/87] loop --- src/arenas/connectFour/js.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index d456943..fe7885b 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -18,7 +18,7 @@ function createElem(type,attributes){ {elem.setAttribute(i,attributes[i]);} return elem; } -function connectFour(bot1,bot2,xd_check){ +function connectFour(bot1,bot2,xd_check, newGame=true){ document.getElementById('fightResult').innerHTML = ''; //create grid @@ -48,6 +48,9 @@ function connectFour(bot1,bot2,xd_check){ if( reponse['strikeX'] > -1){ document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML=reponse['strikeSymbol']; } + if(reponse['continue'] == 1){ + connectFour(bot1,bot2,xd_check, false); + } }else{ @@ -57,5 +60,10 @@ function connectFour(bot1,bot2,xd_check){ }}; xhr.open("POST", '/connectFour', true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + if(newGame){ + var act=newFight; + }else{ + var act=fight; + } xhr.send('act=newFight&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check); } From a1b5a6626f4d18e58f98217f85d164c66db005e3 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 22:59:22 +0200 Subject: [PATCH 51/87] function default parameters in javascript --- src/arenas/connectFour/js.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index fe7885b..5db57ba 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -18,7 +18,10 @@ function createElem(type,attributes){ {elem.setAttribute(i,attributes[i]);} return elem; } -function connectFour(bot1,bot2,xd_check, newGame=true){ +function connectFour(bot1,bot2,xd_check, newGame){ + if (newGame === undefined){ + newGame = true; + } document.getElementById('fightResult').innerHTML = ''; //create grid From b370cf2f9131593ad6f3550e261b6aeaac2708d1 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:00:28 +0200 Subject: [PATCH 52/87] loop --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 5db57ba..b9d6595 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -68,5 +68,5 @@ function connectFour(bot1,bot2,xd_check, newGame){ }else{ var act=fight; } - xhr.send('act=newFight&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check); + xhr.send('act=' + act + '&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check); } From 30d41fa5fab14c04701df1a01d6eba32279bcc29 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:01:51 +0200 Subject: [PATCH 53/87] erf --- src/arenas/connectFour/js.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index b9d6595..0e9d7ce 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -64,9 +64,9 @@ function connectFour(bot1,bot2,xd_check, newGame){ xhr.open("POST", '/connectFour', true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); if(newGame){ - var act=newFight; + var act='newFight'; }else{ - var act=fight; + var act='fight'; } xhr.send('act=' + act + '&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check); } From 535e13392559facaf7de48d4e016787d01cffc51 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:02:58 +0200 Subject: [PATCH 54/87] erf --- src/arenas/connectFour/public.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/public.php b/src/arenas/connectFour/public.php index 3e3dd95..54a584c 100644 --- a/src/arenas/connectFour/public.php +++ b/src/arenas/connectFour/public.php @@ -24,5 +24,5 @@ $bots=get_Bots_Array('connectFou');

-
+
From f73053339abb8e5395b0c455278c284782ff627e Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:07:22 +0200 Subject: [PATCH 55/87] debug --- src/arenas/connectFour/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 73f0a02..b929205 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -133,7 +133,7 @@ switch ($_POST['act']){ if((!$wins) && ($i > 3) && ($j < 3)){ $wins=true; for($x = $i-1, $y = $j+1; $x > $i - 4 ; $x++, $y++){ - if($_SESSION['map'][$j][$x] <> $you){ + if($_SESSION['map'][$y][$x] <> $you){ $wins=false; break; } From 580c084bdf13180e75deb64d35fe800b3af63bea Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:11:32 +0200 Subject: [PATCH 56/87] debug --- src/arenas/connectFour/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index b929205..7392db5 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -130,7 +130,7 @@ switch ($_POST['act']){ } } //tester si 4 pions allignés diagonale vers la gauche - if((!$wins) && ($i > 3) && ($j < 3)){ + if((!$wins) && ($i > 2) && ($j < 2)){ $wins=true; for($x = $i-1, $y = $j+1; $x > $i - 4 ; $x++, $y++){ if($_SESSION['map'][$y][$x] <> $you){ From 7749370b4bac7c1d5480883596cad26b5c488841 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:12:23 +0200 Subject: [PATCH 57/87] debug --- src/arenas/connectFour/js.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 0e9d7ce..cf5d747 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -40,6 +40,9 @@ function connectFour(bot1,bot2,xd_check, newGame){ var xhr = Ajx(); xhr.onreadystatechange = function(){if(xhr.readyState == 4){ if(xhr.status == 200) { + //for debug + alert xhr.responseText; + return; try{ var reponse = JSON.parse(xhr.responseText); }catch(e){ From 637ef5d0891ed40f8c38ab365dd99254b918afc3 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:12:58 +0200 Subject: [PATCH 58/87] debug --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index cf5d747..77a509a 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -41,7 +41,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ xhr.onreadystatechange = function(){if(xhr.readyState == 4){ if(xhr.status == 200) { //for debug - alert xhr.responseText; + alert (xhr.responseText); return; try{ var reponse = JSON.parse(xhr.responseText); From 266f6a7badd5cf94a655bf0c6c068d82f8d15b6e Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:13:47 +0200 Subject: [PATCH 59/87] debug --- src/arenas/connectFour/js.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 77a509a..c270e22 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -42,7 +42,6 @@ function connectFour(bot1,bot2,xd_check, newGame){ if(xhr.status == 200) { //for debug alert (xhr.responseText); - return; try{ var reponse = JSON.parse(xhr.responseText); }catch(e){ From 949d5ac54b360fa66ea6d3f7fa1ea266e29123a4 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:16:02 +0200 Subject: [PATCH 60/87] debug --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index c270e22..3bc27d5 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -41,7 +41,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ xhr.onreadystatechange = function(){if(xhr.readyState == 4){ if(xhr.status == 200) { //for debug - alert (xhr.responseText); + document.getElementById('logs').innerHTML += xhr.responseText + '
'; try{ var reponse = JSON.parse(xhr.responseText); }catch(e){ From 8f9ae20472f4ee478163ca03f83f2f3ffdc32a40 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:19:05 +0200 Subject: [PATCH 61/87] debug --- src/arenas/connectFour/js.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 3bc27d5..d1606bf 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -51,6 +51,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ //fill the grid if( reponse['strikeX'] > -1){ + alert ('polp'); document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML=reponse['strikeSymbol']; } if(reponse['continue'] == 1){ From b50b6c18448232ac2f000bc31db6ffc54fb65e48 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:19:50 +0200 Subject: [PATCH 62/87] debug --- src/arenas/connectFour/js.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index d1606bf..b01fd94 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -50,6 +50,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ } //fill the grid + alert reponse['strikeX']; if( reponse['strikeX'] > -1){ alert ('polp'); document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML=reponse['strikeSymbol']; From 9c0aa879b4763d519a3c5992226ca73af9d13211 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:20:14 +0200 Subject: [PATCH 63/87] debug --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index b01fd94..51c427f 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -50,7 +50,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ } //fill the grid - alert reponse['strikeX']; + alert (reponse['strikeX']); if( reponse['strikeX'] > -1){ alert ('polp'); document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML=reponse['strikeSymbol']; From 4650b3548e6cf32e8e82e24bdcd4bdfff388424c Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:20:51 +0200 Subject: [PATCH 64/87] debug --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 51c427f..c3cb646 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -50,7 +50,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ } //fill the grid - alert (reponse['strikeX']); + if( reponse['strikeX'] > -1){ alert ('polp'); document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML=reponse['strikeSymbol']; From 7cb983d733747679acec6639d6920a6383488fd9 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:21:45 +0200 Subject: [PATCH 65/87] debug --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index c3cb646..f4077a3 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -52,7 +52,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ //fill the grid if( reponse['strikeX'] > -1){ - alert ('polp'); + alert ('td' + reponse['strikeX'] + '-' + reponse['strikeY']); document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML=reponse['strikeSymbol']; } if(reponse['continue'] == 1){ From e095770e733551805435787d08739442a319c41c Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:23:04 +0200 Subject: [PATCH 66/87] debug --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index f4077a3..3d4842f 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -52,7 +52,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ //fill the grid if( reponse['strikeX'] > -1){ - alert ('td' + reponse['strikeX'] + '-' + reponse['strikeY']); + //alert ('td' + reponse['strikeX'] + '-' + reponse['strikeY']); document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML=reponse['strikeSymbol']; } if(reponse['continue'] == 1){ From 862e67e8531d07947e91a6ee3d9762244ad067d6 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:29:19 +0200 Subject: [PATCH 67/87] debug --- src/arenas/connectFour/js.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 3d4842f..e94ee0d 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -53,7 +53,8 @@ function connectFour(bot1,bot2,xd_check, newGame){ if( reponse['strikeX'] > -1){ //alert ('td' + reponse['strikeX'] + '-' + reponse['strikeY']); - document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML=reponse['strikeSymbol']; + //document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML=reponse['strikeSymbol']; + document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML='PROUT'; } if(reponse['continue'] == 1){ connectFour(bot1,bot2,xd_check, false); From c426407b6dcd58d6933c2c84b2163942a5ec7980 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:33:24 +0200 Subject: [PATCH 68/87] debug --- src/arenas/connectFour/js.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index e94ee0d..3d436b0 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -53,8 +53,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ if( reponse['strikeX'] > -1){ //alert ('td' + reponse['strikeX'] + '-' + reponse['strikeY']); - //document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML=reponse['strikeSymbol']; - document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML='PROUT'; + document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML = reponse['strikeSymbol']; } if(reponse['continue'] == 1){ connectFour(bot1,bot2,xd_check, false); From 070ffa013bdde4d1d7c1b1729e05d6d3d63c0df5 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:35:29 +0200 Subject: [PATCH 69/87] debug --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 3d436b0..ee1e706 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -52,7 +52,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ //fill the grid if( reponse['strikeX'] > -1){ - //alert ('td' + reponse['strikeX'] + '-' + reponse['strikeY']); + alert ('td' + reponse['strikeX'] + '-' + reponse['strikeY']); document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML = reponse['strikeSymbol']; } if(reponse['continue'] == 1){ From 879f352d1517b4c484eaaa905ee1015489ac640f Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:36:53 +0200 Subject: [PATCH 70/87] debug --- src/arenas/connectFour/js.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index ee1e706..371d054 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -51,10 +51,10 @@ function connectFour(bot1,bot2,xd_check, newGame){ //fill the grid - if( reponse['strikeX'] > -1){ - alert ('td' + reponse['strikeX'] + '-' + reponse['strikeY']); + //if( reponse['strikeX'] > -1){ + document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML = reponse['strikeSymbol']; - } + //} if(reponse['continue'] == 1){ connectFour(bot1,bot2,xd_check, false); } From 9f1118436a16a95793205b7e9b66e9a0c8862129 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:39:10 +0200 Subject: [PATCH 71/87] debug --- src/arenas/connectFour/js.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 371d054..3508edd 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -51,10 +51,10 @@ function connectFour(bot1,bot2,xd_check, newGame){ //fill the grid - //if( reponse['strikeX'] > -1){ - + if( reponse['strikeX'] > -1){ + alert(reponse['strikeSymbol']); document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML = reponse['strikeSymbol']; - //} + } if(reponse['continue'] == 1){ connectFour(bot1,bot2,xd_check, false); } From d9ba41ed4d85b9e840d4fd3b50366e2a095e9f7b Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:45:16 +0200 Subject: [PATCH 72/87] debug --- src/arenas/connectFour/js.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 3508edd..77591f4 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -22,7 +22,11 @@ function connectFour(bot1,bot2,xd_check, newGame){ if (newGame === undefined){ newGame = true; } - document.getElementById('fightResult').innerHTML = ''; + + //empty + while (document.getElementById('fightResult').firstChild) { + document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); + } //create grid var table=createElem('table',{'class':'battleGrid'}); From e1aa16fa98eabc8c6fbca57510ecbb27ed8f9b27 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:47:15 +0200 Subject: [PATCH 73/87] debug --- src/arenas/connectFour/js.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 77591f4..85157f5 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -56,7 +56,8 @@ function connectFour(bot1,bot2,xd_check, newGame){ //fill the grid if( reponse['strikeX'] > -1){ - alert(reponse['strikeSymbol']); + //alert(reponse['strikeSymbol']); + alert (document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).typeOf); document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML = reponse['strikeSymbol']; } if(reponse['continue'] == 1){ From 8b7933c1e68b2238cdae255dcd9f888b594454bc Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:48:43 +0200 Subject: [PATCH 74/87] debug --- src/arenas/connectFour/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 85157f5..ae68988 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -57,7 +57,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ if( reponse['strikeX'] > -1){ //alert(reponse['strikeSymbol']); - alert (document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).typeOf); + alert ('td' + reponse['strikeX'] + '-' + reponse['strikeY'] + ' ' + document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).typeof); document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML = reponse['strikeSymbol']; } if(reponse['continue'] == 1){ From 9f217eeeb19e7c3594b638380952315ae8fcd705 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:50:56 +0200 Subject: [PATCH 75/87] debug --- src/arenas/connectFour/js.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index ae68988..ef800fe 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -33,7 +33,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ for (var i=6; i > -1; i--){ var tr=createElem('tr'); for (var j=0;j<7; j++){ - var td=createElem('td',{'id': 'td' + j + '-' + i}); + var td=createElem('td',{'id': 'td' + j + '_' + i}); tr.appendChild (td); } @@ -57,8 +57,7 @@ function connectFour(bot1,bot2,xd_check, newGame){ if( reponse['strikeX'] > -1){ //alert(reponse['strikeSymbol']); - alert ('td' + reponse['strikeX'] + '-' + reponse['strikeY'] + ' ' + document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).typeof); - document.getElementById('td' + reponse['strikeX'] + '-' + reponse['strikeY']).innerHTML = reponse['strikeSymbol']; + document.getElementById('td' + reponse['strikeX'] + '_' + reponse['strikeY']).innerHTML = reponse['strikeSymbol']; } if(reponse['continue'] == 1){ connectFour(bot1,bot2,xd_check, false); From e32760329a37e242e0df6b5245f5473945266145 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 14 May 2016 23:53:10 +0200 Subject: [PATCH 76/87] =?UTF-8?q?bon=20ok,=20=C3=A7a=20fait=20une=20heure?= =?UTF-8?q?=20que=20je=20lutte=20=C3=A0=20cause=20de=20cet=20oubli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/arenas/connectFour/js.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index ef800fe..42f81fa 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -23,24 +23,25 @@ function connectFour(bot1,bot2,xd_check, newGame){ newGame = true; } - //empty - while (document.getElementById('fightResult').firstChild) { - document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); + if (newGame){ + //empty + while (document.getElementById('fightResult').firstChild) { + document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); } - //create grid - - var table=createElem('table',{'class':'battleGrid'}); - for (var i=6; i > -1; i--){ - var tr=createElem('tr'); - for (var j=0;j<7; j++){ - var td=createElem('td',{'id': 'td' + j + '_' + i}); - tr.appendChild (td); + //create grid + + var table=createElem('table',{'class':'battleGrid'}); + for (var i=6; i > -1; i--){ + var tr=createElem('tr'); + for (var j=0;j<7; j++){ + var td=createElem('td',{'id': 'td' + j + '_' + i}); + tr.appendChild (td); + } + + table.appendChild(tr); + } + document.getElementById('fightResult').appendChild(table); } - - table.appendChild(tr); - } - document.getElementById('fightResult').appendChild(table); - var xhr = Ajx(); xhr.onreadystatechange = function(){if(xhr.readyState == 4){ if(xhr.status == 200) { From 1f602275ef698d81aa6ee8ed8379f5b0f68a8a95 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 15 May 2016 00:05:31 +0200 Subject: [PATCH 77/87] debug --- src/arenas/connectFour/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 7392db5..ac7297b 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -130,7 +130,7 @@ switch ($_POST['act']){ } } //tester si 4 pions allignés diagonale vers la gauche - if((!$wins) && ($i > 2) && ($j < 2)){ + if((!$wins) && ($i > 2) && ($j < 3)){ $wins=true; for($x = $i-1, $y = $j+1; $x > $i - 4 ; $x++, $y++){ if($_SESSION['map'][$y][$x] <> $you){ From 3d0d969acd0ffe1a410d77832cfd9e7b201aa1be Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 15 May 2016 00:15:51 +0200 Subject: [PATCH 78/87] test vertical --- src/arenas/connectFour/act.php | 12 ++++++++++++ src/arenas/connectFour/js.js | 1 - 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index ac7297b..7207848 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -140,6 +140,18 @@ switch ($_POST['act']){ } } + + //tester si 4 pions allignés vers le haut + if((!$wins) && ($j<3)){ + $wins = true; + for($y = $j+1; $y < $j + 4; $j++){ + if($_SESSION['map'][$y][$i] <> $you){ + $wins=false; + break; + } + } + } + } } } diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 42f81fa..cdf49ea 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -57,7 +57,6 @@ function connectFour(bot1,bot2,xd_check, newGame){ //fill the grid if( reponse['strikeX'] > -1){ - //alert(reponse['strikeSymbol']); document.getElementById('td' + reponse['strikeX'] + '_' + reponse['strikeY']).innerHTML = reponse['strikeSymbol']; } if(reponse['continue'] == 1){ From 107c424c0b5af613ddfec97452328db389da8d2e Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 15 May 2016 00:19:45 +0200 Subject: [PATCH 79/87] oups infinite loop --- src/arenas/connectFour/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 7207848..b3d69ff 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -144,7 +144,7 @@ switch ($_POST['act']){ //tester si 4 pions allignés vers le haut if((!$wins) && ($j<3)){ $wins = true; - for($y = $j+1; $y < $j + 4; $j++){ + for($y = $j+1; $y < $j + 4; $y++){ if($_SESSION['map'][$y][$i] <> $you){ $wins=false; break; From 8c1a5bf8ee74384c465bc5a799db432b05688db9 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 15 May 2016 00:23:45 +0200 Subject: [PATCH 80/87] php --- src/arenas/connectFour/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index b3d69ff..f7aed2d 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -132,7 +132,7 @@ switch ($_POST['act']){ //tester si 4 pions allignés diagonale vers la gauche if((!$wins) && ($i > 2) && ($j < 3)){ $wins=true; - for($x = $i-1, $y = $j+1; $x > $i - 4 ; $x++, $y++){ + for($x = $i-1, $y = $j+1; $x > $i - 3 ; $x++, $y++){ if($_SESSION['map'][$y][$x] <> $you){ $wins=false; break; From 553183b781ba9df10428a1cab72f79199cbe5445 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 15 May 2016 01:01:50 +0200 Subject: [PATCH 81/87] rewrite test --- src/arenas/connectFour/act.php | 138 +++++++++++++++++++++------------ 1 file changed, 87 insertions(+), 51 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index f7aed2d..28c352b 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -103,59 +103,95 @@ switch ($_POST['act']){ $strikeY=$y; //does he win? - for($i=0;$i < 7;$i++){ - for($j=0;$j < 6;$j++){ - if($_SESSION['map'][$j][$i]== $you){ - - $wins=false; - //tester si 4 pions allignés vers la droite - if($i<4){ - $wins=true; - for($x = $i+1; $x < $i+4; $x++){ - if($_SESSION['map'][$j][$x] <> $you){ - $wins=false; - break; - } - } - } - - //tester si 4 pions allignés diagonale vers la droite - if((!$wins) && ($i < 4) && ($j < 3)){ - $wins=true; - for($x = $i+1, $y = $j+1; $x < $i+4 ; $x++, $y++){ - if($_SESSION['map'][$j][$x] <> $you){ - $wins=false; - break; - } - } - } - //tester si 4 pions allignés diagonale vers la gauche - if((!$wins) && ($i > 2) && ($j < 3)){ - $wins=true; - for($x = $i-1, $y = $j+1; $x > $i - 3 ; $x++, $y++){ - if($_SESSION['map'][$y][$x] <> $you){ - $wins=false; - break; - } - } - - } - - //tester si 4 pions allignés vers le haut - if((!$wins) && ($j<3)){ - $wins = true; - for($y = $j+1; $y < $j + 4; $y++){ - if($_SESSION['map'][$y][$i] <> $you){ - $wins=false; - break; - } - } - } - - } - } + $wins=false; + + //diagonale \ + $count=1; + $x=$strikeX; + $y=$strikeY; + while(($x > 0) && ($y < 5) && ($_SESSION['map'][$y + 1][$x - 1] == $you)){ + $x--; + $y++; + $count++; + } + + $x=$strikeX; + $y=$strikeY; + while(($x < 6) && ($y > 0) && ($_SESSION['map'][$y - 1][$x + 1] == $you)){ + $x++; + $y--; + $count++; } + if($count>3){ + $wins=true; + } + + //diagonale / + if(!$wins){ + $count=1; + $x=$strikeX; + $y=$strikeY; + + while(($x < 6) && ($y < 5) && ($_SESSION['map'][$y + 1][$x + 1 ] == $you)){ + $x++; + $y++; + $count++; + } + $x=$strikeX; + $y=$strikeY; + while(($x > 0) && ($y > 0) && ($_SESSION['map'][$y - 1][$x - 1 ] == $you)){ + $x--; + $y--; + $count++; + } + if($count>3){ + $wins=true; + } + } + + + //horizontale + if(!$wins){ + $count=1; + $x=$strikeX; + $y=$strikeY; + while(($x < 6) && ($_SESSION['map'][$y][$x + 1 ] == $you)){ + $x++; + $count++; + } + + $x=$strikeX; + while(($x >0) && ($_SESSION['map'][$y][$x - 1 ] == $you)){ + $count++; + $x--; + } + if($count>3){ + $wins=true; + } + } + + //verticale + if(!$wins){ + $count=1; + $x=$strikeX; + $y=$strikeY; + while(($y < 5) && ($_SESSION['map'][$y + 1 ][$x] == $you)){ + $y++; + $count++; + } + + $y=$strikeY; + while(($y >0) && ($_SESSION['map'][$y - 1][$x] == $you)){ + $count++; + $y--; + } + if($count>3){ + $wins=true; + } + } + + if($wins){ $anwserToJS=array( 'continue' => 0, From dfcaed4bebaf59fe6521aeb499b91f5e01b4b5cd Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 15 May 2016 14:31:50 +0200 Subject: [PATCH 82/87] clean code --- src/arenas/connectFour/act.php | 2 +- src/arenas/connectFour/js.js | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 28c352b..95d50e1 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -198,7 +198,7 @@ switch ($_POST['act']){ 'strikeX' => $strikeX, 'strikeY' => $strikeY, 'strikeSymbol'=> $you, - 'log' => $you." ".$currentBotName." a gagné" + 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer"et a gagné" ); }else{ $anwserToJS=array( diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index cdf49ea..75f5065 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -29,7 +29,6 @@ function connectFour(bot1,bot2,xd_check, newGame){ document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); } //create grid - var table=createElem('table',{'class':'battleGrid'}); for (var i=6; i > -1; i--){ var tr=createElem('tr'); @@ -42,28 +41,27 @@ function connectFour(bot1,bot2,xd_check, newGame){ } document.getElementById('fightResult').appendChild(table); } + //send request var xhr = Ajx(); xhr.onreadystatechange = function(){if(xhr.readyState == 4){ - if(xhr.status == 200) { - //for debug - document.getElementById('logs').innerHTML += xhr.responseText + '
'; + if(xhr.status == 200) { try{ var reponse = JSON.parse(xhr.responseText); }catch(e){ document.getElementById('logs').innerHTML += 'erreur' +xhr.responseText; return; - } - + } + //log + document.getElementById('logs').innerHTML += reponse['log'] + '
'; //fill the grid - if( reponse['strikeX'] > -1){ document.getElementById('td' + reponse['strikeX'] + '_' + reponse['strikeY']).innerHTML = reponse['strikeSymbol']; } + + //if game isn't finished, continue if(reponse['continue'] == 1){ connectFour(bot1,bot2,xd_check, false); } - - }else{ alert ('error ' + xhr.status); return; From 520a7f9c27f05fa154848fa7071a5311d31c61be Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 15 May 2016 14:32:55 +0200 Subject: [PATCH 83/87] fix php parse error --- src/arenas/connectFour/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 95d50e1..4162552 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -198,7 +198,7 @@ switch ($_POST['act']){ 'strikeX' => $strikeX, 'strikeY' => $strikeY, 'strikeSymbol'=> $you, - 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer"et a gagné" + 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer." et a gagné" ); }else{ $anwserToJS=array( From f5a9281d78c82058cadca909d39ec5262815b6d7 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 15 May 2016 14:38:49 +0200 Subject: [PATCH 84/87] scores --- src/arenas/connectFour/act.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 4162552..0f95d45 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -200,6 +200,12 @@ switch ($_POST['act']){ 'strikeSymbol'=> $you, 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer." et a gagné" ); + if($_SESSION['currentPlayer']==1){ + save_battle('connectFou',$bot1['name'],$bot2['name'],1); + }else{ + save_battle('connectFou',$bot1['name'],$bot2['name'],2); + } + }else{ $anwserToJS=array( 'continue' => 1, @@ -219,6 +225,11 @@ switch ($_POST['act']){ 'strikeY' => -1, 'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd" ); + if($_SESSION['currentPlayer']==1){ + save_battle('connectFou',$bot1['name'],$bot2['name'],2); + }else{ + save_battle('connectFou',$bot1['name'],$bot2['name'],1); + } } echo json_encode($anwserToJS); From 4827a2f4dce1d70a03c77c27f1c62841f2494037 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 15 May 2016 14:41:51 +0200 Subject: [PATCH 85/87] scores --- src/arenas/connectFour/act.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 0f95d45..968ad5d 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -201,9 +201,9 @@ switch ($_POST['act']){ 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer." et a gagné" ); if($_SESSION['currentPlayer']==1){ - save_battle('connectFou',$bot1['name'],$bot2['name'],1); + save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],1); }else{ - save_battle('connectFou',$bot1['name'],$bot2['name'],2); + save_battle('connectFou',$_SESSION['bot1'],$_SESSION['bot2']['name'],2); } }else{ @@ -226,9 +226,9 @@ switch ($_POST['act']){ 'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd" ); if($_SESSION['currentPlayer']==1){ - save_battle('connectFou',$bot1['name'],$bot2['name'],2); + save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],2); }else{ - save_battle('connectFou',$bot1['name'],$bot2['name'],1); + save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],1); } } From 4a76e141d148a7e0875f3b2bdf3af321fb3f0007 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 15 May 2016 14:43:18 +0200 Subject: [PATCH 86/87] fix php parse error --- src/arenas/connectFour/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index 968ad5d..badd5e1 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -203,7 +203,7 @@ switch ($_POST['act']){ if($_SESSION['currentPlayer']==1){ save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],1); }else{ - save_battle('connectFou',$_SESSION['bot1'],$_SESSION['bot2']['name'],2); + save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],2); } }else{ From 16e77e03dacad7d4877304004734a5637b9e1ad3 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sun, 15 May 2016 14:48:46 +0200 Subject: [PATCH 87/87] css --- src/arenas/connectFour/js.js | 2 ++ src/arenas/connectFour/public.php | 3 +-- src/arenas/connectFour/style.css | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 75f5065..58e6939 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -40,6 +40,8 @@ function connectFour(bot1,bot2,xd_check, newGame){ table.appendChild(tr); } document.getElementById('fightResult').appendChild(table); + var divLogs=createElem("div",{"id":"logs"}); + document.getElementById('fightResult').appendChild(divLogs); } //send request var xhr = Ajx(); diff --git a/src/arenas/connectFour/public.php b/src/arenas/connectFour/public.php index 54a584c..9cfbe7e 100644 --- a/src/arenas/connectFour/public.php +++ b/src/arenas/connectFour/public.php @@ -24,5 +24,4 @@ $bots=get_Bots_Array('connectFou');

-
-
+
diff --git a/src/arenas/connectFour/style.css b/src/arenas/connectFour/style.css index 8058b46..7017dda 100644 --- a/src/arenas/connectFour/style.css +++ b/src/arenas/connectFour/style.css @@ -1,6 +1,7 @@ .tabledoc{border-collapse:collapse;} .tabledoc tr td,.tabledoc tr th{border: 1px solid green; padding-left: 5px;} - +#fightResult{display:table;} +#logs{display:block;padding-left:10px; height: 200px; overflow-y: scroll;} .battleGrid{display:table-cell; padding-left:10px; border-collapse:collapse; margin: 20px 20px 20px 20px;} .battleGrid tr{} .battleGrid tr td{border: 1px dashed green; text-align: center; font-weight: bold;min-width:20px; height:20px;} \ No newline at end of file