Coder Social home page Coder Social logo

fsmosca / position-trainer Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 28.34 MB

Test your skill to find the best move from the given test position.

License: GNU General Public License v3.0

Python 100.00%
chess chess-positions chess-training python-chess streamlit

position-trainer's Issues

Calculate user performance rating

To calculate the performance rating of the user, we need to get the rating of the opponent of the side not to move in the test position. We also need the score rate of the engine and the score rate of the user selected move. Depending on the test position, the rating of the opponent can be a ?, in this case, we will not be able to calculate the user performance rating and we just have to skip it. The engine score rate and user selected move score rate are available from the test file itself.

In the example below, the test position is r3r1k1/pR3p1p/2n1b2B/3p4/3Pp3/2P3P1/P3P1B1/5RK1 w - -. The actual move played by "White": "Sarrau, Jelle", is game.move or Bh3. The best move according to the "analysis_engine": "Stockfish 15" is engine.move or Rb5 with a score rate of engine.score or 0.58 meaning it is expected to win at 58%. If the user selected the move Rb8 it has a score rate of 0.04. Whatever move the user selects the test file has an equivalent score rate.

{
    "r3r1k1/pR3p1p/2n1b2B/3p4/3Pp3/2P3P1/P3P1B1/5RK1 w - -": {
        "stm": "white",
        "fmvn": 21,
        "hmvc": 2,
        "game": {
            "move": "Bh3",
            "score": -343,
            "rate": 0.21
        },
        "engine": {
            "move": "Rb5",
            "score": 82,
            "rate": 0.58
        },
        "user": {
            "Rb8": {
                "score": -854,
                "rate": 0.04
            },
            "Rbxf7": {
                "score": -653,
                "rate": 0.08
            },

...

        "analysis_engine": "Stockfish 15",
        "analysis_movetime": 1.0,
        "analysis_depth": 1000,
        "header": {
            "Event": "22nd ch-EUR Indiv 2022",
            "Date": "2022.03.27",
            "Round": "1.1",
            "White": "Sarrau, Jelle",
            "Black": "Navara, David",
            "WhiteElo": "2401",
            "BlackElo": "2700"
        }
    },
...

Formula 1

performance_rating = opponent_rating + rating_difference

where:  
rating_difference is derived from the engine score rate and the user selected move score rate.

The following is the formula for the expected score that we are going to use.

Formula 2

es = 1 / (1 + 10 ^ (-rd/600))

where:
es = expected_score or score rate, [0.0 - 1.0]
rd = rating difference

For reference, the FIDE Elo uses around 400 instead of 600.

We can get the rd based from formula 2.

Formula 3

rd = -600 * log10((1-es)/es)

Let's have an example calculation

A test position has:

epd: r3r1k1/pR3p1p/2n1b2B/3p4/3Pp3/2P3P1/P3P1B1/5RK1 w - -

engine_score_rate = 0.58
user_score_rate = 0.08
opponent_rating = 2700

With formula 3 we can calculate the engine rd.

rd = -600 * log10((1-es)/es)
rd = -600 * log10((1-0.58)/0.58)
rd = 84

The user rd is:

rd = -600 * log10((1-es)/es)
rd = -600 * log10((1-0.08)/0.08)
rd = -636

According to the engine, the expected rd is 84 meaning the engine move is stronger, but the user selected move is only -636, which means it is 636 weaker. The rating difference between these 2 numbers are:

rd_diff = user_rd - engine_rd
rd_diff = -636 - 84 = -720

Going back to formula 1.

performance_rating = opponent_rating + rating_difference

The user performance rating is:

performance_rating = opponent_rating + rating_difference
performance_rating = opponent_rating + rd_diff

performance_rating = 2700 + (-720)
performance_rating = 1980

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.