Skip to main content

Crate eurydice_engine

Crate eurydice_engine 

Source
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.


  1. 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§

ByteRange
A range of bytes in the source text.
Diagnostic
Errors, warnings, or other information produced by the engine about a span of code.
DiagnosticLabel
A span of source text that is relevant to a diagnostic.
DiagnosticSource
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.
EvaluationFrame
One frame of the stack trace where a diagnostic was emitted.
Field
Information on how to render an output field.
NamedDistribution
A named distribution produced by an output statement.
PrimitiveMetadata
Presentation metadata for a built-in function.
PrintEvent
A print statement’s name and value.
Program
A parsed Eurydice program, ready to execute.
RunReport
Outputs and diagnostics produced by one submission.
SourceId
Identifies one block of source text within a compilation or engine session.
SourceRange
A byte range within an explicitly identified source.
SuggestedFix
One proposed edit to source text.
TraceBinding
One name to value binding. The value is stringified.

Enums§

DiagnosticCode
A kind of diagnostic being produced.
DiagnosticSeverity
Describes a diagnostic’s severity.
FieldSchema
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.