# game-probability: Simple probability library for dice rolls, card games and similar

A library designed to aid in easily calculating the probability of various outcomes of dice rolls and card draws. The central types are held in the Numeric.Probability.Game.Event module, the dice are defined in the Numeric.Probability.Game.Dice module, and the functions for calculating probabilities are in the Numeric.Probability.Game.Query module. The functions for playing cards cand be found in the Numeric.Probability.Game.Cards module, and more efficient calculation helpers can be found in the Numeric.Probability.Game.Cards.Hand module.

Various examples are scattered throughout the library, but here are some more:

Evalulates the chance of a coin toss turning up heads:

chanceTrue coinToss

Shows the chances of each outcome of rolling two six-sided dice, as a textual bar chart:

show (2*d6)

The chance of getting an 18 when rolling 3 six-sided dice and rerolling on any total less than 8:

chancePred (== 18) ((3*d6) `rerollOn` [3..7])

As a more complex example, this implements my memory/understanding of the original World of Darkness dice system (http://en.wikipedia.org/wiki/Storytelling_System). You roll a given number of 10-sided dice, rolling one extra for every 10 you score if you are specialised. The number of 1s on the original roll are subtracted from the total number of dice that equal or exceed the difficulty target:

successes :: Int -> Int -> Bool -> EventM Int successes target dice specialised = do initial <- replicateM dice d10 extra <- if specialised then replicateM (count (== 10) initial) d10 else return [] return (count (>= target) (initial ++ extra) - count (== 1) initial) where count f xs = length (filter f xs)

If only all RPGs specified their rules in Haskell!

See also the blog posts on the design of the library: http://chplib.wordpress.com/2010/08/13/nice-dice-in-haskell/, http://chplib.wordpress.com/2010/08/23/sharp-cards-in-haskell-drawing-cards/ and http://chplib.wordpress.com/2010/09/08/sharp-cards-in-haskell-the-odds/

## Modules

[Index]

## Downloads

- game-probability-1.1.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)

#### Maintainer's Corner

For package maintainers and hackage trustees

Candidates

- No Candidates

Versions [RSS] | 1.0, 1.1 |
---|---|

Dependencies | base (>=4 && <5), containers (>=0.2 && <0.4), probability (>=0.2 && <0.3), random (>=1.0 && <1.1) [details] |

License | BSD-3-Clause |

Author | Neil Brown |

Maintainer | neil@twistedsquare.com |

Category | Math |

Uploaded | by NeilBrown at 2010-09-08T08:55:00Z |

Distributions | NixOS:1.1 |

Reverse Dependencies | 1 direct, 0 indirect [details] |

Downloads | 1789 total (5 in the last 30 days) |

Rating | (no votes yet) [estimated by Bayesian average] |

Your Rating | |

Status | Docs uploaded by user Build status unknown [no reports yet] |