Skip to content

waldson/dicen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dicen

Parser for dice rolls.

Instalation

composer install w5n/dicen

Usage

use W5n\Dicen\DefaultRandomGenerator;
use W5n\Dicen\DiceEngine;
use W5n\Dicen\DiceParser;

$parser          = new DiceParser();
$randomGenerator = new DefaultRandomGenerator();
$engine          = new DiceEngine($parser, $randomGenerator);

// Dice mode
$engine->roll('5d4+3');

// Math mode
$engine->roll('120+10*33-45');

// Mixed mode
$engine->roll('2d6-4+45-2d10+8');


// Invalid roll throws exception
try {
    $engine->roll('invalid');
} catch (\Exception $ex) {
    //...
}

// Syntax tree
$ast = $parser->parse('2d6+25-1d4-1');

TO-DO

  • Use a custom exception
  • Exploding Dices
  • Keep or Drop some highest/lowest dices
  • Show roll details

References

About

Parser for dice rolls using PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages