@galaxyops/dice-simulator
v0.10.0
Published
`@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.
Downloads
20
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-simulator
Usage
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()); // 6
Dice Notation
The Turn
class supports standard dice notation. For example:
d4
for a four-sided died6
for a six-sided died10
for a ten-sided died20
for a twenty-sided die10d%
for ten one-hundred-sided die3d4+2
for three four-sided die plus two1d2+10*4
for 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.