Git Product home page Git Product logo

dicerolls.jl's Introduction

DiceRolls.jl

This package defines dice and operations with them.

MPL-2.0 License GitHub Travis CI Coveralls Documentation Documentation


This package defines dice and some operations with them. We recommend looking into the docs for a better description of what you can do. As a simple example, here is the distribution of the tradicional ability score roll on Dungeons and Dragons, i.e., rolling 4 six-sided dice, removing the lowest and summing the result.

v, f = DiceRolls.histogram(drop(4d6), normalize=true)
Plots.bar(v, f, size=(400,300), leg=false)
xticks!(v)

Another example is to roll two four-sided dice, subtract 1 from each, and multiply the result.

v, f = DiceRolls.histogram((1d4 - 1) * (1d4 - 1))
Plots.bar(v, f, size=(400,300), leg=false)
xticks!(v)

This example can be found in the examples folder.

dicerolls.jl's People

Contributors

abelsiqueira avatar matbesancon avatar moelf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dicerolls.jl's Issues

Conditional Rolls

As far as I can tell, there's no way to describe dice rolls where parts of the roll depend on another, so you can't for example express something like a standard attack and damage roll in D&D, where you roll an attack roll against some AC, doing no damage if you don't roll above a certain number, doing some damage if you do. Alternatively you do extra damage on a 20.

My motivation for this is, for my D&D character, I want to see how much damage each of my attacks do in various situations. So I want to say "Roll a d20 + some modifier, if it's higher than this AC, roll these dice to do this much damage." I've been doing that experimentally since computation is cheap and I can approximate the actual results well enough, but I feel like it should be possible to do analytically.

Allow subtractions

Currently there is no operator for subtracting dice:

roll(d100 - d100)
ERROR: MethodError: no method matching -(::Dice, ::Dice)
Closest candidates are:
  -(::ChainRulesCore.AbstractThunk, ::Any) at ~/.julia/packages/ChainRulesCore/uxrij/src/tangent_types/thunks.jl:32
  -(::ChainRulesCore.NoTangent, ::Any) at ~/.julia/packages/ChainRulesCore/uxrij/src/tangent_arithmetic.jl:61
  -(::ChainRulesCore.ZeroTangent, ::Any) at ~/.julia/packages/ChainRulesCore/uxrij/src/tangent_arithmetic.jl:101
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[23]:1

It would be great to add such functionality.

Create tests for roll_str

  • To make sure they run
  • To expose examples
  • To check their range
  • To show what's missing

Something like issubset([roll"..." for _ = 1:N], ra:rb]), for instance should work for the first 3 points above.

Create a parseable *_str version

For instance

macro r_str(str)
    # Parse the string and call appropriate functions
end

so that it's easier to run with bots, for instance.

Examples of rolls that would be interesting:

r"2#1d20+6" # Rolls 1d20+6 twice
r"2d20kh1" # Rolls 2d20 and keeps highest
r"Adv 1d20+6" # Rolls  1d20+6 twice and keeps highest (same as `kh1`).

cf. @Jualns @Lucas-Akio

Auto export d4 d6

Ported from Dices.jl. Issue by @xiaodaigh

I think it's better to not auto export these common short names.

using Dices: d4, d6

if I want to use these dices would be better.

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.