• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Glicko2 javascript implementation

Glicko 2 javascript implementation

Build Status

The Glicko-2 rating system is a method for assessing a player's strength in games of skill, such as chess and go. The algorithm is explained by its author, Mark E. Glickman, on http://glicko.net/glicko.html.

Each player begins with a rating, a rating deviation (accuracy of the rating) and a volatility (speed of rating evolution). These values will evolve according to the outcomes of matches with other players.

Usage

In the browser, you need to include the glicko2.js file :

<script src="glicko2.js"></script>

In node.js, just require the module :

var glicko2 = require('glicko2');

First we initiate a ranking manager and create players with initial ratings, rating deviations and volatilities.

var settings = {
  // tau : "Reasonable choices are between 0.3 and 1.2, though the system should
  //      be tested to decide which value results in greatest predictive accuracy."
  tau : 0.5,
  // rating : default rating
  rating : 1500,
  //rd : Default rating deviation 
  //     small number = good confidence on the rating accuracy
  rd : 200,
  //vol : Default volatility (expected fluctation on the player rating)
  vol : 0.06
};
var ranking = new glicko2.Glicko2(settings);

// Create players
var Ryan = ranking.makePlayer();
var Bob = ranking.makePlayer(1400, 30, 0.06);
var John = ranking.makePlayer(1550, 100, 0.06);
var Mary = ranking.makePlayer(1700, 300, 0.06);

We can then enter results, calculate the new ratings...

var matches = [];
matches.push([Ryan, Bob, 1]); //Ryan won over Bob
matches.push([Ryan, John, 0]); //Ryan lost against John
matches.push([Ryan, Mary, 0.5]); //A draw between Ryan and Mary
ranking.updateRatings(matches);

... and get these new ratings.

console.log("Ryan new rating: " + Ryan.getRating());
console.log("Ryan new rating deviation: " + Ryan.getRd());
console.log("Ryan new volatility: " + Ryan.getVol());

Get players list

var players = ranking.getPlayers();

Predict outcome

var expected = ranking.predict(Ryan, Bob); // or Ryan.predict(Bob);
console.log("Ryan has " + (expected * 100) + "% chances of winning against Bob in the next match");

When to update rankings

You should not update the ranking after each match. The typical use of glicko is to calculate the ratings after each tournament (ie collection of matches in a period of time). A player rating will evolve after a tournament has finished, but not during the tournament.

Here is what says Mark E. Glickman about the number of matches in a tournament or rating period (cf. http://www.glicko.net/glicko/glicko2.pdf ) :

The Glicko-2 system works best when the number of games in a rating period is moderate to large, say an average of at least 10-15 games per player in a rating period.

How to deal with a big database of players

If you don't want to load all the players and new matches at once in memory in order to update rankings, here is a strategy you can follow:

Say you want to update rankings each week, and you have a history of the rankings data (rating, rating deviation, volatility) for each player.

At the end of the week, for each player (even those that did not play):

  • load from the database:
    • the player ranking data for the current week
    • the matches the player has played during the week
    • for each match, the player's opponent data for the current week
  • add the player and his opponents to a new glicko instance
  • add the matches to the glicko instance
  • update glicko rankings
  • save the player updated ranking data to database as the next week player data

It is important to update rankings even for players that did not play : this is the way the system can increase their rating deviation over time.

At the last step, don't overwrite the player current week data, as it will be loaded when calculating its opponents new rankings.

Support for multiple competitors matches (experimental)

Note: the glicko2 algorithm was not designed for multiple competitors matches, this is a naive workaround whose results should be taken whith caution.

You can enter results from games where multiple competitors play against each other at the same time (ie swimming, racing...).

First make "Race" objects by entering the results in an array of "positions", where each position is an array of players at this position :

var race1 = glicko.makeRace(
    [
        [Ryan], //Ryan won the race
        [Bob, John], //Bob and John ended ex aequo at the 2nd position
        [Mary] // Mary 4th position
    ]
);

var race2 = glicko.makeRace(
    [
        [Mary], // won
        [Bob],  // 2nd
        [John], // 3rd
        [Ryan], // 4th
    ]
);

Then convert the races to the equivalent matches :

var matches1 = race1.getMatches();
var matches2 = race2.getMatches();

var allMatches = matches1.concat(matches2)

ranking.updateRatings(allMatches);

You can also update ratings for one race without converting to matches :

ranking.updateRatings(race1);

Installation

In the browser

You just need to include the glicko2.js script. See index.html in the example folder.

<script src="glicko2.js"></script>

With bower

$ bower install glicko2
<script src="bower_components/glicko2/glicko2.js"></script>

As a node.js module

glicko2.js is available as a npm module.

Install with:

$ npm install glicko2

More Repositories

1

Category-Theory-for-the-Sciences

ebook versions of the book "Category Theory for the Sciences" by David I. Spivak
HTML
112
star
2

Current_screen_only_on_window_switcher

Gnome extension - limits the windows shown on the switcher to those of the current monitor
JavaScript
63
star
3

vim-markdown-wiki

Vim plugin wich eases links manipulation and navigation in markdown pages
Vim Script
31
star
4

funkwhale-flake

A nix flake for the funkwhale music service
Nix
25
star
5

wikilink

Personal wiki link navigator
Vim Script
18
star
6

funkwhale-nixos

Funkwhale package and deployment for NixOS
Nix
16
star
7

vim-zenmode

zen mode vim plugin
Vim Script
10
star
8

pataphysical-date

A javascript library which convert Gregorian dates to the Pataphysical Calendar
JavaScript
9
star
9

bourcereau

technical website
HTML
7
star
10

phpnix

PHP Mysql Nginx development environment with Nix
PHP
7
star
11

slush-react

A slush generator to scaffold React apps with Fluxxor
JavaScript
7
star
12

scaphandre-flake

A nix flake for Scaphandre, the electrical power consumption metrology agent
Nix
5
star
13

guix-flake

A NixOS flake for Guix
Nix
4
star
14

chiensuperieur

JavaScript
4
star
15

vim-scrum-markdown

Vim plugin to manage a scrum dashboard inside vim
Vim Script
4
star
16

shiny-librarything

A shiny application using librarything data
R
3
star
17

cyclejs-sparklines

Sparklines component for Cycle.js
JavaScript
3
star
18

faustrollianae

A pataphysical bibliomancy web app on Alfred Jarry's Faustroll (cycle.js + material design lite)
JavaScript
2
star
19

jquery.apachetree

Get the content of an Apache Directory Index
JavaScript
2
star
20

bookwyrm-flake

A nixos flake for bookwyrm
Nix
2
star
21

leJeuDeTrictracRenduFacile

Transcription of a 1852 treatise on the game of Trictrac
Shell
2
star
22

github-upload

Ruby
2
star
23

reflex-brick-example

A small console application using reflex-brick
Haskell
1
star
24

kss-generator

Ruby
1
star
25

vim-markdownizer

Rust
1
star
26

proxapi

A helper for accessing quota limited APIs
JavaScript
1
star
27

giaffer

A web implementation of Ron Hale Evan's 'Integrate your Interests' mindhack
JavaScript
1
star
28

playlists

Music services playlist manager
JavaScript
1
star
29

dotfiles

My configuration files. Readme in .dotfiles/Readme.md
Shell
1
star
30

markdownizer

Rust
1
star
31

choix-liseuse-viewer

Un tableau récapitulatif des données utilisées dans l'outil de choix de liseuses ebook d'Eric Daspet
CSS
1
star