R6S AlphaPack chances
by Anton
HTML
<div>
<p>
W/L: <input id="wl-rate" type="number" value="0.75"/><br>
Max.Iterations: <input id="max-iter" type="number" value="1000"/><br>
<button id="run">Run</button>
</p>
<p>
<span id="status">Press button to run</span><br>
<span id="avg">…</span>
</p>
</div>
CSS
#avg:not(.shown) {
display: none;
}
#status {
color: red;
}
#status.running {
color: orange;
}
#status.done {
color: green;
}
JavaScript
$('#run').on('click', run);
function run() {
var wlRate = $('#wl-rate').val() * 1,
winRate = wlRate / (1 + wlRate),
maxIter = $('#max-iter').val() * 1,
games = [];
$('#status').html('Running…')
.removeClass()
.addClass('running');
$('#avg').removeClass();
setTimeout(() => {
for(var i = 0; i < maxIter; i++) {
games.push(iteration(winRate));
}
$('#avg').addClass('shown')
.text('Avg.games till drop: ' + getAvg(games));
$('#status').html('Done')
.removeClass()
.addClass('done');
}, 0);
}
function getAvg(games) {
return games.reduce((prev, curr) => prev + curr)
/ games.length;
}
function iteration(winRate) {
var game = 0,
dropChance = 0,
isWin;
do {
game++;
isWin = Math.random() <= winRate;
if(isWin & Math.random() < dropChance)
break;
dropChance += isWin ? 0.025 : 0.015;
} while(true);
return game;
}