@yipe/dice 0.2.1 → 0.2.2

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.
@@ -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 the total weight is less than 1, a zero PMF will automatically be added to
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 }` objects, each representing an outcome and its probability.
718
- * @param label Optional name for debugging or charting.
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, DiceQuery as b, type OutcomeSnapshot as c, pmfCache as p };
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 the total weight is less than 1, a zero PMF will automatically be added to
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 }` objects, each representing an outcome and its probability.
718
- * @param label Optional name for debugging or charting.
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, DiceQuery as b, type OutcomeSnapshot as c, pmfCache as p };
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.1",
3
+ "version": "0.2.2",
4
4
  "description": "A high-performance dice probability engine for D&D 5e DPR calculations. Powers dprcalc.com.",
5
5
  "keywords": [
6
6
  "dnd",