Giter Site home page Giter Site logo

hrolldice's Introduction

hrolldice

Name

hrolldice - a Haskell program that rolls virtual dice, loosely based on rolldice by Stevie Strickland.

Synopsis

hrolldice dice_string dice_string ...

Description

As an exercise in writing Haskell programs, I wrote my own version of rolldice by Stevie Strickland. It is not an exact clone, but for the majority of dice rolls it is a drop-in replacement.

dice_strings specify the number of dice, what kind of dice, how many to drop, etc. For example:

  • d6: roll a six-sided die.
  • 4d6: roll four six-sided die and sum the result.
  • 2x4d6: same as 4d6, but perform it twice and show each result separately.
  • 4d6s1: same as 4d6 but drop the lowest number rolled.
  • d6*2+1: same as d6 but multiply it by 2 and then add 1
  • d6+1*2: same as d6 but add 1 and then multiply the result by 2.

In other words, the "modifier functions" at the end are processed in order from left to right. +1*2-3 can be thought of as (((result + 1) * 2) - 3). This behaviour is different than rolldice, which will only handle one multiplier and one offset (it takes the last occurrence of each without saying so) and has a specified order of operations (multiplication, then addition/subtraction).

Example usage:

Roll four six-sided dice four times, dropping the lowest number. Repeat six times.

$ hrolldice 6x4d6s1

13 11 10 16 7 8

This is the typical way to generate "ability scores" in RPGs like D&D.

Prior Art

TODO

  • Better error messages on incorrect dice strings.
  • Tests for modifier functions.
  • Better API.

Author

Tavish Armstrong [email protected]

hrolldice's People

Contributors

tarmstrong avatar

Stargazers

 avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.