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
@@ -35,9 +35,7 @@ interface WebhookResponse {
|
||||
error: boolean
|
||||
}
|
||||
|
||||
const MAX_ROUNDS = 10
|
||||
const KO_THRESHOLD = 0
|
||||
const MAX_RESPONSE_BYTES = 10 * 1024 // 10KB
|
||||
import { MAX_ROUNDS, KO_THRESHOLD, MAX_RESPONSE_BYTES, STARTING_HP, ELO_K_FACTOR, ELO_K_FACTOR_MOCK } from '../lib/constants.js'
|
||||
|
||||
// Track bots currently in a fight to prevent concurrent fights
|
||||
const activeFighters = new Set<string>()
|
||||
@@ -333,8 +331,8 @@ async function trackWebhookResult(botId: string, webhookUrl: string, succeeded:
|
||||
}
|
||||
|
||||
async function executeFightRounds(fightId: string, botA: BotRecord, botB: BotRecord, arena: Arena, mode: 'free' | 'ranked' = 'free'): Promise<void> {
|
||||
let hpA = 200
|
||||
let hpB = 200
|
||||
let hpA = STARTING_HP
|
||||
let hpB = STARTING_HP
|
||||
let comboA = 0
|
||||
let comboB = 0
|
||||
let winnerId: string | null = null
|
||||
@@ -447,13 +445,13 @@ async function executeFightRounds(fightId: string, botA: BotRecord, botB: BotRec
|
||||
|
||||
const winnerName = winnerId === botA.id ? botA.name : winnerId === botB.id ? botB.name : 'nobody'
|
||||
const isPerfect = winnerId && (
|
||||
(winnerId === botA.id && hpA === 200) ||
|
||||
(winnerId === botB.id && hpB === 200)
|
||||
(winnerId === botA.id && hpA === STARTING_HP) ||
|
||||
(winnerId === botB.id && hpB === STARTING_HP)
|
||||
)
|
||||
|
||||
// Finalize fight + update bot stats atomically
|
||||
const isMockFight = isMockBot(botA.webhookUrl) || isMockBot(botB.webhookUrl) || isClassicBot(botA.webhookUrl) || isClassicBot(botB.webhookUrl)
|
||||
const kFactor = isMockFight ? 12 : 32 // Dampened Elo for mock/classic fights
|
||||
const kFactor = isMockFight ? ELO_K_FACTOR_MOCK : ELO_K_FACTOR
|
||||
let winnerEloChange = 0
|
||||
let loserEloChange = 0
|
||||
let newWinnerEloFinal = 0
|
||||
|
||||
Reference in New Issue
Block a user