Rating System
Overview
The Elo rating system was invented in the 1960s by Arpad Elo, a Hungarian‑American physics professor and chess master, and was officially adopted by the U.S. Chess Federation in 1960 and by FIDE (the international chess federation) in 1970. (Wikipedia)
In historical terms, it’s a very modern invention, and it definitely did not exist in the Anglo‑Saxon period. However, when adapting Mǽrstánas to an online, multiplayer platform, I wanted to implement a rating system that could be used to compare players' skill level. Therefore, I adapted the Elo system to my game. What follows is a written explanation of the Python code included in the app I wrote. (Source code on Codeberg)
Player Ratings
Starting Rating: Every new player begins with a rating of 1000.
How Ratings Change: After each game, both players’ ratings are adjusted based on the result and the relative strength of their opponents.
The K‑Factor: The maximum adjustment from a single game is 32 points.
Wins and Losses
If you win, your rating goes up.
If you lose, your rating goes down.
The exact number of points gained or lost depends on how strong your opponent was compared to you:
Beating a higher‑rated opponent gives you more points.
Beating a much lower‑rated opponent gives you only a few points.
Losing to a much lower‑rated opponent costs you more points.
Losing to a much higher‑rated opponent costs you only a few points.
Ties
If the game ends in a tie, both players’ ratings move toward each other:
The lower‑rated player gains points.
The higher‑rated player loses points.
The closer the ratings already are, the smaller the adjustment.
This system ensures that ratings reflect not just wins and losses, but also the strength of the opponents you face.
Detailed Explanation
Rating overview
Players can calculate their own ratings after each match using a simple Elo-style method. New players start at 1000. Each result changes ratings by up to 32 points, scaled by how likely the result was based on both players’ current ratings.
What you need
Current ratings: Each player’s rating before the match.
Result: Win, loss, or tie.
K-factor: Use
for every match.
Core formulas
Rating difference
Expected score (your chance of a point)
Score by result
Rating update
Step-by-step for a win or loss
Compute diff
Compute your expected score
Set your actual score
Win:
Loss:
Update your rating
Update your opponent’s rating
Your opponent’s expected score is
.Their actual score is the opposite of yours (win = 0 for them, loss = 1).
Step-by-step for a tie
Compute absolute difference
Compute expected score for the higher-rated player
Both players use
For the higher-rated player, use
.For the lower-rated player, use
.
Examples
Win example (1200 vs. 1000, higher-rated player wins)
You:
, Opponent:diff:
Win
:Winner new rating:
Loser new rating: Opponent’s expected score
New rating
Upset win example (1000 vs. 1200, lower-rated player wins)
diff:
Win
:Winner new rating:
Loser new rating:
Tie example (1200 vs. 1000)
diff (absolute):
Both use
:Higher-rated new rating:
Lower-rated new rating:
Quick reference
Start: Everyone begins at 1000.
K-factor: Always 32.
Expected score:
Update:
Scores: Win = 1, Tie = 0.5, Loss = 0.
Direction: Upsets cause big swings; predictable results cause small swings.