{"id":19270567,"url":"https://github.com/markmusic27/elo-rating-algorithm","last_synced_at":"2025-10-26T20:03:47.004Z","repository":{"id":56371939,"uuid":"290863760","full_name":"markmusic27/elo-rating-algorithm","owner":"markmusic27","description":"♟ The Elo Rating System is used all around the world to rate everything from basketball teams to competitive scrabble players. This is the Elo Rating Algorithm written in JavaScript \u0026 TypeScript. Enjoy!","archived":false,"fork":false,"pushed_at":"2023-10-01T13:08:15.000Z","size":314,"stargazers_count":18,"open_issues_count":1,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T16:11:17.399Z","etag":null,"topics":["algorithm","arpad-elo","chess","dart","elo-rating","elo-rating-algorithm","facesmash","javascript","rating-algorithm","tyepscript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markmusic27.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-27T19:28:39.000Z","updated_at":"2025-01-07T02:52:59.000Z","dependencies_parsed_at":"2024-07-13T09:14:29.095Z","dependency_job_id":"fd11a291-b9dd-4194-82fd-03da7fbba7ee","html_url":"https://github.com/markmusic27/elo-rating-algorithm","commit_stats":null,"previous_names":["markmusic27/elo-rating-algorithm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmusic27%2Felo-rating-algorithm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmusic27%2Felo-rating-algorithm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmusic27%2Felo-rating-algorithm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmusic27%2Felo-rating-algorithm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markmusic27","download_url":"https://codeload.github.com/markmusic27/elo-rating-algorithm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250128513,"owners_count":21379528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","arpad-elo","chess","dart","elo-rating","elo-rating-algorithm","facesmash","javascript","rating-algorithm","tyepscript"],"created_at":"2024-11-09T20:25:47.454Z","updated_at":"2025-10-26T20:03:46.914Z","avatar_url":"https://github.com/markmusic27.png","language":"TypeScript","readme":"# 🔔 Elo Rating Algorithm\n\n### ⏳ Elo Rating Algorithm History\n\nThe Elo Rating algorithm, created by Arpad Elo _(a Hungarian-Amerian Physics Professor)_, is one of the most common algoritms used for rating because of the logic \u0026 functionality behind it.\n\nIt is used by developers wanting to rank chess players to college students wanting to rank girls _(Mark Zucherberg's Facemash)._\n\n![Markdown Logo](https://miro.medium.com/max/559/1*FNfXGwHiRJ9wCjN502CX2w.jpeg)\n\n**_But how does it work? How can I implement it into my code?_**\n\n---\n\n### 🔧 Demystifying The Algorithm\n\nThe algorith is **based on two key formulas**.\n\n1. The first formula tells you how to predict the outcome of the game.\n2. The second formula tells you how to update your rating depending on the outcome of the game.\n\n**This is how they look:**\n\n_Formula A:_\n\n\u003c!-- $\\huge E_a=\\frac{1}{1+10(^{R_b-R_a})^{/400}}$ --\u003e\n\n\u003cimg src=\"formulas/formula4.png\"\u003e\n\n_Formula B:_\n\n\u003c!--$\\huge E_b=1-E_a$--\u003e\n\u003cimg src=\"formulas/formula3.png\"\u003e\n\n**Don't get discouraged by how the formulas look!** We'll go through this step by step.\n\n---\n\n### 🧠 Understanding the Algorithm\n\nWhen Arpad Elo first invented the algorithm, his idea was to asume that **each players ability forms a bell curve.**\n\nImage that each player brings a box with them to every game. Before every game, they pull out a number from that box. **Whoever has the highest number wins.**\n\nThat number represent a players ability to win the match.\n\nThis means that every player has the potencial of playing at a range of different abilities.\n\n\u003e _Somedays, a player might be feel great and pick a high number._\n\n\u003e _Other days, that player might feel sick or unlucky and pick a low number._\n\n\u003e _Most of the time, however, that player picks a number in the middle of their range._\n\n**An elite player will generally be picking from a box of very high numbers. _So they are more likely to win but not always..._**\n\nIf you pay attention at the frequency of the numbers, you'll realize that they form bell curves.\n\n\u003cimg src=\"graph/graph1.png\"\u003e\n\n_Notice how the bell curves are **exactly the same.** The only difference is the center of the curves._\n\n**The center of the curves represents the mean or averge and the averege is that players rating.**\n\n---\n\n### 🏀 Formula 1 (Probability of Winning The Game)\n\nTo get the probability of a player winning a game, we need to find the _**frequency of the differences between the two players.**_\n\nIf you plot that, you get a bell curve. **It's called a logistic curve.**\n\n\u003cimg src=\"graph/graph2.png\"\u003e\n\n**The idea is that the more of the curve is to the right of 0, the more likely that player is to win.**\n\n_Basically, the Elo Rating Algorithm is designed so that if a player has a rating that is 400 points more than another player, they are 10 times more likely to win._\n\nSo in the curve, the area to the right of 0 would be 10 times the area of the curve to the left of 0.\n\n**_If you turn that into a formula, this is the formula that you would get:_**\n\nSo, If Player A has a rating of _R\u003csub\u003ea\u003c/sub\u003e_, and Player B has a rating of _R\u003csub\u003eb\u003c/sub\u003e_, the exact formula for the expected score of Player A is:\n\n\u003cimg src=\"formulas/formula3.png\"\u003e\n\nYou can simmilarly look at the probability for Player B to win by:\n\n\u003cimg src=\"formulas/formula2.png\"\u003e\n\nWith this, you can predict who will win.\n\n**EXAMPLE:** _If the probability of winning is 1, your going to win the game. If the probability of winning is 0, your going to loose the game._\n\n**IMPORTANT:** If the probability of winning is 0.5 (half), then your going to win as many games as you loose. Basically a draw.\n\nNow, lets say that:\n\n| Win | Loose | Draw |\n| --- | ----- | ---- |\n| 1   | 0     | 0.5  |\n\n**Then, the probability can be used as the expected score.**\n\n\u003e It can be wierd like if you have a probability of **0.75**.\n\n\u003e _This means that you could win 75% of the games and loose the other 25%._\n\n\u003e _But it also means that you coud win 50% of the games and draw the other 50% of the games._\n\n\u003e **Either way, we would say the expected score is 0.75**\n\n---\n\n### 🛥 Formula 2 (The Update Formula)\n\n**Whenever a player does better than expected, their rating will increse. The more surprising that the win is, the more points they will get. Up to a max of 32 points.**\n\n_Nothing special about 32, just a choice that they made._\n\n**The same way, if a player does worse than expected, their rating will decrease up to 32 poibts.**\n\nThroughout a tournament, a players raiting **is updated using an update formula.**\n\n_This is how said formula looks:_\n\n\u003cimg src=\"formulas/formula4.png\"\u003e\n\n**For Example:** Let's say that player A has a rating of 1656 and Player B has a rating of 1763. Since player A is the weaker player, he's expected to loose. His expexted win is 0.35 . However, he actually wins the game.\n\n**_If this was the case, we would apply the formula like this:_**\n\n\u003cimg src=\"formulas/formula_example.png\"\u003e\n\n---\n\n### ☝️ Before you leave...\n\n**In the next few paragraphs, I will explain how and why I did this. Keep reading in if you want to:**\n\n_**a) Feel bad for me.**_\n\n_**b) Have a couple laughs**_\n\n**_c) Be thankfull that you didn't have to do it yourself._**\n\nThis project originated when my friend ([Filippo](https://twitter.com/filippofonseca)) asked me to bet on which team was going to with the 2020, NBA title. I said _\"Sure!\"_, and proceeded to overcomplicate my life since I knew very little _(basically nothing)_ about basketball.\n\nThe idea was to create a program that would run every possible scenerio for which a team could win depending on how many games the team had won. Of couse, it would have been 10 times more effective to just do reseach and make an educated guess, but there was one, criticall problem with that take. _It was simply not a cool enough option._\n\nI knew I wanted to include the [The Social Network](https://www.imdb.com/title/tt1285016/)'s rating algorithm but instead of ranking girls, I would rank teams. So I looked up the formula online and **vuala**, there it was, The Elo Rating System in all its glory.\n\nI then watched a couple videos, read some medium articles and proceeded to rethink my life decisions. After some close encounters with mental breakdowns, I ran the command which would determain if the last 48 hours of my life were worth it...\n\n```\nts-node algorithm.ts\n```\n\nThe next 5 seconds felt like they would never end. I closed my eyes and of course it didn't work. So I was back to the drawing board. And after many tries and **soooo mannyyyyyy erorrrrssssss**, it worked.\n\n### Built and maintained with ❤️ by [@markmusic2727](https://www.twitter.com/MarkMusic2727)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmusic27%2Felo-rating-algorithm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkmusic27%2Felo-rating-algorithm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmusic27%2Felo-rating-algorithm/lists"}