npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chessrating

v1.0.1

Published

TypeScript library for calculating Glicko2 rating

Downloads

23

Readme

chessrating

Description

chessrating is a TypeScript library designed to calculate, update, and manage chess(or other game) rating based on Glicko-2 rating system by Professor Mark E. Glickman. It is designed to provide more accurate ratings for players by taking into account not only their rating but also the rating's uncertainty (termed as rating deviation) and the system's volatility.

Installation

npm i chessrating

How to use

You can import all usable classes this way:

import { Player, Glicko2, Match, TournamentMatch, TournamentPlayer } from "chessrating";

You can initialize player with default values, if that player never had any game. You can also pass rating, ratingDeviation and volatility of player if you have executed rating calculation for this player before.

const player1 = new Player();
const player2 = new Player(1400, 30, 0.058);

This is recommended way to execute match between 2 players:

Glicko2.executeMatch(player1, player2, 1);

The last attribute called score can have one of those values: 0 | 0.5 | 1.

  • 1 means that player1 has won.
  • 0.5 means there was a tie.
  • 0 means player2 has won.

Glicko-2 rating system works best for tournaments when, single player played 10-15 matches. This is how you can execute tournament:

const player1 = new TournamentPlayer("Jim", 1500, 200);
const player2 = new TournamentPlayer("Michael", 1400, 30);
const player3 = new TournamentPlayer("Toby", 1550, 100);
const player4 = new TournamentPlayer("Dwight", 1700, 300);

const match1 = new TournamentMatch(player1, player2, 1);
const match2 = new TournamentMatch(player1, player3, 0);
const match3 = new TournamentMatch(player1, player4, 0);

Glicko2.executeTournament([match1, match2, match3]);

Both executeMatch and executeTournament will updates rating, ratingDeviation and volatility fields for each player according to played games. Those values should be saved and used whenever player plays another game.

You can also execute some matches only for one player:

const player1 = new Player(1500, 200, 0.06);
const player2 = new Player(1400, 30, 0.06);
const player3 = new Player(1550, 100, 0.06);
const player4 = new Player(1700, 300, 0.06);

const match1 = new Match(player2, 1);
const match2 = new Match(player3, 0);
const match3 = new Match(player4, 0);
player1.executeMatches([match1, match2, match3]);

Player

constructor attributes

  • rating: number = 1500
  • ratingDeviation: number = 350
  • volatility: number = 0.06

methods

  • executeMatches(matches: Match[]): void - Updates Player fields according to played matches.

Match

constructor attributes

  • opponent: Player
  • score: Score

TournamentPlayer

Used when you want to use executeTournament method from Glicko2. Child of Player class with additional id field.

constructor attributes

  • id: string
  • rating: number = 1500
  • ratingDeviation: number = 350
  • volatility: number = 0.06

TournamentMatch

Used when you want to use executeTournament method from Glicko2.

constructor attributes

  • player1: TournamentPlayer
  • player2: TournamentPlayer,
  • score: Score

Glicko2

constructor attributes

  • player: Player
  • matches: Match[]
  • tau: number = 0.5 - The system constant, τ , which constrains the change in volatility over time.

methods

  • getNewValues(): { rating: number; ratingDeviation: number; volatility: number; }- generates Glicko2 values based on played matches for provided player

static methods

  • executeMatch(player1: Player, player2: Player, result: Score) - takes two players and result of their match, and updates Glicko2 values for both of them.

  • executeTournament(matches: TournamentMatch[]) - takes an array of matches and updates Glicko2 values for every player that took part in any of those matches based on all results.

Types

  • type Score = 0 | 0.5 | 1;

Example

If you want to see an example how this package can be used, you can see this chess app, that uses this package on backend: https://github.com/mwisniewski00/Chess