GithubHelp home page GithubHelp logo

elo-lib's Introduction

elo-lib

Calculate ELO after a result between two players. Enables storing ELO on-chain (and consequently allows for trustless leaderboards & prize pools)

Add to your project (requires foundry):

forge install saucepoint/elo-lib

Usage

import {Elo} from "elo-lib/Elo.sol";

contract MyContract {
    // maps player to their ELO
    mapping(address => uint256) elos;
    
    function updateElo() external {
        // read the results from somewhere
        uint256 result = 100; // player 1 won
        uint256 kFactor = 20; // development factor (established players have lower kFactors)

        (uint256 change, bool negative) = Elo.ratingChange(elos[player1], elos[player2], result, kFactor);

        // update the elos
        if (negative) {
            // add your own overflow checks
            // be aware that change is 2 decimal places (1501 = 15.01 ELO change)
            elos[player1] -= change;
            elos[player2] += change;
        } else {
            elos[player1] += change;
            elos[player2] -= change;
        }
    }
}

elo-lib's People

Contributors

saucepoint avatar

Stargazers

Robert Leifke avatar benzodiazepine avatar Julian Traversa avatar Adam Fuller avatar  avatar Koda avatar N0name avatar 0xBA5ED.eth avatar afrideva avatar feewet avatar highskore avatar 0xRaiden avatar Javed Khan avatar Febby avatar Kaung Htet avatar Bakuchi avatar emp avatar sayan avatar Gbolahan avatar Hilliam T. avatar Shun Kakinoki avatar Stephen Brown avatar  avatar Georgios Konstantopoulos avatar indigo avatar Sourabh avatar takez0_o avatar Adediran Tofunmi avatar t11s avatar clandestine.eth avatar Maddiaa avatar

Watchers

 avatar  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.