-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-probabilities.ts
43 lines (38 loc) · 1.07 KB
/
build-probabilities.ts
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
import {
computeProbs,
probabilityOfFehlwurf,
} from "bratwurm-probabilities/bratwurm/bratwurmFunctions";
// @ts-ignore
import * as file from "fs";
import { number } from "mathjs";
// @ts-ignore
import { TARGETS } from "./src/components/DiceType";
console.debug = () => {};
let content = "";
function formatProb(prob: number): string {
if (prob === 0) {
return "0";
}
if (prob === 1) {
return "1";
}
return prob.toFixed(3).substring(2);
}
const exactProbsMap = new Map<string, number[]>(
[...computeProbs(false)].map((p) => [p.diceCounts.join(""), p.probs])
);
const sumProbs = computeProbs(true);
for (const sum of sumProbs) {
const exact =
exactProbsMap.get(sum.diceCounts.join("")) ?? TARGETS.map(() => 0);
const fw = probabilityOfFehlwurf({
thrown: { diceCount: sum.diceCounts, probability: 1 },
fehlWurf: false,
});
content +=
`${sum.diceCounts.join("")}` +
`:${formatProb(number(fw))}` +
`:${exact.map(formatProb).join(",")}` +
`:${sum.probs.map(formatProb).join(",")}\n`;
}
file.writeFileSync("src/assets/probs.txt", content);