From 365dd04be5117435939788ec02c5821cb0d6b359 Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 29 Jun 2016 00:14:16 +0200 Subject: [PATCH 001/126] tron --- src/PHPMailer | 2 +- src/arenas/tron/act.php | 0 src/arenas/tron/doc-en.html | 0 src/arenas/tron/doc-fr.html | 0 src/arenas/tron/functions.php | 0 src/arenas/tron/js.js | 0 src/arenas/tron/public.php | 0 src/arenas_lists.php | 8 ++++++++ 8 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 src/arenas/tron/act.php create mode 100644 src/arenas/tron/doc-en.html create mode 100644 src/arenas/tron/doc-fr.html create mode 100644 src/arenas/tron/functions.php create mode 100644 src/arenas/tron/js.js create mode 100644 src/arenas/tron/public.php diff --git a/src/PHPMailer b/src/PHPMailer index 7c8b786..1d85f9e 160000 --- a/src/PHPMailer +++ b/src/PHPMailer @@ -1 +1 @@ -Subproject commit 7c8b786228bb9e1561ff60a2d6f7f6ce91be6fee +Subproject commit 1d85f9ef3ecfc42bbc4f3c70d5e37ca9a65f629a diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php new file mode 100644 index 0000000..e69de29 diff --git a/src/arenas/tron/doc-en.html b/src/arenas/tron/doc-en.html new file mode 100644 index 0000000..e69de29 diff --git a/src/arenas/tron/doc-fr.html b/src/arenas/tron/doc-fr.html new file mode 100644 index 0000000..e69de29 diff --git a/src/arenas/tron/functions.php b/src/arenas/tron/functions.php new file mode 100644 index 0000000..e69de29 diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js new file mode 100644 index 0000000..e69de29 diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php new file mode 100644 index 0000000..e69de29 diff --git a/src/arenas_lists.php b/src/arenas_lists.php index 2e990a9..cea47f7 100644 --- a/src/arenas_lists.php +++ b/src/arenas_lists.php @@ -36,6 +36,14 @@ $arenas=array( 'jsFile'=> "js.js", 'cssFile'=> "style.css", 'ludusUrl' => "/testBotScripts/connectfour.html" + ), + array( + 'id' => "tron", + 'url' => "/tron", + 'title' => "Tron", + 'metaDescription' => 'Affrontements de bots à Tron', + 'jsFile'=> "js.js", + 'cssFile'=> "style.css" ) ); \ No newline at end of file From 76e8827b7ce8a90d8b9b7436f969991910a9e987 Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 29 Jun 2016 00:18:33 +0200 Subject: [PATCH 002/126] tron --- src/arenas/tron/style.css | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/arenas/tron/style.css diff --git a/src/arenas/tron/style.css b/src/arenas/tron/style.css new file mode 100644 index 0000000..e69de29 From a72306a568aa708ab02fc4771e047e3d41f542d2 Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 29 Jun 2016 00:30:52 +0200 Subject: [PATCH 003/126] tron --- src/arenas/connectFour/public.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/connectFour/public.php b/src/arenas/connectFour/public.php index df044e4..31beac5 100644 --- a/src/arenas/connectFour/public.php +++ b/src/arenas/connectFour/public.php @@ -11,7 +11,7 @@ # -- END LICENSE BLOCK ----------------------------------------- require_once(__DIR__."/functions.php"); -$bots=get_Bots_Array('connectFou'); +$bots=get_Bots_Array('tron'); ?>

@@ -33,6 +33,6 @@ $bots=get_Bots_Array('connectFou');

-

+

\ No newline at end of file From 638166aef64275143366db98e873d9db83b7bd49 Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 29 Jun 2016 00:31:58 +0200 Subject: [PATCH 004/126] tron --- src/arenas/connectFour/public.php | 4 ++-- src/arenas/tron/public.php | 38 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/arenas/connectFour/public.php b/src/arenas/connectFour/public.php index 31beac5..df044e4 100644 --- a/src/arenas/connectFour/public.php +++ b/src/arenas/connectFour/public.php @@ -11,7 +11,7 @@ # -- END LICENSE BLOCK ----------------------------------------- require_once(__DIR__."/functions.php"); -$bots=get_Bots_Array('tron'); +$bots=get_Bots_Array('connectFou'); ?>

@@ -33,6 +33,6 @@ $bots=get_Bots_Array('tron');

-

+

\ No newline at end of file diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index e69de29..31beac5 100644 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -0,0 +1,38 @@ + +
+

+

+ +  VS  + +

+

+

+
+
\ No newline at end of file From 70e82d1cab74cb57626d747bf7656c8e4e64b9d9 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 09:30:21 +0200 Subject: [PATCH 005/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index e69de29..44ded07 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -0,0 +1,58 @@ +document.createSvg = function(tagName) { + var svgNS = "http://www.w3.org/2000/svg"; + return this.createElementNS(svgNS, tagName); +}; + +var grid = function(numberPerSide, size, pixelsPerSide, colors) { + var svg = document.createSvg("svg"); + svg.setAttribute("width", pixelsPerSide); + svg.setAttribute("height", pixelsPerSide); + svg.setAttribute("viewBox", [0, 0, numberPerSide * size, numberPerSide * size].join(" ")); + + for(var i = 0; i < numberPerSide; i++) { + for(var j = 0; j < numberPerSide; j++) { + var color1 = colors[(i+j) % colors.length]; + var color2 = colors[(i+j+1) % colors.length]; + var g = document.createSvg("g"); + g.setAttribute("transform", ["translate(", i*size, ",", j*size, ")"].join("")); + var number = numberPerSide * i + j; + var box = document.createSvg("rect"); + box.setAttribute("width", size); + box.setAttribute("height", size); + box.setAttribute("fill", color1); + box.setAttribute("id", "b" + number); + g.appendChild(box); + var text = document.createSvg("text"); + text.appendChild(document.createTextNode(i * numberPerSide + j)); + text.setAttribute("fill", color2); + text.setAttribute("font-size", 6); + text.setAttribute("x", 0); + text.setAttribute("y", size/2); + text.setAttribute("id", "t" + number); + g.appendChild(text); + svg.appendChild(g); + } + } + svg.addEventListener( + "click", + function(e){ + var id = e.target.id; + if(id) + alert(id.substring(1)); + }, + false); + return svg; +}; + + + +function tron(bot1,bot2,xdcheck){ + //empty + while (document.getElementById('fightResult').firstChild) { + document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); + } + document.getElementById('fightResult').appendChild(grid(1000,10,40,["red", "white"])); + + + +} \ No newline at end of file From dc14625e60553c12087b8681081df9a96eaa51ed Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 10:40:08 +0200 Subject: [PATCH 006/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 46 +------------------------------------------ 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 44ded07..24dea3c 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -1,48 +1,4 @@ -document.createSvg = function(tagName) { - var svgNS = "http://www.w3.org/2000/svg"; - return this.createElementNS(svgNS, tagName); -}; -var grid = function(numberPerSide, size, pixelsPerSide, colors) { - var svg = document.createSvg("svg"); - svg.setAttribute("width", pixelsPerSide); - svg.setAttribute("height", pixelsPerSide); - svg.setAttribute("viewBox", [0, 0, numberPerSide * size, numberPerSide * size].join(" ")); - - for(var i = 0; i < numberPerSide; i++) { - for(var j = 0; j < numberPerSide; j++) { - var color1 = colors[(i+j) % colors.length]; - var color2 = colors[(i+j+1) % colors.length]; - var g = document.createSvg("g"); - g.setAttribute("transform", ["translate(", i*size, ",", j*size, ")"].join("")); - var number = numberPerSide * i + j; - var box = document.createSvg("rect"); - box.setAttribute("width", size); - box.setAttribute("height", size); - box.setAttribute("fill", color1); - box.setAttribute("id", "b" + number); - g.appendChild(box); - var text = document.createSvg("text"); - text.appendChild(document.createTextNode(i * numberPerSide + j)); - text.setAttribute("fill", color2); - text.setAttribute("font-size", 6); - text.setAttribute("x", 0); - text.setAttribute("y", size/2); - text.setAttribute("id", "t" + number); - g.appendChild(text); - svg.appendChild(g); - } - } - svg.addEventListener( - "click", - function(e){ - var id = e.target.id; - if(id) - alert(id.substring(1)); - }, - false); - return svg; -}; @@ -55,4 +11,4 @@ function tron(bot1,bot2,xdcheck){ -} \ No newline at end of file +} From 7a2cb96bb5c8fa8905e2902d7ae9d4d8da9fa5da Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 10:42:14 +0200 Subject: [PATCH 007/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 24dea3c..b30ec6d 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -7,8 +7,17 @@ function tron(bot1,bot2,xdcheck){ while (document.getElementById('fightResult').firstChild) { document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); } - document.getElementById('fightResult').appendChild(grid(1000,10,40,["red", "white"])); + - + // "circle" may be any tag name + var shape = document.createElementNS("http://www.w3.org/2000/svg", "circle"); + // Set any attributes as desired + shape.setAttribute("cx", 25); + shape.setAttribute("cy", 25); + shape.setAttribute("r", 20); + shape.setAttribute("fill", "green"); + // Add to a parent node; document.documentElement should be the root svg element. + // Acquiring a parent element with document.getElementById() would be safest. + document.getElementById('fightResult').appendChild(shape); } From 0a559d9f883c2c5f3d082e0c7ffd7a867a480d29 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 10:44:08 +0200 Subject: [PATCH 008/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index b30ec6d..1353172 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -8,7 +8,7 @@ function tron(bot1,bot2,xdcheck){ document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); } - +alert("plop"); // "circle" may be any tag name var shape = document.createElementNS("http://www.w3.org/2000/svg", "circle"); // Set any attributes as desired From 762ad54f1b1593fa6342e492e6061f9dde06e4a7 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 11:35:10 +0200 Subject: [PATCH 009/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 1353172..60a2cda 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -1,4 +1,9 @@ - +function createElem(type,attributes){ + var elem=document.createElement(type); + for (var i in attributes) + {elem.setAttribute(i,attributes[i]);} + return elem; +} @@ -7,6 +12,9 @@ function tron(bot1,bot2,xdcheck){ while (document.getElementById('fightResult').firstChild) { document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); } + + var mapImg = createElem('svg',{'alt' : 'map'}); + alert("plop"); // "circle" may be any tag name @@ -18,6 +26,7 @@ alert("plop"); shape.setAttribute("fill", "green"); // Add to a parent node; document.documentElement should be the root svg element. // Acquiring a parent element with document.getElementById() would be safest. - document.getElementById('fightResult').appendChild(shape); + mapImg.appendChild(shape); + document.getElementById('fightResult').appendChild(mapImg); } From deb0f289734cda0a59fb005af76742532c3d1b5f Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 11:36:50 +0200 Subject: [PATCH 010/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 60a2cda..060fa27 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -13,10 +13,7 @@ function tron(bot1,bot2,xdcheck){ document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); } - var mapImg = createElem('svg',{'alt' : 'map'}); - - -alert("plop"); + var mapImg = createElem('svg',{'alt' : 'map','width':'200','height':'200'}); // "circle" may be any tag name var shape = document.createElementNS("http://www.w3.org/2000/svg", "circle"); // Set any attributes as desired From dbe245db5b0ea9e2b6b4c3637ec6b560bdc02652 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 11:42:18 +0200 Subject: [PATCH 011/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 060fa27..d691dac 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -15,15 +15,8 @@ function tron(bot1,bot2,xdcheck){ var mapImg = createElem('svg',{'alt' : 'map','width':'200','height':'200'}); // "circle" may be any tag name - var shape = document.createElementNS("http://www.w3.org/2000/svg", "circle"); - // Set any attributes as desired - shape.setAttribute("cx", 25); - shape.setAttribute("cy", 25); - shape.setAttribute("r", 20); - shape.setAttribute("fill", "green"); - // Add to a parent node; document.documentElement should be the root svg element. - // Acquiring a parent element with document.getElementById() would be safest. - mapImg.appendChild(shape); + mapImg.innerHTML = ''; + document.getElementById('fightResult').appendChild(mapImg); } From e38534f89c3fb10f77bee3efbfb6663847904619 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 11:46:10 +0200 Subject: [PATCH 012/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 6 ++---- src/arenas/tron/public.php | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index d691dac..349dcd5 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -9,14 +9,12 @@ function createElem(type,attributes){ function tron(bot1,bot2,xdcheck){ //empty - while (document.getElementById('fightResult').firstChild) { - document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); - } + var mapImg = createElem('svg',{'alt' : 'map','width':'200','height':'200'}); // "circle" may be any tag name mapImg.innerHTML = ''; - document.getElementById('fightResult').appendChild(mapImg); + document.getElementById('mainArticle').appendChild(mapImg); } diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index 31beac5..b50ddb6 100644 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -13,7 +13,7 @@ require_once(__DIR__."/functions.php"); $bots=get_Bots_Array('tron'); ?> -
+

-
+
\ No newline at end of file From f34ce0722615758b1d092311a39144b3d5d86fad Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 11:48:12 +0200 Subject: [PATCH 013/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 349dcd5..5f88a7a 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -13,8 +13,7 @@ function tron(bot1,bot2,xdcheck){ var mapImg = createElem('svg',{'alt' : 'map','width':'200','height':'200'}); // "circle" may be any tag name - mapImg.innerHTML = ''; - + mapImg.innerHTML = ' '; document.getElementById('mainArticle').appendChild(mapImg); } From 0577612b2dd301f8e4ea946ff56665744423cea1 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 11:52:08 +0200 Subject: [PATCH 014/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 5f88a7a..e411bdd 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -8,10 +8,7 @@ function createElem(type,attributes){ function tron(bot1,bot2,xdcheck){ - //empty - - - var mapImg = createElem('svg',{'alt' : 'map','width':'200','height':'200'}); + var mapImg = createElem('svg',{'alt' : 'map','width':'200px','height':'200px','xmlns':'http://www.w3.org/2000/svg'}); // "circle" may be any tag name mapImg.innerHTML = ' '; document.getElementById('mainArticle').appendChild(mapImg); From b6c95f797974041d662fcaab5a9faa3d69139df0 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 11:59:47 +0200 Subject: [PATCH 015/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index e411bdd..847dd67 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -8,7 +8,7 @@ function createElem(type,attributes){ function tron(bot1,bot2,xdcheck){ - var mapImg = createElem('svg',{'alt' : 'map','width':'200px','height':'200px','xmlns':'http://www.w3.org/2000/svg'}); + var mapImg = createElem('svg',{'alt' : 'map','width':'200','height':'200','xmlns':'http://www.w3.org/2000/svg','viewBox':'0 0 20 20'}); // "circle" may be any tag name mapImg.innerHTML = ' '; document.getElementById('mainArticle').appendChild(mapImg); From 289e1eac2d836bf8b22ea7568c7a23eb2efade45 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 12:04:49 +0200 Subject: [PATCH 016/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- src/arenas/tron/public.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 847dd67..dd03c32 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -8,7 +8,7 @@ function createElem(type,attributes){ function tron(bot1,bot2,xdcheck){ - var mapImg = createElem('svg',{'alt' : 'map','width':'200','height':'200','xmlns':'http://www.w3.org/2000/svg','viewBox':'0 0 20 20'}); + var mapImg = createElem('svg',{'version':'1.1','alt' : 'map','width':'200','height':'200','xmlns':'http://www.w3.org/2000/svg','viewBox':'0 0 20 20'}); // "circle" may be any tag name mapImg.innerHTML = ' '; document.getElementById('mainArticle').appendChild(mapImg); diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index b50ddb6..02ea46c 100644 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -34,5 +34,7 @@ $bots=get_Bots_Array('tron');

- + + +
\ No newline at end of file From 4c628de03a8d345a3e786c406b61e81f73a3811e Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 12:09:02 +0200 Subject: [PATCH 017/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 10 ++++++---- src/arenas/tron/public.php | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index dd03c32..11596b6 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -8,9 +8,11 @@ function createElem(type,attributes){ function tron(bot1,bot2,xdcheck){ - var mapImg = createElem('svg',{'version':'1.1','alt' : 'map','width':'200','height':'200','xmlns':'http://www.w3.org/2000/svg','viewBox':'0 0 20 20'}); - // "circle" may be any tag name - mapImg.innerHTML = ' '; - document.getElementById('mainArticle').appendChild(mapImg); + + var mapImg = document.getElementById("map"); + + var rect=createElem('rect',{'x':'10','y':'10','width':'50','height':'80','style':'stroke:#000000; fill:none;'}); + + mapImg.appendChild(rect); } diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index 02ea46c..1ceb7ca 100644 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -34,7 +34,7 @@ $bots=get_Bots_Array('tron');

- - - + + + \ No newline at end of file From b219848f504eebd11015032b1ea3f77ef399a656 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 12:14:01 +0200 Subject: [PATCH 018/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 11596b6..ae9e2f8 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -4,15 +4,20 @@ function createElem(type,attributes){ {elem.setAttribute(i,attributes[i]);} return elem; } - +function createElemNs(type,attributes){ + var elem=document.createElement(type); + for (var i in attributes) + {elem.setAttributeNs(i,attributes[i]);} + return elem; +} function tron(bot1,bot2,xdcheck){ - var mapImg = document.getElementById("map"); - - var rect=createElem('rect',{'x':'10','y':'10','width':'50','height':'80','style':'stroke:#000000; fill:none;'}); + var svg = document.getElementById("map"); + var svgDoc = svg.contentDocument; + var rect=createElemNs('rect',{'x':'10','y':'10','width':'50','height':'80','style':'stroke:#000000; fill:none;'}); - mapImg.appendChild(rect); + svgDoc.appendChild(rect); } From a7542125de1384555762faf47431a7204415c9b0 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 12:15:45 +0200 Subject: [PATCH 019/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index ae9e2f8..fbf85c7 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -7,7 +7,7 @@ function createElem(type,attributes){ function createElemNs(type,attributes){ var elem=document.createElement(type); for (var i in attributes) - {elem.setAttributeNs(i,attributes[i]);} + {elem.setAttributeNs(null,i,attributes[i]);} return elem; } From f186b5ebe6a146bdfa5c3557a1aca2013fb3b22c Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 12:20:16 +0200 Subject: [PATCH 020/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index fbf85c7..0673607 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -5,7 +5,7 @@ function createElem(type,attributes){ return elem; } function createElemNs(type,attributes){ - var elem=document.createElement(type); + var elem=document.createElementNS("http://www.w3.org/2000/svg",type); for (var i in attributes) {elem.setAttributeNs(null,i,attributes[i]);} return elem; From b81e5f36d41ed4a081def71fa977ab93f5d60267 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 12:21:11 +0200 Subject: [PATCH 021/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 0673607..f2bc05f 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -7,7 +7,7 @@ function createElem(type,attributes){ function createElemNs(type,attributes){ var elem=document.createElementNS("http://www.w3.org/2000/svg",type); for (var i in attributes) - {elem.setAttributeNs(null,i,attributes[i]);} + {elem.setAttribute(i,attributes[i]);} return elem; } From 02dc6a18c69b388b39e4becc7540ac44f6d818c8 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 12:25:05 +0200 Subject: [PATCH 022/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index f2bc05f..a9c0220 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -7,17 +7,16 @@ function createElem(type,attributes){ function createElemNs(type,attributes){ var elem=document.createElementNS("http://www.w3.org/2000/svg",type); for (var i in attributes) - {elem.setAttribute(i,attributes[i]);} + {elem.setAttributeNs(null,i,attributes[i]);} return elem; } function tron(bot1,bot2,xdcheck){ - var svg = document.getElementById("map"); - var svgDoc = svg.contentDocument; + //var svgDoc = svg.contentDocument; var rect=createElemNs('rect',{'x':'10','y':'10','width':'50','height':'80','style':'stroke:#000000; fill:none;'}); - svgDoc.appendChild(rect); + document.getElementById("map").appendChild(rect); } From 50f1686af25fcf68abbd7b40244d3460cdde0300 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 12:26:03 +0200 Subject: [PATCH 023/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index a9c0220..24cf07d 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -4,10 +4,10 @@ function createElem(type,attributes){ {elem.setAttribute(i,attributes[i]);} return elem; } -function createElemNs(type,attributes){ +function createElemNS(type,attributes){ var elem=document.createElementNS("http://www.w3.org/2000/svg",type); for (var i in attributes) - {elem.setAttributeNs(null,i,attributes[i]);} + {elem.setAttributeNS(null,i,attributes[i]);} return elem; } @@ -15,7 +15,7 @@ function createElemNs(type,attributes){ function tron(bot1,bot2,xdcheck){ //var svgDoc = svg.contentDocument; - var rect=createElemNs('rect',{'x':'10','y':'10','width':'50','height':'80','style':'stroke:#000000; fill:none;'}); + var rect=createElemNS('rect',{'x':'10','y':'10','width':'50','height':'80','style':'stroke:#000000; fill:none;'}); document.getElementById("map").appendChild(rect); From 64f9faf277fcda47ef04084b6b304da5268c231d Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 12:55:45 +0200 Subject: [PATCH 024/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 14 +++++++++----- src/arenas/tron/public.php | 5 ++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 24cf07d..489740b 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -13,10 +13,14 @@ function createElemNS(type,attributes){ function tron(bot1,bot2,xdcheck){ + //empty + while (document.getElementById('fightResult').firstChild) { + document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); + } + // draw border; + var svg = createElem('svg',{'id':'map','width':'1000','height':'1000'}); + var rect=createElemNS('rect',{'x':'0','y':'0','width':'1000','height':'1000','style':'stroke:#000000; fill:none;'}); + svg.appendChild(rect); - //var svgDoc = svg.contentDocument; - var rect=createElemNS('rect',{'x':'10','y':'10','width':'50','height':'80','style':'stroke:#000000; fill:none;'}); - - document.getElementById("map").appendChild(rect); - + document.getElementById("fightResult").appendChild(svg); } diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index 1ceb7ca..e6f3618 100644 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -34,7 +34,6 @@ $bots=get_Bots_Array('tron');

- - - +
+ \ No newline at end of file From b844b80af1baf78546054c3b41c1676ecae81f99 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 12:56:59 +0200 Subject: [PATCH 025/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 489740b..d0292b7 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -18,7 +18,7 @@ function tron(bot1,bot2,xdcheck){ document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); } // draw border; - var svg = createElem('svg',{'id':'map','width':'1000','height':'1000'}); + var svg = createElementNS('svg',{'id':'map','width':'1000','height':'1000'}); var rect=createElemNS('rect',{'x':'0','y':'0','width':'1000','height':'1000','style':'stroke:#000000; fill:none;'}); svg.appendChild(rect); From 23a7da69a9fa83dac70198ae10bea0afc3a980e4 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 12:57:48 +0200 Subject: [PATCH 026/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index d0292b7..51b29d0 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -18,7 +18,7 @@ function tron(bot1,bot2,xdcheck){ document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); } // draw border; - var svg = createElementNS('svg',{'id':'map','width':'1000','height':'1000'}); + var svg = createElemNS('svg',{'id':'map','width':'1000','height':'1000'}); var rect=createElemNS('rect',{'x':'0','y':'0','width':'1000','height':'1000','style':'stroke:#000000; fill:none;'}); svg.appendChild(rect); From 63e96d265ca541a20acf948b0142ad9fe4ebf002 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 13:03:20 +0200 Subject: [PATCH 027/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 51b29d0..8df1004 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -18,7 +18,7 @@ function tron(bot1,bot2,xdcheck){ document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); } // draw border; - var svg = createElemNS('svg',{'id':'map','width':'1000','height':'1000'}); + var svg = createElemNS('svg',{'id':'map','width':'200','height':'200','viewBox':'0 0 1000 1000"}); var rect=createElemNS('rect',{'x':'0','y':'0','width':'1000','height':'1000','style':'stroke:#000000; fill:none;'}); svg.appendChild(rect); From ab64f3625f5c17cd27776423714b40236a2bb728 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 13:04:03 +0200 Subject: [PATCH 028/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 8df1004..2e6414e 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -18,7 +18,7 @@ function tron(bot1,bot2,xdcheck){ document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); } // draw border; - var svg = createElemNS('svg',{'id':'map','width':'200','height':'200','viewBox':'0 0 1000 1000"}); + var svg = createElemNS('svg',{'id':'map','width':'200','height':'200','viewBox':'0 0 1000 1000'}); var rect=createElemNS('rect',{'x':'0','y':'0','width':'1000','height':'1000','style':'stroke:#000000; fill:none;'}); svg.appendChild(rect); From 54fdebc9b15951d64b42a9ae2e859c80f85d1145 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 13:04:30 +0200 Subject: [PATCH 029/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 2e6414e..d41a3a6 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -18,7 +18,7 @@ function tron(bot1,bot2,xdcheck){ document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); } // draw border; - var svg = createElemNS('svg',{'id':'map','width':'200','height':'200','viewBox':'0 0 1000 1000'}); + var svg = createElemNS('svg',{'id':'map','width':'500','height':'500','viewBox':'0 0 1000 1000'}); var rect=createElemNS('rect',{'x':'0','y':'0','width':'1000','height':'1000','style':'stroke:#000000; fill:none;'}); svg.appendChild(rect); From 5703818c3b88c63294aeff00bc23c3c7ac88f0c5 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 13:43:20 +0200 Subject: [PATCH 030/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index d41a3a6..00142cf 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -5,13 +5,25 @@ function createElem(type,attributes){ return elem; } function createElemNS(type,attributes){ + //same as createElem but with ns for svg file var elem=document.createElementNS("http://www.w3.org/2000/svg",type); for (var i in attributes) {elem.setAttributeNS(null,i,attributes[i]);} return elem; } +function applyInitMessage(){ + if(request.readyState == 4){ + if(request.status == 200) { + alert ("ok"); + }else{ + alert ('error ' + xhr.status); + document.getElementById('fightButton').disabled=false; + return; + } + } +} function tron(bot1,bot2,xdcheck){ //empty while (document.getElementById('fightResult').firstChild) { @@ -23,4 +35,15 @@ function tron(bot1,bot2,xdcheck){ svg.appendChild(rect); document.getElementById("fightResult").appendChild(svg); + + //ask arena to send bots init messages + var request = new XMLHttpRequest(); + request.onreadystatechange = applyInitMessage; + request.open("POST", '/tron', true); + request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + request.send('act=initGame&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check + '&fullLogs=' + document.getElementById("fullLogs").checked); + } + + + } From df7c01f966eed059b1cee03896d9ca61eb622f14 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 13:44:58 +0200 Subject: [PATCH 031/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 00142cf..8494f08 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -42,8 +42,4 @@ function tron(bot1,bot2,xdcheck){ request.open("POST", '/tron', true); request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); request.send('act=initGame&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check + '&fullLogs=' + document.getElementById("fullLogs").checked); - } - - - } From a532b3468f37207c03b7b8e050c26a20bc01ac0a Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 13:49:38 +0200 Subject: [PATCH 032/126] try to draw 1000*1000 svg grig --- src/arenas/tron/public.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index e6f3618..a10e3fc 100644 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -33,7 +33,7 @@ $bots=get_Bots_Array('tron');

-

+

\ No newline at end of file From 3c9b76835f11d01f974499bd4660ab7c1ca6fa83 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 13:51:05 +0200 Subject: [PATCH 033/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 8494f08..e0ddbf2 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -12,7 +12,7 @@ function createElemNS(type,attributes){ return elem; } -function applyInitMessage(){ +function applyInitMessage(request){ if(request.readyState == 4){ if(request.status == 200) { alert ("ok"); @@ -37,7 +37,7 @@ function tron(bot1,bot2,xdcheck){ document.getElementById("fightResult").appendChild(svg); //ask arena to send bots init messages - var request = new XMLHttpRequest(); + var request = new XMLHttpRequest(request); request.onreadystatechange = applyInitMessage; request.open("POST", '/tron', true); request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); From 2a8fc385e29598233334bca68d6ecd20d56f51ac Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 13:51:45 +0200 Subject: [PATCH 034/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index e0ddbf2..0b2b066 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -24,7 +24,7 @@ function applyInitMessage(request){ } } } -function tron(bot1,bot2,xdcheck){ +function tron(bot1,bot2,xd_check){ //empty while (document.getElementById('fightResult').firstChild) { document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); From 41467e8ab5685eb9258a5754f4d089700945ed7a Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 13:55:23 +0200 Subject: [PATCH 035/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 0b2b066..22199f3 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -12,9 +12,9 @@ function createElemNS(type,attributes){ return elem; } -function applyInitMessage(request){ - if(request.readyState == 4){ - if(request.status == 200) { +function applyInitMessage(req){ + if(req.readyState == 4){ + if(req.status == 200) { alert ("ok"); }else{ @@ -37,8 +37,8 @@ function tron(bot1,bot2,xd_check){ document.getElementById("fightResult").appendChild(svg); //ask arena to send bots init messages - var request = new XMLHttpRequest(request); - request.onreadystatechange = applyInitMessage; + var request = new XMLHttpRequest(); + request.onreadystatechange = applyInitMessage(request); request.open("POST", '/tron', true); request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); request.send('act=initGame&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check + '&fullLogs=' + document.getElementById("fullLogs").checked); From 06610e96466efa85f5e5dbd27983de82d25fa675 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 13:56:10 +0200 Subject: [PATCH 036/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 22199f3..fea8610 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -38,7 +38,7 @@ function tron(bot1,bot2,xd_check){ //ask arena to send bots init messages var request = new XMLHttpRequest(); - request.onreadystatechange = applyInitMessage(request); + request.onreadystatechange = function(){applyInitMessage(request)}; request.open("POST", '/tron', true); request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); request.send('act=initGame&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check + '&fullLogs=' + document.getElementById("fullLogs").checked); From 7599202cbb7b750a8c963fafc8c15a5017b84ea5 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 16:30:39 +0200 Subject: [PATCH 037/126] class playersTron --- src/arenas/tron/act.php | 22 +++++++++++ src/arenas/tron/functions.php | 71 +++++++++++++++++++++++++++++++++++ src/arenas/tron/js.js | 3 +- src/functions.php | 2 +- 4 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index e69de29..e825e0c 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -0,0 +1,22 @@ +direction == "x-")) + || (($newDir == "x-") && ($this->direction == "x+")) + || (($newDir == "y+") && ($this->direction == "y-")) + || (($newDir == "y-") && ($this->direction == "y+")) + ){ + return false; + } + $this->direction = $newdir; + return true; + } + + public function grow($dir=""){ + if($dir == ""){ + $dir = $this->direction; + } + + $headCoords = end($this->tail); + + + switch $dir{ + case "y+": + $targetCoords = array($headCoords[0],$headCoords[1]++); + break; + case "y-": + $targetCoords = array($headCoords[0],$headCoords[1]--); + break; + case "x+": + $targetCoords = array($headCoords[0]++,$headCoords[1]); + break; + case "x-": + $targetCoords = array($headCoords[0]--,$headCoords[1]); + break; + default: + return false; + + } + + } + + + public function __construct($id,$initialX0,$initialY0,$initialDirection){ + $lnBdd = conn_bdd(); + $rs = mysqli_query($lnBdd, + "SELECT name,url FROM bots WHERE game='tron' AND id='".mysqli_real_escape_string($lnBdd, $id)."';" + ); + if(($r=mysqli_fetch_row($rs)) && in_array($initialDirection,array('x-','x+','y-','y+'))){ + $this->name = $r[0]; + $this->url = $r[1]; + $this->tail = array(array($initialX,$initialY)); + $this->direction = $initialDirection; + $this->state= true; + }else{ + $this->state = false; + } + + + + } +} \ No newline at end of file diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index fea8610..9c0f9be 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -13,9 +13,10 @@ function createElemNS(type,attributes){ } function applyInitMessage(req){ + //callback function when init game request if(req.readyState == 4){ if(req.status == 200) { - alert ("ok"); + alert (req.responseTxt); }else{ alert ('error ' + xhr.status); diff --git a/src/functions.php b/src/functions.php index 45cc289..e289bf2 100644 --- a/src/functions.php +++ b/src/functions.php @@ -151,7 +151,7 @@ function conn_bdd(){ } mysqli_select_db($linkMysql,$mysqlParams['database']); mysqli_set_charset($linkMysql, 'utf8'); - return $linkMysql; //does PHP can do that? + return $linkMysql; } function get_battles_history($game){ From 0252c5b89946e414103b371901752c7b5ae9c8e7 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 16:42:21 +0200 Subject: [PATCH 038/126] class playersTron --- src/arenas/tron/functions.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/arenas/tron/functions.php b/src/arenas/tron/functions.php index 0867391..e0451b2 100644 --- a/src/arenas/tron/functions.php +++ b/src/arenas/tron/functions.php @@ -5,7 +5,7 @@ class TronPlayer{ private $name; private $tail = array(); private $direction; - public $state; + private $state; private function set_direction($newDir){ //can't be the opposite of the previous direction @@ -25,7 +25,9 @@ class TronPlayer{ if($dir == ""){ $dir = $this->direction; } - + if(!$this->set_direction()){ + return false; + } $headCoords = end($this->tail); @@ -46,6 +48,7 @@ class TronPlayer{ return false; } + $this->tail[] = $targetCoords; } From 9c2f3eb26a810920afaf55e64b9ee032afd106a6 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 16:56:24 +0200 Subject: [PATCH 039/126] try to draw 1000*1000 svg grig --- src/arenas/tron/act.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index e825e0c..3a7e539 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -11,9 +11,35 @@ # -- END LICENSE BLOCK ----------------------------------------- require_once(__DIR__."/functions.php"); + + switch ($_POST['act']){ case "initGame": + //check if bots exists + $bots=get_Bots_Array('tron'); + + $bot1Exists = false; + $bot2Exists = false; + foreach($bots as $bot){ + if($bot['id'] == $_POST['bot1']){ + $_SESSION['bots'][]=new TronPlayer($bot['id']); + $bot1Exists =true; + } + if($bot['id'] == $_POST['bot2']){ + $_SESSION['bots'][]=new TronPlayer($bot['id']); + $bot2Exists =true; + } + if ($bot1Exists && $bot2Exists){ + break; + } + } + if ((!$bot1Exists) OR (!$bot2Exists)){ + error (500,"missing parameter 2"); + } + + echo "plop"; + break; default: From c17b6cb69ea8ac559fcd314f7d088d3576daa15e Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 16:57:45 +0200 Subject: [PATCH 040/126] try to draw 1000*1000 svg grig --- src/arenas/tron/act.php | 4 ++-- src/arenas/tron/functions.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index 3a7e539..87fdafe 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -23,11 +23,11 @@ switch ($_POST['act']){ $bot2Exists = false; foreach($bots as $bot){ if($bot['id'] == $_POST['bot1']){ - $_SESSION['bots'][]=new TronPlayer($bot['id']); + $_SESSION['bots'][]=new TronPlayer($bot['id'],1,1); $bot1Exists =true; } if($bot['id'] == $_POST['bot2']){ - $_SESSION['bots'][]=new TronPlayer($bot['id']); + $_SESSION['bots'][]=new TronPlayer($bot['id'],998,998); $bot2Exists =true; } if ($bot1Exists && $bot2Exists){ diff --git a/src/arenas/tron/functions.php b/src/arenas/tron/functions.php index e0451b2..81f34e3 100644 --- a/src/arenas/tron/functions.php +++ b/src/arenas/tron/functions.php @@ -31,7 +31,7 @@ class TronPlayer{ $headCoords = end($this->tail); - switch $dir{ + switch ($dir){ case "y+": $targetCoords = array($headCoords[0],$headCoords[1]++); break; From f599309984e060c9cba371912ebf661c1a694796 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 17:00:23 +0200 Subject: [PATCH 041/126] try to draw 1000*1000 svg grig --- src/arenas/tron/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 9c0f9be..4f5d245 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -16,7 +16,7 @@ function applyInitMessage(req){ //callback function when init game request if(req.readyState == 4){ if(req.status == 200) { - alert (req.responseTxt); + alert (req.responseText); }else{ alert ('error ' + xhr.status); From aff0657d6ebcc425789cd52a2f09311f928d77f6 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 17:02:24 +0200 Subject: [PATCH 042/126] try to draw 1000*1000 svg grig --- src/arenas/tron/act.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index 87fdafe..5c2be93 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -23,11 +23,11 @@ switch ($_POST['act']){ $bot2Exists = false; foreach($bots as $bot){ if($bot['id'] == $_POST['bot1']){ - $_SESSION['bots'][]=new TronPlayer($bot['id'],1,1); + $_SESSION['bots'][]=new TronPlayer($bot['id'],500,10,'y+'); $bot1Exists =true; } if($bot['id'] == $_POST['bot2']){ - $_SESSION['bots'][]=new TronPlayer($bot['id'],998,998); + $_SESSION['bots'][]=new TronPlayer($bot['id'],500,989,'y-'); $bot2Exists =true; } if ($bot1Exists && $bot2Exists){ From 54ca6d7a206bc7ad3306eb6e0c25f653548620ba Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 17:03:06 +0200 Subject: [PATCH 043/126] try to draw 1000*1000 svg grig --- src/arenas/tron/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/functions.php b/src/arenas/tron/functions.php index 81f34e3..1267fdf 100644 --- a/src/arenas/tron/functions.php +++ b/src/arenas/tron/functions.php @@ -53,7 +53,7 @@ class TronPlayer{ } - public function __construct($id,$initialX0,$initialY0,$initialDirection){ + public function __construct($id,$initialX,$initialY,$initialDirection){ $lnBdd = conn_bdd(); $rs = mysqli_query($lnBdd, "SELECT name,url FROM bots WHERE game='tron' AND id='".mysqli_real_escape_string($lnBdd, $id)."';" From fee43385d9cc85bbd8407bb0bf1a6047786ad2ad Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 17:20:56 +0200 Subject: [PATCH 044/126] try to draw 1000*1000 svg grig --- src/arenas/tron/act.php | 2 +- src/arenas/tron/public.php | 30 +++++++++++++----------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index 5c2be93..c9231c4 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -38,7 +38,7 @@ switch ($_POST['act']){ error (500,"missing parameter 2"); } - echo "plop"; + break; diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index a10e3fc..3d446c0 100644 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -12,26 +12,22 @@ require_once(__DIR__."/functions.php"); $bots=get_Bots_Array('tron'); +$botsArr=array(); +foreach($bots as $bot){ + $botsArr[]=array('id' => $bot['id'], 'name' => $bot['name']); +} ?>

-

- -  VS  - -

+
+ +
+ + +

From 35fc852ee953732381313ded71679a1a5ae877b5 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 29 Jun 2016 17:21:46 +0200 Subject: [PATCH 045/126] try to draw 1000*1000 svg grig --- src/arenas/tron/public.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index 3d446c0..d5a4302 100644 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -23,7 +23,7 @@ foreach($bots as $bot){ From 561d76001b5a7b1d35346a3844ffa51ed1c7320c Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 29 Jun 2016 23:08:43 +0200 Subject: [PATCH 046/126] js --- src/arenas/tron/js.js | 16 ++++++++++++++++ src/arenas/tron/public.php | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 4f5d245..d96a5d2 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -11,6 +11,22 @@ function createElemNS(type,attributes){ {elem.setAttributeNS(null,i,attributes[i]);} return elem; } +function show_bot_panel(number){ + //configurePlayers + var fieldset = createElem('fieldset',{'class':'botFormulaire'}); + var p=createElem('p'); + var select = createElem('select',{'id':'selectBot' + number, 'onchange':'changeSelect(this.value);'}); + for each (var bot in botsAvailable){ + var option = createElem('option',{'value':bot['id']}); + option.innerHTML = bot['name']; + select.appendChild(option); + } + p.appendChild(select); + fieldset.appendChild(p); + + + document.getElementById('configurePlayers').appendChild(fieldset); +} function applyInitMessage(req){ //callback function when init game request diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index d5a4302..3dfa844 100644 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -19,9 +19,9 @@ foreach($bots as $bot){ ?>

-
+
+ - - -

+

-
\ No newline at end of file From 8f093f6966fd9e4286df75dc0d59aeea1465a75a Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 22 Jul 2016 18:45:17 +0200 Subject: [PATCH 122/126] some fixes --- countBattles.txt | 2 +- src/arenas/tron/TronGame.php | 20 ++++++++++++-------- src/arenas/tron/act.php | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index d10f97d..7e4fd5e 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1549 \ No newline at end of file +1559 \ No newline at end of file diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index 57f5de8..9a10f67 100644 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -75,6 +75,7 @@ class TronGame foreach($this->bots as $bot){ $trailsArr[] = $bot->trail; } + //echo json_encode($trailsArr); return json_encode($trailsArr); } public function new_lap(){ @@ -83,14 +84,14 @@ class TronGame $nbeBots = count($this->bots); $urls = array(); $paramToSend = array(); - $board = $this->getBoard(); + $board = $this->get_trails(); $loosers = array(); $lastsCells = array(); for ($botCount = 0; $botCount < $nbeBots; $botCount++){ - if ($this->bots[$botCount]->getStatus()){ + if ($this->bots[$botCount]->isAlive){ - $urls[$botCount] = $this->bots[$botCount]->getURL(); + $urls[$botCount] = $this->bots[$botCount]->url; $paramsToSend[$botCount] = array( 'game-id' => "".$this->gameId, @@ -105,16 +106,20 @@ class TronGame $responses = $this->get_multi_IAS_Responses($urls,$paramsToSend); + print_r($responses); + //grow bots'tails for ($botCount = 0; $botCount < $nbeBots; $botCount++){ - if ($this->bots[$botCount]->getStatus()){ - $lastsCells[$botCount] = $this->bots[$botCount]->grow($responses[$botCount]['responseArr']['play']); + if ($this->bots[$botCount]->isAlive){ + $dir = Direction::make($responses[$botCount]['responseArr']['play']); + $lastsCells[$botCount] = $this->bots[$botCount]->grow($dir); } } + //test if loose for ($botCount = 0; $botCount < $nbeBots; $botCount++){ - if ($this->bots[$botCount]->getStatus()){ + if ($this->bots[$botCount]->isAlive){ foreach($this->bots as $otherBot){ if($otherBot->trail->contains($lastsCells($botCount))) $loosers[] = $botCount; @@ -248,5 +253,4 @@ class TronGame } return $err; } - -} +} \ No newline at end of file diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index 2bec0ac..c7df199 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -61,7 +61,7 @@ switch ($_POST['act']){ $game = unserialize($_SESSION['game']); - if($game->getGameId() <> $_POST['gameId']){ + if($game->gameId <> $_POST['gameId']){ //sometimes if an ajax callback is applied after init an other game echo '{"status":"error"}'; die; @@ -73,7 +73,7 @@ switch ($_POST['act']){ $continue = 0; } echo json_encode(array( - 'gameId' => $game->getGameId(), + 'gameId' => $game->gameId, 'continue' => $continue, 'lap' => $lap )); From aced31b12c38ca8d349f129712cccd66db9f7dfa Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 25 Jul 2016 18:38:48 +0200 Subject: [PATCH 123/126] some fixes --- countBattles.txt | 2 +- src/arenas/tron/Trail.php | 17 +++++++++-------- src/arenas/tron/TronGame.php | 7 +++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 7e4fd5e..7157ddd 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1559 \ No newline at end of file +1579 \ No newline at end of file diff --git a/src/arenas/tron/Trail.php b/src/arenas/tron/Trail.php index c740b36..8150eb2 100644 --- a/src/arenas/tron/Trail.php +++ b/src/arenas/tron/Trail.php @@ -34,20 +34,21 @@ class Trail { $this->trail->push($value); } public function __toString(){ - $arr = ""; - foreach($this->trail as $value) { - $arr[] = $value; + return json_encode($this->getTrailAsArray()); + } + public function getTrailAsArray(){ + $arr = array(); + foreach($this->trail as $coord) { + $arr[] = array($coord->x,$coord->y); } - return json_encode($arr); - - + return $arr; } public function contains($searchedValue) { foreach($this->trail as $value) { - if($value == $searchedValue) return TRUE; + if($value == $searchedValue) return true; } - return FALSE; + return false; } public static function kind($var) { diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index 9a10f67..e186945 100644 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -73,9 +73,8 @@ class TronGame //return all trails for draw svg $trailsArr = array(); foreach($this->bots as $bot){ - $trailsArr[] = $bot->trail; + $trailsArr[] = $bot->trail->getTrailAsArray(); } - //echo json_encode($trailsArr); return json_encode($trailsArr); } public function new_lap(){ @@ -105,13 +104,13 @@ class TronGame } $responses = $this->get_multi_IAS_Responses($urls,$paramsToSend); - print_r($responses); - //grow bots'tails for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ + $dir = Direction::make($responses[$botCount]['responseArr']['play']); + $lastsCells[$botCount] = $this->bots[$botCount]->grow($dir); } } From 60c95835a4202aeaabfd4750fe3ca85f0a64dc3b Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 25 Jul 2016 19:01:38 +0200 Subject: [PATCH 124/126] some fixes --- countBattles.txt | 2 +- src/arenas/tron/TronGame.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 7157ddd..46547e5 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1579 \ No newline at end of file +1591 \ No newline at end of file diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index e186945..d484315 100644 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -75,7 +75,7 @@ class TronGame foreach($this->bots as $bot){ $trailsArr[] = $bot->trail->getTrailAsArray(); } - return json_encode($trailsArr); + return $trailsArr; } public function new_lap(){ // for all alive bots @@ -104,7 +104,7 @@ class TronGame } $responses = $this->get_multi_IAS_Responses($urls,$paramsToSend); - print_r($responses); + //print_r($responses); //grow bots'tails for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ @@ -120,7 +120,7 @@ class TronGame for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ foreach($this->bots as $otherBot){ - if($otherBot->trail->contains($lastsCells($botCount))) + if($otherBot->trail->contains($lastsCells[$botCount])) $loosers[] = $botCount; $this->bots[$botCount]->loose(); break; From 5935b750d0334817b38d0370bbb3df1154bee331 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 25 Jul 2016 22:01:58 +0200 Subject: [PATCH 125/126] . --- countBattles.txt | 2 +- src/arenas/tron/TronGame.php | 9 +++++++-- src/arenas/tron/TronPlayer.php | 3 --- src/arenas/tron/js.js | 4 ++++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 46547e5..30ab544 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1591 \ No newline at end of file +1593 \ No newline at end of file diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index d484315..86c210d 100644 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -119,12 +119,17 @@ class TronGame //test if loose for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ - foreach($this->bots as $otherBot){ - if($otherBot->trail->contains($lastsCells[$botCount])) + for( $botCount2 = 0; $botCount2 < $nbeBots; $botCount2++){ + + if(($botCount <> $botCount2) + && ($this->bots[$botCount2]->trail->contains($lastsCells[$botCount])) + ){ $loosers[] = $botCount; $this->bots[$botCount]->loose(); break; } + + } } } diff --git a/src/arenas/tron/TronPlayer.php b/src/arenas/tron/TronPlayer.php index ba8c357..60115f8 100644 --- a/src/arenas/tron/TronPlayer.php +++ b/src/arenas/tron/TronPlayer.php @@ -5,14 +5,12 @@ class TronPlayer{ public $name; public $trail; private $direction; - public $isAlive = true; public function grow(Direction $dir){ $this->trail->add($this->trail->last()->addDirection($dir)); return $this->trail->last(); } - public function loose(){ $this->isAlive = false; $this->trail->emptyTrail(); @@ -29,5 +27,4 @@ class TronPlayer{ public function __construct(){ $this->state = false; } - } \ No newline at end of file diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 9f01129..c189820 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -104,6 +104,10 @@ function play(gameId,xd_check){ if(req.status == 200) { addLog(req.responseText); var reponse = JSON.parse(req.responseText); + + growTails(reponse['lap']); + play(gameId,xd_check); + }else{ } From 1d5624462f07c40f032adb6898ae6b7b177179e8 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 26 Jul 2016 19:55:40 +0200 Subject: [PATCH 126/126] it draws the tail --- countBattles.txt | 2 +- src/arenas/tron/act.php | 1 + src/arenas/tron/js.js | 29 ++++++++++++++++++++++++----- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 30ab544..f84ccb2 100644 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1593 \ No newline at end of file +1617 \ No newline at end of file diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index c7df199..5cc1d81 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -77,6 +77,7 @@ switch ($_POST['act']){ 'continue' => $continue, 'lap' => $lap )); + $_SESSION['game'] = serialize($game); die; break; diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index c189820..1223cbf 100644 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -43,9 +43,9 @@ function changeSelect(number,botId){ return; }else{ show_bot_panel(next); - } + } if(number > 0){ - document.getElementById('fightButton').disabled = false; + document.getElementById('fightButton').disabled = false; } } } @@ -96,6 +96,22 @@ function applyInitMessage(req,xd_check){ } } } + + +function drawMap(map){ + console.log(map); + var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue']; + + for (var botId in map){ + for(var coordsI in map[botId]){ + coords = map[botId][coordsI]; + //draw the point + var rect=createElemNS('rect',{'x':coords[0],'y':coords[1],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'}); + document.getElementById('map').appendChild(rect); + } + } +} + function play(gameId,xd_check){ var req = new XMLHttpRequest(); @@ -105,8 +121,12 @@ function play(gameId,xd_check){ addLog(req.responseText); var reponse = JSON.parse(req.responseText); - growTails(reponse['lap']); - play(gameId,xd_check); + + + drawMap(reponse['lap']); + if(reponse['continue'] == '1'){ + play(gameId,xd_check); + } }else{ @@ -116,7 +136,6 @@ function play(gameId,xd_check){ req.open("POST", '/tron', true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send('act=play&xd_check=' + xd_check + '&gameId=' + gameId + '&fullLogs=' + document.getElementById("fullLogs").checked); - } function tron(xd_check){ //empty