Skip to content

Commit

Permalink
feat: change to vitest, pnpm and update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
hoersamu committed Dec 26, 2023
1 parent e92c695 commit 8d73760
Show file tree
Hide file tree
Showing 15 changed files with 5,408 additions and 34 deletions.
69 changes: 52 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,75 @@
# packageName
# multi-elo

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![bundle][bundle-src]][bundle-href]
[![Codecov][codecov-src]][codecov-href]

This is my package description.
This package implements a multiplayer extension of the popular Elo rating system.

## Usage
- [Installation](#installation)
- [Example Usage](#example-usage)
- [Methodology](#methodology)
- [Traditional Elo ratings](#traditional-elo-ratings)
- [Extension to multiplayer](#extension-to-multiplayer)

Install package:
This Package is based on [djcunningham0s python implementation](https://github.com/djcunningham0/multielo/).
For additional information, see his [blog post](https://towardsdatascience.com/developing-a-generalized-elo-rating-system-for-multiplayer-games-b9b495e87802) on Towards Data Science (or try [this link](https://towardsdatascience.com/developing-a-generalized-elo-rating-system-for-multiplayer-games-b9b495e87802?sk=89615c121aa78c7b502e9dce35ece5e1) if you hit a paywall).

## Installation

The package can be installed from GitHub or npm by using `npm`.

```sh
# npm
npm install packageName
npm install multi-elo

# yarn
yarn add packageName
yarn add multi-elo

# pnpm
pnpm install packageName
pnpm install multi-elo

# bun
bun install packageName
bun install multi-elo
```

Import:

```js
// ESM
import {} from "packageName";
import {} from "multi-elo";

// CommonJS
const {} = require("packageName");
const {} = require("multi-elo");
```

## Example Usage

The following example shows how to calculate updated Elo ratings after a matchup using the default settings in the package.

```typescript
import { MultiElo } from 'multi-elo';

# player with 1200 rating beats a player with 1000 rating
MultiElo.getNewRatings([1200, 1000])
# [1207.68809835, 992.31190165]

# player with 900 rating beats player with 1000 rating
MultiElo.getNewRatings([900, 1000])
# [920.48207999, 979.51792001]

# 3-way matchup
MultiElo.getNewRatings([1200, 900, 1000])
# [1208.34629612, 910.43382278, 981.21988111]
```

See [`demo.md`](https://github.com/hoersamu/multi-elo/blob/main/demo.md) for a more in-depth tutorial, including details on parameters that can be tuned in the Elo algorithm.

## Methodology

For more Info on the methodology read [djcunningham0s Readme](https://github.com/djcunningham0/multielo/).

## Development

- Clone this repository
Expand All @@ -45,17 +80,17 @@ const {} = require("packageName");

## License

Made with 💛
Made with 💛 by Samuel Höra

Published under [MIT License](./LICENSE).

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/packageName?style=flat&colorA=18181B&colorB=F0DB4F
[npm-version-href]: https://npmjs.com/package/packageName
[npm-downloads-src]: https://img.shields.io/npm/dm/packageName?style=flat&colorA=18181B&colorB=F0DB4F
[npm-downloads-href]: https://npmjs.com/package/packageName
[npm-version-src]: https://img.shields.io/npm/v/multi-elo?style=flat&colorA=18181B&colorB=F0DB4F
[npm-version-href]: https://npmjs.com/package/multi-elo
[npm-downloads-src]: https://img.shields.io/npm/dm/multi-elo?style=flat&colorA=18181B&colorB=F0DB4F
[npm-downloads-href]: https://npmjs.com/package/multi-elo
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/packageName/main?style=flat&colorA=18181B&colorB=F0DB4F
[codecov-href]: https://codecov.io/gh/unjs/packageName
[bundle-src]: https://img.shields.io/bundlephobia/minzip/packageName?style=flat&colorA=18181B&colorB=F0DB4F
[bundle-href]: https://bundlephobia.com/result?p=packageName
[bundle-src]: https://img.shields.io/bundlephobia/minzip/multi-elo?style=flat&colorA=18181B&colorB=F0DB4F
[bundle-href]: https://bundlephobia.com/result?p=multi-elo
80 changes: 80 additions & 0 deletions demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Demo

This file is heavily based on djcunningham0s demo file.

## imports

You can either import the static functions:

```typescript
import { getNewRatings, getExpectedScores } from "multi-elo";
```

or use the MultiElo class to fine tune your calculations:

```typescript
import { MultiElo } from "multi-elo";
```

## using `multi-elo` to calculate changes in Elo ratings

Suppose we have a matchup where a player with an Elo rating of 1200 beats a player with an Elo rating of 1000. We can use the getNewRatings method to calculate the new Elo ratings for those players. The ratings should be listed in the order of finish.

```typescript
const result = [1200, 1000];

// uses the default values
getNewRatings(result);
```

We can pass different parameter values to the MultiElo object if we don't want to use the default values.

```typescript
const elo = new MultiElo({ k: 64, d: 800 });

elo.getNewRatings(result);
```

We can also use the getExpectedScores method to get the expected scores for each player (in 1-on-1 matchups, this can be interpreted as the predicted win probability).

```typescript
getExpectedScores(result);
```

We can calculate expected scores and new Elo ratings for multiplayer matchups using the same MultiElo object. The methodology behind this implementation of multiplayer Elo is described in the README. In this four-player example, a player with a 1200 rating comes in 1st, 1000 comes in second, 800 comes in third, and 900 comes in last.

```typescript
multiplayerResult = [1200, 1000, 800, 900];

getNewRatings(multiplayerResult);

// the expected scores are less interpretable than the 1-on-1 case
getExpectedScores(multiplayerResult);
```

## handling ties

This Elo implementation can handle ties. The syntax to annotate ties in the MultiElo object is shown below.

In `multi-elo`, use the resultOrder parameter to indicate which place each player finished in, where lower indicates a better finishing position. (Note: the exact values do not matter -- they just need to be increasing)

```typescript
// first player beat the second in a two-player matchup (default)
getNewRatings([1200, 1000], [1, 2]);

// two players tied in a two-player matchup
getNewRatings([1200, 1000], [1, 1]);

// tie for first place in three-player matchup
getNewRatings([1200, 1000, 800], [1, 1, 2]);

// tie for last place in three-player matchup
getNewRatings([1200, 1000, 800], [1, 2, 2]);

// three-way tie in three-player matchup
getNewRatings([1200, 1000, 800], [1, 1, 1]);
```

## loging

You can enable verbose logging by passing `verbose:true` as part of the `MultiEloConfig` to the `MultiElo` constructor
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "packageName",
"version": "0.0.0",
"name": "multi-elo",
"version": "2.2.0",
"description": "",
"repository": "unjs/packageName",
"repository": "hoersamu/multi-elo",
"license": "MIT",
"sideEffects": false,
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions playground/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { test } from "../src";
import { MultiElo } from "../dist";

console.log(test());
console.log(MultiElo.getNewRatings([1200, 900, 1000]));
Loading

0 comments on commit 8d73760

Please sign in to comment.