-
Notifications
You must be signed in to change notification settings - Fork 9
/
listdrop.html
417 lines (367 loc) · 16.3 KB
/
listdrop.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<html>
<head>
<title>Fallout 76 List drop Monte-Carlo simulation</title>
<style>
* {
font-family: sans-serif;
font-size: 20px;
}
td {
padding: 2px;
border: 1px solid black;
}
table.infoTable {
border: 1px solid black;
border-collapse: collapse;
}
table.infoTable td {
border: 1px solid black;
}
</style>
</head>
<body>
<center>
<span style="font-size: 36px; font-weight: bold;">Fallout 76 List drop Monte-Carlo simulation (0.2)</span><br/>
<br/>
<a href='leveledlist'>Documentation</a>
<br/>
<br/>
Options: <input id='count' type="number" min="1" value='6' style='width: 100px;'><button id='createTableBtn'>Create</button>
<hr>
List mode: <select id='mode'>
<option value='all'>Use all</option>
<option value='random'>For each</option>
<option value='first'>First match condition</option>
</select>
Max (all mode): <input id='max' type='number' value='0' min='0' style='width: 70px;'>
<!--
Quantity(for-each mode): <input id='quantity' type='number' value='1' min='0' style='width: 70px;'></br>
-->
<br/><br/>
<table id='main' style='border-collapse: collapse;'>
<tr style='font-weight: bold;'>
<td colspan='2'>Condition</td>
<td rowspan='2'>Chance None (%)</td>
<td rowspan='2'>Probability (sim)</td>
<td rowspan='2'>Probability (formula)</td>
</tr>
<tr style='font-weight: bold;'>
<td>Logic</td>
<td>RNG match chance (%)</td>
</tr>
</table>
<br/>
Rounds: <input id='rounds' type="number" min="1" value='1000000'> <button id='runBtn'>Run!</button>
</center>
<script>
function createTable() {
var n = parseInt(document.getElementById("count").value);
var tbl = document.getElementById("main");
for (var i = tbl.rows.length - 1; i > 1; i--) {
tbl.deleteRow(i);
}
for (var i = 1; i <= n; i++) {
var row = tbl.insertRow(tbl.rows.length);
c2 = row.insertCell(row.cells.length);
c2.style.textAlign = "center";
c2.innerHTML = "<input id='condition" + i + "' type='checkbox' checked='checked'>";
c2.style.border = "1px solid black";
var c1 = row.insertCell(row.cells.length);
c1.innerHTML = "<input id='rng" + i + "' type='number' min='0' max='100' value='100'>";
c1.style.border = "1px solid black";
var c1 = row.insertCell(row.cells.length);
c1.innerHTML = "<input id='chanceNone" + i + "' type='number' min='0' max='100' value='0'>";
c1.style.border = "1px solid black";
c2 = row.insertCell(row.cells.length);
c2.id = "probsim" + i;
c2.innerText = "0.000 %";
c2.style.textAlign = "right";
c2.style.border = "1px solid black";
c2 = row.insertCell(row.cells.length);
c2.id = "probformula" + i;
c2.innerText = "0.000 %";
c2.style.textAlign = "right";
c2.style.border = "1px solid black";
document.getElementById("chanceNone" + i).oninput = run;
document.getElementById("condition" + i).oninput = run;
document.getElementById("rng" + i).oninput = run;
}
var row = tbl.insertRow(tbl.rows.length);
var cll = row.insertCell(row.cells.length);
cll.innerText = "Empty";
cll.colSpan = 3;
cll.style.border = "1px solid black";
cll = row.insertCell(row.cells.length);
cll.id = "emptysim";
cll.innerText = "0.000 %";
cll.style.textAlign = "right";
cll.style.border = "1px solid black";
cll = row.insertCell(row.cells.length);
cll.id = "emptyformula";
cll.innerText = "0.000 %";
cll.style.textAlign = "right";
cll.style.border = "1px solid black";
}
function cap(value) {
if (value < 0) {
return 0;
}
if (value > 1) {
return 1
}
return value;
}
function run() {
var tbl = document.getElementById("main");
var rounds = parseInt(document.getElementById("rounds").value);
var modeSel = document.getElementById("mode");
var mode = modeSel.options[modeSel.selectedIndex].value;
var max = parseInt(document.getElementById("max").value);
var count = parseInt(document.getElementById("count").value);
// var quantity = parseInt(document.getElementById("quantity").value);
var quantity = 1;
var entries = [];
var hasRng = false;
for (var i = 1; i <= count; i++) {
document.getElementById("probsim" + i).innerText = "";
document.getElementById("probformula" + i).innerText = "";
if (document.getElementById("condition" + i).checked) {
var rng = cap(parseFloat(document.getElementById("rng" + i).value) / 100.0);
var chanceNone = cap(parseFloat(document.getElementById("chanceNone" + i).value) / 100.0);
if (rng < 1) {
hasRng = true;
}
entries.push({
index: i,
chanceNone: chanceNone,
conditionRandom: rng,
count: 0
});
}
}
simulate(mode, max, entries, rounds, hasRng, quantity);
for (var entry of entries) {
entry.count = 0;
}
formula(mode, max, entries, hasRng, quantity);
}
function filterIfRng(entriesBase, hasRng) {
if (hasRng) {
var result = [];
for (var e of entriesBase) {
if (e.conditionRandom > Math.random()) {
result.push(e);
}
}
return result;
}
return entriesBase;
}
function simulate(mode, max, entriesBase, rounds, hasRng, quantity) {
var empty = 0;
if (entriesBase.length != 0) {
if (mode == 'all') {
for (var r = 0; r < rounds; r++) {
var entries = filterIfRng(entriesBase, hasRng);
var found = 0;
for (var entry of entries) {
if (entry.chanceNone <= Math.random()) {
entry.count++;
if (++found == max) {
break;
}
}
}
if (found == 0) {
empty++;
}
}
}
else if (mode == 'random') {
for (var r = 0; r < rounds; r++) {
var entries = filterIfRng(entriesBase, hasRng);
if (entries.length != 0) {
var idx = Math.floor(entries.length * Math.random());
var entry = entries[idx];
if (entry.chanceNone <= Math.random()) {
entry.count++;
} else {
empty++;
}
} else {
empty++;
}
}
}
else if (mode == 'first') {
for (var r = 0; r < rounds; r++) {
var entries = filterIfRng(entriesBase, hasRng);
if (entries.length != 0) {
var entry = entries[0];
if (entry.chanceNone <= Math.random()) {
entry.count++;
} else {
empty++;
}
} else {
empty++;
}
}
}
} else {
empty = rounds;
}
for (var entry of entriesBase) {
document.getElementById("probsim" + entry.index).innerText = (entry.count * 100.0 / rounds).toFixed(3) + " %";
}
document.getElementById("emptysim").innerText = (empty * 100.0 / rounds).toFixed(3) + " %";
}
function formula(mode, max, entries, hasRng, quantity) {
var empty = 1;
if (mode == 'all') {
if (max == 0) {
for (var entry of entries) {
var selfChance = (1 - entry.chanceNone) * entry.conditionRandom;
entry.count = selfChance;
empty *= 1 - selfChance;
}
}
else if (max == 1) {
for (var entry of entries) {
var selfChance = (1 - entry.chanceNone) * entry.conditionRandom;
entry.count = selfChance * empty;
empty *= (1 - selfChance);
}
}
else {
empty = maxFormula(entries, max);
}
}
else if (mode == "random") {
if (entries.length != 0) {
if (!hasRng) {
empty = 0;
var m = 1.0 / entries.length;
for (var entry of entries) {
entry.count = (1 - entry.chanceNone) * m;
empty += entry.chanceNone * m;
}
} else {
empty = binaryFormula(entries);
}
} else {
empty = 1;
}
}
else if (mode == "first") {
if (hasRng) {
var sum = 0;
for (var entry of entries) {
var selfChance = (1 - entry.chanceNone) * entry.conditionRandom;
entry.count = selfChance * empty;
empty *= (1 - entry.conditionRandom);
sum += entry.count;
}
empty = 1 - sum;
} else {
var entry = entries[0];
entry.count = (1 - entry.chanceNone);
empty = entry.chanceNone;
}
}
for (var entry of entries) {
document.getElementById("probformula" + entry.index).innerText = (entry.count * 100.0).toFixed(3) + " %";
}
document.getElementById("emptyformula").innerText = (empty * 100.0).toFixed(3) + " %";
}
function bitCount(n) {
n = n - ((n >> 1) & 0x55555555);
n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
function maxFormula(entries, max) {
var empty = 1.0;
for (var i = 0; i < max; i++) {
var entry = entries[i];
var selfChance = (1 - entry.chanceNone) * entry.conditionRandom;
entry.count = selfChance;
empty *= 1 - selfChance;
}
var residue = 0;
for (var i = max; i < entries.length; i++) {
var sum = 0;
var minPattern = 1 << (i - 1);
var maxPattern = ((1 << i) - 1);
for (var p = minPattern; p <= maxPattern; p++) {
if (bitCount(p) == max) {
var product = 1.0;
for (var b = 0; b < i; b++) {
var mask = 1 << b;
var e = entries[b];
var selfChance = (1 - e.chanceNone) * e.conditionRandom;
if ((p & mask) != 0) {
product *= selfChance;
} else {
product *= 1 - selfChance;
}
}
sum += product;
}
}
residue += sum;
var entry = entries[i];
var selfChance = (1 - entry.chanceNone) * entry.conditionRandom;
entry.count = selfChance * (1 - residue);
empty *= 1 - selfChance;
}
return empty;
}
function binaryFormula(entries) {
var n = entries.length;
var bits = 1 << n;
var empty = 1;
for (var i = 0; i < bits; i++) {
var product = 1;
var nonZeroCount = 0;
for (var j = 0; j < n; j++) {
var mask = 1 << j;
var entry = entries[j];
var cr = entry.conditionRandom;
if ((i & mask) != 0) {
product *= cr;
nonZeroCount++;
} else {
product *= (1 - cr);
}
}
if (i == 0) {
empty = product;
} else {
product /= nonZeroCount;
for (var j = 0; j < n; j++) {
var mask = 1 << j;
var entry = entries[j];
if ((i & mask) != 0) {
entry.count += product;
}
}
}
}
var sum = 0;
for (var entry of entries) {
var baseChance = entry.count;
entry.count = (1 - entry.chanceNone) * baseChance;
sum += entry.count;
}
return 1 - sum;
}
document.getElementById("createTableBtn").onclick = createTable;
document.getElementById("runBtn").onclick = run;
document.getElementById("mode").oninput = run;
document.getElementById("max").oninput = run;
//document.getElementById("quantity").oninput = run;
createTable();
run();
</script>
</body>
</html>