dice

package module
v5.1.4+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2018 License: MIT Imports: 4 Imported by: 1

README

go-dice

I like dice. A lot. I might have something of an obsession. Ok, I have a problem. So I hacked together a little library for dice.

I also decided to use this project as a testbed for git tagging using semver and actually using Go's builtin unit testing.

Documentation at godoc

Documentation

Overview

Package dice utilises the standard "nds" notation where n = number of die and s = number of sides; i.e 1d6, 3d10, 8d8 etc in order to create individual sets of a single type of die or bags of mixed collections that can then be manipulated or rolled

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bag

type Bag struct {
	// contains filtered or unexported fields
}

Bag is a collection of different types of Dice; i.e [3d20, 2d4, 1d6]

func NewBag

func NewBag(dice ...string) (*Bag, error)

NewBag returns a new Bag object. A bag can be created with a collection of dice specified in string form for convenience. I.e b := NewBag("2d20", "1d6", "8d8"). Returns error if any item in dice is not a valid dice string

func (*Bag) Add

func (b *Bag) Add(s string) error

Add puts more dice in the bag, adding to existing sets where possible. Returns error if s is not a valid dice string

func (*Bag) Max

func (b *Bag) Max() int

Max returns the maximum possible roll

func (*Bag) Min

func (b *Bag) Min() int

Min returns the minimum possible roll

func (*Bag) Remove

func (b *Bag) Remove(s string) error

Remove reduces the number of dice by the specified s string if s exists in the bag. Returns error if s is not a valid dice string

func (*Bag) Roll

func (b *Bag) Roll() (int, map[string][]int)

Roll returns aggregate rolls of all Dice in the bag and a map set of results

func (*Bag) String

func (b *Bag) String() string

String satisfies the Stringer interface for Bags

type Dice

type Dice struct {
	// contains filtered or unexported fields
}

Dice represents a set of 1 type of dice, i.e: 3d20 OR 2d4 OR 1d6

func NewDice

func NewDice(s string) (*Dice, error)

NewDice takes the common notation "nds" where n is the number of dice and s is the number of sides; i.e 1d6 and returns a new Dice set. Returns error if s is not a valid dice string

func (*Dice) Add

func (d *Dice) Add(n int)

Add adds n die to a single set

func (*Dice) Max

func (d *Dice) Max() int

Max returns the maximum possible roll

func (*Dice) Min

func (d *Dice) Min() int

Min returns the minimume possible roll

func (*Dice) Remove

func (d *Dice) Remove(n int)

Remove removes n die from a single set to a minimum of 1

func (*Dice) Roll

func (d *Dice) Roll() (int, []int)

Roll all dice in set and return the aggregate result and an array of individual results

func (*Dice) String

func (d *Dice) String() string

String satisfies the Stringer interface for Dice

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL