refactor: extract magic numbers to named constants
Frontend: choreography selection ratios, morph trigger chances, creator cameo/ultimate chances, dodge/counter probabilities. Server: HP, K-factors, Elo divisor, tier thresholds, fight loop interval. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
1731a64ae8
commit
7c8e404cf1
@@ -1,3 +1,4 @@
|
||||
import { ELO_DIVISOR, TIER_THRESHOLDS } from '../lib/constants.js'
|
||||
import type { Challenge } from './challenges.js'
|
||||
import { pick } from '../lib/utils.js'
|
||||
import { checkAnswer } from './answers.js'
|
||||
@@ -523,7 +524,7 @@ export function calculateElo(
|
||||
loserElo: number,
|
||||
k: number = 32,
|
||||
): { newWinnerElo: number; newLoserElo: number } {
|
||||
const expectedWinner = 1 / (1 + Math.pow(10, (loserElo - winnerElo) / 400))
|
||||
const expectedWinner = 1 / (1 + Math.pow(10, (loserElo - winnerElo) / ELO_DIVISOR))
|
||||
const expectedLoser = 1 - expectedWinner
|
||||
|
||||
return {
|
||||
@@ -534,13 +535,10 @@ export function calculateElo(
|
||||
|
||||
// Tier calculation
|
||||
export function calculateTier(elo: number, wins: number): number {
|
||||
if (elo >= 1900 && wins >= 40) return 6 // Legend
|
||||
if (elo >= 1700 && wins >= 25) return 5 // Diamond
|
||||
if (elo >= 1500 && wins >= 15) return 4 // Platinum
|
||||
if (elo >= 1350 && wins >= 7) return 3 // Gold
|
||||
if (elo >= 1200 && wins >= 3) return 2 // Silver
|
||||
if (wins >= 1) return 1 // Bronze
|
||||
return 0 // Baby
|
||||
for (const t of TIER_THRESHOLDS) {
|
||||
if (elo >= t.elo && wins >= t.wins) return t.tier
|
||||
}
|
||||
return 0 // Baby
|
||||
}
|
||||
|
||||
export const TIER_NAMES = ['BABY', 'BRONZE', 'SILVER', 'GOLD', 'PLATINUM', 'DIAMOND', 'LEGEND'] as const
|
||||
|
||||
Reference in New Issue
Block a user