Skip to content

Commit

Permalink
Refactor cheat detection logic and enhance Elo rating calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
codergautam committed Nov 19, 2024
1 parent 2797968 commit a34d511
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 4 additions & 4 deletions components/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -1820,10 +1820,10 @@ setShowCountryButtons(false)
useEffect(() => {
function checkForCheats() {
if(document.getElementById("coordinates")) return true;
try {
if(window.localStorage.getItem("banned")) return true;
} catch(e) {
}
// try {
// if(window.localStorage.getItem("banned")) return true;
// } catch(e) {
// }
return false;
}
function banGame() {
Expand Down
16 changes: 12 additions & 4 deletions components/utils/eloSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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 L = 5; // Additional scaling factor for score differences
const maxElo = 10000;

// Function to calculate expected outcome
Expand All @@ -19,15 +19,23 @@ function updateElo(Ra, Rb, Sa, Pa, Pb) {
const Ea = expectedOutcome(Ra, Rb);
const scoreFactor = Pa / (Pa + Pb);
const victoryBonus = Sa * V;
const newRa = Ra + K * (Sa - Ea) + L * scoreFactor + victoryBonus;
let gainedElo = K * (Sa - Ea) + L * scoreFactor + victoryBonus;

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

const newRa = Ra + gainedElo;
return Math.min(maxElo, Math.round(Math.max(newRa, Rmin))); // Ensure rating doesn't drop below Rmin
}

export default function calculateOutcomes(player1Rating, player2Rating, winner) {
const player1Outcome = winner === 1 ? 1 : winner === 0.5 ? 0.5 : 0;
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, player1Outcome, player2Outcome);
const newRating2 = updateElo(player2Rating, player1Rating, player2Outcome, player1Outcome, player2Outcome);

return { newRating1, newRating2 };
}
1 change: 1 addition & 0 deletions ws/classes/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class Player {
setElo(newElo, gameData) {
if(!this.accountId) return;
this.elo = newElo;
this.league = getLeague(newElo).name;
setElo(this.accountId, newElo, gameData);

this.send({
Expand Down

0 comments on commit a34d511

Please sign in to comment.