Skip to content

Commit

Permalink
Merge pull request #49 from codergautam/futurepear
Browse files Browse the repository at this point in the history
elo formula change
  • Loading branch information
codergautam authored Jan 11, 2025
2 parents a0908be + af5b680 commit b8a3c8c
Show file tree
Hide file tree
Showing 3 changed files with 3,102 additions and 2,494 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
.DS_Store
*.pem
logs

#visual studio
.vs

# debug
npm-debug.log*
yarn-debug.log*
Expand Down
27 changes: 16 additions & 11 deletions components/utils/eloSystem.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
// Constants
const K = 32; // Scaling factor for Elo rating changes
const K = 50; // Scaling factor for Elo rating changes
const c = 500; // Factor for expected outcome calculation
const Rmin = 100; // Minimum Elo rating to avoid negative experiences
export const Ra0 = 1000; // Initial Elo rating for new players

const V = 10; // Bonus factor for victories
const L = 5; // Additional scaling factor for score differences

const maxElo = 10000;
const exponentBase = 1.7;

// Function to calculate expected outcome
function expectedOutcome(Ra, Rb) {
const Qa = Math.pow(10, Ra / c);
const Qb = Math.pow(10, Rb / c);
const Qa = Math.pow(exponentBase, Ra / c);
const Qb = Math.pow(exponentBase, Rb / c);
return Qa / (Qa + Qb);
}

// Function to update Elo rating
function updateElo(Ra, Rb, Sa, Pa, Pb) {
function updateElo(Ra, Rb, Pa, Pb) {
const Ea = expectedOutcome(Ra, Rb);
const scoreFactor = Pa / (Pa + Pb);
const victoryBonus = Sa * V;
let gainedElo = K * (Sa - Ea) + L * scoreFactor + victoryBonus;

//https://www.desmos.com/calculator/mwnadmf8e0
let gainedElo = K * (Pa - Ea - 0.5) + 34 - 3 * Pa;
if(Pa === 0)
gainedElo = Math.min(0, gainedElo); //curve pokes above 0 at the left side

// Quadruple the gained Elo if the player wins and their rating is below 2000
if (Sa === 1 && Ra < 2000) {
if (Pa === 1 && Ra < 2000) {
gainedElo *= 4;
}

Expand All @@ -31,11 +36,11 @@ function updateElo(Ra, Rb, Sa, Pa, Pb) {
}

export default function calculateOutcomes(player1Rating, player2Rating, winner) {
const player1Outcome = winner === 1 ? 1 : winner === 0.5 ? 0.5 : 0;
const player1Outcome = winner === 1 ? 1 : winner === 0.5 ? 0.5 : 0; //1 if player1 wins
const player2Outcome = 1 - player1Outcome;

const newRating1 = updateElo(player1Rating, player2Rating, player1Outcome, player1Outcome, player2Outcome);
const newRating2 = updateElo(player2Rating, player1Rating, player2Outcome, player1Outcome, player2Outcome);
const newRating1 = updateElo(player1Rating, player2Rating, player1Outcome, player2Outcome);
const newRating2 = updateElo(player2Rating, player1Rating, player1Outcome, player2Outcome);

return { newRating1, newRating2 };
}
Loading

0 comments on commit b8a3c8c

Please sign in to comment.