@yipe/dice 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -30
- package/dist/builder/index.cjs +588 -552
- package/dist/builder/index.cjs.map +1 -1
- package/dist/builder/index.d.cts +15 -3
- package/dist/builder/index.d.ts +15 -3
- package/dist/builder/index.js +588 -552
- package/dist/builder/index.js.map +1 -1
- package/dist/index.cjs +63 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +56 -20
- package/dist/index.js.map +1 -1
- package/dist/{pmf-DIegvlyA.d.cts → pmf-D1p2Re-J.d.cts} +29 -12
- package/dist/{pmf-DIegvlyA.d.ts → pmf-D1p2Re-J.d.ts} +29 -12
- package/package.json +21 -18
|
@@ -33,6 +33,14 @@ type DamageDistribution = Record<number, number>;
|
|
|
33
33
|
/** Canonical outcome labels supported by the query helpers. */
|
|
34
34
|
type OutcomeType = "crit" | "hit" | "missNone" | "missDamage" | "saveHalf" | "saveFail" | "pc";
|
|
35
35
|
type Rounding = "none" | "floor" | "round" | "ceil";
|
|
36
|
+
declare const onAnyHit: OutcomeType[];
|
|
37
|
+
declare const onCritOnly: OutcomeType[];
|
|
38
|
+
declare const onHitOnly: OutcomeType[];
|
|
39
|
+
declare const onMissOnly: OutcomeType[];
|
|
40
|
+
declare const onMissDamageOnly: OutcomeType[];
|
|
41
|
+
declare const onSaveHalfOnly: OutcomeType[];
|
|
42
|
+
declare const onSaveFailOnly: OutcomeType[];
|
|
43
|
+
declare const onPotentCantripOnly: OutcomeType[];
|
|
36
44
|
|
|
37
45
|
/**
|
|
38
46
|
* Query interface for analyzing dice roll probability distributions.
|
|
@@ -705,24 +713,33 @@ declare class PMF {
|
|
|
705
713
|
* - A PMF representing its outcome (e.g., damage dice).
|
|
706
714
|
* - A weight representing its probability of being selected.
|
|
707
715
|
*
|
|
708
|
-
* This is useful for modeling situations like:
|
|
709
|
-
* - Sneak Attack: 6d6 if first hit is a crit, 3d6 if first hit is non-crit, 0 otherwise.
|
|
710
|
-
* - Multiple exclusive spells: Fireball vs Cone of Cold vs nothing.
|
|
711
|
-
*
|
|
712
716
|
* Notes:
|
|
713
|
-
* - If
|
|
714
|
-
* make up the remaining probability.
|
|
715
|
-
* - Throws an error if the total weight is greater than 1 (invalid probability sum).
|
|
717
|
+
* - If total weight < 1 (within eps), leftover mass is assumed to be PMF.zero()
|
|
716
718
|
*
|
|
717
|
-
* @param options Array of `{ pmf, weight }`
|
|
718
|
-
* @param
|
|
719
|
-
* @param eps Optional tolerance for floating point rounding
|
|
720
|
-
* @returns A single PMF representing the exclusive mixture of all options.
|
|
719
|
+
* @param options Array of `{ pmf, weight }` or `[PMF, number]`.
|
|
720
|
+
* @param eps Optional tolerance for floating point rounding.
|
|
721
721
|
*/
|
|
722
722
|
static exclusive(options: Array<{
|
|
723
723
|
pmf: PMF;
|
|
724
724
|
weight: number;
|
|
725
725
|
} | [PMF, number]>, eps?: number): PMF;
|
|
726
|
+
/**
|
|
727
|
+
* PMF.mix()
|
|
728
|
+
*
|
|
729
|
+
* Builds a PMF as a linear combination of input PMFs with the given weights.
|
|
730
|
+
* Unlike `exclusive`, this does NOT:
|
|
731
|
+
* - enforce that weights sum to 1
|
|
732
|
+
* - add leftover probability to δ0 (PMF.zero())
|
|
733
|
+
*
|
|
734
|
+
* Use when outcomes are not mutually exclusive, or for interpolation/blending.
|
|
735
|
+
*
|
|
736
|
+
* @param options Array of `{ pmf, weight }` or `[PMF, number]`.
|
|
737
|
+
* @param eps Optional tolerance for skipping tiny weights.
|
|
738
|
+
*/
|
|
739
|
+
static mix(options: Array<{
|
|
740
|
+
pmf: PMF;
|
|
741
|
+
weight: number;
|
|
742
|
+
} | [PMF, number]>, eps?: number): PMF;
|
|
726
743
|
/**
|
|
727
744
|
* General-purpose N-way mixture.
|
|
728
745
|
* weights: Array of [weight, PMF].
|
|
@@ -881,4 +898,4 @@ declare class PMF {
|
|
|
881
898
|
query(): DiceQuery;
|
|
882
899
|
}
|
|
883
900
|
|
|
884
|
-
export { type Bin as B, type DamageDistribution as D, EPS as E, LRUCache as L, type OutcomeLabelMap as O, PMF as P, type Rounding as R, type Snapshot as S, type OutcomeType as a,
|
|
901
|
+
export { type Bin as B, type DamageDistribution as D, EPS as E, LRUCache as L, type OutcomeLabelMap as O, PMF as P, type Rounding as R, type Snapshot as S, type OutcomeType as a, onCritOnly as b, onHitOnly as c, onMissOnly as d, onMissDamageOnly as e, onSaveHalfOnly as f, onSaveFailOnly as g, onPotentCantripOnly as h, DiceQuery as i, type OutcomeSnapshot as j, onAnyHit as o, pmfCache as p };
|
|
@@ -33,6 +33,14 @@ type DamageDistribution = Record<number, number>;
|
|
|
33
33
|
/** Canonical outcome labels supported by the query helpers. */
|
|
34
34
|
type OutcomeType = "crit" | "hit" | "missNone" | "missDamage" | "saveHalf" | "saveFail" | "pc";
|
|
35
35
|
type Rounding = "none" | "floor" | "round" | "ceil";
|
|
36
|
+
declare const onAnyHit: OutcomeType[];
|
|
37
|
+
declare const onCritOnly: OutcomeType[];
|
|
38
|
+
declare const onHitOnly: OutcomeType[];
|
|
39
|
+
declare const onMissOnly: OutcomeType[];
|
|
40
|
+
declare const onMissDamageOnly: OutcomeType[];
|
|
41
|
+
declare const onSaveHalfOnly: OutcomeType[];
|
|
42
|
+
declare const onSaveFailOnly: OutcomeType[];
|
|
43
|
+
declare const onPotentCantripOnly: OutcomeType[];
|
|
36
44
|
|
|
37
45
|
/**
|
|
38
46
|
* Query interface for analyzing dice roll probability distributions.
|
|
@@ -705,24 +713,33 @@ declare class PMF {
|
|
|
705
713
|
* - A PMF representing its outcome (e.g., damage dice).
|
|
706
714
|
* - A weight representing its probability of being selected.
|
|
707
715
|
*
|
|
708
|
-
* This is useful for modeling situations like:
|
|
709
|
-
* - Sneak Attack: 6d6 if first hit is a crit, 3d6 if first hit is non-crit, 0 otherwise.
|
|
710
|
-
* - Multiple exclusive spells: Fireball vs Cone of Cold vs nothing.
|
|
711
|
-
*
|
|
712
716
|
* Notes:
|
|
713
|
-
* - If
|
|
714
|
-
* make up the remaining probability.
|
|
715
|
-
* - Throws an error if the total weight is greater than 1 (invalid probability sum).
|
|
717
|
+
* - If total weight < 1 (within eps), leftover mass is assumed to be PMF.zero()
|
|
716
718
|
*
|
|
717
|
-
* @param options Array of `{ pmf, weight }`
|
|
718
|
-
* @param
|
|
719
|
-
* @param eps Optional tolerance for floating point rounding
|
|
720
|
-
* @returns A single PMF representing the exclusive mixture of all options.
|
|
719
|
+
* @param options Array of `{ pmf, weight }` or `[PMF, number]`.
|
|
720
|
+
* @param eps Optional tolerance for floating point rounding.
|
|
721
721
|
*/
|
|
722
722
|
static exclusive(options: Array<{
|
|
723
723
|
pmf: PMF;
|
|
724
724
|
weight: number;
|
|
725
725
|
} | [PMF, number]>, eps?: number): PMF;
|
|
726
|
+
/**
|
|
727
|
+
* PMF.mix()
|
|
728
|
+
*
|
|
729
|
+
* Builds a PMF as a linear combination of input PMFs with the given weights.
|
|
730
|
+
* Unlike `exclusive`, this does NOT:
|
|
731
|
+
* - enforce that weights sum to 1
|
|
732
|
+
* - add leftover probability to δ0 (PMF.zero())
|
|
733
|
+
*
|
|
734
|
+
* Use when outcomes are not mutually exclusive, or for interpolation/blending.
|
|
735
|
+
*
|
|
736
|
+
* @param options Array of `{ pmf, weight }` or `[PMF, number]`.
|
|
737
|
+
* @param eps Optional tolerance for skipping tiny weights.
|
|
738
|
+
*/
|
|
739
|
+
static mix(options: Array<{
|
|
740
|
+
pmf: PMF;
|
|
741
|
+
weight: number;
|
|
742
|
+
} | [PMF, number]>, eps?: number): PMF;
|
|
726
743
|
/**
|
|
727
744
|
* General-purpose N-way mixture.
|
|
728
745
|
* weights: Array of [weight, PMF].
|
|
@@ -881,4 +898,4 @@ declare class PMF {
|
|
|
881
898
|
query(): DiceQuery;
|
|
882
899
|
}
|
|
883
900
|
|
|
884
|
-
export { type Bin as B, type DamageDistribution as D, EPS as E, LRUCache as L, type OutcomeLabelMap as O, PMF as P, type Rounding as R, type Snapshot as S, type OutcomeType as a,
|
|
901
|
+
export { type Bin as B, type DamageDistribution as D, EPS as E, LRUCache as L, type OutcomeLabelMap as O, PMF as P, type Rounding as R, type Snapshot as S, type OutcomeType as a, onCritOnly as b, onHitOnly as c, onMissOnly as d, onMissDamageOnly as e, onSaveHalfOnly as f, onSaveFailOnly as g, onPotentCantripOnly as h, DiceQuery as i, type OutcomeSnapshot as j, onAnyHit as o, pmfCache as p };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yipe/dice",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "A high-performance dice probability engine for D&D 5e DPR calculations. Powers dprcalc.com.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dnd",
|
|
@@ -24,30 +24,30 @@
|
|
|
24
24
|
"packageManager": "yarn@4.9.4",
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
"require": {
|
|
32
|
-
"types": "./dist/index.d.cts",
|
|
33
|
-
"default": "./dist/index.cjs"
|
|
34
|
-
}
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"require": "./dist/index.cjs"
|
|
35
30
|
},
|
|
36
31
|
"./builder": {
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
"require": {
|
|
42
|
-
"types": "./dist/builder/index.d.cts",
|
|
43
|
-
"default": "./dist/builder/index.cjs"
|
|
44
|
-
}
|
|
32
|
+
"types": "./dist/builder/index.d.ts",
|
|
33
|
+
"import": "./dist/builder/index.js",
|
|
34
|
+
"require": "./dist/builder/index.cjs"
|
|
45
35
|
},
|
|
46
36
|
"./package.json": "./package.json"
|
|
47
37
|
},
|
|
48
38
|
"main": "./dist/index.cjs",
|
|
49
39
|
"module": "./dist/index.js",
|
|
50
40
|
"types": "./dist/index.d.ts",
|
|
41
|
+
"typesVersions": {
|
|
42
|
+
"*": {
|
|
43
|
+
"builder": [
|
|
44
|
+
"dist/builder/index.d.ts"
|
|
45
|
+
],
|
|
46
|
+
"": [
|
|
47
|
+
"dist/index.d.ts"
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
51
|
"directories": {
|
|
52
52
|
"example": "examples",
|
|
53
53
|
"test": "tests"
|
|
@@ -57,7 +57,10 @@
|
|
|
57
57
|
"README.md",
|
|
58
58
|
"LICENSE"
|
|
59
59
|
],
|
|
60
|
-
"sideEffects":
|
|
60
|
+
"sideEffects": [
|
|
61
|
+
"./dist/builder/ac.js",
|
|
62
|
+
"./dist/builder/dc.js"
|
|
63
|
+
],
|
|
61
64
|
"scripts": {
|
|
62
65
|
"lint": "eslint .",
|
|
63
66
|
"typecheck": "tsc -p config/tsconfig.build.json --noEmit",
|