-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcortex_prime.html
More file actions
760 lines (677 loc) · 33.1 KB
/
cortex_prime.html
File metadata and controls
760 lines (677 loc) · 33.1 KB
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
<!DOCTYPE html>
<html>
<head>
<title>Cortex Prime calculator</title>
<link rel="stylesheet" href="styles.css">
<link rel="shortcut icon" type="image/png" href="favicon.png">
<meta property="og:title" content="Cortex Prime calculator" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://highdiceroller.github.io/icepool/apps/cortex_prime.html" />
<meta property="og:image" content="https://highdiceroller.github.io/icepool/apps/cortex_prime_preview.png" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="Cortex Prime calculator" />
<meta name="twitter:site" content="@highdiceroller" />
<meta name="twitter:creator" content="@highdiceroller" />
<meta name="twitter:image" content="https://highdiceroller.github.io/icepool/apps/cortex_prime_preview.png" />
<script src="https://cdn.jsdelivr.net/pyodide/v0.26.0/full/pyodide.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.5.1/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
<script src="common.js"></script>
</head>
<body>
<h1>Cortex Prime calculator <span style="font-size:75%;">powered by <a href="https://github.com/HighDiceRoller/icepool"><img src="favicon.png" height="24" width="24" /></a> Icepool</span></h1>
<div class="floating_controls">
<form id="inputs">
<table>
<tr>
<th></th>
<th>d4</th>
<th>d6</th>
<th>d8</th>
<th>d10</th>
<th>d12</th>
<th style="border-left: 2px solid #bfbfbf;">Drop</th>
<th>Keep</th>
</tr>
<tr id="pinputs">
<th style="text-align:left;">Roller</th>
<td><input name="p4" id="p4" type="number" min="0" max="10" value="0" required onwheel="" /></td>
<td><input name="p6" id="p6" type="number" min="0" max="10" value="2" required onwheel="" /></td>
<td><input name="p8" id="p8" type="number" min="0" max="10" value="0" required onwheel="" /></td>
<td><input name="p10" id="p10" type="number" min="0" max="10" value="0" required onwheel="" /></td>
<td><input name="p12" id="p12" type="number" min="0" max="10" value="0" required onwheel="" /></td>
<td style="border-left: 2px solid #bfbfbf;"><input name="pd" id="pd" type="number" min="0" max="10"
value="0" required onwheel="" /></td>
<td><input name="pk" id="pk" type="number" min="0" max="10" value="2" required onwheel="" /></td>
</tr>
<tr id="oinputs">
<th style="text-align:left;">Difficulty</th>
<td><input name="o4" id="o4" type="number" min="0" max="10" value="0" required onwheel="" /></td>
<td><input name="o6" id="o6" type="number" min="0" max="10" value="2" required onwheel="" /></td>
<td><input name="o8" id="o8" type="number" min="0" max="10" value="0" required onwheel="" /></td>
<td><input name="o10" id="o10" type="number" min="0" max="10" value="0" required onwheel="" /></td>
<td><input name="o12" id="o12" type="number" min="0" max="10" value="0" required onwheel="" /></td>
<td style="border-left: 2px solid #bfbfbf;"><input name="od" id="od" type="number" min="0" max="10"
value="0" required onwheel="" /></td>
<td><input name="ok" id="ok" type="number" min="0" max="10" value="2" required onwheel="" /></td>
</tr>
</table>
</form>
<form id="options">
<input name="heroic" , id="heroic" , type="checkbox"> Account for heroic successes (experimental).<br/>
<input name="hitch1" , id="hitch1" , type="checkbox"> Hitches count as 1s (rather than 0s), but still can't be used for effect.
</form>
</div>
<h2>Total and effect die</h2>
<div style="width: 90%; margin: auto;">
<div style="font-size: 150%;">
Show:
<select id="distSelect">
<option value="pmf">Chance of total exactly</option>
<option value="ccdf" selected="selected">Chance of beating difficulty</option>
</select>
</div>
<div class="chart_container"><canvas id="totalChart"></canvas></div>
<table style="margin: auto; text-align:right;">
<tr>
<th style="width:120px;">Mean roll</th>
<th style="width:120px;">Mean difficulty</th>
<th style="width:140px; border-left: 2px solid #bfbfbf;"></th>
<th style="width:60px;">Fail</th>
<th style="width:60px; color:rgba(140, 0, 0, 1.0);">d4</th>
<th style="width:60px; color:rgba(140, 120, 0, 1.0);">d6</th>
<th style="width:60px; color:rgba(0, 120, 0, 1.0);">d8</th>
<th style="width:60px; color:rgba(0, 120, 160, 1.0);">d10</th>
<th style="width:60px; color:rgba(0, 0, 160, 1.0);">d12</th>
<th style="width:60px; color:rgba(140, 0, 160, 1.0);">Beyond</th>
</tr>
<tr>
<td><span id="pmean"></span></td>
<td><span id="omean"></span></td>
<td style="border-left: 2px solid #bfbfbf;">Effect die exactly:</td>
<td><span id="failChance">%</span></td>
<td><span id="d4Chance" style="color:rgba(140, 0, 0, 1.0)">%</span></td>
<td><span id="d6Chance" style="color:rgba(140, 120, 0, 1.0)">%</span></td>
<td><span id="d8Chance" style="color:rgba(0, 120, 0, 1.0)">%</span></td>
<td><span id="d10Chance" style="color:rgba(0, 120, 160, 1.0)">%</span></td>
<td><span id="d12Chance" style="color:rgba(0, 0, 160, 1.0)">%</span></td>
<td><span id="beyondChance" style="color:rgba(140, 0, 160, 1.0)">%</span></td>
</tr>
<tr>
<td><span></span></td>
<td></td>
<td style="border-left: 2px solid #bfbfbf;">Effect die at least:</td>
<td><span></span></td>
<td><span id="d4Plus" style="color:rgba(140, 0, 0, 1.0)">%</span></td>
<td><span id="d6Plus" style="color:rgba(140, 120, 0, 1.0)">%</span></td>
<td><span id="d8Plus" style="color:rgba(0, 120, 0, 1.0)">%</span></td>
<td><span id="d10Plus" style="color:rgba(0, 120, 160, 1.0)">%</span></td>
<td><span id="d12Plus" style="color:rgba(0, 0, 160, 1.0)">%</span></td>
<td><span id="beyondPlus" style="color:rgba(140, 0, 160, 1.0)">%</span></td>
</tr>
</table>
</div>
<h2>Hitches</h2>
<div style="width: 90%; margin: auto;">
<div style="font-size: 150%;">
Show:
<select id="hitchDistSelect">
<option value="pmf">Chance of exactly</option>
<option value="ccdf" selected>Chance of at least</option>
</select>
</div>
<div class="chart_container"><canvas id="hitchChart"></canvas></div>
</div>
<script type="text/javascript">
setInputsFromSearchQuery();
var totalChartContext = document.getElementById('totalChart').getContext('2d');
var totalChart = new Chart(totalChartContext, {
type: 'line',
data: {
labels: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],
datasets: [
{
label: 'Any effect',
order: 5,
// fill: '+1',
borderColor: 'rgba(220, 0, 0, 1.0)',
backgroundColor: 'rgba(220, 0, 0, 0.25)',
pointStyle: 'triangle',
radius: 5,
data: [],
},
{
label: 'd6+ effect',
order: 4,
// fill: '+1',
borderColor: 'rgba(220, 200, 0, 1.0)',
backgroundColor: 'rgba(220, 200, 0, 0.25)',
pointStyle: 'rect',
radius: 4,
data: [],
},
{
label: 'd8+ effect',
order: 3,
// fill: '+1',
borderColor: 'rgba(0, 200, 0, 1.0)',
backgroundColor: 'rgba(0, 200, 0, 0.25)',
pointStyle: 'rectRot',
radius: 4,
data: [],
},
{
label: 'd10+ effect',
order: 2,
// fill: '+1',
borderColor: 'rgba(0, 200, 240, 1.0)',
backgroundColor: 'rgba(0, 200, 240, 0.25)',
pointStyle: 'crossRot',
radius: 5,
data: [],
},
{
label: 'd12+ effect',
order: 1,
// fill: {value: 0},
borderColor: 'rgba(0, 0, 240, 1.0)',
backgroundColor: 'rgba(0, 0, 240, 0.25)',
pointStyle: 'circle',
radius: 4,
data: [],
},
{
label: 'Beyond',
order: 0,
// fill: {value: 0},
borderColor: 'rgba(220, 0, 240, 1.0)',
backgroundColor: 'rgba(220, 0, 240, 0.25)',
pointStyle: 'star',
radius: 4,
data: [],
},
{
label: 'Difficulty',
order: 6,
borderColor: 'rgba(15, 15, 15, 1.0)',
pointStyle: 'circle',
radius: 0,
data: [],
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
interaction: {
intersect: false,
mode: 'index',
},
scales: {
x: {
title: {
display: true,
},
},
y: {
beginAtZero: true,
title: {
display: true,
text: 'Chance of beating difficulty',
},
ticks: {
callback: (val) => (val.toPrecision(3) * 1.0 + '%'),
},
},
y1: {
display: true,
position: 'right',
title: {
display: true,
text: 'Chance of difficulty exactly',
},
grid: {
drawOnChartArea: false, // only want the grid lines for one axis to show up
},
ticks: {
callback: (val) => (val.toPrecision(3) * 1.0 + '%'),
},
},
},
plugins: {
title: {
fullSize: true,
display: true,
font: {
size: 36,
},
},
tooltip: {
callbacks: {
label: (ctx) => ctx.dataset.label + ': ' + ctx.raw.toPrecision(3) + '%',
},
},
},
},
});
var hitchChartContext = document.getElementById('hitchChart').getContext('2d');
var hitchChart = new Chart(hitchChartContext, {
type: 'line',
data: {
labels: [],
datasets: [
{
label: 'Roller',
borderColor: 'rgba(220, 0, 0, 1.0)',
data: [],
},
{
label: 'Opposition',
borderColor: 'rgba(15, 15, 15, 1.0)',
data: [],
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
interaction: {
intersect: false,
},
scales: {
x: {
title: {
display: true,
text: 'Hitches',
},
},
y: {
beginAtZero: true,
title: {
display: true,
text: 'Chance (%)',
},
ticks: {
callback: (val) => (val.toPrecision(3) * 1.0 + '%'),
},
},
},
plugins: {
title: {
fullSize: true,
display: true,
font: {
size: 36,
},
},
tooltip: {
callbacks: {
label: (ctx) => ctx.dataset.label + ': ' + ctx.raw.toPrecision(3) + '%',
},
},
},
},
});
function setLoadingText(text) {
console.log(text);
let loadingText = text.match(/Loading \w+/);
if (!loadingText) {
return;
}
totalChart.options.plugins.title.text = loadingText[0];
totalChart.update();
hitchChart.options.plugins.title.text = loadingText[0];
hitchChart.update();
}
async function initPyodide() {
setLoadingText('Loading pyodide')
let pyodide = await loadPyodide({
indexURL: "https://cdn.jsdelivr.net/pyodide/v0.26.0/full/",
});
await pyodide.loadPackage(["micropip"],
{messageCallback : setLoadingText}
);
setLoadingText('Loading icepool')
await pyodide.runPythonAsync(`
import micropip
await micropip.install('icepool==1.6.0')
import js
import pyodide
import icepool
from bisect import bisect_left
from icepool import Die, MultisetEvaluator, Order, Pool, highest, coin, multiset_function
from functools import cache
possible_die_sizes = [4, 6, 8, 10, 12]
zero_die = Die([0])
class CortexEvaluator(MultisetEvaluator):
def __init__(self, drop_lowest, keep, target_effect):
# drop_lowest doesn't include the effect die
# it may be negative, will be rectified at start
self._drop_lowest = drop_lowest
self._keep = keep
self._target_effect = target_effect
def next_state(self, state, outcome, count):
if state is None:
drop = self._drop_lowest
keep = self._keep
total = 0
got_effect = False
if self._target_effect <= 4:
got_effect = True
# Can delay keeping by one more die.
drop += 1
drop = max(drop, 0)
else:
drop, keep, total, got_effect = state
if count > 0:
value, negative_die_size = outcome
is_effective = -negative_die_size >= self._target_effect
if is_effective and not got_effect:
count -= 1
got_effect = True
to_drop = min(count, drop)
count -= to_drop
drop -= to_drop
to_keep = min(count, keep)
keep -= to_keep
total += to_keep * value
return drop, keep, total, got_effect
def final_outcome(self, final_state):
if final_state is None:
return 0
drop, keep, total, got_effect = final_state
if not got_effect:
return 0
return total
def order(self):
return Order.Ascending
@cache
def cached_evaluator(drop_lowest, keep, target_effect):
return CortexEvaluator(drop_lowest, keep, target_effect)
@cache
def joint_evaluator(drop_lowest, keep):
d4_evaluator = cached_evaluator(drop_lowest, keep, 4)
d6_evaluator = cached_evaluator(drop_lowest, keep, 6)
d8_evaluator = cached_evaluator(drop_lowest, keep, 8)
d10_evaluator = cached_evaluator(drop_lowest, keep, 10)
d12_evaluator = cached_evaluator(drop_lowest, keep, 12)
@multiset_function
def evaluator(rolls):
return (
rolls.evaluate(evaluator=d4_evaluator),
rolls.evaluate(evaluator=d6_evaluator),
rolls.evaluate(evaluator=d8_evaluator),
rolls.evaluate(evaluator=d10_evaluator),
rolls.evaluate(evaluator=d12_evaluator),
)
return evaluator
def c(die_size, hitch_1):
return Die([int(hitch_1)] + [i for i in range(2, die_size+1)])
@cache
def ci(die_size, hitch_1):
return Die([(int(hitch_1), 0)] + [(i, -die_size) for i in range(2, die_size+1)])
def calc_any_effect(die_sizes, drop, keep, hitch_1):
dice = [c(die_size, hitch_1) for die_size in die_sizes]
return highest([0] + dice, drop=drop, keep=keep)
def calc_hitches(die_sizes):
hitch = zero_die
for n in die_sizes:
hitch += coin(1, n)
return hitch
HEROIC_MARGINS = [0, 4, 9, 14, 19, 24]
def apply_heroic_successes(totals):
result = [0] * 6
for i in range(5):
result[i] = max(totals[i - j] - HEROIC_MARGINS[j] for j in range(i + 1))
result[5] = max(totals[5 - j] - HEROIC_MARGINS[j] for j in range(1, 6))
return tuple(result)
any_effect, d6_effect, d8_effect, d10_effect, d12_effect, beyond_effect, hitch_player = (zero_die,) * 7
die_opposition, hitch_opposition = (zero_die,) * 2
def calc_player():
hitch_1 = js.document.getElementById('hitch1').checked
heroic = js.document.getElementById('heroic').checked
die_sizes = sum(([die_size] * int(js.document.getElementById(f'p{die_size}').value) for die_size in possible_die_sizes), [])
if len(die_sizes) == 0:
return (zero_die,) * 6
drop = int(js.document.getElementById('pd').value)
keep = int(js.document.getElementById('pk').value)
pool = Pool([ci(n, hitch_1) for n in die_sizes]).lowest(len(die_sizes) - drop)
drop_lowest = len(die_sizes) - 1 - keep - drop
if not heroic:
any_effect = calc_any_effect(die_sizes, drop, keep, hitch_1)
result = [any_effect]
for effect_die in [6, 8, 10, 12]:
evaluator = cached_evaluator(drop_lowest, keep, effect_die)
result.append(evaluator(pool))
result.append(zero_die)
else:
evaluator = joint_evaluator(drop_lowest, keep)
joint_result = evaluator(pool).map(apply_heroic_successes)
result = [joint_result.marginals[i] for i in range(6)]
hitch = calc_hitches(die_sizes)
result.append(hitch)
return result
def calc_opposition():
hitch_1 = js.document.getElementById('hitch1').checked
die_sizes = sum(([die_size] * int(js.document.getElementById(f'o{die_size}').value) for die_size in possible_die_sizes), [])
drop = int(js.document.getElementById('od').value)
keep = int(js.document.getElementById('ok').value)
any_effect = calc_any_effect(die_sizes, drop, keep, hitch_1)
hitch = calc_hitches(die_sizes)
return any_effect, hitch
def total_data(die, selected_dist):
if selected_dist == 'pmf':
return pyodide.ffi.to_js([die.probability(x, percent=True) for x in range(2, 26)])
else:
return pyodide.ffi.to_js([die.probability('>', x, percent=True) for x in range(2, 26)])
`);
totalChart.options.plugins.title = {
text: "",
fullSize: false,
display: false,
};
hitchChart.options.plugins.title = {
text: "",
fullSize: false,
display: false,
};
return pyodide;
}
let pyodideReadyPromise = initPyodide();
async function updatePlayerRoll() {
let pyodide = await pyodideReadyPromise;
pyodide.runPython(`
any_effect, d6_effect, d8_effect, d10_effect, d12_effect, beyond_effect, hitch_player = calc_player()
`);
}
async function updateOppositionRoll() {
let pyodide = await pyodideReadyPromise;
pyodide.runPython(`
opposition, hitch_opposition = calc_opposition()
`);
}
async function updateTotalResults() {
let selected_dist = document.getElementById('distSelect').value;
if (selected_dist === 'pmf') {
for (let i = 0; i < 6; i++) {
totalChart.data.datasets[i].fill = false;
}
totalChart.data.datasets[1].borderColor = 'rgba(220, 200, 0, 0.25)';
totalChart.data.datasets[2].borderColor = 'rgba(0, 200, 0, 0.125)';
totalChart.data.datasets[3].borderColor = 'rgba(0, 200, 240, 0.125)';
totalChart.data.datasets[4].borderColor = 'rgba(0, 0, 240, 0.125)';
totalChart.data.datasets[5].borderColor = 'rgba(220, 0, 240, 0.125)';
totalChart.options.scales.y.title.text = 'Chance of exactly';
totalChart.options.scales.y1.display = false;
totalChart.data.datasets[6].yAxisID = 'y';
} else {
for (let i = 0; i < 5; i++) {
totalChart.data.datasets[i].fill = '+1';
}
totalChart.data.datasets[5].fill = 'origin';
totalChart.data.datasets[1].borderColor = 'rgba(220, 200, 0, 1.0)';
totalChart.data.datasets[2].borderColor = 'rgba(0, 200, 0, 1.0)';
totalChart.data.datasets[3].borderColor = 'rgba(0, 200, 240, 1.0)';
totalChart.data.datasets[4].borderColor = 'rgba(0, 0, 240, 1.0)';
totalChart.data.datasets[5].borderColor = 'rgba(220, 0, 240, 1.0)';
totalChart.options.scales.y.title.text = 'Chance of beating difficulty';
totalChart.options.scales.y1.display = true;
totalChart.data.datasets[6].yAxisID = 'y1';
}
let pyodide = await pyodideReadyPromise;
pyodide.runPython(`
js.document.getElementById('pmean').innerHTML = '%0.2f' % any_effect.mean()
js.document.getElementById('omean').innerHTML = '%0.2f' % opposition.mean()
d4_chance = (any_effect > opposition).mean() - (d6_effect > opposition).mean()
d6_chance = (d6_effect > opposition).mean() - (d8_effect > opposition).mean()
d8_chance = (d8_effect > opposition).mean() - (d10_effect > opposition).mean()
d10_chance = (d10_effect > opposition).mean() - (d12_effect > opposition).mean()
d12_chance = (d12_effect > opposition).mean() - (beyond_effect > opposition).mean()
beyond_chance = (beyond_effect > opposition).mean()
js.document.getElementById('failChance').innerHTML = '%0.2f%%' % ((any_effect <= opposition).mean() * 100.0)
js.document.getElementById('d4Chance').innerHTML = '%0.2f%%' % (d4_chance * 100.0)
js.document.getElementById('d6Chance').innerHTML = '%0.2f%%' % (d6_chance * 100.0)
js.document.getElementById('d8Chance').innerHTML = '%0.2f%%' % (d8_chance * 100.0)
js.document.getElementById('d10Chance').innerHTML = '%0.2f%%' % (d10_chance * 100.0)
js.document.getElementById('d12Chance').innerHTML = '%0.2f%%' % (d12_chance * 100.0)
js.document.getElementById('beyondChance').innerHTML = '%0.2f%%' % (beyond_chance * 100.0)
js.document.getElementById('d4Plus').innerHTML = '%0.2f%%' % ((any_effect > opposition).mean() * 100.0)
js.document.getElementById('d6Plus').innerHTML = '%0.2f%%' % ((d6_effect > opposition).mean() * 100.0)
js.document.getElementById('d8Plus').innerHTML = '%0.2f%%' % ((d8_effect > opposition).mean() * 100.0)
js.document.getElementById('d10Plus').innerHTML = '%0.2f%%' % ((d10_effect > opposition).mean() * 100.0)
js.document.getElementById('d12Plus').innerHTML = '%0.2f%%' % ((d12_effect > opposition).mean() * 100.0)
js.document.getElementById('beyondPlus').innerHTML = '%0.2f%%' % ((beyond_effect > opposition).mean() * 100.0)
selected_dist = js.document.getElementById('distSelect').value
js.totalChart.data.datasets[0].data = total_data(any_effect, selected_dist)
js.totalChart.data.datasets[1].data = total_data(d6_effect, selected_dist)
js.totalChart.data.datasets[2].data = total_data(d8_effect, selected_dist)
js.totalChart.data.datasets[3].data = total_data(d10_effect, selected_dist)
js.totalChart.data.datasets[4].data = total_data(d12_effect, selected_dist)
js.totalChart.data.datasets[5].data = total_data(beyond_effect, selected_dist)
js.totalChart.data.datasets[6].data = total_data(opposition, 'pmf')
if opposition.mean() > 0:
js.totalChart.data.datasets[6].hidden = pyodide.ffi.to_js(False)
else:
js.totalChart.data.datasets[6].hidden = pyodide.ffi.to_js(True)
js.totalChart.options.scales.y1.display = pyodide.ffi.to_js(False);
heroic = js.document.getElementById('heroic').checked;
if heroic:
for i in range(6):
js.totalChart.data.datasets[i].hidden = pyodide.ffi.to_js(False)
else:
player_die_sizes = sum(([die_size] * int(js.document.getElementById(f'p{die_size}').value) for die_size in possible_die_sizes), [])
for effect_die in [6, 8, 10, 12]:
data_set_index = effect_die // 2 - 2
js.totalChart.data.datasets[data_set_index].hidden = pyodide.ffi.to_js(effect_die not in player_die_sizes)
js.totalChart.data.datasets[5].hidden = pyodide.ffi.to_js(True)
`);
totalChart.update();
}
async function updateHitchResults() {
let pyodide = await pyodideReadyPromise;
pyodide.runPython(`
outcomes = icepool.consecutive(hitch_player, hitch_opposition)
js.hitchChart.data.labels = pyodide.ffi.to_js(outcomes)
selected_dist = js.document.getElementById('hitchDistSelect').value
if selected_dist == 'pmf':
js.hitchChart.data.datasets[0].data = pyodide.ffi.to_js([hitch_player.probability(x, percent=True) for x in outcomes])
js.hitchChart.data.datasets[1].data = pyodide.ffi.to_js([hitch_opposition.probability(x, percent=True) for x in outcomes])
else:
js.hitchChart.data.datasets[0].data = pyodide.ffi.to_js([hitch_player.probability('>=', x, percent=True) for x in outcomes])
js.hitchChart.data.datasets[1].data = pyodide.ffi.to_js([hitch_opposition.probability('>=', x, percent=True) for x in outcomes])
`);
hitchChart.update();
}
function validatePlayerInputsAndUpdate() {
if (validateInputs()) {
updatePlayerRoll();
updateTotalResults();
updateHitchResults();
updateSearchQueryFromForms();
}
}
function updatePlayerIfValid() {
if (inputsAreValid()) {
updatePlayerRoll();
updateTotalResults();
updateHitchResults();
updateSearchQueryFromForms();
}
}
function validateOppositionInputsAndUpdate() {
if (validateInputs()) {
updateOppositionRoll();
updateTotalResults();
updateHitchResults();
updateSearchQueryFromForms();
}
}
function updateOppositionIfValid() {
if (inputsAreValid()) {
updateOppositionRoll();
updateTotalResults();
updateHitchResults();
updateSearchQueryFromForms();
}
}
updatePlayerRoll();
updateOppositionRoll();
updateTotalResults();
updateHitchResults();
updateSearchQueryFromForms();
let pinputs = document.querySelector('#pinputs');
pinputs.addEventListener('change', validatePlayerInputsAndUpdate);
pinputs.addEventListener('input', updatePlayerIfValid);
let oinputs = document.querySelector('#oinputs');
oinputs.addEventListener('change', validateOppositionInputsAndUpdate);
oinputs.addEventListener('input', updateOppositionIfValid);
let options = document.querySelector('#options');
options.addEventListener('input', validateInputs);
options.addEventListener('input', updatePlayerRoll);
options.addEventListener('input', updateOppositionRoll);
options.addEventListener('input', updateTotalResults);
options.addEventListener('input', updateHitchResults);
options.addEventListener('input', updateSearchQueryFromForms);
let dist_select = document.querySelector('#distSelect');
dist_select.addEventListener('input', updateTotalResults);
let hitch_dist_select = document.querySelector('#hitchDistSelect');
hitch_dist_select.addEventListener('input', updateHitchResults);
</script>
<div class="text_content">
<h2>Notes</h2>
<ul>
<li>If more dice are specified to be dropped and/or kept than there are in the pool, the excess kept dice do not contribute to the total.</li>
<li>"Drop" is used for e.g. the Burst SFX and removes the highest-rolling dice before keeping among the rest. In case of a tie, the smaller die is removed.</li>
<li>Remember that the roller loses ties, dice that roll a 1 (hitch) can't be used for the total or effect, and there is always the option to have a "free" d4 effect.</li>
<li>Because the roller loses ties, the difference between a normal success and the first heroic success is 4 rather than 5.</li>
<li>On the "exactly" plot, the effect die curves show the chance of rolling exactly a total while keeping an effect die of <b>at least</b> that size.</li>
<li>On the "beating difficulty" plot:
<ul>
<li>The vertical <b>position</b> of each effect die <b>curve</b> at a particular total is the chance of beating that difficulty while keeping an effect die of <b>at least</b> that size.</li>
<li>The vertical <b>extent</b> of each effect die <b>area</b> at a particular total is the chance of beating that difficulty while keeping an effect die of <b>exactly</b> that size.</li>
<li>The area above the d4 curve represents failure.</li>
</ul>
</ul>
<h3>How does it work?</h3>
<p>
I built this using <a href="https://pyodide.org/en/stable/">Pyodide</a>, <a
href="https://www.chartjs.org/">Chart.js</a>,
and of course, my own <a href="https://github.com/HighDiceRoller/icepool">Icepool</a> Python library.
</p>
<h3>Prior work</h3>
<p>
Here is a <a href="https://ramblurr.github.io/firefly-rpg-generator/probability.html">previous calculator by
Casey Link</a>, which uses exponential-time enumeration of all possible die results.
While my calculator needs to load <a href="https://pyodide.org/en/stable/">pyodide</a>, it can compute
larger pools at interactive speed due to a <a
href="https://github.com/HighDiceRoller/icepool/blob/main/papers/icepool_preprint.pdf">polynomial-time
algorithm</a>.
</p>
<p>
Questions, comments, or suggestions? Find me on <a
href="https://www.reddit.com/user/HighDiceRoller">Reddit</a> or <a
href="https://twitter.com/highdiceroller">Twitter</a>.
</p>
</div>
<br />
</body>