Created
September 19, 2022 12:15
-
-
Save sesm/0b6977539a10582e9d9cb3d9382ce380 to your computer and use it in GitHub Desktop.
Awakening simulation WIP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// points are basically index + 3 | |
let points = [ | |
3, // E- | |
4, // E | |
5, // E+ | |
6, // D- | |
7, // D | |
8, // D+ | |
9, // C- | |
10, // C | |
11, // C+ | |
12, // B- | |
13, // B+ | |
14, // B | |
15, // A- | |
16, // A | |
17, // A+ | |
18, // S | |
19, // SS | |
20, // SSS | |
] | |
let odds = [ | |
4.3, // E- | |
19.8, // E | |
28.8, // E+ | |
20, // D- | |
9.2, // D | |
4.8, // D+ | |
4.4, // C- | |
4.3, // C | |
2.13, // C+ | |
1.62, // B- | |
0.55, // B+ | |
0.0745, // B | |
0.015, // A- | |
0.0065, // A | |
0.0025, // A+ | |
0.0015, // S | |
0, // SS | |
0, // SSS | |
] | |
let retireCosts = [ | |
10, // E- | |
15, // E | |
20, // E+ | |
30, // D- | |
50, // D | |
70, // D+ | |
] | |
let oddsSum = odds.reduce((a,b) => a+b, 0) // should be 100 | |
let breakpoints = new Array(odds.length) | |
for(let i = 0; i < odds.length; i++) { | |
breakpoints[i] = odds.slice(0, i+1).reduce((a,b) => a+b, 0) | |
} | |
// No retirement | |
let pointGoal = 200 | |
let startingPoints = 0 | |
function simulateNoRetire(pointGoal, startingPoints, iterations) { | |
let results = [] | |
for(let iter = 0; iter < iterations; iter++) { | |
let points = startingPoints | |
let rolls = 0 | |
while(points < pointGoal) { | |
rolls++ | |
const roll = Math.random() * 100 | |
for(let i = 0; i < breakpoints.length; i++) { | |
if(roll < breakpoints[i]) { | |
points += i+3 | |
break; | |
} | |
} | |
} | |
if(results[rolls]) { | |
results[rolls]++ | |
} else { | |
results[rolls] = 1 | |
} | |
} | |
return results | |
} | |
function simulateRetireDplus(pointGoal, startingPoints, iterations) { | |
let results = [] | |
for(let iter = 0; iter < iterations; iter++) { | |
let points = startingPoints | |
let csg = 0 | |
let csgBuffer = 0 | |
while(points < pointGoal) { | |
csg+= 100 | |
const roll = Math.random() * 100 | |
for(let i = 0; i < breakpoints.length; i++) { | |
if(roll < breakpoints[i]) { | |
points += i+3 | |
if(i < 6) { | |
csgBuffer += retireCosts[i] | |
if (csgBuffer >= 100) { | |
csgBuffer -= 100 | |
csg -= 100 | |
} | |
} | |
break; | |
} | |
} | |
} | |
if(results[csg]) { | |
results[csg]++ | |
} else { | |
results[csg] = 1 | |
} | |
} | |
return results | |
} | |
function simulateRetireDplus2(pointGoal, startingPoints, iterations) { | |
let results = [] | |
for(let iter = 0; iter < iterations; iter++) { | |
let points = startingPoints | |
let csg = 0 | |
while(points < pointGoal) { | |
csg+= 100 | |
const roll = Math.random() * 100 | |
for(let i = 0; i < breakpoints.length; i++) { | |
if(roll < breakpoints[i]) { | |
points += i+3 | |
if(i < 6) { | |
csg -= retireCosts[i] | |
} | |
break; | |
} | |
} | |
} | |
if(results[csg]) { | |
results[csg]++ | |
} else { | |
results[csg] = 1 | |
} | |
} | |
return results | |
} | |
function processResults(res) { | |
let resFilled = new Array(res.length) | |
for(let i = 0; i < res.length; i++) { | |
resFilled[i] = res[i] || 0 | |
} | |
let newRes = new Array(res.length) | |
for(let i = 0; i < res.length; i++) { | |
newRes[i] = res.slice(0, i+1).reduce((a,b) => a+b, 0) | |
} | |
for(let i = 0; i < res.length; i++) { | |
newRes[i] = newRes[i] * 100 / newRes[newRes.length - 1] | |
} | |
return newRes | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment