如何基于指定胜率计算从起始分到达目标评分的游戏次数
胜率场景下评分达标场次计算
核心计算逻辑
- 目标分数差:从5000分降到1000分,总共需要减少 4000分
- 单场分数变化期望:胜率27%意味着每场有27%概率赢(+30分)、73%概率输(-30分),单场均分变化为
30*0.27 + (-30)*0.73 = -13.8分/场 - 期望场次:总降幅除以单场均降幅的绝对值,即
4000 / 13.8 ≈ 289.86,向上取整为 290场(场次必须为整数,需确保分数降到目标值以下)
代码实现
方式1:数学期望计算(直接得理论场次)
function calculateRequiredGames(startPts, targetPts, winRate) { const scoreDiff = startPts - targetPts; if (scoreDiff <= 0) return 0; const avgScoreChangePerGame = winRate * 30 + (1 - winRate) * (-30); if (avgScoreChangePerGame >= 0) return Infinity; // 期望分数上升,无法降到目标值 return Math.ceil(scoreDiff / Math.abs(avgScoreChangePerGame)); } // 代入参数计算 console.log(calculateRequiredGames(5000, 1000, 0.27)); // 输出:290
方式2:蒙特卡洛模拟(多次模拟取平均)
如果需要模拟实际概率场景,可通过多次运行取平均场次:
function simulateOneRun(startPts, targetPts, winRate) { let currentPts = startPts; let games = 0; while (currentPts > targetPts) { const isWin = Math.random() < winRate; currentPts += isWin ? 30 : -30; games++; } return games; } function simulateMultipleRuns(startPts, targetPts, winRate, runs) { let totalGames = 0; for (let i = 0; i < runs; i++) { totalGames += simulateOneRun(startPts, targetPts, winRate); } return Math.round(totalGames / runs); } // 模拟10000次取平均 console.log(simulateMultipleRuns(5000, 1000, 0.27, 10000)); // 结果接近290
内容的提问来源于stack exchange,提问作者BXOPE BXOPE
相关产品推荐
相关产品推荐

