Package Exports
- @galaxyops/dice-simulator
- @galaxyops/dice-simulator/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@galaxyops/dice-simulator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@galaxyops/dice-simulator
@galaxyops/dice-simulator is a versatile JavaScript library for simulating
dice rolls. It supports various dice notations and provides a straightforward
API to interact with dice outcomes.
Installation
You can install @galaxyops/dice-simulator via npm:
npm install @galaxyops/dice-simulatorUsage
The @galaxyops/dice-simulator library provides a Turn class to simulate dice
rolls. Here’s a basic example:
import { Turn } from '@galaxyops/dice-simulator';
// Create a new Turn instance with a six-sided die (d6)
const turn = new Turn('d6');
// Roll the die
const total = turn.roll();
console.log('Roll Result:', total); // e.g., 4
// Get potential outcomes
console.log('Minimum Potential:', turn.minPotential()); // 1
console.log('Average Outcome:', turn.averageOutcome); // 3.5
console.log('Maximum Potential:', turn.maxPotential()); // 6Dice Notation
The Turn class supports standard dice notation. For example:
d4for a four-sided died6for a six-sided died10for a ten-sided died20for a twenty-sided die10d%for ten one-hundred-sided die3d4+2for three four-sided die plus two1d2+10*4for a coin toss plus ten times four
Turn has a second optional parameter called luck to be passed which influences roll outcome over time. This allows a character to gear to grant them luck overall, or for a affliction to decrease luck overall in a game engine.
License
This project is licensed under the MIT License. See the LICENSE file for details.