From f3cd4bd9f09dffeebc3c3234032be60478ca6bb3 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 9 Jun 2016 21:30:24 +0200 Subject: [PATCH 01/16] adapt database for ELO classement --- install.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/install.sql b/install.sql index c4bda2e..d4ccf65 100644 --- a/install.sql +++ b/install.sql @@ -29,9 +29,11 @@ CREATE TABLE IF NOT EXISTS `bots` ( `date_inscription` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `validate_secret` varchar(8) NOT NULL, `author_email` text NOT NULL, - PRIMARY KEY (`id`) + `ELO` int(11) NOT NULL DEFAULT '1500', + PRIMARY KEY (`id`) ); + -- -- Contenu de la table `bots` only stupid ias -- From 3f0bae6d071dd7412fc430c836f18a773cc397c7 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 9 Jun 2016 22:44:58 +0200 Subject: [PATCH 02/16] ELO --- src/functions.php | 51 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/src/functions.php b/src/functions.php index 8f4c669..9e1c61a 100644 --- a/src/functions.php +++ b/src/functions.php @@ -177,6 +177,34 @@ function get_battles_history($game){ } return $results; } + +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) * ($score - (1/ (1 + pow(10,(($elo1 - $elo2) / 400;))))) + ); +} function save_battle($game,$bot1,$bot2,$resultat){ //resultat: 0 match nul, 1 bot1 gagne 2 bot 2 gagne @@ -186,11 +214,12 @@ function save_battle($game,$bot1,$bot2,$resultat){ //chercher les id de bot 1 et bot2 - $rs=mysqli_query($lnMysql,"SELECT name,id FROM bots + $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)."'"); while($r=mysqli_fetch_row($rs)){ $bots[$r[0]]=$r[1]; + $actualELO[$r[0]]=$r[2]; } if((!isset($bots[$bot1])) OR (!isset($bots[$bot2]))){ @@ -201,25 +230,41 @@ function save_battle($game,$bot1,$bot2,$resultat){ switch($resultat){ case 0: $field="nulCount"; + $eloScore = 0.5; break; case 1: $field="player1_winsCount"; + $eloScore = 1; break; case 2: $field="player2_winsCount"; + $eloScore = 0; break; default: error (500,"something impossible has happened"); break; } - mysqli_query($lnMysql, - "INSERT INTO arena_history(game,player1_id,player2_id,".$field.") VALUES + $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 ('".mysqli_real_escape_string($lnMysql,$game)."', '".$bots[$bot1]."', '".$bots[$bot2]."', '1') ON DUPLICATE KEY UPDATE ".$field." = ".$field." + 1;"); + } function get_unique_id(){ From ad131a4345c97750226103b5b47445621c647d50 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 9 Jun 2016 22:48:52 +0200 Subject: [PATCH 03/16] ELO --- src/functions.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/functions.php b/src/functions.php index 9e1c61a..f5b8f97 100644 --- a/src/functions.php +++ b/src/functions.php @@ -246,7 +246,18 @@ function save_battle($game,$bot1,$bot2,$resultat){ } $newRanks = ELO_get_new_ranks($actualELO[$bot1],$actualELO[$bot2],$eloScore); - + + echo + " + UPDATE bots + SET ELO='".$newRanks[0]."' + WHERE id='".$bots[$bot1]."'; + + UPDATE bots + SET ELO='".$newRanks[1]."' + WHERE id='".$bots[$bot2]."';"; + + mysqli_multi_query($lnMysql, " UPDATE bots From 2c0ffbb0c53936158689ca14b96acddd83b221c0 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 9 Jun 2016 22:50:40 +0200 Subject: [PATCH 04/16] ELO --- src/functions.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/functions.php b/src/functions.php index f5b8f97..e7d656f 100644 --- a/src/functions.php +++ b/src/functions.php @@ -201,8 +201,8 @@ function ELO_get_new_ranks($elo1,$elo2,$score){ //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) * ($score - (1/ (1 + pow(10,(($elo1 - $elo2) / 400;))))) + $elo1 + ELO_get_k($elo1) * ($score - (1/ (1 + pow(10,(($elo2 - $elo1) / 400))))), + $elo2 + ELO_get_k($elo2) * ($score - (1/ (1 + pow(10,(($elo1 - $elo2) / 400))))) ); } function save_battle($game,$bot1,$bot2,$resultat){ @@ -246,18 +246,7 @@ function save_battle($game,$bot1,$bot2,$resultat){ } $newRanks = ELO_get_new_ranks($actualELO[$bot1],$actualELO[$bot2],$eloScore); - - echo - " - UPDATE bots - SET ELO='".$newRanks[0]."' - WHERE id='".$bots[$bot1]."'; - - UPDATE bots - SET ELO='".$newRanks[1]."' - WHERE id='".$bots[$bot2]."';"; - - + mysqli_multi_query($lnMysql, " UPDATE bots From f4ebd66f9d89f68f012e279dece12d440da3d301 Mon Sep 17 00:00:00 2001 From: gnieark Date: Thu, 9 Jun 2016 22:53:04 +0200 Subject: [PATCH 05/16] ELO --- src/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions.php b/src/functions.php index e7d656f..ff5528d 100644 --- a/src/functions.php +++ b/src/functions.php @@ -202,7 +202,7 @@ function ELO_get_new_ranks($elo1,$elo2,$score){ //(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) * ($score - (1/ (1 + pow(10,(($elo1 - $elo2) / 400))))) + $elo2 + ELO_get_k($elo2) * (1 - $score - (1/ (1 + pow(10,(($elo1 - $elo2) / 400))))) ); } function save_battle($game,$bot1,$bot2,$resultat){ From 307b2e00131b20cbb34f78c6f81e54382f804c18 Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 10 Jun 2016 00:21:57 +0200 Subject: [PATCH 06/16] ranks --- html/imgs/Bronze_Medal.svg | 236 ++++++++ html/imgs/Emoji_u1f4a9.svg | 55 ++ html/imgs/Gold_Medal.svg | 1151 ++++++++++++++++++++++++++++++++++++ html/imgs/Silver_Medal.svg | 227 +++++++ html/index.php | 26 + src/functions.php | 15 +- src/legals.html | 1 + 7 files changed, 1710 insertions(+), 1 deletion(-) create mode 100644 html/imgs/Bronze_Medal.svg create mode 100644 html/imgs/Emoji_u1f4a9.svg create mode 100644 html/imgs/Gold_Medal.svg create mode 100644 html/imgs/Silver_Medal.svg diff --git a/html/imgs/Bronze_Medal.svg b/html/imgs/Bronze_Medal.svg new file mode 100644 index 0000000..7465099 --- /dev/null +++ b/html/imgs/Bronze_Medal.svg @@ -0,0 +1,236 @@ + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/html/imgs/Emoji_u1f4a9.svg b/html/imgs/Emoji_u1f4a9.svg new file mode 100644 index 0000000..8c1b2e8 --- /dev/null +++ b/html/imgs/Emoji_u1f4a9.svg @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/html/imgs/Gold_Medal.svg b/html/imgs/Gold_Medal.svg new file mode 100644 index 0000000..c12f700 --- /dev/null +++ b/html/imgs/Gold_Medal.svg @@ -0,0 +1,1151 @@ + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/html/imgs/Silver_Medal.svg b/html/imgs/Silver_Medal.svg new file mode 100644 index 0000000..6764e2b --- /dev/null +++ b/html/imgs/Silver_Medal.svg @@ -0,0 +1,227 @@ + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/html/index.php b/html/index.php index 458ef89..b8ffa11 100644 --- a/html/index.php +++ b/html/index.php @@ -48,6 +48,32 @@ if(isset($_GET['arena'])){ $mainSectionScript="../src/arenas/".$currentArena."/public.php"; $asideSectionContent='

infos:

'.$lang['DEV-YOUR-OWN-BOT'].'
'.$lang['DOC_SPECS_LINKS'].'

Scores

'; + + $podium=ELO_get_podium($currentArena); + $count=0; + foreach($podium as $sc){ + $count++; + switch ($count){ + case 1: + $img= + break; + case 2: + + break; + + case 3: + + break; + default: + + break; + + + } + + + } + foreach($hist as $sc){ $asideSectionContent.='

'.$sc['bot1'].' VS '.$sc['bot2'].'

    diff --git a/src/functions.php b/src/functions.php index ff5528d..3e20f51 100644 --- a/src/functions.php +++ b/src/functions.php @@ -177,7 +177,20 @@ function get_battles_history($game){ } return $results; } - +function ELO_get_podium($arena){ + global $lnMysql; + $podium=array(); + $rs=mysqli_query($lnMysql,"SELECT id,name,description,ELO FROM bots WHERE game='".$arena."' AND active='1' ORDER BY ELO DESC, name"); + while($r = mysqli_fetch_row($rs)){ + $podium[]=array( + 'id' => $r[0], + 'name' => $r[1], + 'description' => $r[2], + 'ELO' => $r[3] + ); + } + return $podium; +} function ELO_get_k($elo){ if ($elo < 1000){ return 80; diff --git a/src/legals.html b/src/legals.html index f072ec7..026ea63 100644 --- a/src/legals.html +++ b/src/legals.html @@ -19,6 +19,7 @@

    Il intègre quelques morceaux de code tiers:

    GNU GENERAL PUBLIC LICENSE

    From 514a6590211f279fabf1a27ad67612f8562de898 Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 10 Jun 2016 00:23:35 +0200 Subject: [PATCH 07/16] ranks --- html/index.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/html/index.php b/html/index.php index b8ffa11..cefbefd 100644 --- a/html/index.php +++ b/html/index.php @@ -51,28 +51,29 @@ if(isset($_GET['arena'])){ $podium=ELO_get_podium($currentArena); $count=0; + echo '
      '; foreach($podium as $sc){ $count++; - switch ($count){ + switch $count{ case 1: - $img= + $img='Gold_Medal.svg'; break; case 2: - + $img='Silver_Medal.svg'; break; - case 3: - + $img='Bronze_Medal.svg'; break; default: - + $img='caca'; break; } - - + + echo '
    • '.$img.''.htmlentities($sc['name']).' ELO Rank: '.$sc['ELO'].'
    • '; } + echo '
    '; foreach($hist as $sc){ $asideSectionContent.='

    '.$sc['bot1'].' VS '.$sc['bot2'].'

    From 35dc419ce0a74b38e77724c884bb9068fefa9ef3 Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 10 Jun 2016 00:24:50 +0200 Subject: [PATCH 08/16] ranks --- html/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/html/index.php b/html/index.php index cefbefd..c20dcee 100644 --- a/html/index.php +++ b/html/index.php @@ -54,7 +54,8 @@ if(isset($_GET['arena'])){ echo '
      '; foreach($podium as $sc){ $count++; - switch $count{ + + switch($count){ case 1: $img='Gold_Medal.svg'; break; From f5d90f02a658ba11ea0ff1bda789cfbfaa539804 Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 10 Jun 2016 00:26:22 +0200 Subject: [PATCH 09/16] fix --- html/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/html/index.php b/html/index.php index c20dcee..9ace24d 100644 --- a/html/index.php +++ b/html/index.php @@ -51,7 +51,7 @@ if(isset($_GET['arena'])){ $podium=ELO_get_podium($currentArena); $count=0; - echo '
        '; + $asideSectionContent.=''; + $asideSectionContent.='
      '; foreach($hist as $sc){ $asideSectionContent.='

      '.$sc['bot1'].' VS '.$sc['bot2'].'

      From 4d476409aec020dbe073535efca7be6786fde7d5 Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 10 Jun 2016 00:28:30 +0200 Subject: [PATCH 10/16] css --- html/index.php | 4 ++-- html/style.css | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/html/index.php b/html/index.php index 9ace24d..3519857 100644 --- a/html/index.php +++ b/html/index.php @@ -72,9 +72,9 @@ if(isset($_GET['arena'])){ } - $asideSectionContent.='
    • '.$img.''.htmlentities($sc['name']).' ELO Rank: '.$sc['ELO'].'
    • '; + $asideSectionContent.='
    • '.$img.''.htmlentities($sc['name']).' ELO rank: '.$sc['ELO'].'
    • '; } - $asideSectionContent.='
    '; + $asideSectionContent.='

détail des matchs

'; foreach($hist as $sc){ $asideSectionContent.='

'.$sc['bot1'].' VS '.$sc['bot2'].'

diff --git a/html/style.css b/html/style.css index b6c1228..3bffe8a 100644 --- a/html/style.css +++ b/html/style.css @@ -104,6 +104,7 @@ pre{ border-left: 4px solid #CCC; padding-left: 8px; } +.podium li img {height: 50px;} @media screen and (max-width: 800px){ aside, article{display: block; width: 100%; border-right:none;} From 45b2118bf78b922804c3b5d3ce76a8ce3755d459 Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 10 Jun 2016 00:29:55 +0200 Subject: [PATCH 11/16] css --- html/style.css | 1 + 1 file changed, 1 insertion(+) diff --git a/html/style.css b/html/style.css index 3bffe8a..55b3426 100644 --- a/html/style.css +++ b/html/style.css @@ -104,6 +104,7 @@ pre{ border-left: 4px solid #CCC; padding-left: 8px; } +.podium{list-style-type:none;} .podium li img {height: 50px;} @media screen and (max-width: 800px){ aside, article{display: block; width: 100%; border-right:none;} From eb14bf6c22d34d24bc986fe04f3572b32f292408 Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 10 Jun 2016 00:32:04 +0200 Subject: [PATCH 12/16] css --- html/style.css | 1 + 1 file changed, 1 insertion(+) diff --git a/html/style.css b/html/style.css index 55b3426..61b5a3a 100644 --- a/html/style.css +++ b/html/style.css @@ -105,6 +105,7 @@ pre{ padding-left: 8px; } .podium{list-style-type:none;} +.podium li{padding: 5px 20px 5px 0;} .podium li img {height: 50px;} @media screen and (max-width: 800px){ aside, article{display: block; width: 100%; border-right:none;} From bcf6a626cc6a6d6f57b28e9ffe2f34f6e7f0b3a8 Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 10 Jun 2016 00:32:33 +0200 Subject: [PATCH 13/16] css --- html/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/style.css b/html/style.css index 61b5a3a..d4bb67f 100644 --- a/html/style.css +++ b/html/style.css @@ -104,7 +104,7 @@ pre{ border-left: 4px solid #CCC; padding-left: 8px; } -.podium{list-style-type:none;} +.podium{list-style-type:none;padding: 5px 20px 5px 0;} .podium li{padding: 5px 20px 5px 0;} .podium li img {height: 50px;} @media screen and (max-width: 800px){ From 1bd1d8eb1b90c01ce28335f7f278af437d1e8f2e Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 10 Jun 2016 00:34:40 +0200 Subject: [PATCH 14/16] css --- html/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/style.css b/html/style.css index d4bb67f..73703e7 100644 --- a/html/style.css +++ b/html/style.css @@ -106,7 +106,7 @@ pre{ } .podium{list-style-type:none;padding: 5px 20px 5px 0;} .podium li{padding: 5px 20px 5px 0;} -.podium li img {height: 50px;} +.podium li img {height: 50px; vertical-align:middle;} @media screen and (max-width: 800px){ aside, article{display: block; width: 100%; border-right:none;} From d3777666aa4e8c56c751a54fe570ba7869361ae9 Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 10 Jun 2016 00:35:40 +0200 Subject: [PATCH 15/16] css --- html/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/index.php b/html/index.php index 3519857..1d82ec0 100644 --- a/html/index.php +++ b/html/index.php @@ -74,7 +74,7 @@ if(isset($_GET['arena'])){ $asideSectionContent.='
  • '.$img.''.htmlentities($sc['name']).' ELO rank: '.$sc['ELO'].'
  • '; } - $asideSectionContent.='

    détail des matchs

    '; + $asideSectionContent.='

    Détail des matchs

    '; foreach($hist as $sc){ $asideSectionContent.='

    '.$sc['bot1'].' VS '.$sc['bot2'].'

    From 0ac12efccc295d4a9ba5160cf9247f6a274a446e Mon Sep 17 00:00:00 2001 From: gnieark Date: Fri, 10 Jun 2016 00:36:12 +0200 Subject: [PATCH 16/16] css --- html/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/index.php b/html/index.php index 1d82ec0..0c1fca5 100644 --- a/html/index.php +++ b/html/index.php @@ -72,7 +72,7 @@ if(isset($_GET['arena'])){ } - $asideSectionContent.='
  • '.$img.''.htmlentities($sc['name']).' ELO rank: '.$sc['ELO'].'
  • '; + $asideSectionContent.='
  • '.$img.' '.htmlentities($sc['name']).' ELO rank: '.$sc['ELO'].'
  • '; } $asideSectionContent.='

    Détail des matchs

    ';