Giter Club home page Giter Club logo

elo-rating's Introduction

elo-rating.js

elo-rating.js is a simple utility to calculate elo ratings for Node.js. See https://en.wikipedia.org/wiki/Elo_rating_system for more information about elo rating.

Installation

npm install elo-rating

Usage

var EloRating = require('elo-rating');

var playerWin = false;
var result = EloRating.calculate(1750, 1535, playerWin);

console.log(result.playerRating) // Output: 1735
console.log(result.opponentRating) // Output: 1550

result = EloRating.calculate(1750, 1535);

console.log(result.playerRating) // Output: 1754
console.log(result.opponentRating) // Output: 1531

Functions

EloRating.ratingDifference(playerRating, opponentRating)

Calculates the rating difference, capped at -400 and +400.

var EloRating = require('elo-rating');

console.log(EloRating.ratingDifference(1500, 1350)); // Output: 150
console.log(EloRating.ratingDifference(1200, 2000)); // Output: -400

EloRating.expected(playerRating, opponentRating)

Calculates the expected value for the player with the given rating if he plays against an opponent with the given rating. (0 = Loss, 0.5 = Draw, 1 = Win).

var EloRating = require('elo-rating');

console.log(EloRating.expected(1800, 1800)); // Output: 0.5
console.log(EloRating.expected(1500, 1350)); // Output: 0.70...
console.log(EloRating.expected(1200, 2000)); // Output: 0.09...

EloRating.calculate(playerRating, opponentRating, playerWin = true, k = 20)

Calculates the new rating for the player and his opponent.

var EloRating = require('elo-rating');

console.log(EloRating.calculate(1800, 1800));
// Output: { playerRating: 1810, opponentRating: 1790 }
console.log(EloRating.calculate(1200, 1500, false));
// Output: { playerRating: 1197, opponentRating: 1503 }
console.log(EloRating.calculate(1200, 1500, false, 40));
// Output: { playerRating: 1194, opponentRating: 1506 }

License

The MIT License (MIT)

Similar modules

There are several other modules for Node.js, which provide similar functionality. Check them out as well:

elo-rating's People

Contributors

zlypher avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.