Expand description
§eurydice_engine
The dice probability engine used by Eurydice, an implementation of the AnyDice language.
use eurydice_engine::Engine;
let mut engine = Engine::new();
let report = engine.run_source("output 2d6 named \"roll\"");
assert!(report.diagnostics.first_error().is_none());
assert_eq!(report.outputs[0].name, "roll");
assert_eq!(
report.outputs[0].distribution.entries().next(),
Some(([2].as_slice(), 1.0 / 36.0)),
);The language is documented in the Eurydice specification; it is a near-strict superset of AnyDice, documented at the AnyDice docs
Probabilities are computed exactly with rational arithmetic and converted to
f64 only at the end. When possible, computation uses the Icepool
algorithm.1
This crate offers no real extension points today, but methods to have the host program insert new primitives or modify the AST are planned.
§Features
serde derives Serialize on the public report types. Enable it when a
frontend needs to serialize engine results.
§This project is not affiliated with AnyDice
AnyDice was created by Jasper Flick. This is an independent reimplementation of its language.
§License
Apache-2.0.
Liu, A. J. (2022). Icepool: Efficient Computation of Dice Pool Probabilities. Proceedings of the AAAI Conference on Artificial Intelligence and Interactive Digital Entertainment, 18(1), 258-265. https://doi.org/10.1609/aiide.v18i1.21971 ↩
Structs§
- Byte
Range - A range of bytes in the source text.
- Diagnostic
- Errors, warnings, or other information produced by the engine about a span of code.
- Diagnostic
Label - A span of source text that is relevant to a diagnostic.
- Diagnostic
Source - A block of source text referenced by a diagnostic.
- Diagnostics
- Diagnostics produced by compiling or running a program, together with every source text needed to render them.
- Distribution
- A distribution of outcomes, each with a probability.
- Engine
- Stateful façade for parsing and evaluating Eurydice programs.
- Evaluation
Frame - One frame of the stack trace where a diagnostic was emitted.
- Field
- Information on how to render an output field.
- Named
Distribution - A named distribution produced by an
outputstatement. - Primitive
Metadata - Presentation metadata for a built-in function.
- Print
Event - A
printstatement’s name and value. - Program
- A parsed Eurydice program, ready to execute.
- RunReport
- Outputs and diagnostics produced by one submission.
- Source
Id - Identifies one block of source text within a compilation or engine session.
- Source
Range - A byte range within an explicitly identified source.
- Suggested
Fix - One proposed edit to source text.
- Trace
Binding - One name to value binding. The value is stringified.
Enums§
- Diagnostic
Code - A kind of diagnostic being produced.
- Diagnostic
Severity - Describes a diagnostic’s severity.
- Field
Schema - Describes how one output field’s values are displayed, shared by every outcome of a distribution.
Functions§
- primitive_
metadata - Returns completion and documentation metadata for every built-in function.