dice

package module
v0.0.0-...-151592f Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: MIT Imports: 7 Imported by: 0

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
  • Fudge: xdf[+/-c] - rolls and sums x fudge dice (Dice that returns numbers between -1 and 1), and optionally adding or subtracting c. Example: 4df+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 git.sonnix.tk/sr/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

This section is empty.

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 FudgeResult

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

func (FudgeResult) Description

func (r FudgeResult) Description() string

func (FudgeResult) Int

func (r FudgeResult) Int() int

func (FudgeResult) String

func (r FudgeResult) String() string

type FudgeRoller

type FudgeRoller struct{}

func (FudgeRoller) Pattern

func (FudgeRoller) Pattern() *regexp.Regexp

func (FudgeRoller) Roll

func (FudgeRoller) 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