Phaser AE

Flexible dice

Free packv3.0.0-2Logic

A dice pool that leaves the rules to you. Standard dice, weighted dice, negative dice and symbolic attack and defence dice share one contract, any of them can be held, every roll can be replayed, and the exact odds of any result are a call away.

This is a Free pack. Every phaser.io account can use it in their games.

Released October 14, 2026 · updated October 19, 2026

Flexible dice: a screenshot of its demo
A note about these graphics

Expansion packs don't come with graphics. This screenshot is one way of drawing what the pack does, made for its demo: none of the sprites, tiles or backgrounds in it are in the pack.

That's by design. A pack is a game's logic, mechanics and effects, and it works with whatever art you give it. Some packs draw effects, backdrops or 3D scenes of their own, but none carries a game's sprites.

So the look is yours. Make the art on phaser.io, bring your own, or let your agent draw it in code: the same pack can look like anything.

The pack

diceCore

function diceCore(): Pack<{ diceCore: typeof rules }>

Install generic dice, holds, reproducible randomness and finite probability utilities.

Helpers

createDicePool

function createDicePool(options: DiceOptions): DicePool

Construct an independently usable dice pool.

diceProbability

function diceProbability(dice: readonly DieDefinition[], predicate: (values: readonly (number | string)[]) => boolean, budget = 100000): ProbabilityResult

Exact probability for any numeric/symbolic predicate on independent dice, bounded before enumeration.

diceSumDistribution

function diceSumDistribution(dice: readonly DieDefinition[], budget = 100000): { status: 'exact'; sums: { value: number; probability: number }[]; operations: number } | { status: 'budget-exhausted'; operations: number; budget: number }

Convolve integer-valued dice sums; supports negative/custom/weighted values and reports work exhaustion.

standardDie

function standardDie(id: string, sides = 6, start = 1): DieDefinition

Create a fair numeric die, including d4/d6/d8/d10/d12/d20 or other finite sizes.

Classes

DicePool

class DicePool

A headless mixed dice pool. Rules about turns, reroll limits and scoring belong to consumers.

  • constructor(options: DiceOptions)
  • observation(): { dice: { id: string; face: DieFace | null; held: boolean }[]; rolls: number } — Copies of currently showing faces; no random state or future outcomes.
  • hold(id: string, held: boolean): DiceResult — Set a hold only on a die that has been rolled. Rejections do not consume randomness.
  • release(): void — Release all holds; useful at a game-defined turn boundary.
  • apply(action: DiceAction): DiceResult — Apply a generic command; consumers may record these for deterministic animated replay.
  • roll(ids?: readonly string[]): DiceResult — Roll unheld dice, or an explicit subset of unheld IDs. Selection is validated atomically.
  • snapshot(): DiceSnapshot — Save data contains RNG state and must not be passed to a bot/hint as an observation.
  • restore(snapshot: DiceSnapshot): void — Restore validated state for this exact pool; failure leaves the live pool unchanged.

Types

DiceAction

type DiceAction = { kind: 'roll'; ids?: string[] } | { kind: 'hold'; id: string; held: boolean } | { kind: 'release' }

Generic replayable commands; no game-specific roll or score limits.

DiceEvent

type DiceEvent = { kind: 'roll'; roll: number; dice: { id: string; face: DieFace }[] } | { kind: 'hold'; id: string; held: boolean }

One ordered, public dice event.

DiceOptions

interface DiceOptions

Configuration for a renderer-independent dice pool.

  • seed: number — Unsigned 32-bit seed.
  • dice: DieDefinition[] — One to 64 independently rolled dice.

DiceResult

type DiceResult = { ok: true; events: DiceEvent[] } | { ok: false; reason: string }

Accepted action and its events, or a rejection with no mutation.

DiceSnapshot

interface DiceSnapshot

A serializable dice pool with restorable random state.

  • version: 1 — Snapshot format.
  • options: DiceOptions — Original definitions and seed.
  • randomState: number[] — Where the kernel's seeded stream stands (the four words of createRng(seed).snapshot()). The pool draws from this array in place, so a copy of the snapshot is a copy of the stream. Privileged save data, not a future-roll hint.
  • faces: (string | null)[] — Face IDs, null before the first roll.
  • held: boolean[] — Held dice are excluded from ordinary rolls.
  • rolls: number — Number of successful rolls.

DieDefinition

interface DieDefinition

An arbitrary finite die. Multiple dice may use the same faces.

  • id: string — Unique within the pool.
  • faces: DieFace[] — One to 256 distinct faces.

DieFace

interface DieFace

A numeric or symbolic face; its stable ID is independent of its display label.

  • id: string — Unique within this die.
  • value: number | string — Game-defined numeric or symbolic result.
  • label?: string — Optional display text.
  • weight?: number — Positive relative probability; default 1.

ProbabilityResult

type ProbabilityResult = { status: 'exact'; probability: number; outcomes: number } | { status: 'budget-exhausted'; required: number; budget: number }

Exact finite enumeration succeeds only when the complete support fits the budget.