@yipe/dice 0.1.0 → 0.1.1

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/dist/index.d.cts CHANGED
@@ -572,7 +572,7 @@ declare class DiceQuery {
572
572
  * const bonusAttack = parse("(d20 + 3 AC 15) * (1d6 + 1)");
573
573
  * const bothAttacks = mainAttack.convolve(bonusAttack);
574
574
  */
575
- convolve(other: DiceQuery, eps?: number): DiceQuery;
575
+ convolve(other: DiceQuery): DiceQuery;
576
576
  /**
577
577
  * First-success split over an ordered list of DISTINCT single-swing PMFs.
578
578
  * Each PMF may have different success/subset probabilities (from labels).
@@ -635,7 +635,7 @@ declare class PMF {
635
635
  constructor(map?: Map<number, Bin>, epsilon?: number, normalized?: boolean, identifier?: string, _preservedProvidence?: boolean);
636
636
  static empty(epsilon?: number, identifier?: string): PMF;
637
637
  static zero(epsilon?: number): PMF;
638
- static emptyMass(epsilon?: number): PMF;
638
+ static emptyMass(): PMF;
639
639
  [Symbol.iterator](): IterableIterator<[number, Bin]>;
640
640
  static clearCache(): void;
641
641
  /**
@@ -741,7 +741,7 @@ declare class PMF {
741
741
  * If you want to query any atLeast probabilities, you should use the DiceQuery class instead without power().
742
742
  */
743
743
  power(n: number, eps?: number): PMF;
744
- replicate(n: number, eps?: number): PMF[];
744
+ replicate(n: number): PMF[];
745
745
  mass(): number;
746
746
  outcomeMass(outcome: string): number;
747
747
  faceTotal(): number;
package/dist/index.d.ts CHANGED
@@ -572,7 +572,7 @@ declare class DiceQuery {
572
572
  * const bonusAttack = parse("(d20 + 3 AC 15) * (1d6 + 1)");
573
573
  * const bothAttacks = mainAttack.convolve(bonusAttack);
574
574
  */
575
- convolve(other: DiceQuery, eps?: number): DiceQuery;
575
+ convolve(other: DiceQuery): DiceQuery;
576
576
  /**
577
577
  * First-success split over an ordered list of DISTINCT single-swing PMFs.
578
578
  * Each PMF may have different success/subset probabilities (from labels).
@@ -635,7 +635,7 @@ declare class PMF {
635
635
  constructor(map?: Map<number, Bin>, epsilon?: number, normalized?: boolean, identifier?: string, _preservedProvidence?: boolean);
636
636
  static empty(epsilon?: number, identifier?: string): PMF;
637
637
  static zero(epsilon?: number): PMF;
638
- static emptyMass(epsilon?: number): PMF;
638
+ static emptyMass(): PMF;
639
639
  [Symbol.iterator](): IterableIterator<[number, Bin]>;
640
640
  static clearCache(): void;
641
641
  /**
@@ -741,7 +741,7 @@ declare class PMF {
741
741
  * If you want to query any atLeast probabilities, you should use the DiceQuery class instead without power().
742
742
  */
743
743
  power(n: number, eps?: number): PMF;
744
- replicate(n: number, eps?: number): PMF[];
744
+ replicate(n: number): PMF[];
745
745
  mass(): number;
746
746
  outcomeMass(outcome: string): number;
747
747
  faceTotal(): number;
package/dist/index.js CHANGED
@@ -1,8 +1,12 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+
1
5
  // src/lru-cache.ts
2
6
  var LRUCache = class {
3
7
  constructor(maxSize = 1e3) {
4
8
  this.maxSize = maxSize;
5
- this.cache = /* @__PURE__ */ new Map();
9
+ __publicField(this, "cache", /* @__PURE__ */ new Map());
6
10
  }
7
11
  get(key) {
8
12
  const value = this.cache.get(key);
@@ -47,6 +51,8 @@ var TEST_EPS = 1e-10;
47
51
  // src/query.ts
48
52
  var _DiceQuery = class _DiceQuery {
49
53
  constructor(singles, combined) {
54
+ __publicField(this, "singles");
55
+ __publicField(this, "combined");
50
56
  this.singles = Array.isArray(singles) ? singles : [singles];
51
57
  const c = combined ?? PMF.convolveMany(this.singles);
52
58
  this.combined = Math.abs(c.mass() - 1) <= 1e-12 ? c : c.normalize();
@@ -993,7 +999,7 @@ var _DiceQuery = class _DiceQuery {
993
999
  outcomeTotals(outcomes = this.outcomeKeys()) {
994
1000
  const totals = /* @__PURE__ */ new Map();
995
1001
  outcomes.forEach((o) => totals.set(o, 0));
996
- for (const [x, row] of this.combined.map) {
1002
+ for (const [, row] of this.combined.map) {
997
1003
  for (const o of outcomes) {
998
1004
  const p = row.count[o] || 0;
999
1005
  totals.set(o, (totals.get(o) || 0) + p);
@@ -1208,7 +1214,7 @@ var _DiceQuery = class _DiceQuery {
1208
1214
  * const bonusAttack = parse("(d20 + 3 AC 15) * (1d6 + 1)");
1209
1215
  * const bothAttacks = mainAttack.convolve(bonusAttack);
1210
1216
  */
1211
- convolve(other, eps) {
1217
+ convolve(other) {
1212
1218
  const singles = [...this.singles, ...other.singles];
1213
1219
  return new _DiceQuery(singles);
1214
1220
  }
@@ -1264,11 +1270,11 @@ var _DiceQuery = class _DiceQuery {
1264
1270
  return [a, b, any, none];
1265
1271
  }
1266
1272
  };
1267
- _DiceQuery.DEFAULT_OUTCOMES = [
1273
+ __publicField(_DiceQuery, "DEFAULT_OUTCOMES", [
1268
1274
  "hit",
1269
1275
  "crit",
1270
1276
  "missNone"
1271
- ];
1277
+ ]);
1272
1278
  var DiceQuery = _DiceQuery;
1273
1279
  var EPSILON = COMPUTATIONAL_EPS;
1274
1280
  var pmfCache = new LRUCache(1e3);
@@ -1279,6 +1285,14 @@ var _PMF = class _PMF {
1279
1285
  this.normalized = normalized;
1280
1286
  this.identifier = identifier;
1281
1287
  this._preservedProvidence = _preservedProvidence;
1288
+ // Cached computed values
1289
+ __publicField(this, "_support");
1290
+ __publicField(this, "_min");
1291
+ __publicField(this, "_max");
1292
+ __publicField(this, "_totalMass");
1293
+ __publicField(this, "_mean");
1294
+ __publicField(this, "_variance");
1295
+ __publicField(this, "_stdev");
1282
1296
  }
1283
1297
  static empty(epsilon = EPSILON, identifier = "empty") {
1284
1298
  return new _PMF(/* @__PURE__ */ new Map(), epsilon, false, identifier);
@@ -1290,7 +1304,7 @@ var _PMF = class _PMF {
1290
1304
  return new _PMF(m, epsilon, false, "zero");
1291
1305
  }
1292
1306
  // This creates a single bin at value 0, but with weight 0.
1293
- static emptyMass(epsilon = EPSILON) {
1307
+ static emptyMass() {
1294
1308
  return _PMF.zero().scaleMass(0);
1295
1309
  }
1296
1310
  // Makes PMF iterable over [damage, bin] pairs.
@@ -1498,7 +1512,7 @@ var _PMF = class _PMF {
1498
1512
  /*
1499
1513
  * Helper for chaining multiple identical attacks
1500
1514
  */
1501
- replicate(n, eps = this.epsilon) {
1515
+ replicate(n) {
1502
1516
  if (!Number.isInteger(n) || n <= 0) {
1503
1517
  throw new Error("combineN(n): n must be a positive integer");
1504
1518
  }
@@ -2096,7 +2110,7 @@ var _PMF = class _PMF {
2096
2110
  }
2097
2111
  };
2098
2112
  // Unique ID generator for anonymous PMFs to avoid cache key collisions
2099
- _PMF.__anonIdCounter = 1;
2113
+ __publicField(_PMF, "__anonIdCounter", 1);
2100
2114
  var PMF = _PMF;
2101
2115
  function getPowerCacheKey(base, n, eps) {
2102
2116
  const id = base.identifier;
@@ -2108,10 +2122,11 @@ function getPowerCacheKey(base, n, eps) {
2108
2122
  // src/dice.ts
2109
2123
  var Dice = class _Dice {
2110
2124
  constructor(x = 0) {
2111
- this.faces = {};
2112
- this.privateData = {};
2113
- this.outcomeData = {};
2114
- this.hasHitDistributionCalculated = false;
2125
+ __publicField(this, "faces", {});
2126
+ __publicField(this, "privateData", {});
2127
+ __publicField(this, "outcomeData", {});
2128
+ __publicField(this, "hasHitDistributionCalculated", false);
2129
+ __publicField(this, "identifier");
2115
2130
  if (x <= 0) return;
2116
2131
  for (let i = 1; i <= x; i++) {
2117
2132
  this.faces[i] = 1;
@@ -2780,20 +2795,12 @@ function parseArgumentInternal(s, n) {
2780
2795
  case "k":
2781
2796
  assertToken(s, "k");
2782
2797
  return parseKeep(s, n);
2783
- case "0":
2784
- case "1":
2785
- case "2":
2786
- case "3":
2787
- case "4":
2788
- case "5":
2789
- case "6":
2790
- case "7":
2791
- case "8":
2792
- case "9":
2793
2798
  case "n":
2794
2799
  return parseNumber(s, n);
2800
+ default:
2801
+ if (isDigit(c)) return parseNumber(s, n);
2802
+ return;
2795
2803
  }
2796
- return;
2797
2804
  }
2798
2805
  function parseBinaryArgument(arg, arr, n) {
2799
2806
  if (arr.length >= 4 && arr[0] === "h" && peek(arr, "half")) {