# CF rough chance calculations

Nov 18th, 2020 (edited)
833
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. let chanceToRoll = [0.074409,   0.101869,   0.165654,   0.275538,   0.030763,   0.330264, 0,    0.021503];
2.
3. let nothingObtained = [0, 0, 0, 0, 0, 0, 0, 0];
4.
5. function equals (a, b) {
6.     for (let i = 0; i < 8; ++i)
7.     {
8.         if (a[i] != b[i]) return false;
9.     }
10.     return true;
11. }
12.
13. function available(state, total) {
14.     let available = total;
15.     for (let i = 0; i < 8; ++i)
16.     {
17.         available -= (i + 1) * state[i];
18.     }
19.     return available;
20. }
21.
23.     for (let index = 0; index < currentData.length; ++index) {
24.         if (equals(currentData[index][0], pair[0])) {
25.             currentData[index][1] += pair[1];
26.             return;
27.         }
28.     }
29.     currentData.push(pair);
30. }
31.
32. function calculate(startingPoints, runUntil, rank) {
33.     let data = [[nothingObtained, 1]];
34.     for (let total = startingPoints + 1; total <= runUntil; total++) {
35.         let newData = [];
36.         for(let pair of data) {
37.             let state = pair[0];
38.             let baseChance = pair[1];
39.             let toSpend = available(pair[0], total);
40.             for (let index = 0; index < toSpend; index++) {
41.                 let newState = pair[0].slice(0, 8);
42.                 newState[index]++;
43.                 addToData(newData, [newState, baseChance * chanceToRoll[index]]);
44.             }
45.             let chanceToMiss = baseChance * chanceToRoll.slice(toSpend, 8).reduce((a, b) => a+b, 0);
46.             if (chanceToMiss > 0) {
48.             }
49.         }
50.         data = newData;
51.     }
52.     let chanceToObtain = 0;
53.     for(let pair of data) {
54.         let state = pair[0];
55.         let chance = pair[1];
56.         if (state[rank - 1] > 0) {
57.             chanceToObtain += chance;
58.         }
59.     }
60.     return chanceToObtain;
61. }
62.
63. function makeTable(startingPoints, rolls) {
64.     const output = [];
65.     for (let roll = 1; roll <= rolls; roll++) {
66.         for (let rank = 1; rank <= 8; ++rank) {
67.             output.push(calculate(startingPoints, startingPoints + roll, rank) + '\t');
68.         }
69.         output.push('\n');
70.     }
71.     return output.join('');
72. }
RAW Paste Data