Skip to content

Instantly share code, notes, and snippets.

@matortheeternal
Created December 25, 2020 19:54
Show Gist options
  • Save matortheeternal/30a4ca0eb1e9cbfaf8e53b9ca4c54d4f to your computer and use it in GitHub Desktop.
Save matortheeternal/30a4ca0eb1e9cbfaf8e53b9ca4c54d4f to your computer and use it in GitHub Desktop.
Simulating arknights banner pulls for W and Weedy.
let randomEntry = function(a) {
let index = Math.floor(Math.random() * a.length);
return a[index];
};
let count = function(a, test) {
return a.reduce((counter, v) => {
return counter + test(v);
}, 0);
};
let simulate = function() {
let baseSixStarChance = 0.02;
let numPulls = 0;
let sixStarPityCounter = 0;
let sixStarInfo = {
rateUp: 0.7,
chance: baseSixStarChance,
rateUpOps: ['W', 'Weedy']
};
let opsPulled = [];
let pull = function() {
numPulls++;
let p = Math.random();
if (p < sixStarInfo.chance) {
if (Math.random() < sixStarInfo.rateUp)
opsPulled.push(randomEntry(sixStarInfo.rateUpOps));
sixStarPityCounter = 0;
sixStarInfo.chance = baseSixStarChance;
return;
}
sixStarPityCounter++;
if (sixStarPityCounter >= 50)
sixStarInfo.chance += 0.02;
};
let redeemSparks = function() {
if (!opsPulled.includes('Weedy')) {
opsPulled.push('Weedy')
} else if (!opsPulled.includes('W')) {
opsPulled.push('W');
}
};
while (!opsPulled.includes('W') || !opsPulled.includes('Weedy')) {
pull();
if (numPulls % 300 === 0) redeemSparks();
}
return numPulls;
};
let totalPulls = 0;
let pullCounts = [];
let simulationCount = 1000000;
for (let i = 0; i < simulationCount; i++) {
let count = simulate();
pullCounts.push(count);
totalPulls += count;
}
console.log('Average pulls:', totalPulls / simulationCount);
for (let i = 10; i <= 300; i += 10) {
let c = 100 * count(pullCounts, p => p <= i) / simulationCount;
console.log(`Chance in ${i} pulls or less: ${c.toFixed(2)}%`);
}
Average pulls: 141.943186
Chance in 10 pulls or less: 0.42%
Chance in 20 pulls or less: 1.64%
Chance in 30 pulls or less: 3.50%
Chance in 40 pulls or less: 5.87%
Chance in 50 pulls or less: 8.63%
Chance in 60 pulls or less: 12.52%
Chance in 70 pulls or less: 18.30%
Chance in 80 pulls or less: 24.19%
Chance in 90 pulls or less: 29.87%
Chance in 100 pulls or less: 35.27%
Chance in 110 pulls or less: 40.79%
Chance in 120 pulls or less: 47.18%
Chance in 130 pulls or less: 52.53%
Chance in 140 pulls or less: 57.07%
Chance in 150 pulls or less: 61.20%
Chance in 160 pulls or less: 64.99%
Chance in 170 pulls or less: 68.63%
Chance in 180 pulls or less: 72.11%
Chance in 190 pulls or less: 75.11%
Chance in 200 pulls or less: 77.71%
Chance in 210 pulls or less: 80.06%
Chance in 220 pulls or less: 82.17%
Chance in 230 pulls or less: 84.09%
Chance in 240 pulls or less: 85.87%
Chance in 250 pulls or less: 87.41%
Chance in 260 pulls or less: 88.77%
Chance in 270 pulls or less: 90.00%
Chance in 280 pulls or less: 91.08%
Chance in 290 pulls or less: 92.06%
Chance in 300 pulls or less: 99.97%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment