From 365dd04be5117435939788ec02c5821cb0d6b359 Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 29 Jun 2016 00:14:16 +0200 Subject: [PATCH 001/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] 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/144] . --- 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/144] 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 From f873d6233d39cd011ebad9051a007e15d50e08b0 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 27 Sep 2016 18:54:42 +0200 Subject: [PATCH 127/144] Less data on each query --- .gitignore | 0 .gitmodules | 0 LICENSE | 0 Makefile | 0 README.md | 0 countBattles.txt | 2 +- html/.htaccess | 0 html/imgs/Arenes-Nimes.jpg | Bin html/imgs/Bronze_Medal.svg | 0 html/imgs/Emoji_u1f4a9.svg | 0 html/imgs/Gold_Medal.svg | 0 html/imgs/Silver_Medal.svg | 0 html/index.php | 0 html/log.txt | 0 html/principe.gif | Bin html/style.css | 0 html/testBotScripts/connectfour.html | 0 html/testBotScripts/index.html | 0 html/testBotScripts/tictactoe.html | 0 install.sql | 0 lang/en.php | 0 lang/fr.php | 0 src/about.html | 0 src/aboutBot.php | 0 src/act.php | 0 src/addBot.php | 0 src/arenas/Battleship/act.php | 0 src/arenas/Battleship/doc-en.html | 0 src/arenas/Battleship/doc-fr.html | 0 src/arenas/Battleship/functions.php | 0 src/arenas/Battleship/js.js | 0 src/arenas/Battleship/public.php | 0 src/arenas/Battleship/style.css | 0 src/arenas/Battleship/testBot.html | 0 src/arenas/connectFour/act.php | 0 src/arenas/connectFour/doc-en.html | 0 src/arenas/connectFour/doc-fr.html | 0 src/arenas/connectFour/functions.php | 0 src/arenas/connectFour/js.js | 0 src/arenas/connectFour/public.php | 0 src/arenas/connectFour/style.css | 0 src/arenas/tictactoe/act.php | 0 src/arenas/tictactoe/doc-en.html | 0 src/arenas/tictactoe/doc-fr.html | 0 src/arenas/tictactoe/doc.html | 0 src/arenas/tictactoe/functions.php | 0 src/arenas/tictactoe/js.js | 0 src/arenas/tictactoe/public.php | 0 src/arenas/tictactoe/style.css | 0 src/arenas/tictactoe/testBot.html | 0 src/arenas/tron/Coords.php | 0 src/arenas/tron/Direction.php | 0 src/arenas/tron/Trail.php | 1 + src/arenas/tron/TronGame.php | 10 +++++++++- src/arenas/tron/TronPlayer.php | 0 src/arenas/tron/act.php | 2 +- 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 | 13 ++++++++++++- src/arenas/tron/public.php | 0 src/arenas/tron/style.css | 0 src/arenas/tron/test/CoordsTest.php | 0 src/arenas/tron/test/DirectionTest.php | 0 src/arenas/tron/test/TrailTest.php | 0 src/arenas_lists.php | 0 src/config.php.empty | 0 src/editBot.php | 0 src/functions.php | 0 src/home.php | 0 src/legals.html | 0 src/scores.php | 0 src/validateEditBot.php | 0 73 files changed, 24 insertions(+), 4 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 .gitmodules mode change 100644 => 100755 LICENSE mode change 100644 => 100755 Makefile mode change 100644 => 100755 README.md mode change 100644 => 100755 countBattles.txt mode change 100644 => 100755 html/.htaccess mode change 100644 => 100755 html/imgs/Arenes-Nimes.jpg mode change 100644 => 100755 html/imgs/Bronze_Medal.svg mode change 100644 => 100755 html/imgs/Emoji_u1f4a9.svg mode change 100644 => 100755 html/imgs/Gold_Medal.svg mode change 100644 => 100755 html/imgs/Silver_Medal.svg mode change 100644 => 100755 html/index.php mode change 100644 => 100755 html/log.txt mode change 100644 => 100755 html/principe.gif mode change 100644 => 100755 html/style.css mode change 100644 => 100755 html/testBotScripts/connectfour.html mode change 100644 => 100755 html/testBotScripts/index.html mode change 100644 => 100755 html/testBotScripts/tictactoe.html mode change 100644 => 100755 install.sql mode change 100644 => 100755 lang/en.php mode change 100644 => 100755 lang/fr.php mode change 100644 => 100755 src/about.html mode change 100644 => 100755 src/aboutBot.php mode change 100644 => 100755 src/act.php mode change 100644 => 100755 src/addBot.php mode change 100644 => 100755 src/arenas/Battleship/act.php mode change 100644 => 100755 src/arenas/Battleship/doc-en.html mode change 100644 => 100755 src/arenas/Battleship/doc-fr.html mode change 100644 => 100755 src/arenas/Battleship/functions.php mode change 100644 => 100755 src/arenas/Battleship/js.js mode change 100644 => 100755 src/arenas/Battleship/public.php mode change 100644 => 100755 src/arenas/Battleship/style.css mode change 100644 => 100755 src/arenas/Battleship/testBot.html mode change 100644 => 100755 src/arenas/connectFour/act.php mode change 100644 => 100755 src/arenas/connectFour/doc-en.html mode change 100644 => 100755 src/arenas/connectFour/doc-fr.html mode change 100644 => 100755 src/arenas/connectFour/functions.php mode change 100644 => 100755 src/arenas/connectFour/js.js mode change 100644 => 100755 src/arenas/connectFour/public.php mode change 100644 => 100755 src/arenas/connectFour/style.css mode change 100644 => 100755 src/arenas/tictactoe/act.php mode change 100644 => 100755 src/arenas/tictactoe/doc-en.html mode change 100644 => 100755 src/arenas/tictactoe/doc-fr.html mode change 100644 => 100755 src/arenas/tictactoe/doc.html mode change 100644 => 100755 src/arenas/tictactoe/functions.php mode change 100644 => 100755 src/arenas/tictactoe/js.js mode change 100644 => 100755 src/arenas/tictactoe/public.php mode change 100644 => 100755 src/arenas/tictactoe/style.css mode change 100644 => 100755 src/arenas/tictactoe/testBot.html mode change 100644 => 100755 src/arenas/tron/Coords.php mode change 100644 => 100755 src/arenas/tron/Direction.php mode change 100644 => 100755 src/arenas/tron/Trail.php mode change 100644 => 100755 src/arenas/tron/TronGame.php mode change 100644 => 100755 src/arenas/tron/TronPlayer.php mode change 100644 => 100755 src/arenas/tron/act.php mode change 100644 => 100755 src/arenas/tron/doc-en.html mode change 100644 => 100755 src/arenas/tron/doc-fr.html mode change 100644 => 100755 src/arenas/tron/functions.php mode change 100644 => 100755 src/arenas/tron/js.js mode change 100644 => 100755 src/arenas/tron/public.php mode change 100644 => 100755 src/arenas/tron/style.css mode change 100644 => 100755 src/arenas/tron/test/CoordsTest.php mode change 100644 => 100755 src/arenas/tron/test/DirectionTest.php mode change 100644 => 100755 src/arenas/tron/test/TrailTest.php mode change 100644 => 100755 src/arenas_lists.php mode change 100644 => 100755 src/config.php.empty mode change 100644 => 100755 src/editBot.php mode change 100644 => 100755 src/functions.php mode change 100644 => 100755 src/home.php mode change 100644 => 100755 src/legals.html mode change 100644 => 100755 src/scores.php mode change 100644 => 100755 src/validateEditBot.php diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.gitmodules b/.gitmodules old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/countBattles.txt b/countBattles.txt old mode 100644 new mode 100755 index f84ccb2..5b208ae --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1617 \ No newline at end of file +1622 \ No newline at end of file diff --git a/html/.htaccess b/html/.htaccess old mode 100644 new mode 100755 diff --git a/html/imgs/Arenes-Nimes.jpg b/html/imgs/Arenes-Nimes.jpg old mode 100644 new mode 100755 diff --git a/html/imgs/Bronze_Medal.svg b/html/imgs/Bronze_Medal.svg old mode 100644 new mode 100755 diff --git a/html/imgs/Emoji_u1f4a9.svg b/html/imgs/Emoji_u1f4a9.svg old mode 100644 new mode 100755 diff --git a/html/imgs/Gold_Medal.svg b/html/imgs/Gold_Medal.svg old mode 100644 new mode 100755 diff --git a/html/imgs/Silver_Medal.svg b/html/imgs/Silver_Medal.svg old mode 100644 new mode 100755 diff --git a/html/index.php b/html/index.php old mode 100644 new mode 100755 diff --git a/html/log.txt b/html/log.txt old mode 100644 new mode 100755 diff --git a/html/principe.gif b/html/principe.gif old mode 100644 new mode 100755 diff --git a/html/style.css b/html/style.css old mode 100644 new mode 100755 diff --git a/html/testBotScripts/connectfour.html b/html/testBotScripts/connectfour.html old mode 100644 new mode 100755 diff --git a/html/testBotScripts/index.html b/html/testBotScripts/index.html old mode 100644 new mode 100755 diff --git a/html/testBotScripts/tictactoe.html b/html/testBotScripts/tictactoe.html old mode 100644 new mode 100755 diff --git a/install.sql b/install.sql old mode 100644 new mode 100755 diff --git a/lang/en.php b/lang/en.php old mode 100644 new mode 100755 diff --git a/lang/fr.php b/lang/fr.php old mode 100644 new mode 100755 diff --git a/src/about.html b/src/about.html old mode 100644 new mode 100755 diff --git a/src/aboutBot.php b/src/aboutBot.php old mode 100644 new mode 100755 diff --git a/src/act.php b/src/act.php old mode 100644 new mode 100755 diff --git a/src/addBot.php b/src/addBot.php old mode 100644 new mode 100755 diff --git a/src/arenas/Battleship/act.php b/src/arenas/Battleship/act.php old mode 100644 new mode 100755 diff --git a/src/arenas/Battleship/doc-en.html b/src/arenas/Battleship/doc-en.html old mode 100644 new mode 100755 diff --git a/src/arenas/Battleship/doc-fr.html b/src/arenas/Battleship/doc-fr.html old mode 100644 new mode 100755 diff --git a/src/arenas/Battleship/functions.php b/src/arenas/Battleship/functions.php old mode 100644 new mode 100755 diff --git a/src/arenas/Battleship/js.js b/src/arenas/Battleship/js.js old mode 100644 new mode 100755 diff --git a/src/arenas/Battleship/public.php b/src/arenas/Battleship/public.php old mode 100644 new mode 100755 diff --git a/src/arenas/Battleship/style.css b/src/arenas/Battleship/style.css old mode 100644 new mode 100755 diff --git a/src/arenas/Battleship/testBot.html b/src/arenas/Battleship/testBot.html old mode 100644 new mode 100755 diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php old mode 100644 new mode 100755 diff --git a/src/arenas/connectFour/doc-en.html b/src/arenas/connectFour/doc-en.html old mode 100644 new mode 100755 diff --git a/src/arenas/connectFour/doc-fr.html b/src/arenas/connectFour/doc-fr.html old mode 100644 new mode 100755 diff --git a/src/arenas/connectFour/functions.php b/src/arenas/connectFour/functions.php old mode 100644 new mode 100755 diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js old mode 100644 new mode 100755 diff --git a/src/arenas/connectFour/public.php b/src/arenas/connectFour/public.php old mode 100644 new mode 100755 diff --git a/src/arenas/connectFour/style.css b/src/arenas/connectFour/style.css old mode 100644 new mode 100755 diff --git a/src/arenas/tictactoe/act.php b/src/arenas/tictactoe/act.php old mode 100644 new mode 100755 diff --git a/src/arenas/tictactoe/doc-en.html b/src/arenas/tictactoe/doc-en.html old mode 100644 new mode 100755 diff --git a/src/arenas/tictactoe/doc-fr.html b/src/arenas/tictactoe/doc-fr.html old mode 100644 new mode 100755 diff --git a/src/arenas/tictactoe/doc.html b/src/arenas/tictactoe/doc.html old mode 100644 new mode 100755 diff --git a/src/arenas/tictactoe/functions.php b/src/arenas/tictactoe/functions.php old mode 100644 new mode 100755 diff --git a/src/arenas/tictactoe/js.js b/src/arenas/tictactoe/js.js old mode 100644 new mode 100755 diff --git a/src/arenas/tictactoe/public.php b/src/arenas/tictactoe/public.php old mode 100644 new mode 100755 diff --git a/src/arenas/tictactoe/style.css b/src/arenas/tictactoe/style.css old mode 100644 new mode 100755 diff --git a/src/arenas/tictactoe/testBot.html b/src/arenas/tictactoe/testBot.html old mode 100644 new mode 100755 diff --git a/src/arenas/tron/Coords.php b/src/arenas/tron/Coords.php old mode 100644 new mode 100755 diff --git a/src/arenas/tron/Direction.php b/src/arenas/tron/Direction.php old mode 100644 new mode 100755 diff --git a/src/arenas/tron/Trail.php b/src/arenas/tron/Trail.php old mode 100644 new mode 100755 index 8150eb2..195a692 --- a/src/arenas/tron/Trail.php +++ b/src/arenas/tron/Trail.php @@ -36,6 +36,7 @@ class Trail { public function __toString(){ return json_encode($this->getTrailAsArray()); } + public function getTrailAsArray(){ $arr = array(); foreach($this->trail as $coord) { diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php old mode 100644 new mode 100755 index 86c210d..f790989 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -77,6 +77,14 @@ class TronGame } return $trailsArr; } + public function get_lasts_trails(){ + //return only the lasts coords for each tail + $trailsArr = array(); + foreach($this->bots as $bot){ + $trailsArr[] = $bot->trail->last(); + } + return $trailsArr; + } public function new_lap(){ // for all alive bots $logs = ""; @@ -133,7 +141,7 @@ class TronGame } } - return $this->get_trails(); + return $this->get_lasts_trails(); } diff --git a/src/arenas/tron/TronPlayer.php b/src/arenas/tron/TronPlayer.php old mode 100644 new mode 100755 diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php old mode 100644 new mode 100755 index 5cc1d81..c8dcde0 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -44,7 +44,7 @@ switch ($_POST['act']){ 'status' => $game->get_continue(), 'logs' => $logs, 'gameId' => $game->gameId, - 'botsPosition' => $game->get_trails() + 'botsPosition' => $game->get_lasts_trails() )); $_SESSION['game'] = serialize($game); diff --git a/src/arenas/tron/doc-en.html b/src/arenas/tron/doc-en.html old mode 100644 new mode 100755 diff --git a/src/arenas/tron/doc-fr.html b/src/arenas/tron/doc-fr.html old mode 100644 new mode 100755 diff --git a/src/arenas/tron/functions.php b/src/arenas/tron/functions.php old mode 100644 new mode 100755 diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js old mode 100644 new mode 100755 index 1223cbf..969d8e3 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -12,6 +12,7 @@ function addLog(message){ divLogs.scrollTop = divLogs.scrollHeight; } +/* function growTails(newPointsByPlayer){ var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue']; @@ -28,6 +29,7 @@ function growTails(newPointsByPlayer){ } } } +*/ function createElemNS(type,attributes){ //same as createElem but with ns for svg file var elem=document.createElementNS("http://www.w3.org/2000/svg",type); @@ -85,7 +87,7 @@ function applyInitMessage(req,xd_check){ } addLog(ret['logs']); if(ret['status'] == true){ - growTails(ret['botsPosition']); + drawMap(ret['botsPosition']); play(ret['gameId'],xd_check); } @@ -103,12 +105,18 @@ function drawMap(map){ var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue']; for (var botId in map){ + //draw the point + var rect=createElemNS('rect',{'x':map[botId]['x'],'y':map[botId]['y'],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'}); + document.getElementById('map').appendChild(rect); + /* 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); } + */ } } @@ -126,9 +134,12 @@ function play(gameId,xd_check){ drawMap(reponse['lap']); if(reponse['continue'] == '1'){ play(gameId,xd_check); + }else{ + alert ('game ended'); } }else{ + alert('erreur' + req.status); } } diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php old mode 100644 new mode 100755 diff --git a/src/arenas/tron/style.css b/src/arenas/tron/style.css old mode 100644 new mode 100755 diff --git a/src/arenas/tron/test/CoordsTest.php b/src/arenas/tron/test/CoordsTest.php old mode 100644 new mode 100755 diff --git a/src/arenas/tron/test/DirectionTest.php b/src/arenas/tron/test/DirectionTest.php old mode 100644 new mode 100755 diff --git a/src/arenas/tron/test/TrailTest.php b/src/arenas/tron/test/TrailTest.php old mode 100644 new mode 100755 diff --git a/src/arenas_lists.php b/src/arenas_lists.php old mode 100644 new mode 100755 diff --git a/src/config.php.empty b/src/config.php.empty old mode 100644 new mode 100755 diff --git a/src/editBot.php b/src/editBot.php old mode 100644 new mode 100755 diff --git a/src/functions.php b/src/functions.php old mode 100644 new mode 100755 diff --git a/src/home.php b/src/home.php old mode 100644 new mode 100755 diff --git a/src/legals.html b/src/legals.html old mode 100644 new mode 100755 diff --git a/src/scores.php b/src/scores.php old mode 100644 new mode 100755 diff --git a/src/validateEditBot.php b/src/validateEditBot.php old mode 100644 new mode 100755 From 0fb60e7cf444d5181e67692dd9aad46a88dd0b97 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 30 Sep 2016 18:36:24 +0200 Subject: [PATCH 128/144] fixes --- countBattles.txt | 2 +- src/arenas/tron/Direction.php | 5 ++++- src/arenas/tron/Trail.php | 7 +++--- src/arenas/tron/TronGame.php | 40 ++++++++++++++++++++++----------- src/arenas/tron/act.php | 2 ++ src/arenas/tron/js.js | 42 +++++++++-------------------------- 6 files changed, 48 insertions(+), 50 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 5b208ae..377ce3c 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1622 \ No newline at end of file +1660 \ No newline at end of file diff --git a/src/arenas/tron/Direction.php b/src/arenas/tron/Direction.php index 4f1396f..69105e2 100755 --- a/src/arenas/tron/Direction.php +++ b/src/arenas/tron/Direction.php @@ -73,7 +73,10 @@ class Direction $dir->setValue(Direction::$bottom); break; default: - throw new InvalidDirectionException("expected 'x+', 'x-', 'y+' or 'y-'". (string)$str."received."); + //error_log("expected 'x+', 'x-', 'y+' or 'y-'". (string)$str."received."); + return false; + //throw new InvalidDirectionException("expected 'x+', 'x-', 'y+' or 'y-'". (string)$str."received."); + break; } return $dir; } diff --git a/src/arenas/tron/Trail.php b/src/arenas/tron/Trail.php index 195a692..dca329b 100755 --- a/src/arenas/tron/Trail.php +++ b/src/arenas/tron/Trail.php @@ -25,9 +25,10 @@ class Trail { } if($this->contains($value)) { - throw new AlreadyBeenAddedException( - 'value has already been added to the trail' - ); + //throw new AlreadyBeenAddedException( + // 'value has already been added to the trail'.$value.'|'.$this->__toString() + //); + return false; } } diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index f790989..afd17d2 100755 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -92,6 +92,7 @@ class TronGame $urls = array(); $paramToSend = array(); $board = $this->get_trails(); + //$board = $this->get_lasts_trails(); $loosers = array(); $lastsCells = array(); @@ -108,27 +109,40 @@ class TronGame 'player-index' => $botCount, // To do: verifier que ça restera le même à chaque tour 'players' => $nbeBots ); + //!!!!!!!!!!!!! To debug + //error_log(json_encode($paramsToSend[$botCount])); } } $responses = $this->get_multi_IAS_Responses($urls,$paramsToSend); - //print_r($responses); - //grow bots'tails + + //grow bots'tails for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ - $dir = Direction::make($responses[$botCount]['responseArr']['play']); + if(!$dir = Direction::make($responses[$botCount]['responseArr']['play'])){ + //he loses , non conform response + $loosers[] = $botCount; + $this->bots[$botCount]->loose(); + }else{ - $lastsCells[$botCount] = $this->bots[$botCount]->grow($dir); + $lastsCells[$botCount] = $this->bots[$botCount]->grow($dir); + if($lastsCells[$botCount] === false){ + $loosers[] = $botCount; + $this->bots[$botCount]->loose(); + } + + } } } //test if loose - for ($botCount = 0; $botCount < $nbeBots; $botCount++){ + for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ - for( $botCount2 = 0; $botCount2 < $nbeBots; $botCount2++){ - + + //tester si collusion avec les cases actuelles + for( $botCount2 = 0; $botCount2 < $nbeBots; $botCount2++){ if(($botCount <> $botCount2) && ($this->bots[$botCount2]->trail->contains($lastsCells[$botCount])) ){ @@ -137,13 +151,13 @@ class TronGame break; } - } + } + } } return $this->get_lasts_trails(); - - + } @@ -218,11 +232,11 @@ class TronGame $nbeBots = count($this->bots); for ($botCount = 0; $botCount < $nbeBots; $botCount++){ $messageArr = array( - 'game-id' => "".$this->gameId, - 'action' => 'init', + 'game-id' => "".$this->gameId, + 'action' => 'init', 'game' => 'tron', 'board' => '', - 'players' => $nbeBots, + 'players' => $nbeBots, 'player-index' => $botCount ); diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index c8dcde0..f527950 100755 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -10,6 +10,8 @@ # # -- END LICENSE BLOCK ----------------------------------------- +//error_log(json_encode($_SESSION,true)."\n\n"); + require_once ("TronGame.php"); require_once ("TronPlayer.php"); require_once ("Direction.php"); diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 969d8e3..5e44b37 100755 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -12,24 +12,7 @@ function addLog(message){ divLogs.scrollTop = divLogs.scrollHeight; } -/* -function growTails(newPointsByPlayer){ - var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue']; - //document.getElementById('map'); - for (var botId in newPointsByPlayer){ - - var tail = newPointsByPlayer[botId]['tail']; - for(var coordsIx in tail){ - - coords = tail[coordsIx]; - //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 createElemNS(type,attributes){ //same as createElem but with ns for svg file var elem=document.createElementNS("http://www.w3.org/2000/svg",type); @@ -92,7 +75,7 @@ function applyInitMessage(req,xd_check){ } }else{ - alert ('error ' + req.status); + alert ('error ' + req.status + req.responseText ); document.getElementById('fightButton').disabled=false; return; } @@ -108,15 +91,6 @@ function drawMap(map){ //draw the point var rect=createElemNS('rect',{'x':map[botId]['x'],'y':map[botId]['y'],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'}); document.getElementById('map').appendChild(rect); - /* - 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); - } - */ } } @@ -127,13 +101,17 @@ function play(gameId,xd_check){ if(req.readyState == 4){ if(req.status == 200) { addLog(req.responseText); - var reponse = JSON.parse(req.responseText); - - - + var reponse = JSON.parse(req.responseText); drawMap(reponse['lap']); if(reponse['continue'] == '1'){ - play(gameId,xd_check); + + setTimeout(function(){ + play(gameId,xd_check); + } ,500); + + + + }else{ alert ('game ended'); } From 759230082cef1a8f1a305d121e5c400212cceee3 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 30 Sep 2016 18:51:10 +0200 Subject: [PATCH 129/144] resolve the 100% CPU curl multi --- countBattles.txt | 2 +- src/arenas/tron/TronGame.php | 17 ++++------------- src/arenas/tron/js.js | 9 +++------ 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 377ce3c..c7f4ad9 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1660 \ No newline at end of file +1662 \ No newline at end of file diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index afd17d2..c2a1792 100755 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -181,22 +181,13 @@ class TronGame ); curl_multi_add_handle($cmh,$ch[$i]); } + //send the requests do { $returnVal = curl_multi_exec($cmh, $runningHandles); - } while ($returnVal == CURLM_CALL_MULTI_PERFORM); - // Loop and continue processing the request - while ($runningHandles && $returnVal== CURLM_OK) { - // Wait forever for network - $numberReady = curl_multi_select($cmh); - if ($numberReady != -1) { - // Pull in any new data, or at least handle timeouts - do { - $returnVal = curl_multi_exec($cmh, $runningHandles); - } while ($returnVal == CURLM_CALL_MULTI_PERFORM); - } - } - + }while($runningHandles > 0); + + //Get results for ($i = 0; $i < count($iasUrls); $i++){ // Check for errors diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 5e44b37..919cf38 100755 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -105,13 +105,10 @@ function play(gameId,xd_check){ drawMap(reponse['lap']); if(reponse['continue'] == '1'){ - setTimeout(function(){ + //setTimeout(function(){ play(gameId,xd_check); - } ,500); - - - - + //} ,500); + }else{ alert ('game ended'); } From 9a2224f019a243c302f5440f13a6033f01b59019 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 30 Sep 2016 19:25:25 +0200 Subject: [PATCH 130/144] . --- countBattles.txt | 2 +- src/arenas/tron/TronGame.php | 22 ++++++++++++++-------- src/arenas/tron/act.php | 2 +- src/arenas/tron/js.js | 4 ++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index c7f4ad9..3641460 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1662 \ No newline at end of file +1671 \ No newline at end of file diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index c2a1792..bb978d4 100755 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -66,9 +66,7 @@ class TronGame save_battle('tron',$winer,$loser,1,'id'); } } - } - public function get_trails(){ //return all trails for draw svg $trailsArr = array(); @@ -109,8 +107,6 @@ class TronGame 'player-index' => $botCount, // To do: verifier que ça restera le même à chaque tour 'players' => $nbeBots ); - //!!!!!!!!!!!!! To debug - //error_log(json_encode($paramsToSend[$botCount])); } } @@ -156,11 +152,21 @@ class TronGame } } - return $this->get_lasts_trails(); - + + //loosers list (in order to pass their id) + $loosersList = array(); + foreach($loosers as $looser){ + $loosersList[] = array( + 'order' => $looser, + 'id' => $this->bots[$looser]->id + ); + } + + return array( + 'last_points' => $this->get_lasts_trails(), + 'loosers' => $loosersList + ); } - - private function get_multi_IAS_Responses($iasUrls, $postParams){ //same as the get_IAS_Responses function // but more than one bot requested parallely diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index f527950..7fffca6 100755 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -36,7 +36,7 @@ switch ($_POST['act']){ $botsInfos[] = $botsFullArr[$id]; } } - //************ + $game = new TronGame($botsInfos); diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 919cf38..9cde497 100755 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -100,9 +100,9 @@ function play(gameId,xd_check){ req.onreadystatechange = function(){ if(req.readyState == 4){ if(req.status == 200) { - addLog(req.responseText); + //addLog(req.responseText); var reponse = JSON.parse(req.responseText); - drawMap(reponse['lap']); + drawMap(reponse['lap']['last_points']); if(reponse['continue'] == '1'){ //setTimeout(function(){ From 1f1f6dcd47c6c360762cd5f22a5dda78d57b5e7f Mon Sep 17 00:00:00 2001 From: root Date: Mon, 3 Oct 2016 19:12:07 +0200 Subject: [PATCH 131/144] it works, lets debug --- countBattles.txt | 2 +- src/arenas/tron/Coords.php | 10 +++++ src/arenas/tron/Trail.php | 12 +++-- src/arenas/tron/TronGame.php | 82 +++++++++++++++++++--------------- src/arenas/tron/TronPlayer.php | 7 +++ 5 files changed, 72 insertions(+), 41 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 3641460..f350689 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1671 \ No newline at end of file +1677 \ No newline at end of file diff --git a/src/arenas/tron/Coords.php b/src/arenas/tron/Coords.php index 31a42b3..fe760e2 100755 --- a/src/arenas/tron/Coords.php +++ b/src/arenas/tron/Coords.php @@ -1,16 +1,26 @@ min) || ($x > $this->max) || ($y < $this->min) || ($y > $this->max)){ + //out of limits + return false; + } + $this->x = $x; $this->y = $y; + + } public function __toString(){ return $this->x.",".$this->y; + } public function addDirection(Direction $dir){ diff --git a/src/arenas/tron/Trail.php b/src/arenas/tron/Trail.php index dca329b..7361574 100755 --- a/src/arenas/tron/Trail.php +++ b/src/arenas/tron/Trail.php @@ -9,6 +9,9 @@ class Trail { } public function last() { + if($this->trail->isEmpty()){ + return false; + } return $this->trail->top(); } @@ -19,9 +22,12 @@ class Trail { public function add($value) { if(!$this->trail->isEmpty()) { if(Trail::kind($this->trail->bottom()) !== Trail::kind($value)) { - throw new TypeError( - 'items added to a trail must be of the same kind' - ); + + // + // throw new TypeError( + // 'items added to a trail must be of the same kind' + // ); + return false; } if($this->contains($value)) { diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index bb978d4..c002205 100755 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -123,6 +123,7 @@ class TronGame }else{ $lastsCells[$botCount] = $this->bots[$botCount]->grow($dir); + if($lastsCells[$botCount] === false){ $loosers[] = $botCount; $this->bots[$botCount]->loose(); @@ -151,8 +152,7 @@ class TronGame } } - - + //loosers list (in order to pass their id) $loosersList = array(); foreach($loosers as $looser){ @@ -173,19 +173,21 @@ class TronGame $cmh = curl_multi_init(); for ($i = 0; $i < count($iasUrls); $i++){ - $data_string = json_encode($postParams[$i]); - - $ch[$i] = curl_init($iasUrls[$i]); - curl_setopt($ch[$i], CURLOPT_CUSTOMREQUEST, "POST"); - curl_setopt($ch[$i], CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($ch[$i], CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch[$i], CURLOPT_POSTFIELDS, $data_string); - curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch[$i], CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($data_string)) - ); - curl_multi_add_handle($cmh,$ch[$i]); + if(isset($postParams[$i])){ //dont use already deads bots + $data_string = json_encode($postParams[$i]); + + $ch[$i] = curl_init($iasUrls[$i]); + curl_setopt($ch[$i], CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($ch[$i], CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch[$i], CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch[$i], CURLOPT_POSTFIELDS, $data_string); + curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch[$i], CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($data_string)) + ); + curl_multi_add_handle($cmh,$ch[$i]); + } } //send the requests @@ -195,34 +197,40 @@ class TronGame //Get results - for ($i = 0; $i < count($iasUrls); $i++){ - // Check for errors - $curlError = curl_error($ch[$i]); - if($curlError == "") { - $response = curl_multi_getcontent($ch[$i]); - if(! $arr = json_decode($response,TRUE)){ - $arr=array(); - } - $res[$i] = array( - 'messageSend' => json_encode($postParams[$i]), - 'response' => $response, - 'httpStatus' => curl_getinfo($ch[$i])['http_code'], - 'responseArr' => $arr - ); - - }else{ - $res[$i] = false; + + for ($i = 0; $i < count($iasUrls); $i++){ + + if(isset($postParams[$i])){ + // Check for errors + $curlError = curl_error($ch[$i]); + if($curlError == "") { + $response = curl_multi_getcontent($ch[$i]); + if(! $arr = json_decode($response,TRUE)){ + $arr=array(); + } + $res[$i] = array( + 'messageSend' => json_encode($postParams[$i]), + 'response' => $response, + 'httpStatus' => curl_getinfo($ch[$i])['http_code'], + 'responseArr' => $arr + ); + + }else{ + $res[$i] = false; + } + //close + curl_multi_remove_handle($cmh, $ch[$i]); + curl_close($ch[$i]); + } - //close - curl_multi_remove_handle($cmh, $ch[$i]); - curl_close($ch[$i]); + } // Clean up the curl_multi handle curl_multi_close($cmh); return $res; } - public function init_game(){ + public function init_game(){ //send init messages to bots $logs = ""; $fullLogs = ""; @@ -246,7 +254,7 @@ class TronGame return array($logs,$fullLogs); } - public function __construct($botsInfos){ + public function __construct($botsInfos){ $this->gameId = get_unique_id(); $this->bots = array(); $positions = array(); diff --git a/src/arenas/tron/TronPlayer.php b/src/arenas/tron/TronPlayer.php index 60115f8..e1ce1de 100755 --- a/src/arenas/tron/TronPlayer.php +++ b/src/arenas/tron/TronPlayer.php @@ -8,12 +8,19 @@ class TronPlayer{ public $isAlive = true; public function grow(Direction $dir){ + $dest = $this->trail->last()->addDirection($dir); + if($dest == false){ + $this->loose(); + return false; + } + $this->trail->add($this->trail->last()->addDirection($dir)); return $this->trail->last(); } public function loose(){ $this->isAlive = false; $this->trail->emptyTrail(); + error_log($this->name." a perdu"); return false; } public function make($botId, Coords $initialsCoords,$name,$url){ From 78bbfbcc3bf88bb60389cbb7388dea1a2403e72e Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 4 Oct 2016 21:13:31 +0200 Subject: [PATCH 132/144] specs fr --- countBattles.txt | 2 +- src/arenas/tron/TronGame.php | 4 +- src/arenas/tron/doc-fr.html | 75 ++++++++++++++++++++++++++++++++++++ src/arenas/tron/style.css | 5 +++ 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index f350689..07c5b74 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1677 \ No newline at end of file +1681 \ No newline at end of file diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index c002205..660cb8c 100755 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -175,7 +175,9 @@ class TronGame for ($i = 0; $i < count($iasUrls); $i++){ if(isset($postParams[$i])){ //dont use already deads bots $data_string = json_encode($postParams[$i]); - + + error_log($data_string); + $ch[$i] = curl_init($iasUrls[$i]); curl_setopt($ch[$i], CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch[$i], CURLOPT_SSL_VERIFYHOST, false); diff --git a/src/arenas/tron/doc-fr.html b/src/arenas/tron/doc-fr.html index e69de29..f3ceb05 100755 --- a/src/arenas/tron/doc-fr.html +++ b/src/arenas/tron/doc-fr.html @@ -0,0 +1,75 @@ +

Fonctionnement des combats de Tron

+

Règles du jeu (hors specs techniques)

+

Chaque bot démarre depuis une case choisie au hazard par l'arène.

+

A chaque tour, il est demandé aux bots de grandir d'une case. Il peut choisir la direction. Sa queue s'allonge.

+

Si un bot percute une case déjà prise par sa queue ou celle d'un autre, il perd.

+

Ce n'est pas du tour par tour, les bots jouent simultanément, ils peuvent donc perdre en choisissant la même case de destination qu'un autre serpent

+

Exemple:

+ + + + + + + + + + + +
9
8
7
6
5
4oOoO
3
2
1
0123456789
+

Si dans le même tour le serpent vert et le serpent rouge décident d'aller respectivement vers la gauche et vers la droite, ils vont se télescopper et perdre tous les deux.

+ + + + + + + + + + + +
9
8
7
6
5
4): :(
3
2
1
0123456789
+

Lorsqu'un serpent meurt, (lorsqu'un bot perd) Sa queue est effacée et les cases prises par cette dernière devienent libres pour les serpents encore en vie.

+

Le jeu prend fin lorsqu'il reste moins de deux serpents.

+

La grille

+
    +
  • largeur: 1000 cases
  • +
  • hauteur: 1000 cases
  • +
+ +

Communications entre l'arène et les bots

+

L'arène fait emet des requetes http(s) à destination des bots.

+
    +
  • Type: POST
  • +
  • informations: au format JSON dans le corps de la requetes
  • +
+ +

Initialisation de la partie

+

L'arène (ce site) envoie le message (exemple) suivant à votre bot:

+
+{"game-id":"1679","action":"init","game":"tron","board":"","players":4,"player-index":2}
+
+
    +
  • game-id String Identifiant unique de la partie. Votre bot peut être emmené à jouer plusieurs parties en simultané. Si le fonctionnement de votre bot nécessite de suivre / conserver des valeurs entre deux tours dfe l'arène, cet identifiant vous sera utile.
  • +
  • action String, peut prendre les valeurs init ou play-turn, mais à cette étape, c'est init
  • +
  • game String, sera toujours "tron" ici. Peut vous servir si vous utilisez la même URL pour plusieurs bots.
  • +
  • board Sera vide à cette étape
  • +
  • players Entier Vous indique le nombre de joueurs sur cette partie. Il est possible que votre bot "joue" plusieurs joueurs. Et si vous les faisiez collaborer en ce cas là?
  • +
  • player-index Entier Le numéro de votre bot. Le premier bot a le numéro 0. Vous gardez le même numéro durant toute la partie, même si des joueurs sont déjà morts
  • +
+ +

Votre bot doit répondre par un tableau au format json, comme ceci:

+
+{"name":"botName"}
+
+

L'arène ne vérifie pas actuellement cette réponse, l'étape d'init a été insérée pour assurer la compatibilité avec Bolosseum. + Si votre bot repond une page blanche à cette étape (action=init), ça marchera dans le cadre de botsarena.

+ +

Tours de jeu

+

Exemple de message envoyé par l'arène au premier tour de jeu:

+ +

Exemple de message envoyé par l'arène après quelques tours de jeu:

+
+{"game-id":"1680","action":"play-turn","game":"tron","board":[[[687,110],[687,111],[686,111],[686,110],[686,109],[686,108],[686,107],[685,107],[685,108],[685,109],[684,109],[684,110],[684,111],[684,112],[684,113],[683,113],[682,113],[681,113],[681,114],[681,115],[681,116],[680,116],[680,117],[679,117],[679,116],[679,115],[679,114],[679,113],[679,112],[679,111],[679,110],[679,109],[678,109],[678,108],[677,108],[676,108],[676,107],[676,106],[676,105],[676,104],[676,103],[675,103],[674,103],[674,102],[673,102],[672,102],[672,101],[671,101],[670,101],[669,101],[669,102],[669,103],[669,104],[669,105],[669,106],[669,107],[668,107],[668,108],[668,109],[668,110],[668,111],[668,112],[667,112],[667,111],[667,110],[666,110],[666,109],[666,108],[665,108],[664,108],[664,107],[664,106],[663,106],[663,107],[663,108],[662,108],[661,108],[660,108],[660,107],[659,107],[659,106],[658,106],[657,106],[657,105],[657,104],[656,104],[656,103],[655,103],[655,102],[655,101],[654,101],[654,102],[654,103],[654,104],[653,104],[653,103],[653,102],[653,101],[653,100],[652,100],[651,100],[651,101],[651,102],[651,103],[651,104],[650,104],[650,105],[650,106],[649,106],[649,105],[648,105]],[[100,225],[100,226],[100,227],[100,228],[100,229],[100,230],[100,231],[99,231],[98,231],[98,232],[97,232],[96,232],[96,231],[96,230],[96,229],[96,228],[96,227],[96,226],[96,225],[96,224],[96,223],[95,223],[95,222],[94,222],[94,221],[94,220],[93,220],[92,220],[92,219],[92,218],[92,217],[92,216],[92,215],[91,215],[91,214],[90,214],[89,214],[89,213],[89,212],[88,212],[88,213],[88,214],[87,214],[87,213],[86,213],[86,214],[86,215],[85,215],[85,214],[84,214],[84,215],[83,215],[83,216],[83,217],[82,217],[82,216],[81,216],[81,215],[80,215],[80,216],[79,216],[79,215],[79,214],[78,214],[77,214],[77,213],[77,212],[76,212],[75,212],[75,211],[75,210],[75,209],[74,209],[74,210],[74,211],[73,211],[73,210],[72,210],[72,209],[71,209],[71,210],[70,210],[70,209],[69,209],[68,209],[68,210],[68,211],[67,211],[67,210],[67,209],[67,208],[66,208],[66,207],[66,206],[66,205],[66,204],[66,203],[65,203],[65,204],[64,204],[64,203],[63,203],[63,204],[63,205],[63,206],[62,206],[61,206],[61,207],[60,207],[60,208],[59,208]]],"player-index":0,"players":2}
+
\ No newline at end of file diff --git a/src/arenas/tron/style.css b/src/arenas/tron/style.css index eac3e3a..c848e32 100755 --- a/src/arenas/tron/style.css +++ b/src/arenas/tron/style.css @@ -1,3 +1,8 @@ +.tabledoc{border-collapse:collapse;} +.tabledoc tr td,.tabledoc tr th{border: 1px solid green; padding-left: 5px;width: 20px; height: 20px;} +.green{background-color: green;} +.red{background-color: red;} +.brown{background-color: grey;} #configurePlayers{width: 100%;} #configurePlayers fieldset{display: block; width: 100px; float:left;} #logs{display:block;padding-left:10px; height: 200px; overflow-y: scroll;} From db1dc561e5f93c4dc06e8aa69ca91ac0589b8a1f Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 12 Oct 2016 18:53:43 +0200 Subject: [PATCH 133/144] doc --- countBattles.txt | 2 +- src/arenas/tron/TronPlayer.php | 2 +- src/arenas/tron/act.php | 2 +- src/arenas/tron/doc-fr.html | 71 +++++++++++++++++++++++++++++++++- src/arenas/tron/js.js | 43 ++++++++++++++++---- src/arenas/tron/style.css | 3 +- 6 files changed, 111 insertions(+), 12 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 07c5b74..870e31e 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1681 \ No newline at end of file +1697 \ No newline at end of file diff --git a/src/arenas/tron/TronPlayer.php b/src/arenas/tron/TronPlayer.php index e1ce1de..de123e1 100755 --- a/src/arenas/tron/TronPlayer.php +++ b/src/arenas/tron/TronPlayer.php @@ -20,7 +20,7 @@ class TronPlayer{ public function loose(){ $this->isAlive = false; $this->trail->emptyTrail(); - error_log($this->name." a perdu"); + //error_log($this->name." a perdu"); return false; } public function make($botId, Coords $initialsCoords,$name,$url){ diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index 7fffca6..374ca48 100755 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -3,7 +3,7 @@ # # This file is part of botsArena. # -# Copyright (C) Gnieark et contributeurs +# Copyright (C) Gnieark https://blog-du-grouik.tinad.fr et contributeurs # Licensed under the GPL version 3.0 license. # See LICENSE file or # http://www.gnu.org/licenses/gpl-3.0-standalone.html diff --git a/src/arenas/tron/doc-fr.html b/src/arenas/tron/doc-fr.html index f3ceb05..2231cfb 100755 --- a/src/arenas/tron/doc-fr.html +++ b/src/arenas/tron/doc-fr.html @@ -72,4 +72,73 @@

Exemple de message envoyé par l'arène après quelques tours de jeu:

 {"game-id":"1680","action":"play-turn","game":"tron","board":[[[687,110],[687,111],[686,111],[686,110],[686,109],[686,108],[686,107],[685,107],[685,108],[685,109],[684,109],[684,110],[684,111],[684,112],[684,113],[683,113],[682,113],[681,113],[681,114],[681,115],[681,116],[680,116],[680,117],[679,117],[679,116],[679,115],[679,114],[679,113],[679,112],[679,111],[679,110],[679,109],[678,109],[678,108],[677,108],[676,108],[676,107],[676,106],[676,105],[676,104],[676,103],[675,103],[674,103],[674,102],[673,102],[672,102],[672,101],[671,101],[670,101],[669,101],[669,102],[669,103],[669,104],[669,105],[669,106],[669,107],[668,107],[668,108],[668,109],[668,110],[668,111],[668,112],[667,112],[667,111],[667,110],[666,110],[666,109],[666,108],[665,108],[664,108],[664,107],[664,106],[663,106],[663,107],[663,108],[662,108],[661,108],[660,108],[660,107],[659,107],[659,106],[658,106],[657,106],[657,105],[657,104],[656,104],[656,103],[655,103],[655,102],[655,101],[654,101],[654,102],[654,103],[654,104],[653,104],[653,103],[653,102],[653,101],[653,100],[652,100],[651,100],[651,101],[651,102],[651,103],[651,104],[650,104],[650,105],[650,106],[649,106],[649,105],[648,105]],[[100,225],[100,226],[100,227],[100,228],[100,229],[100,230],[100,231],[99,231],[98,231],[98,232],[97,232],[96,232],[96,231],[96,230],[96,229],[96,228],[96,227],[96,226],[96,225],[96,224],[96,223],[95,223],[95,222],[94,222],[94,221],[94,220],[93,220],[92,220],[92,219],[92,218],[92,217],[92,216],[92,215],[91,215],[91,214],[90,214],[89,214],[89,213],[89,212],[88,212],[88,213],[88,214],[87,214],[87,213],[86,213],[86,214],[86,215],[85,215],[85,214],[84,214],[84,215],[83,215],[83,216],[83,217],[82,217],[82,216],[81,216],[81,215],[80,215],[80,216],[79,216],[79,215],[79,214],[78,214],[77,214],[77,213],[77,212],[76,212],[75,212],[75,211],[75,210],[75,209],[74,209],[74,210],[74,211],[73,211],[73,210],[72,210],[72,209],[71,209],[71,210],[70,210],[70,209],[69,209],[68,209],[68,210],[68,211],[67,211],[67,210],[67,209],[67,208],[66,208],[66,207],[66,206],[66,205],[66,204],[66,203],[65,203],[65,204],[64,204],[64,203],[63,203],[63,204],[63,205],[63,206],[62,206],[61,206],[61,207],[60,207],[60,208],[59,208]]],"player-index":0,"players":2}
-
\ No newline at end of file + +

Les champs suivants sont les mêmes qu'au paragraphe précédent:

+
    +
  • game-id
  • +
  • game
  • +
  • players
  • +
  • player-index
  • +
+ +Les champs qui différent sont: +
    +
  • actionString, est toujours "play-turn" à cette étape
  • +
  • boardJe vous explique ça au chapitre suivant.
  • +
+

La Carte (board)

+

Elle est repésentée dans le champs "board" du JSON envoyé par l'arène. Elle décrit les cases prises par chaque joueur.

+

Elle est composée de plusieurs sous-arrays/sous-objets (en fonction de votre language de programmation). Elle se décompose en sous tableaux de la forme suivante:

+

    +
  • Board: +
      +
    • Joueur 1 +
        +
      • Case1 +
          +
        • coordonée X
        • +
        • Coordonée Y
        • +
        +
      • +
      • Case2 +
          +
        • coordonée X
        • +
        • Coordonée Y
        • +
        +
      • +
      +
    • +
    • Joueur 2> +
        +
      • Case1 +
          +
        • coordonée X
        • +
        • Coordonée Y
        • +
        +
      • +
      • Case2 +
          +
        • coordonée X
        • +
        • Coordonée Y
        • +
        +
      • +
      + +
    • +
    • ...
    • +
        + +
      +

      La représentation JSON est la suivante:

      + +

      +[
      +  [
      +    [x1,y1],[x2,y2],[x3,y3]
      +  ],
      +  [
      +    (...)
      +  ]
      +

      +

      L'ordre des "queues" des serpents dans ce tableau correspond à l'ordre des joueurs. Donc votre serpent est representée par la queue correspondant à player-index (le décompte de player-index commence par 0).

      +

      L'ordre des couples de coordonnées de chaque bot, est dans le sens queue vers la tête. Les bots grandissent à chaque tour en déplaçant leur tête.

      diff --git a/src/arenas/tron/js.js b/src/arenas/tron/js.js index 9cde497..826b72c 100755 --- a/src/arenas/tron/js.js +++ b/src/arenas/tron/js.js @@ -84,16 +84,30 @@ function applyInitMessage(req,xd_check){ function drawMap(map){ - console.log(map); + //console.log(map); var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue']; - for (var botId in map){ - //draw the point - var rect=createElemNS('rect',{'x':map[botId]['x'],'y':map[botId]['y'],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'}); - document.getElementById('map').appendChild(rect); + for (var botId in map){ + if(typeof(map[botId]['x']) != 'undefined'){ //don't draw deads bots + //draw the point + var rect=createElemNS('rect',{'x':map[botId]['x'],'y':map[botId]['y'],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'}); + document.getElementById('map').appendChild(rect); + } } } - +function delTrail(order){ + var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue']; + //on supprime tous les elements ayant la couleur correspndante. + + var container = document.getElementById('map'); + + var listNode = container.children; + for (var i= 0; i < listNode.length; i++){ + if( listNode[i].style.fill == botsColor[order] ){ + container.removeChild(listNode[i]); + } + } +} function play(gameId,xd_check){ var req = new XMLHttpRequest(); @@ -101,7 +115,22 @@ function play(gameId,xd_check){ if(req.readyState == 4){ if(req.status == 200) { //addLog(req.responseText); - var reponse = JSON.parse(req.responseText); + var reponse = JSON.parse(req.responseText); + + //to do Effacer les bots perdants + for(var i=0; i < reponse['lap']['loosers'].length; i++){ + //alert (req.responseText); + //return; + delTrail(reponse['lap']['loosers'][i]['order']); + + //find the bot name + for (var j = 0; j < botsAvailable.length; j ++){ + if(botsAvailable[j]['id'] == reponse['lap']['loosers'][i]['order']){ + var botName = botsAvailable[j]['name']; + } + } + addLog("Bot " + reponse['lap']['loosers'][i]['order'] + "id " + reponse['lap']['loosers'][i]['id'] + " Name: " + botName + " a perdu."); + } drawMap(reponse['lap']['last_points']); if(reponse['continue'] == '1'){ diff --git a/src/arenas/tron/style.css b/src/arenas/tron/style.css index c848e32..b307116 100755 --- a/src/arenas/tron/style.css +++ b/src/arenas/tron/style.css @@ -6,4 +6,5 @@ #configurePlayers{width: 100%;} #configurePlayers fieldset{display: block; width: 100px; float:left;} #logs{display:block;padding-left:10px; height: 200px; overflow-y: scroll;} -#logs p em {color: grey; font-size: 70%; test-transform:italic;} \ No newline at end of file +#logs p em {color: grey; font-size: 70%; test-transform:italic;} +code{font-family: monospace;} \ No newline at end of file From 3b4957398871466f6d461b9479df9d7e7c7b6f74 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 12 Oct 2016 19:24:24 +0200 Subject: [PATCH 134/144] fixes --- countBattles.txt | 2 +- src/arenas/tron/TronGame.php | 16 +++++++++------- src/arenas/tron/act.php | 1 + 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 870e31e..9b21444 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1697 \ No newline at end of file +1703 \ No newline at end of file diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index 660cb8c..4d6a949 100755 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -22,19 +22,21 @@ class TronGame private function apply_looses($loosersArr){ //save draws - if( count($loosersArr) > 1 ){ + if( count($loosersArr) > 0 ){ $loosersById = array(); foreach($loosersArr as $bot){ $loosersById[] = $this->bots[$bot]->id; } + + } + if( count($loosersArr) > 1 ){ //...que si au moins deux joueurs ont perdu sur le meme tour $this->save_draw_bots($loosersById); } - //save victories if( count($loosersArr) > 0 ){ //make victorous bots array $vbots = array(); - for ($botCount = 0; $botCount < $nbeBots; $botCount++){ + for ($botCount = 0; $botCount < count($this->bots); $botCount++){ if($this->bots[$botCount]->isAlive){ $vbots[] = $this->bots[$botCount]->id; } @@ -62,8 +64,8 @@ class TronGame private function save_losers_winers($arrLoosers,$arrWiners){ foreach($arrWiners as $winner){ - foreach($arrLoosers as $loser){ - save_battle('tron',$winer,$loser,1,'id'); + foreach($arrLoosers as $looser){ + save_battle('tron',$winner,$looser,1,'id'); } } } @@ -161,7 +163,7 @@ class TronGame 'id' => $this->bots[$looser]->id ); } - + $this->apply_looses($loosersList); return array( 'last_points' => $this->get_lasts_trails(), 'loosers' => $loosersList @@ -176,7 +178,7 @@ class TronGame if(isset($postParams[$i])){ //dont use already deads bots $data_string = json_encode($postParams[$i]); - error_log($data_string); + //error_log($data_string); $ch[$i] = curl_init($iasUrls[$i]); curl_setopt($ch[$i], CURLOPT_CUSTOMREQUEST, "POST"); diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index 374ca48..3a4714b 100755 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -28,6 +28,7 @@ switch ($_POST['act']){ $botsArrayTemp = json_decode($_POST['bots']); + error_log($botsArrayTemp); $botsInfos = array(); foreach($botsArrayTemp as $id){ From 7939a6a91119c2905109cad5b13f77a36b14f56c Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 14 Oct 2016 21:24:55 +0200 Subject: [PATCH 135/144] fixes --- countBattles.txt | 2 +- src/arenas/tron/ScoreLap.php | 57 ++++++++++++++++++++++++++++++++++++ src/arenas/tron/TronGame.php | 18 +++++++----- src/arenas/tron/act.php | 5 ++-- src/arenas/tron/doc-fr.html | 7 +++++ src/functions.php | 1 + 6 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 src/arenas/tron/ScoreLap.php diff --git a/countBattles.txt b/countBattles.txt index 9b21444..f754216 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1703 \ No newline at end of file +1716 \ No newline at end of file diff --git a/src/arenas/tron/ScoreLap.php b/src/arenas/tron/ScoreLap.php new file mode 100644 index 0000000..9c42848 --- /dev/null +++ b/src/arenas/tron/ScoreLap.php @@ -0,0 +1,57 @@ +playersIdsByOrder[$order] = $id; + } + + public function addLoser($order){ + $this->looserList[] = $order; + } + public function __construct() { + $this->playersIdsByOrder = array(); + $this->looserList = array(); + } + public function make($botsList){ + //$botsList must be like array[{botOrder:BotId},{botOrder:BotId}] + $this->looserList = $botsList; + } + + private function ApplyDraws(){ + //apply draw match to all losers + if(count($this->looserList) > 1){ //no draw if only 0 or one user at this lap + foreach($looserList as $looser1){ + foreach($looserList as $looser2){ + save_battle('tron', + $this->playersIdsByOrder[$looser1], + $this->playersIdsByOrder[$looser2], + 0, + 'id'); + } + } + } + } + private function ApplyWins(){ + foreach($this->looserList as $looser){ + foreach($playersIdsByOrder as $order=>$player){ + if(!in_array($order,$this->looserList)){ + save_battle('tron', + $this->playersIdsByOrder[$looser], + $player, + 2, + 'id'); + } + } + } + + } + public function ApplyScores(){ + $this-> ApplyDraws(); + $this-> ApplyWins(); + + } +} \ No newline at end of file diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index 4d6a949..6288e0c 100755 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -20,12 +20,15 @@ class TronGame } } - private function apply_looses($loosersArr){ + private function apply_looses($loosersArr){ + //$loosersArr est construit comme ça: [{"order":1,"id":54"},{"order":3,"id":54"}] + //save draws if( count($loosersArr) > 0 ){ $loosersById = array(); foreach($loosersArr as $bot){ - $loosersById[] = $this->bots[$bot]->id; + //error_log('apply lose '.$bot['id']); + $loosersById[] = $bot['id']; } } @@ -96,9 +99,13 @@ class TronGame $loosers = array(); $lastsCells = array(); + $scoring = new ScoreLap(); + + for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ + $scoreLap->addBotOnLap($botCount,$this->bots[$botCount]->id); $urls[$botCount] = $this->bots[$botCount]->url; $paramsToSend[$botCount] = array( @@ -134,8 +141,6 @@ class TronGame } } } - - //test if loose for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ @@ -148,13 +153,10 @@ class TronGame $loosers[] = $botCount; $this->bots[$botCount]->loose(); break; - } - + } } - } } - //loosers list (in order to pass their id) $loosersList = array(); foreach($loosers as $looser){ diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index 3a4714b..d88e0ee 100755 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -17,6 +17,7 @@ require_once ("TronPlayer.php"); require_once ("Direction.php"); require_once ("Trail.php"); require_once ("Coords.php"); +require_once ("ScoreLap.php"); switch ($_POST['act']){ case "initGame": @@ -28,12 +29,12 @@ switch ($_POST['act']){ $botsArrayTemp = json_decode($_POST['bots']); - error_log($botsArrayTemp); + //error_log($_POST['bots']); $botsInfos = array(); foreach($botsArrayTemp as $id){ //tester si le bot existe dans la bdd - if(isset($botsFullArr[$id])){ + if((isset($botsFullArr[$id])) && ($id > 0)){ $botsInfos[] = $botsFullArr[$id]; } } diff --git a/src/arenas/tron/doc-fr.html b/src/arenas/tron/doc-fr.html index 2231cfb..1170785 100755 --- a/src/arenas/tron/doc-fr.html +++ b/src/arenas/tron/doc-fr.html @@ -142,3 +142,10 @@ Les champs qui différent sont:

      L'ordre des "queues" des serpents dans ce tableau correspond à l'ordre des joueurs. Donc votre serpent est representée par la queue correspondant à player-index (le décompte de player-index commence par 0).

      L'ordre des couples de coordonnées de chaque bot, est dans le sens queue vers la tête. Les bots grandissent à chaque tour en déplaçant leur tête.

      +

      Scoring

      +

      Le scorring (classement EHLO) reste sur une logique de duels, bien que ce jeu puisse contenir plus de deux bots par match. Le score est modifié au fur et à mesure de la partie à chaque fois qu'un bot "décède":

      +
        +
      • Lors de la défaite d'un bot, l'arène enregistre un match nul contre tous les autres bots qui ont aussi perdu au même tour de jeu.
      • +
      • Elle enregistre aussi une défaite des bots morts contre tous les bots encore en course à la fin du tour.
      • +
      + diff --git a/src/functions.php b/src/functions.php index 8fd041a..3c44b40 100755 --- a/src/functions.php +++ b/src/functions.php @@ -114,6 +114,7 @@ function get_language_array(){ return $lang; } function error($code,$message){ + error_log($code." ".$message); switch($code){ case 404: header("HTTP/1.0 404 Not Found"); From 87d2c4cf1e7dfb6782bd229830a46a73c85257d1 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 18 Oct 2016 20:18:32 +0200 Subject: [PATCH 136/144] scoring class --- countBattles.txt | 2 +- src/arenas/tron/ScoreLap.php | 45 +++++++++++++------- src/arenas/tron/TronGame.php | 80 +++++------------------------------- 3 files changed, 42 insertions(+), 85 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index f754216..44fb745 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1716 \ No newline at end of file +1726 \ No newline at end of file diff --git a/src/arenas/tron/ScoreLap.php b/src/arenas/tron/ScoreLap.php index 9c42848..ddd0a91 100644 --- a/src/arenas/tron/ScoreLap.php +++ b/src/arenas/tron/ScoreLap.php @@ -3,40 +3,55 @@ class ScoreLap { private $playersIdsByOrder; //array containing id's of alive players at the beginning of the match, Put only alive bots in! - private $looserList; //only containing theirs orders + private $looserList; //idem but only loosers public function addBotOnLap($order,$id){ $this->playersIdsByOrder[$order] = $id; } - public function addLoser($order){ - $this->looserList[] = $order; + public function addLoser($order,$id){ + $this->looserList[$order] = $order; } public function __construct() { $this->playersIdsByOrder = array(); $this->looserList = array(); } - public function make($botsList){ - //$botsList must be like array[{botOrder:BotId},{botOrder:BotId}] - $this->looserList = $botsList; - } + + public function getLoosersList(){ + return $this->looserList; + } + + //NO! + // public function make($botsList){ + // //$botsList must be like array[{botOrder:BotId},{botOrder:BotId}] + // $this->looserList = $botsList; + // } private function ApplyDraws(){ //apply draw match to all losers if(count($this->looserList) > 1){ //no draw if only 0 or one user at this lap - foreach($looserList as $looser1){ - foreach($looserList as $looser2){ - save_battle('tron', - $this->playersIdsByOrder[$looser1], - $this->playersIdsByOrder[$looser2], - 0, - 'id'); + foreach($looserList as $order1 => $looser1){ + foreach($looserList as $order2 => $looser2){ + if($order1 <> $order2){ + save_battle('tron', + $this->playersIdsByOrder[$looser1], + $this->playersIdsByOrder[$looser2], + 0, + 'id'); + } } } } } private function ApplyWins(){ - foreach($this->looserList as $looser){ + + //need to make losers List. simply array of orders + $loosersOrdersArr = array(); + foreach($this->looserList as $order => $looser){ + $loosersOrdersArr[] = $order; + } + + foreach($this->looserList as $looserOrder => $looserId){ foreach($playersIdsByOrder as $order=>$player){ if(!in_array($order,$this->looserList)){ save_battle('tron', diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index 6288e0c..00edf86 100755 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -20,58 +20,6 @@ class TronGame } } - private function apply_looses($loosersArr){ - //$loosersArr est construit comme ça: [{"order":1,"id":54"},{"order":3,"id":54"}] - - //save draws - if( count($loosersArr) > 0 ){ - $loosersById = array(); - foreach($loosersArr as $bot){ - //error_log('apply lose '.$bot['id']); - $loosersById[] = $bot['id']; - } - - } - if( count($loosersArr) > 1 ){ //...que si au moins deux joueurs ont perdu sur le meme tour - $this->save_draw_bots($loosersById); - } - //save victories - if( count($loosersArr) > 0 ){ - //make victorous bots array - $vbots = array(); - for ($botCount = 0; $botCount < count($this->bots); $botCount++){ - if($this->bots[$botCount]->isAlive){ - $vbots[] = $this->bots[$botCount]->id; - } - } - $this->save_losers_winers($loosersById,$vbots); - } - - } - private function save_draw_bots($arr){ - /* - * Recursive function who save all combionaisons of draw matches - */ - - if(count($arr) < 2){ - return; - }else{ - $a = $arr[0]; - array_shift($arr); - foreach($arr as $bot){ - save_battle('tron',$a,$bot,0,'id'); - } - $this->save_draw_bots($arr); - } - } - - private function save_losers_winers($arrLoosers,$arrWiners){ - foreach($arrWiners as $winner){ - foreach($arrLoosers as $looser){ - save_battle('tron',$winner,$looser,1,'id'); - } - } - } public function get_trails(){ //return all trails for draw svg $trailsArr = array(); @@ -96,7 +44,6 @@ class TronGame $paramToSend = array(); $board = $this->get_trails(); //$board = $this->get_lasts_trails(); - $loosers = array(); $lastsCells = array(); $scoring = new ScoreLap(); @@ -104,8 +51,8 @@ class TronGame for ($botCount = 0; $botCount < $nbeBots; $botCount++){ if ($this->bots[$botCount]->isAlive){ - - $scoreLap->addBotOnLap($botCount,$this->bots[$botCount]->id); + + $scoring->addBotOnLap($botCount,$this->bots[$botCount]->id); $urls[$botCount] = $this->bots[$botCount]->url; $paramsToSend[$botCount] = array( @@ -127,15 +74,16 @@ class TronGame if(!$dir = Direction::make($responses[$botCount]['responseArr']['play'])){ //he loses , non conform response - $loosers[] = $botCount; + $scoring-> addLoser($botCount,$this->bots[$botCount]->id); $this->bots[$botCount]->loose(); }else{ $lastsCells[$botCount] = $this->bots[$botCount]->grow($dir); if($lastsCells[$botCount] === false){ - $loosers[] = $botCount; - $this->bots[$botCount]->loose(); + //$loosers[] = $botCount; + $scoring-> addLoser($botCount,$this->bots[$botCount]->id); + $this->bots[$botCount]->loose(); } } @@ -150,25 +98,19 @@ class TronGame if(($botCount <> $botCount2) && ($this->bots[$botCount2]->trail->contains($lastsCells[$botCount])) ){ - $loosers[] = $botCount; + + $scoring-> addLoser($botCount,$this->bots[$botCount]->id); $this->bots[$botCount]->loose(); break; } } } } - //loosers list (in order to pass their id) - $loosersList = array(); - foreach($loosers as $looser){ - $loosersList[] = array( - 'order' => $looser, - 'id' => $this->bots[$looser]->id - ); - } - $this->apply_looses($loosersList); + + //$this->apply_looses($loosersList); return array( 'last_points' => $this->get_lasts_trails(), - 'loosers' => $loosersList + 'loosers' => $scoring->getLoosersList() ); } private function get_multi_IAS_Responses($iasUrls, $postParams){ From c4e99fccc7c91ffa898c9d55746c61a836f397c2 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 2 Nov 2016 19:39:23 +0100 Subject: [PATCH 137/144] rewrite trongame --- countBattles.txt | 2 +- src/arenas/tron/Coords.php | 7 +- src/arenas/tron/ScoreLap.php | 74 +++++-------- src/arenas/tron/Trail.php | 13 +-- src/arenas/tron/TronGame.php | 195 ++++++++++++++++++++++----------- src/arenas/tron/TronPlayer.php | 14 ++- src/arenas/tron/functions.php | 4 - 7 files changed, 186 insertions(+), 123 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index 44fb745..e6d1b72 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1726 \ No newline at end of file +1747 \ No newline at end of file diff --git a/src/arenas/tron/Coords.php b/src/arenas/tron/Coords.php index fe760e2..9fdb5e4 100755 --- a/src/arenas/tron/Coords.php +++ b/src/arenas/tron/Coords.php @@ -1,14 +1,15 @@ min) || ($x > $this->max) || ($y < $this->min) || ($y > $this->max)){ + if (($x < Coords::$min) || ($x > Coords::$max) || ($y < Coords::$min) || ($y > Coords::$max)){ //out of limits + error_log("a bot out of limits"); return false; } diff --git a/src/arenas/tron/ScoreLap.php b/src/arenas/tron/ScoreLap.php index ddd0a91..a529252 100644 --- a/src/arenas/tron/ScoreLap.php +++ b/src/arenas/tron/ScoreLap.php @@ -2,71 +2,57 @@ class ScoreLap { - private $playersIdsByOrder; //array containing id's of alive players at the beginning of the match, Put only alive bots in! - private $looserList; //idem but only loosers - public function addBotOnLap($order,$id){ - $this->playersIdsByOrder[$order] = $id; + private $participants; //array containing bots objects + private $loosers; //those who losed + + + public function addBotOnLap(TronPlayer $bot){ + $this->participants[] = $bot; } - public function addLoser($order,$id){ - $this->looserList[$order] = $order; + public function addLoser(TronPlayer $bot){ + $this->loosers[] = $bot; } public function __construct() { - $this->playersIdsByOrder = array(); - $this->looserList = array(); + $this->participants= array(); + $this->loosers = array(); } public function getLoosersList(){ - return $this->looserList; + return $this->$loosers; } - - //NO! - // public function make($botsList){ - // //$botsList must be like array[{botOrder:BotId},{botOrder:BotId}] - // $this->looserList = $botsList; - // } + + private function ApplyDraws(){ - private function ApplyDraws(){ //apply draw match to all losers - if(count($this->looserList) > 1){ //no draw if only 0 or one user at this lap - foreach($looserList as $order1 => $looser1){ - foreach($looserList as $order2 => $looser2){ - if($order1 <> $order2){ - save_battle('tron', - $this->playersIdsByOrder[$looser1], - $this->playersIdsByOrder[$looser2], - 0, - 'id'); - } - } + if(count($this->looserList) < 2) return; + + foreach($loosers as $$looser1){ + foreach($loosers as $looser2){ + if($looser1->playerIndex == $looser2->playerIndex) continue; + save_battle('tron', $looser1->id, $looser2->id, 0, 'id' ); } - } + } } - private function ApplyWins(){ + + + private function ApplyWins(){ //need to make losers List. simply array of orders - $loosersOrdersArr = array(); - foreach($this->looserList as $order => $looser){ - $loosersOrdersArr[] = $order; + $loosersIndexArr = array(); + foreach($this->looserList as $looser){ + $loosersIndexArr[] = $looser->playerIndex; } - - foreach($this->looserList as $looserOrder => $looserId){ - foreach($playersIdsByOrder as $order=>$player){ - if(!in_array($order,$this->looserList)){ - save_battle('tron', - $this->playersIdsByOrder[$looser], - $player, - 2, - 'id'); - } + foreach($this->loosers as $looser){ + foreach($this->participants as $participant){ + if(in_array($participant->playerIndex,$loosersIndexArr)) continue; + save_battle('tron', $looser->id, $participant->id, 2, 'id'); } } - } public function ApplyScores(){ $this-> ApplyDraws(); $this-> ApplyWins(); - } } \ No newline at end of file diff --git a/src/arenas/tron/Trail.php b/src/arenas/tron/Trail.php index 7361574..9740d18 100755 --- a/src/arenas/tron/Trail.php +++ b/src/arenas/tron/Trail.php @@ -18,15 +18,14 @@ class Trail { public function emptyTrail(){ $this->trail = new SplStack(); } - + public function mergeWith($trailToMerge){ + foreach($trailToMerge as $value) { + $this->trail->add($value); + } + } public function add($value) { if(!$this->trail->isEmpty()) { if(Trail::kind($this->trail->bottom()) !== Trail::kind($value)) { - - // - // throw new TypeError( - // 'items added to a trail must be of the same kind' - // ); return false; } @@ -43,7 +42,7 @@ class Trail { public function __toString(){ return json_encode($this->getTrailAsArray()); } - + public function getTrailAsArray(){ $arr = array(); foreach($this->trail as $coord) { diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index 00edf86..0d55fb6 100755 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -4,16 +4,38 @@ class TronGame private $bots; //array of bots public $gameId; private $status; //false => Game ended or not initialised + + private function getAliveBots(){ + $aliveBots = array(); + foreach($this->bots as $bot){ + if($bot->isAlive){ + $aliveBots[] = $bot; + } + } + return $aliveBots; + } - public function get_continue(){ - //count bots alive. if less than 1, game is ended - $count = 0; + private function getBotByPlayerIndex($index){ foreach($this->bots as $bot){ - if( $bot->isAlive == true){ - $count++; + if($bot->playerIndex == $index){ + return $bot; } } - if($count > 1){ + return false; + } + private function initScoring(){ + /* + *Add all alive bots on a ScoreLap object and return it + */ + $scoring = new ScoreLap(); + foreach($this->getAliveBots()as $bot){ + $scoring->addBotOnLap($bot); + } + return $scoring; + } + public function get_continue(){ + //count bots alive. if less than 1, game is ended + if(count($this->getAliveBots()) > 1){ return true; }else{ return false; @@ -28,6 +50,14 @@ class TronGame } return $trailsArr; } + private function get_map_as_an_unique_trail(){ + $trail = new Trail; + foreach($this->bots as $bot){ + $trail->mergeWith($bot->trail); + } + return trail; + + } public function get_lasts_trails(){ //return only the lasts coords for each tail $trailsArr = array(); @@ -37,83 +67,126 @@ class TronGame return $trailsArr; } public function new_lap(){ - // for all alive bots - $logs = ""; - $nbeBots = count($this->bots); - $urls = array(); - $paramToSend = array(); - $board = $this->get_trails(); - //$board = $this->get_lasts_trails(); - $lastsCells = array(); + + if($this->get_continue() === false){ + return false; + } + + $scoreObj = $this->initScoring(); + $aliveBots = $this->getAliveBots(); - $scoring = new ScoreLap(); + //fixed Query parameters + $nbeBots = count($this->bots); + $board = $this->get_trails(); //same for each bot + $initialMapAsATrail = $this->get_map_as_an_unique_trail(); + //Open curl multi + $cmh = curl_multi_init(); + $ch = array(); - for ($botCount = 0; $botCount < $nbeBots; $botCount++){ - if ($this->bots[$botCount]->isAlive){ - - $scoring->addBotOnLap($botCount,$this->bots[$botCount]->id); - $urls[$botCount] = $this->bots[$botCount]->url; - - $paramsToSend[$botCount] = array( + + + foreach($aliveBots as $bot){ + $i = $bot->playerIndex; //because $i is shorter + + $bodyRequestArr[$i] = array( 'game-id' => "".$this->gameId, 'action' => 'play-turn', 'game' => 'tron', 'board' => $board, - 'player-index' => $botCount, // To do: verifier que ça restera le même à chaque tour + 'player-index' => $i, 'players' => $nbeBots ); - } + $data_string = json_encode($bodyRequestArr[$i]); + $ch[$i] = curl_init($bot->url); + curl_setopt($ch[$i], CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($ch[$i], CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch[$i], CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch[$i], CURLOPT_POSTFIELDS, $data_string); + curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch[$i], CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($data_string)) + ); + curl_multi_add_handle($cmh,$ch[$i]); } - - $responses = $this->get_multi_IAS_Responses($urls,$paramsToSend); - //grow bots'tails - for ($botCount = 0; $botCount < $nbeBots; $botCount++){ - if ($this->bots[$botCount]->isAlive){ + //send the requests + do { + $returnVal = curl_multi_exec($cmh, $runningHandles); + }while($runningHandles > 0); + + //get results + foreach($ch as $playerIndex=>$cr){ + $currentBot = $this->getBotByPlayerIndex($playerIndex); + + // Check for errors + $curlError = curl_error($cr); + $response = curl_multi_getcontent($cr); - if(!$dir = Direction::make($responses[$botCount]['responseArr']['play'])){ - //he loses , non conform response - $scoring-> addLoser($botCount,$this->bots[$botCount]->id); - $this->bots[$botCount]->loose(); - }else{ + if($curlError !== "") { + //erreur curl, he loses + $scoreObj-> addLoser($currentBot); + $currentBot->loose(); + + }elseif(! $arr = json_decode($response,TRUE)){ + //la reponse n'est pas un json, il a perdu + $scoreObj-> addLoser($currentBot); + $currentBot->loose(); - $lastsCells[$botCount] = $this->bots[$botCount]->grow($dir); - - if($lastsCells[$botCount] === false){ - //$loosers[] = $botCount; - $scoring-> addLoser($botCount,$this->bots[$botCount]->id); - $this->bots[$botCount]->loose(); - } - - } + }elseif(Direction::make($arr['play']) === false){ + //tester ici la réponse + //he loose il utilise probablement une de ses propres cases + $scoreObj-> addLoser($currentBot); + $currentBot->loose(); + }elseif($initialMapAsATrail->contains($currentBot->trail->last()->addDirection(Direction::make($arr['play'])))){ //ounch + //le bot tente d'aller sur une case qui était prise au début du round + $scoreObj-> addLoser($currentBot); + $currentBot->loose(); + }else{ + //mettre de coté la direction du bot + $currentBot->nextDir = Direction::make($arr['play']); } + //close curl + curl_multi_remove_handle($cmh, $cr); + curl_close($cr); + } - //test if loose - for ($botCount = 0; $botCount < $nbeBots; $botCount++){ - if ($this->bots[$botCount]->isAlive){ - - //tester si collusion avec les cases actuelles - for( $botCount2 = 0; $botCount2 < $nbeBots; $botCount2++){ - if(($botCount <> $botCount2) - && ($this->bots[$botCount2]->trail->contains($lastsCells[$botCount])) - ){ - - $scoring-> addLoser($botCount,$this->bots[$botCount]->id); - $this->bots[$botCount]->loose(); - break; - } + + $aliveBots = $this->getAliveBots(); + //pour tous les bots encore vivants, on teste si deux d'entre eux ne cibleraient pas la même case + foreach ($aliveBots as $bot1){ + foreach ($aliveBots as $bot2){ + if($bot1-> $playerIndex == $bot2-> $playerIndex) continue; + if($bot1->trail->last()->addDirection($bot1->nextDir) == $bot2->trail->last()->addDirection($bot2->nextDir)){ + //he loose + $scoreObj-> addLoser($bot1); + $bot1->loose(); + break; } } } - //$this->apply_looses($loosersList); + //ok, faire grossir les bots qui restent + foreach($this->getAliveBots() as $bot){ + $bot-> applyNextDir(); + } + + //apply scores: + $scoreObj-> ApplyScores(); + return array( 'last_points' => $this->get_lasts_trails(), - 'loosers' => $scoring->getLoosersList() + 'loosers' => $scoreObj->getLoosersList() ); } + + + private function get_multi_IAS_Responses($iasUrls, $postParams){ + //bug here le resultat retourné ne prend pas les bots ayant déjà perdus + + //same as the get_IAS_Responses function // but more than one bot requested parallely @@ -158,7 +231,7 @@ class TronGame } $res[$i] = array( 'messageSend' => json_encode($postParams[$i]), - 'response' => $response, + 'response' => $response, 'httpStatus' => curl_getinfo($ch[$i])['http_code'], 'responseArr' => $arr ); @@ -222,7 +295,7 @@ class TronGame $startCoord = new Coords($x,$y); $this->bots[$botCount] = new TronPlayer(); - $this->bots[$botCount]->make($bot['id'],$startCoord,$bot['name'],$bot['url']); + $this->bots[$botCount]->make($bot['id'],$startCoord,$bot['name'],$bot['url'],$botCount); if ($this->bots[$botCount]->isAlive === false){ $err .= "Something went wrong for ".$this->bots[$botCount]->getName()."
      "; diff --git a/src/arenas/tron/TronPlayer.php b/src/arenas/tron/TronPlayer.php index de123e1..8949332 100755 --- a/src/arenas/tron/TronPlayer.php +++ b/src/arenas/tron/TronPlayer.php @@ -4,12 +4,14 @@ class TronPlayer{ public $id; public $name; public $trail; - private $direction; public $isAlive = true; + public $playerIndex = -1; //if unset is -1 + public $looseCause = ""; + public $nextDir; public function grow(Direction $dir){ $dest = $this->trail->last()->addDirection($dir); - if($dest == false){ + if($dest === false){ $this->loose(); return false; } @@ -17,19 +19,25 @@ class TronPlayer{ $this->trail->add($this->trail->last()->addDirection($dir)); return $this->trail->last(); } + + public function applyNextDir(){ + $this-> grow($this->nextDir); + } + public function loose(){ $this->isAlive = false; $this->trail->emptyTrail(); //error_log($this->name." a perdu"); return false; } - public function make($botId, Coords $initialsCoords,$name,$url){ + public function make($botId, Coords $initialsCoords,$name,$url,$playerIndex = -1){ $this->id = $botId; $this->trail = new Trail; $this->trail->add($initialsCoords); $this->name = $name; $this->url = $url; $this->state = true; + $this->playerIndex = $playerIndex; } public function __construct(){ $this->state = false; diff --git a/src/arenas/tron/functions.php b/src/arenas/tron/functions.php index 0705b1d..b3d9bbc 100755 --- a/src/arenas/tron/functions.php +++ b/src/arenas/tron/functions.php @@ -1,5 +1 @@ Date: Tue, 8 Nov 2016 19:27:55 +0100 Subject: [PATCH 138/144] Scoring --- countBattles.txt | 2 +- src/DUEL.php | 80 +++++++++++++++++++++++ src/arenas/tron/ScoreLap.php | 16 +++-- src/arenas/tron/Trail.php | 13 +++- src/arenas/tron/TronGame.php | 85 +++++------------------- src/arenas/tron/doc-fr.html | 2 +- src/functions.php | 123 ++++++++++++++--------------------- 7 files changed, 167 insertions(+), 154 deletions(-) create mode 100644 src/DUEL.php diff --git a/countBattles.txt b/countBattles.txt index e6d1b72..e6ad4d7 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1747 \ No newline at end of file +1784 \ No newline at end of file diff --git a/src/DUEL.php b/src/DUEL.php new file mode 100644 index 0000000..0b158c5 --- /dev/null +++ b/src/DUEL.php @@ -0,0 +1,80 @@ +rank1 = $r1; + $this->rank2 = $r2; + } + private function get_k($rank){ + if ($rank < 1000) return 80; + if ($rank < 2000) return 50; + if ($rank <= 2400) return 30; + return 20; + } + private function changeScores($score){ + $this->rank1 = $this->rank1 + $this->get_k($this->rank1) * ($score - (1/ (1 + pow(10,(($this->rank2 - $this->rank1) / $this->factor))))); + $this->rank2 = $this->rank2 + $this->get_k($this->rank2) * (1 - $score - (1/ (1 + pow(10,(($this->rank1 - $this->rank2) / $this->factor))))); + } + + public function oneWinsAgainstTwo(){ + $this->changeScores(1); + } + public function twoWinsAgainstOne(){ + $this->changeScores(0); + } + public function drawGame(){ + $this->changeScores(0.5); + } +} + + + + + + + + + + + +class ELO +{ + public $rank = 1500; //default rank + + public function __construct($v=1500) { + $this->rank = $v; + } + + private function ELO_get_new_ranks($elo1,$elo2,$score){ + /* + * return an array containing new ELO scores after a battle + * $score : 0 player 2 won + * 0.5 draws + * 1 player 1 won + */ + + //good luck for understanding it + //(see https://blog.antoine-augusti.fr/2012/06/maths-et-code-le-classement-elo/) + return array( + $elo1 + ELO_get_k($elo1) * ($score - (1/ (1 + pow(10,(($elo2 - $elo1) / 400))))), + $elo2 + ELO_get_k($elo2) * (1 - $score - (1/ (1 + pow(10,(($elo1 - $elo2) / 400))))) + ); + } + + + + public function looseAgainst(ELO $winer){ + + } + public function winAgainst(ELO $looser){ + + } + public function drawAgainst(ELO $drawPlayer){ + + } + +} diff --git a/src/arenas/tron/ScoreLap.php b/src/arenas/tron/ScoreLap.php index a529252..eb6f7a2 100644 --- a/src/arenas/tron/ScoreLap.php +++ b/src/arenas/tron/ScoreLap.php @@ -20,16 +20,22 @@ class ScoreLap } public function getLoosersList(){ - return $this->$loosers; + //return losers as a digest array + $arr = array(); + + foreach($this->loosers as $looser){ + $arr[] = array("id" => $looser->id,"order" => $looser->playerIndex); + } + return $arr; } private function ApplyDraws(){ //apply draw match to all losers - if(count($this->looserList) < 2) return; + if(count($this->loosers) < 2) return; - foreach($loosers as $$looser1){ - foreach($loosers as $looser2){ + foreach($this->loosers as $looser1){ + foreach($this->loosers as $looser2){ if($looser1->playerIndex == $looser2->playerIndex) continue; save_battle('tron', $looser1->id, $looser2->id, 0, 'id' ); } @@ -41,7 +47,7 @@ class ScoreLap //need to make losers List. simply array of orders $loosersIndexArr = array(); - foreach($this->looserList as $looser){ + foreach($this->loosers as $looser){ $loosersIndexArr[] = $looser->playerIndex; } foreach($this->loosers as $looser){ diff --git a/src/arenas/tron/Trail.php b/src/arenas/tron/Trail.php index 9740d18..17604d0 100755 --- a/src/arenas/tron/Trail.php +++ b/src/arenas/tron/Trail.php @@ -18,11 +18,18 @@ class Trail { public function emptyTrail(){ $this->trail = new SplStack(); } + public function getTrail(){ + return $this->trail; + } public function mergeWith($trailToMerge){ - foreach($trailToMerge as $value) { - $this->trail->add($value); + if($trailToMerge->getTrail()->isEmpty()) return; + + foreach($trailToMerge->getTrail() as $value) { + $this->trail->push($value); } + } + public function add($value) { if(!$this->trail->isEmpty()) { if(Trail::kind($this->trail->bottom()) !== Trail::kind($value)) { @@ -42,7 +49,7 @@ class Trail { public function __toString(){ return json_encode($this->getTrailAsArray()); } - + public function getTrailAsArray(){ $arr = array(); foreach($this->trail as $coord) { diff --git a/src/arenas/tron/TronGame.php b/src/arenas/tron/TronGame.php index 0d55fb6..f49905e 100755 --- a/src/arenas/tron/TronGame.php +++ b/src/arenas/tron/TronGame.php @@ -48,14 +48,16 @@ class TronGame foreach($this->bots as $bot){ $trailsArr[] = $bot->trail->getTrailAsArray(); } + //error_log("*********".json_encode($trailsArr,true)."********"); return $trailsArr; + } private function get_map_as_an_unique_trail(){ $trail = new Trail; foreach($this->bots as $bot){ $trail->mergeWith($bot->trail); } - return trail; + return $trail; } public function get_lasts_trails(){ @@ -125,24 +127,33 @@ class TronGame $response = curl_multi_getcontent($cr); if($curlError !== "") { + //erreur curl, he loses $scoreObj-> addLoser($currentBot); $currentBot->loose(); - + error_log("no curl response".$playerIndex); //debug + }elseif(! $arr = json_decode($response,TRUE)){ + //la reponse n'est pas un json, il a perdu $scoreObj-> addLoser($currentBot); $currentBot->loose(); + error_log("la reponse est pas JSON".$playerIndex); //debug }elseif(Direction::make($arr['play']) === false){ + //tester ici la réponse //he loose il utilise probablement une de ses propres cases $scoreObj-> addLoser($currentBot); $currentBot->loose(); + error_log("La reponse ne contient pas une direction".$playerIndex); //debug + }elseif($initialMapAsATrail->contains($currentBot->trail->last()->addDirection(Direction::make($arr['play'])))){ //ounch + //le bot tente d'aller sur une case qui était prise au début du round $scoreObj-> addLoser($currentBot); $currentBot->loose(); + error_log("Il joue sur une case deja prise".$playerIndex); //debug }else{ //mettre de coté la direction du bot $currentBot->nextDir = Direction::make($arr['play']); @@ -157,7 +168,7 @@ class TronGame //pour tous les bots encore vivants, on teste si deux d'entre eux ne cibleraient pas la même case foreach ($aliveBots as $bot1){ foreach ($aliveBots as $bot2){ - if($bot1-> $playerIndex == $bot2-> $playerIndex) continue; + if($bot1->playerIndex == $bot2->playerIndex) continue; if($bot1->trail->last()->addDirection($bot1->nextDir) == $bot2->trail->last()->addDirection($bot2->nextDir)){ //he loose $scoreObj-> addLoser($bot1); @@ -183,73 +194,7 @@ class TronGame - private function get_multi_IAS_Responses($iasUrls, $postParams){ - //bug here le resultat retourné ne prend pas les bots ayant déjà perdus - - - //same as the get_IAS_Responses function - // but more than one bot requested parallely - - $cmh = curl_multi_init(); - for ($i = 0; $i < count($iasUrls); $i++){ - if(isset($postParams[$i])){ //dont use already deads bots - $data_string = json_encode($postParams[$i]); - - //error_log($data_string); - - $ch[$i] = curl_init($iasUrls[$i]); - curl_setopt($ch[$i], CURLOPT_CUSTOMREQUEST, "POST"); - curl_setopt($ch[$i], CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($ch[$i], CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch[$i], CURLOPT_POSTFIELDS, $data_string); - curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch[$i], CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($data_string)) - ); - curl_multi_add_handle($cmh,$ch[$i]); - } - } - - //send the requests - do { - $returnVal = curl_multi_exec($cmh, $runningHandles); - }while($runningHandles > 0); - - - //Get results - - for ($i = 0; $i < count($iasUrls); $i++){ - - if(isset($postParams[$i])){ - // Check for errors - $curlError = curl_error($ch[$i]); - if($curlError == "") { - $response = curl_multi_getcontent($ch[$i]); - if(! $arr = json_decode($response,TRUE)){ - $arr=array(); - } - $res[$i] = array( - 'messageSend' => json_encode($postParams[$i]), - 'response' => $response, - 'httpStatus' => curl_getinfo($ch[$i])['http_code'], - 'responseArr' => $arr - ); - - }else{ - $res[$i] = false; - } - //close - curl_multi_remove_handle($cmh, $ch[$i]); - curl_close($ch[$i]); - - } - - } - // Clean up the curl_multi handle - curl_multi_close($cmh); - return $res; - } + public function init_game(){ //send init messages to bots diff --git a/src/arenas/tron/doc-fr.html b/src/arenas/tron/doc-fr.html index 1170785..d821de8 100755 --- a/src/arenas/tron/doc-fr.html +++ b/src/arenas/tron/doc-fr.html @@ -141,7 +141,7 @@ Les champs qui différent sont:   ]

      L'ordre des "queues" des serpents dans ce tableau correspond à l'ordre des joueurs. Donc votre serpent est representée par la queue correspondant à player-index (le décompte de player-index commence par 0).

      -

      L'ordre des couples de coordonnées de chaque bot, est dans le sens queue vers la tête. Les bots grandissent à chaque tour en déplaçant leur tête.

      +

      L'ordre des couples de coordonnées de chaque bot, est dans le sens tête vers queue. Les bots grandissent à chaque tour en déplaçant leur tête.

      Scoring

      Le scorring (classement EHLO) reste sur une logique de duels, bien que ce jeu puisse contenir plus de deux bots par match. Le score est modifié au fur et à mesure de la partie à chaque fois qu'un bot "décède":

        diff --git a/src/functions.php b/src/functions.php index 3c44b40..da9153e 100755 --- a/src/functions.php +++ b/src/functions.php @@ -9,6 +9,7 @@ # http://www.gnu.org/licenses/gpl-3.0-standalone.html # # -- END LICENSE BLOCK ----------------------------------------- +include(__DIR__."/DUEL.php"); function get_arenas_list(){ include (__DIR__."/arenas_lists.php"); @@ -203,99 +204,73 @@ function ELO_get_podium($arena){ } return $podium; } -function ELO_get_k($elo){ - if ($elo < 1000){ - return 80; - } - if ($elo < 2000){ - return 50; - } - if ($elo <= 2400){ - return 30; - } - return 20; -} -function ELO_get_new_ranks($elo1,$elo2,$score){ - /* - * return an array containing new ELO scores after a battle - * $score : 0 player 2 won - * 0.5 draws - * 1 player 1 won - */ - - //good luck for understanding it - //(see https://blog.antoine-augusti.fr/2012/06/maths-et-code-le-classement-elo/) - return array( - $elo1 + ELO_get_k($elo1) * ($score - (1/ (1 + pow(10,(($elo2 - $elo1) / 400))))), - $elo2 + ELO_get_k($elo2) * (1 - $score - (1/ (1 + pow(10,(($elo1 - $elo2) / 400))))) - ); -} -function save_battle($game,$bot1,$bot2,$resultat,$nameOrIds = 'name'){ - //$bots1 and $bots2 are bots'names - //resultat: 0 match nul, 1 bot1 gagne 2 bot 2 gagne +function save_battle($game,$bot1,$bot2,$result,$nameOrIds = 'name'){ + /* + * Calculate new ELO ranks and save them on conn_bdd + */ + global $lnMysql; $game=substr($game,0,8); //limit 8 char for limitting mysql index size - - if($nameOrIds == "name"){ - //chercher les id de bot 1 et bot2 - $rs=mysqli_query($lnMysql,"SELECT name,id,ELO FROM bots - WHERE name='".mysqli_real_escape_string($lnMysql,$bot1)."' - OR name='".mysqli_real_escape_string($lnMysql,$bot2)."'"); + + if($nameOrIds == "name"){ + for( $i=1; $i<3; $i++){ + $str = "bot".$i; + $botName = $$str; + $rs=mysqli_query($lnMysql,"SELECT id,ELO FROM bots WHERE name='".mysqli_real_escape_string($lnMysql,$botName)."'"); + $r = mysqli_fetch_row($rs); + $bot[$i] = array( + 'id' => $r[0], + 'ELO' => $r[1] + ); + } }else{ - $rs = mysqli_query($lnMysql, "SELECT name,id,ELO FROM bots - WHERE id='".mysqli_real_escape_string($lnMysql,$bot1)."' - OR id='".mysqli_real_escape_string($lnMysql,$bot2)."'"); - } - while($r=mysqli_fetch_row($rs)){ - $bots[$r[0]]=$r[1]; - $actualELO[$r[0]]=$r[2]; + //the same, but query by id + for( $i=1; $i<3; $i++){ + $str = "bot".$i; + $botName = $$str; + $rs=mysqli_query($lnMysql,"SELECT id,ELO FROM bots WHERE id='".mysqli_real_escape_string($lnMysql,$botName)."'"); + $r = mysqli_fetch_row($rs); + $bot[$i] = array( + 'id' => $r[0], + 'ELO' => $r[1] + ); + } } - if((!isset($bots[$bot1])) OR (!isset($bots[$bot2]))){ - error (500,"database corrupt"); - die; - } - - switch($resultat){ + //apply $result + $duel = new DUEL( $bot[1]["ELO"] , $bot[2]["ELO"]); + + switch ($result){ case 0: + $duel->drawGame(); $field="nulCount"; - $eloScore = 0.5; break; case 1: - $field="player1_winsCount"; - $eloScore = 1; + $duel->oneWinsAgainstTwo(); + $field="player1_winsCount"; break; case 2: - $field="player2_winsCount"; - $eloScore = 0; - break; + $duel->twoWinsAgainstOne(); + $field="player2_winsCount"; + break; default: - error (500,"something impossible has happened"); + error (500,"Oups"); break; } - $newRanks = ELO_get_new_ranks($actualELO[$bot1],$actualELO[$bot2],$eloScore); - - mysqli_multi_query($lnMysql, - " - UPDATE bots - SET ELO='".$newRanks[0]."' - WHERE id='".$bots[$bot1]."'; - - UPDATE bots - SET ELO='".$newRanks[1]."' - WHERE id='".$bots[$bot2]."'; - - - INSERT INTO arena_history(game,player1_id,player2_id,".$field.") VALUES + //update ELO rank on database + mysqli_multi_query($lnMysql," + UPDATE bots SET ELO = '".$duel->rank1."' WHERE id='".$bot[1]["id"]."'; + UPDATE bots SET ELO = '".$duel->rank2."' WHERE id='".$bot[2]["id"]."'; + INSERT INTO arena_history(game,player1_id,player2_id,".$field.") VALUES ('".mysqli_real_escape_string($lnMysql,$game)."', - '".$bots[$bot1]."', - '".$bots[$bot2]."', + '".$bot[1]["id"]."', + '".$bot[2]["id"]."', '1') - ON DUPLICATE KEY UPDATE ".$field." = ".$field." + 1;"); - + ON DUPLICATE KEY UPDATE ".$field." = ".$field." + 1; + "); } function get_unique_id(){ //increment the number From 79e3054c85a1d8a991112224399d635283a49d39 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 10 Nov 2016 21:33:13 +0100 Subject: [PATCH 139/144] . --- countBattles.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/countBattles.txt b/countBattles.txt index e6ad4d7..e0ae305 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1784 \ No newline at end of file +1790 \ No newline at end of file From 15da3fd2ccc20b2ce99bcf76843ee904b4a72342 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 15 Nov 2016 18:54:27 +0100 Subject: [PATCH 140/144] orthographe dans la doc --- countBattles.txt | 2 +- src/arenas/tron/doc-en.html | 151 ++++++++++++++++++++++++++++++++++++ src/arenas/tron/doc-fr.html | 28 +++---- 3 files changed, 166 insertions(+), 15 deletions(-) diff --git a/countBattles.txt b/countBattles.txt index e0ae305..d870964 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1790 \ No newline at end of file +1822 \ No newline at end of file diff --git a/src/arenas/tron/doc-en.html b/src/arenas/tron/doc-en.html index e69de29..200a99c 100755 --- a/src/arenas/tron/doc-en.html +++ b/src/arenas/tron/doc-en.html @@ -0,0 +1,151 @@ +

        Fonctionnement des combats de Tron

        +

        Règles du jeu (hors specs techniques)

        +

        Chaque bot démarre depuis une case choisie au hasard par l'arène.

        +

        A chaque tour, il est demandé aux bots de grandir d'une case. Il peut choisir la direction. Sa queue s'allonge.

        +

        Si un bot percute une case déjà prise par sa queue ou celle d'un autre, il perd.

        +

        Ce n'est pas du tour par tour, les bots jouent simultanément, ils peuvent donc perdre en choisissant la même case de destination qu'un autre serpent

        +

        Exemple:

        + + + + + + + + + + + +
        9
        8
        7
        6
        5
        4oOoO
        3
        2
        1
        0123456789
        +

        Si dans le même tour le serpent vert et le serpent rouge décident d'aller respectivement vers la gauche et vers la droite, ils vont se télescoper et perdre tous les deux.

        + + + + + + + + + + + +
        9
        8
        7
        6
        5
        4): :(
        3
        2
        1
        0123456789
        +

        Lorsqu'un serpent meurt, (lorsqu'un bot perd) Sa queue est effacée et les cases prises par cette dernière deviennent libres pour les serpents encore en vie.

        +

        Le jeu prend fin lorsqu'il reste moins de deux serpents.

        +

        La grille

        +
          +
        • largeur: 1000 cases
        • +
        • hauteur: 1000 cases
        • +
        + +

        Communications entre l'arène et les bots

        +

        L'arène fait émet des requêtes http(s) à destination des bots.

        +
          +
        • Type: POST
        • +
        • informations: au format JSON dans le corps de la requetes
        • +
        + +

        Initialisation de la partie

        +

        L'arène (ce site) envoie le message (exemple) suivant à votre bot:

        +
        +{"game-id":"1679","action":"init","game":"tron","board":"","players":4,"player-index":2}
        +
        +
          +
        • game-id String Identifiant unique de la partie. Votre bot peut être emmené à jouer plusieurs parties en simultané. Si le fonctionnement de votre bot nécessite de suivre / conserver des valeurs entre deux tours de l'arène, cet identifiant vous sera utile.
        • +
        • action String, peut prendre les valeurs init ou play-turn, mais à cette étape, c'est init
        • +
        • game String, sera toujours "tron" ici. Peut vous servir si vous utilisez la même URL pour plusieurs bots.
        • +
        • board Sera vide à cette étape
        • +
        • players Entier Vous indique le nombre de joueurs sur cette partie. Il est possible que votre bot "joue" plusieurs joueurs. Et si vous les faisiez collaborer en ce cas là?
        • +
        • player-index Entier Le numéro de votre bot. Le premier bot a le numéro 0. Vous gardez le même numéro durant toute la partie, même si des joueurs sont déjà morts
        • +
        + +

        Votre bot doit répondre par un tableau au format json, comme ceci:

        +
        +{"name":"botName"}
        +
        +

        L'arène ne vérifie pas actuellement cette réponse, l'étape d'init a été insérée pour assurer la compatibilité avec Bolosseum. + Si votre bot repond une page blanche à cette étape (action=init), ça marchera dans le cadre de botsarena.

        + +

        Tours de jeu

        +

        Exemple de message envoyé par l'arène au premier tour de jeu:

        + +

        Exemple de message envoyé par l'arène après quelques tours de jeu:

        +
        +{"game-id":"1680","action":"play-turn","game":"tron","board":[[[687,110],[687,111],[686,111],[686,110],[686,109],[686,108],[686,107],[685,107],[685,108],[685,109],[684,109],[684,110],[684,111],[684,112],[684,113],[683,113],[682,113],[681,113],[681,114],[681,115],[681,116],[680,116],[680,117],[679,117],[679,116],[679,115],[679,114],[679,113],[679,112],[679,111],[679,110],[679,109],[678,109],[678,108],[677,108],[676,108],[676,107],[676,106],[676,105],[676,104],[676,103],[675,103],[674,103],[674,102],[673,102],[672,102],[672,101],[671,101],[670,101],[669,101],[669,102],[669,103],[669,104],[669,105],[669,106],[669,107],[668,107],[668,108],[668,109],[668,110],[668,111],[668,112],[667,112],[667,111],[667,110],[666,110],[666,109],[666,108],[665,108],[664,108],[664,107],[664,106],[663,106],[663,107],[663,108],[662,108],[661,108],[660,108],[660,107],[659,107],[659,106],[658,106],[657,106],[657,105],[657,104],[656,104],[656,103],[655,103],[655,102],[655,101],[654,101],[654,102],[654,103],[654,104],[653,104],[653,103],[653,102],[653,101],[653,100],[652,100],[651,100],[651,101],[651,102],[651,103],[651,104],[650,104],[650,105],[650,106],[649,106],[649,105],[648,105]],[[100,225],[100,226],[100,227],[100,228],[100,229],[100,230],[100,231],[99,231],[98,231],[98,232],[97,232],[96,232],[96,231],[96,230],[96,229],[96,228],[96,227],[96,226],[96,225],[96,224],[96,223],[95,223],[95,222],[94,222],[94,221],[94,220],[93,220],[92,220],[92,219],[92,218],[92,217],[92,216],[92,215],[91,215],[91,214],[90,214],[89,214],[89,213],[89,212],[88,212],[88,213],[88,214],[87,214],[87,213],[86,213],[86,214],[86,215],[85,215],[85,214],[84,214],[84,215],[83,215],[83,216],[83,217],[82,217],[82,216],[81,216],[81,215],[80,215],[80,216],[79,216],[79,215],[79,214],[78,214],[77,214],[77,213],[77,212],[76,212],[75,212],[75,211],[75,210],[75,209],[74,209],[74,210],[74,211],[73,211],[73,210],[72,210],[72,209],[71,209],[71,210],[70,210],[70,209],[69,209],[68,209],[68,210],[68,211],[67,211],[67,210],[67,209],[67,208],[66,208],[66,207],[66,206],[66,205],[66,204],[66,203],[65,203],[65,204],[64,204],[64,203],[63,203],[63,204],[63,205],[63,206],[62,206],[61,206],[61,207],[60,207],[60,208],[59,208]]],"player-index":0,"players":2}
        +
        +

        Les champs suivants sont les mêmes qu'au paragraphe précédent:

        +
          +
        • game-id
        • +
        • game
        • +
        • players
        • +
        • player-index
        • +
        + +Les champs qui différent sont: +
          +
        • actionString, est toujours "play-turn" à cette étape
        • +
        • boardJe vous explique ça au chapitre suivant.
        • +
        +

        La Carte (board)

        +

        Elle est représentée dans le champs "board" du JSON envoyé par l'arène. Elle décrit les cases prises par chaque joueur.

        +

        Elle est composée de plusieurs sous-arrays/sous-objets (en fonction de votre language de programmation). Elle se décompose en sous tableaux de la forme suivante:

        +

          +
        • Board: +
            +
          • Joueur 1 +
              +
            • Case1 +
                +
              • Coordonnée X
              • +
              • Coordonnée Y
              • +
              +
            • +
            • Case2 +
                +
              • coordonnée X
              • +
              • Coordonnée Y
              • +
              +
            • +
            +
          • +
          • Joueur 2> +
              +
            • Case1 +
                +
              • coordonnée X
              • +
              • Coordonnée Y
              • +
              +
            • +
            • Case2 +
                +
              • coordonnée X
              • +
              • Coordonnée Y
              • +
              +
            • +
            + +
          • +
          • ...
          • +
              + +
            +

            La représentation JSON est la suivante:

            + +

            +[
            +  [
            +    [x1,y1],[x2,y2],[x3,y3]
            +  ],
            +  [
            +    (...)
            +  ]
            +

            +

            L'ordre des "queues" des serpents dans ce tableau correspond à l'ordre des joueurs. Donc votre serpent est representée par la queue correspondant à player-index (le décompte de player-index commence par 0).

            +

            L'ordre des couples de coordonnées de chaque bot, est dans le sens tête vers queue. Les bots grandissent à chaque tour en déplaçant leur tête.

            +

            Scoring

            +

            Le scorring (classement EHLO) reste sur une logique de duels, bien que ce jeu puisse contenir plus de deux bots par match. Le score est modifié au fur et à mesure de la partie à chaque fois qu'un bot "décède":

            +
              +
            • Lors de la défaite d'un bot, l'arène enregistre un match nul contre tous les autres bots qui ont aussi perdu au même tour de jeu.
            • +
            • Elle enregistre aussi une défaite des bots morts contre tous les bots encore en course à la fin du tour.
            • +
            + diff --git a/src/arenas/tron/doc-fr.html b/src/arenas/tron/doc-fr.html index d821de8..200a99c 100755 --- a/src/arenas/tron/doc-fr.html +++ b/src/arenas/tron/doc-fr.html @@ -1,6 +1,6 @@

            Fonctionnement des combats de Tron

            Règles du jeu (hors specs techniques)

            -

            Chaque bot démarre depuis une case choisie au hazard par l'arène.

            +

            Chaque bot démarre depuis une case choisie au hasard par l'arène.

            A chaque tour, il est demandé aux bots de grandir d'une case. Il peut choisir la direction. Sa queue s'allonge.

            Si un bot percute une case déjà prise par sa queue ou celle d'un autre, il perd.

            Ce n'est pas du tour par tour, les bots jouent simultanément, ils peuvent donc perdre en choisissant la même case de destination qu'un autre serpent

            @@ -17,7 +17,7 @@ 1 0123456789 -

            Si dans le même tour le serpent vert et le serpent rouge décident d'aller respectivement vers la gauche et vers la droite, ils vont se télescopper et perdre tous les deux.

            +

            Si dans le même tour le serpent vert et le serpent rouge décident d'aller respectivement vers la gauche et vers la droite, ils vont se télescoper et perdre tous les deux.

            @@ -30,7 +30,7 @@
            9
            8
            1
            0123456789
            -

            Lorsqu'un serpent meurt, (lorsqu'un bot perd) Sa queue est effacée et les cases prises par cette dernière devienent libres pour les serpents encore en vie.

            +

            Lorsqu'un serpent meurt, (lorsqu'un bot perd) Sa queue est effacée et les cases prises par cette dernière deviennent libres pour les serpents encore en vie.

            Le jeu prend fin lorsqu'il reste moins de deux serpents.

            La grille

              @@ -39,7 +39,7 @@

            Communications entre l'arène et les bots

            -

            L'arène fait emet des requetes http(s) à destination des bots.

            +

            L'arène fait émet des requêtes http(s) à destination des bots.

            • Type: POST
            • informations: au format JSON dans le corps de la requetes
            • @@ -51,7 +51,7 @@ {"game-id":"1679","action":"init","game":"tron","board":"","players":4,"player-index":2}
                -
              • game-id String Identifiant unique de la partie. Votre bot peut être emmené à jouer plusieurs parties en simultané. Si le fonctionnement de votre bot nécessite de suivre / conserver des valeurs entre deux tours dfe l'arène, cet identifiant vous sera utile.
              • +
              • game-id String Identifiant unique de la partie. Votre bot peut être emmené à jouer plusieurs parties en simultané. Si le fonctionnement de votre bot nécessite de suivre / conserver des valeurs entre deux tours de l'arène, cet identifiant vous sera utile.
              • action String, peut prendre les valeurs init ou play-turn, mais à cette étape, c'est init
              • game String, sera toujours "tron" ici. Peut vous servir si vous utilisez la même URL pour plusieurs bots.
              • board Sera vide à cette étape
              • @@ -87,7 +87,7 @@ Les champs qui différent sont:
              • boardJe vous explique ça au chapitre suivant.

              La Carte (board)

              -

              Elle est repésentée dans le champs "board" du JSON envoyé par l'arène. Elle décrit les cases prises par chaque joueur.

              +

              Elle est représentée dans le champs "board" du JSON envoyé par l'arène. Elle décrit les cases prises par chaque joueur.

              Elle est composée de plusieurs sous-arrays/sous-objets (en fonction de votre language de programmation). Elle se décompose en sous tableaux de la forme suivante:

              • Board: @@ -96,14 +96,14 @@ Les champs qui différent sont:
                • Case1
                    -
                  • coordonée X
                  • -
                  • Coordonée Y
                  • +
                  • Coordonnée X
                  • +
                  • Coordonnée Y
                • Case2
                    -
                  • coordonée X
                  • -
                  • Coordonée Y
                  • +
                  • coordonnée X
                  • +
                  • Coordonnée Y
                @@ -112,14 +112,14 @@ Les champs qui différent sont:
                • Case1
                    -
                  • coordonée X
                  • -
                  • Coordonée Y
                  • +
                  • coordonnée X
                  • +
                  • Coordonnée Y
                • Case2
                    -
                  • coordonée X
                  • -
                  • Coordonée Y
                  • +
                  • coordonnée X
                  • +
                  • Coordonnée Y
                From 3758ab5866905bad0a40b54775a1cdfc4a1a444e Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 15 Nov 2016 19:18:39 +0100 Subject: [PATCH 141/144] . --- src/arenas/tron/doc-en.html | 20 ++++++++++++++++++++ src/arenas/tron/doc-fr.html | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/arenas/tron/doc-en.html b/src/arenas/tron/doc-en.html index 200a99c..eeeabe5 100755 --- a/src/arenas/tron/doc-en.html +++ b/src/arenas/tron/doc-en.html @@ -142,10 +142,30 @@ Les champs qui différent sont:

                L'ordre des "queues" des serpents dans ce tableau correspond à l'ordre des joueurs. Donc votre serpent est representée par la queue correspondant à player-index (le décompte de player-index commence par 0).

                L'ordre des couples de coordonnées de chaque bot, est dans le sens tête vers queue. Les bots grandissent à chaque tour en déplaçant leur tête.

                +

                La réponse de votre bot

                +

                Il retourne la direction qu'il souhaite prendre sous la forme d'un array.

                4 possibilités:

                + +
                +{"play":"x+"}
                +
                +
                +{"play":"x-"}
                +
                +
                +{"play":"y+"}
                +
                +
                +{"play":"y-"}
                +
                +

                La façon de noter les directions me semble assez explicite pour que je ne détaille pas.

                Scoring

                Le scorring (classement EHLO) reste sur une logique de duels, bien que ce jeu puisse contenir plus de deux bots par match. Le score est modifié au fur et à mesure de la partie à chaque fois qu'un bot "décède":

                • Lors de la défaite d'un bot, l'arène enregistre un match nul contre tous les autres bots qui ont aussi perdu au même tour de jeu.
                • Elle enregistre aussi une défaite des bots morts contre tous les bots encore en course à la fin du tour.
                +

                +

                Outils pour développer et tester votre bot

                +

                Malheureusement aucun outil pour le moment. Ca viendra dans les semaines qui viennent, peut être sous la forme d'une interface swagger

                +

                Et il faut aussi que je développe une AI moins stupide que stupid IA, car actuellement comme il se suicide trop vite, ça ne permet ni de tester l'arène ni un bot plus intelligent

                \ No newline at end of file diff --git a/src/arenas/tron/doc-fr.html b/src/arenas/tron/doc-fr.html index 200a99c..eeeabe5 100755 --- a/src/arenas/tron/doc-fr.html +++ b/src/arenas/tron/doc-fr.html @@ -142,10 +142,30 @@ Les champs qui différent sont:

                L'ordre des "queues" des serpents dans ce tableau correspond à l'ordre des joueurs. Donc votre serpent est representée par la queue correspondant à player-index (le décompte de player-index commence par 0).

                L'ordre des couples de coordonnées de chaque bot, est dans le sens tête vers queue. Les bots grandissent à chaque tour en déplaçant leur tête.

                +

                La réponse de votre bot

                +

                Il retourne la direction qu'il souhaite prendre sous la forme d'un array.

                4 possibilités:

                + +
                +{"play":"x+"}
                +
                +
                +{"play":"x-"}
                +
                +
                +{"play":"y+"}
                +
                +
                +{"play":"y-"}
                +
                +

                La façon de noter les directions me semble assez explicite pour que je ne détaille pas.

                Scoring

                Le scorring (classement EHLO) reste sur une logique de duels, bien que ce jeu puisse contenir plus de deux bots par match. Le score est modifié au fur et à mesure de la partie à chaque fois qu'un bot "décède":

                • Lors de la défaite d'un bot, l'arène enregistre un match nul contre tous les autres bots qui ont aussi perdu au même tour de jeu.
                • Elle enregistre aussi une défaite des bots morts contre tous les bots encore en course à la fin du tour.
                +

                +

                Outils pour développer et tester votre bot

                +

                Malheureusement aucun outil pour le moment. Ca viendra dans les semaines qui viennent, peut être sous la forme d'une interface swagger

                +

                Et il faut aussi que je développe une AI moins stupide que stupid IA, car actuellement comme il se suicide trop vite, ça ne permet ni de tester l'arène ni un bot plus intelligent

                \ No newline at end of file From aa35d1a2bb4a523ae3ceb763d153284eaee10dee Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 16 Nov 2016 19:19:50 +0100 Subject: [PATCH 142/144] en doc --- src/arenas/tron/doc-en.html | 140 ++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 68 deletions(-) diff --git a/src/arenas/tron/doc-en.html b/src/arenas/tron/doc-en.html index eeeabe5..f764fef 100755 --- a/src/arenas/tron/doc-en.html +++ b/src/arenas/tron/doc-en.html @@ -1,10 +1,10 @@ -

                Fonctionnement des combats de Tron

                -

                Règles du jeu (hors specs techniques)

                -

                Chaque bot démarre depuis une case choisie au hasard par l'arène.

                -

                A chaque tour, il est demandé aux bots de grandir d'une case. Il peut choisir la direction. Sa queue s'allonge.

                -

                Si un bot percute une case déjà prise par sa queue ou celle d'un autre, il perd.

                -

                Ce n'est pas du tour par tour, les bots jouent simultanément, ils peuvent donc perdre en choisissant la même case de destination qu'un autre serpent

                -

                Exemple:

                +

                How Tron Fights Works

                +

                Game's rules (excluding technical specs)

                +

                Each bot starts from a point randomly selected by the arena.

                +

                At each turn, bots are asked to grow one square. they can choose the direction.

                +

                If a bot strikes a cell already taken by its trail or that of another, it loses.

                +

                It is not turn-based, bots are playinig simultaneously, so they can lose by choosing the same destination cell as another snake.

                +

                Example:

                @@ -17,7 +17,7 @@
                9
                8
                1
                0123456789
                -

                Si dans le même tour le serpent vert et le serpent rouge décident d'aller respectivement vers la gauche et vers la droite, ils vont se télescoper et perdre tous les deux.

                +

                If in the same turn the green snake and the red snake decide to go respectively to the left and to the right, they will telescope and both will lose.

                @@ -30,96 +30,99 @@
                9
                8
                1
                0123456789
                -

                Lorsqu'un serpent meurt, (lorsqu'un bot perd) Sa queue est effacée et les cases prises par cette dernière deviennent libres pour les serpents encore en vie.

                -

                Le jeu prend fin lorsqu'il reste moins de deux serpents.

                -

                La grille

                +

                When a snake dies, (when a bot loses) its tail is erased and cells taken by it become free for snakes still alive.

                +

                The game ends when there are less than two snakes left

                +

                Grid

                  -
                • largeur: 1000 cases
                • -
                • hauteur: 1000 cases
                • +
                • width: 1000 cells
                • +
                • Height: 1000 cells
                -

                Communications entre l'arène et les bots

                -

                L'arène fait émet des requêtes http(s) à destination des bots.

                +

                Communications between the arena and the bots

                +

                The arena does send http (s) requests to the bots.

                • Type: POST
                • -
                • informations: au format JSON dans le corps de la requetes
                • +
                • in JSON format inside the query's body
                -

                Initialisation de la partie

                -

                L'arène (ce site) envoie le message (exemple) suivant à votre bot:

                +

                Initialization of the game

                +

                The arena (this site) sends the following exemple message to your bot:

                 {"game-id":"1679","action":"init","game":"tron","board":"","players":4,"player-index":2}
                 
                  -
                • game-id String Identifiant unique de la partie. Votre bot peut être emmené à jouer plusieurs parties en simultané. Si le fonctionnement de votre bot nécessite de suivre / conserver des valeurs entre deux tours de l'arène, cet identifiant vous sera utile.
                • -
                • action String, peut prendre les valeurs init ou play-turn, mais à cette étape, c'est init
                • -
                • game String, sera toujours "tron" ici. Peut vous servir si vous utilisez la même URL pour plusieurs bots.
                • -
                • board Sera vide à cette étape
                • -
                • players Entier Vous indique le nombre de joueurs sur cette partie. Il est possible que votre bot "joue" plusieurs joueurs. Et si vous les faisiez collaborer en ce cas là?
                • -
                • player-index Entier Le numéro de votre bot. Le premier bot a le numéro 0. Vous gardez le même numéro durant toute la partie, même si des joueurs sont déjà morts
                • +
                • game-id String The unique identifier of the game. Your bot can be led to play several parts simultaneously. If the functioning of your bot requires to keep data ​​between two turns of the arena, this identifier will be useful.
                • +
                • action String, can be "init" or "play-turn". For the current step, it's "init"
                • +
                • game String, Always "tron" here,can be usefull if you use the same URL to serve many bots
                • +
                • board Is empty at this step./li> +
                • players Intreger indicating how many bots are playing this game.Your bot can "play" several players on the same game. What if you had them collaborate in that case?
                • +
                • player-index Entier Your bot number. The first bot is player-index: 0. You'll keep the same number throughout the game, even if some others players are already dead.
                -

                Votre bot doit répondre par un tableau au format json, comme ceci:

                +

                Your bot must respond with an array in json format, like this:

                 {"name":"botName"}
                 
                -

                L'arène ne vérifie pas actuellement cette réponse, l'étape d'init a été insérée pour assurer la compatibilité avec Bolosseum. - Si votre bot repond une page blanche à cette étape (action=init), ça marchera dans le cadre de botsarena.

                - -

                Tours de jeu

                -

                Exemple de message envoyé par l'arène au premier tour de jeu:

                +

                +The arena does not currently verify this response, the init step has been inserted to ensure compatibility with Bolosseum. If your bot answers a blank page at this stage (action = init), it will work as part of botsarena. +

                -

                Exemple de message envoyé par l'arène après quelques tours de jeu:

                +

                Game's laps

                +

                Exemple of arena's message send on the first lap:

                + + +

                Exemple of arena's message send after some laps:

                 {"game-id":"1680","action":"play-turn","game":"tron","board":[[[687,110],[687,111],[686,111],[686,110],[686,109],[686,108],[686,107],[685,107],[685,108],[685,109],[684,109],[684,110],[684,111],[684,112],[684,113],[683,113],[682,113],[681,113],[681,114],[681,115],[681,116],[680,116],[680,117],[679,117],[679,116],[679,115],[679,114],[679,113],[679,112],[679,111],[679,110],[679,109],[678,109],[678,108],[677,108],[676,108],[676,107],[676,106],[676,105],[676,104],[676,103],[675,103],[674,103],[674,102],[673,102],[672,102],[672,101],[671,101],[670,101],[669,101],[669,102],[669,103],[669,104],[669,105],[669,106],[669,107],[668,107],[668,108],[668,109],[668,110],[668,111],[668,112],[667,112],[667,111],[667,110],[666,110],[666,109],[666,108],[665,108],[664,108],[664,107],[664,106],[663,106],[663,107],[663,108],[662,108],[661,108],[660,108],[660,107],[659,107],[659,106],[658,106],[657,106],[657,105],[657,104],[656,104],[656,103],[655,103],[655,102],[655,101],[654,101],[654,102],[654,103],[654,104],[653,104],[653,103],[653,102],[653,101],[653,100],[652,100],[651,100],[651,101],[651,102],[651,103],[651,104],[650,104],[650,105],[650,106],[649,106],[649,105],[648,105]],[[100,225],[100,226],[100,227],[100,228],[100,229],[100,230],[100,231],[99,231],[98,231],[98,232],[97,232],[96,232],[96,231],[96,230],[96,229],[96,228],[96,227],[96,226],[96,225],[96,224],[96,223],[95,223],[95,222],[94,222],[94,221],[94,220],[93,220],[92,220],[92,219],[92,218],[92,217],[92,216],[92,215],[91,215],[91,214],[90,214],[89,214],[89,213],[89,212],[88,212],[88,213],[88,214],[87,214],[87,213],[86,213],[86,214],[86,215],[85,215],[85,214],[84,214],[84,215],[83,215],[83,216],[83,217],[82,217],[82,216],[81,216],[81,215],[80,215],[80,216],[79,216],[79,215],[79,214],[78,214],[77,214],[77,213],[77,212],[76,212],[75,212],[75,211],[75,210],[75,209],[74,209],[74,210],[74,211],[73,211],[73,210],[72,210],[72,209],[71,209],[71,210],[70,210],[70,209],[69,209],[68,209],[68,210],[68,211],[67,211],[67,210],[67,209],[67,208],[66,208],[66,207],[66,206],[66,205],[66,204],[66,203],[65,203],[65,204],[64,204],[64,203],[63,203],[63,204],[63,205],[63,206],[62,206],[61,206],[61,207],[60,207],[60,208],[59,208]]],"player-index":0,"players":2}
                 
                -

                Les champs suivants sont les mêmes qu'au paragraphe précédent:

                +

                Following fields are as in the previous paragraph:

                • game-id
                • game
                • players
                • player-index
                - -Les champs qui différent sont: +

                Not same fields are:

                  -
                • actionString, est toujours "play-turn" à cette étape
                • -
                • boardJe vous explique ça au chapitre suivant.
                • +
                • actionString, always "play-turn" for this step.
                • +
                • boardA full chapter is needed ti explain that.
                -

                La Carte (board)

                -

                Elle est représentée dans le champs "board" du JSON envoyé par l'arène. Elle décrit les cases prises par chaque joueur.

                -

                Elle est composée de plusieurs sous-arrays/sous-objets (en fonction de votre language de programmation). Elle se décompose en sous tableaux de la forme suivante:

                +

                The map / the board

                +

                It is contained on "board" field. All the cells taken by each player are writted in.

                + +It is composed of several subarrays / subobjects (depending on your programming language). +the sub-tables haved the following form:
                • Board:
                    -
                  • Joueur 1 +
                  • Player 1
                      -
                    • Case1 +
                    • Cell 1
                        -
                      • Coordonnée X
                      • -
                      • Coordonnée Y
                      • +
                      • Coordinate X
                      • +
                      • Coordinate Y
                    • -
                    • Case2 +
                    • Cell2
                        -
                      • coordonnée X
                      • -
                      • Coordonnée Y
                      • +
                      • Coordinate X
                      • +
                      • Coordinate Y
                  • -
                  • Joueur 2> +
                  • Player 2>
                      -
                    • Case1 +
                    • Cell 1
                        -
                      • coordonnée X
                      • -
                      • Coordonnée Y
                      • +
                      • Coordinate X
                      • +
                      • Coordinate Y
                    • -
                    • Case2 +
                    • Cell 2
                        -
                      • coordonnée X
                      • -
                      • Coordonnée Y
                      • +
                      • Coordinate X
                      • +
                      • Coordinate Y
                    @@ -129,7 +132,7 @@ Les champs qui différent sont:
                    -

                    La représentation JSON est la suivante:

                    +

                    JSON form is as follows:

                    [
                    @@ -140,10 +143,11 @@ Les champs qui différent sont:     (...)
                      ]

                    -

                    L'ordre des "queues" des serpents dans ce tableau correspond à l'ordre des joueurs. Donc votre serpent est representée par la queue correspondant à player-index (le décompte de player-index commence par 0).

                    -

                    L'ordre des couples de coordonnées de chaque bot, est dans le sens tête vers queue. Les bots grandissent à chaque tour en déplaçant leur tête.

                    -

                    La réponse de votre bot

                    -

                    Il retourne la direction qu'il souhaite prendre sous la forme d'un array.

                    4 possibilités:

                    +

                    Trails'order on this table is the same as Player's order. So, your "snake" has the trail corresponding with player-index. (First player-index value is 0).

                    +

                    coordinate's are from the head to the trail. Bots grow by moving their heads.

                    + +

                    Bot's awnser

                    +

                    It returns direction it wants on a JSON array.

                    4 possibilies:

                     {"play":"x+"}
                    @@ -157,15 +161,15 @@ Les champs qui différent sont:
                     
                     {"play":"y-"}
                     
                    -

                    La façon de noter les directions me semble assez explicite pour que je ne détaille pas.

                    +

                    The way to note the directions seems fairly explicit for me to not explain.

                    Scoring

                    -

                    Le scorring (classement EHLO) reste sur une logique de duels, bien que ce jeu puisse contenir plus de deux bots par match. Le score est modifié au fur et à mesure de la partie à chaque fois qu'un bot "décède":

                    -
                      -
                    • Lors de la défaite d'un bot, l'arène enregistre un match nul contre tous les autres bots qui ont aussi perdu au même tour de jeu.
                    • -
                    • Elle enregistre aussi une défaite des bots morts contre tous les bots encore en course à la fin du tour.
                    • -
                    -

                    +

                    The scoring (EHLO classification) remains on a logic of duels, although this game can contain more than two bots per game. The score is changed as the game happens each time a bot dies:

                    +
                      +
                    • During the defeat of a bot, the arena records a draw against all the other bots that also lost in the same round of play.
                    • +
                    • It also records a defeat of the dead bots against all the bots still in the race at the end of the round.
                    • +
                    -

                    Outils pour développer et tester votre bot

                    -

                    Malheureusement aucun outil pour le moment. Ca viendra dans les semaines qui viennent, peut être sous la forme d'une interface swagger

                    -

                    Et il faut aussi que je développe une AI moins stupide que stupid IA, car actuellement comme il se suicide trop vite, ça ne permet ni de tester l'arène ni un bot plus intelligent

                    \ No newline at end of file +

                    Tools to develop and test your bot

                    +

                    Unfortunately no tools yet. It will come in the weeks to come, maybe in the form of a swagger interface

                    +

                    And I must also develop an AI less stupid than stupid IA, because currently as it commits suicide too fast, it does not allow to test the arena nor a more intelligent bot.

                    +ent

                    \ No newline at end of file From 5173d10fe4dc0963ba30a62c83b9ee247ecd9639 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 16 Nov 2016 19:26:49 +0100 Subject: [PATCH 143/144] en doc --- countBattles.txt | 2 +- src/arenas/tron/public.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/countBattles.txt b/countBattles.txt index d870964..688e608 100755 --- a/countBattles.txt +++ b/countBattles.txt @@ -1 +1 @@ -1822 \ No newline at end of file +1825 \ No newline at end of file diff --git a/src/arenas/tron/public.php b/src/arenas/tron/public.php index 7479ade..671c790 100755 --- a/src/arenas/tron/public.php +++ b/src/arenas/tron/public.php @@ -18,6 +18,7 @@ foreach($bots as $bot){ } ?>
                    +

                    Cette arène n'est qu'à moitié ouverte. Elle fonctionne et la documentation est écrite, mais les outils pour vous aider à débogguer et tester un bot n'ont pas été créés. Ca viendra.