dice

package
v2.49.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT, MIT Imports: 7 Imported by: 1

README

Golang dice

This is a simple library for rolling RPG-style dice. The following formats are supported:

  • Standard: xdy[[k|d][h|l]z][+/-c] - rolls and sums x y-sided dice, keeping or dropping the lowest or highest z dice and optionally adding or subtracting c. Example: 4d6kh3+4
  • Versus: xdy[e|r]vt - rolls x y-sided dice, counting the number that roll t or greater.
  • EotE: xc [xc ...] - rolls x dice of color c (b, blk, g, p, r, w, y) and returns the aggregate result.

Adding an e to the Versus rolls above makes dice 'explode' - Dice are rerolled and have the rolled value added to their total when they roll a y. Adding an r makes dice rolling a y add another die to the pool instead.

Installation

The usual go get github.com/justinian/dice.

Usage

The main entrypoint to the library is the dice.Roll function:

func Roll(desc string) (fmt.Stringer, error)

The desc argument takes any string that matches the formats above and rolls correctly. The result is returned as a RollResult (which is a fmt.Stringer for simple printing, but also contains different information based on the type of roll). See the individual roll styles for their result structures.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooManyLoops = errors.New("Too many loops, you either specified too many dices or sides")
)
View Source
var (
	MaxLoop int64 = 1000
)

Functions

This section is empty.

Types

type EoteDie

type EoteDie struct {
	Type string
	S    int // success
	A    int // advantage
	T    int // triumph
	D    int // despair
	F    int // force
}

func (*EoteDie) Add

func (d *EoteDie) Add(o EoteDie)

func (EoteDie) String

func (d EoteDie) String() string

type EoteResult

type EoteResult struct {
	EoteDie
	Rolls []EoteDie
	// contains filtered or unexported fields
}

func (EoteResult) Description

func (r EoteResult) Description() string

func (EoteResult) Int

func (r EoteResult) Int() int

func (EoteResult) String

func (r EoteResult) String() string

type EoteRoller

type EoteRoller struct{}

func (EoteRoller) Pattern

func (EoteRoller) Pattern() *regexp.Regexp

func (EoteRoller) Roll

func (EoteRoller) Roll(matches []string) (RollResult, error)

type RollResult

type RollResult interface {
	fmt.Stringer
	Description() string
	Int() int
}

func Roll

func Roll(desc string) (RollResult, string, error)

type StdResult

type StdResult struct {
	Rolls   []int
	Dropped []int
	Total   int
	// contains filtered or unexported fields
}

func (StdResult) Description

func (r StdResult) Description() string

func (StdResult) Int

func (r StdResult) Int() int

func (StdResult) String

func (r StdResult) String() string

type StdRoller

type StdRoller struct{}

func (StdRoller) Pattern

func (StdRoller) Pattern() *regexp.Regexp

func (StdRoller) Roll

func (StdRoller) Roll(matches []string) (RollResult, error)

type VsResult

type VsResult struct {
	Rolls     []int
	Successes int
	// contains filtered or unexported fields
}

func (VsResult) Description

func (r VsResult) Description() string

func (VsResult) Int

func (r VsResult) Int() int

func (VsResult) String

func (r VsResult) String() string

type VsRoller

type VsRoller struct{}

func (VsRoller) Pattern

func (VsRoller) Pattern() *regexp.Regexp

func (VsRoller) Roll

func (VsRoller) Roll(matches []string) (RollResult, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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