expression

package
v0.0.0-...-7afa4bb Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Expression

type Expression struct {
	Die      polyhedral.Die
	Quantity uint
	Modifier *modifier.Modifier
}

Expression represents a dice expression. Dice expressions consist of a polyhedral.Die, a positive quantity (i.e. the number of times the Die instance is to be rolled), and a modifier, which is an int.

func New

New takes as input a positive quantity, a polyhedral.Die, and a pointer to a modifier. It returns a pointer to a polyhedral.Expression or an error.

func Parse

func Parse(s string, seed *int64) (*Expression, error)

Parse takes as input a string representing a dice expression, e.g., "3d6" or "2d10+2". The structure of the input must exactly match the regular expression, `^\s*(\d+)?\s*[dD]{1}(\d+)\s*([\+\-–\*×]?\d+)?\s*$`. Assuming the input string can be successfully parsed, a pointer to a polyhedral.Expression will be returned. Otherwise, an error will be returned.

func (*Expression) Eval

func (x *Expression) Eval() (int, []int)

Eval evaluates the expression and returns the score and a slice of the individual dice scores.

func (*Expression) String

func (x *Expression) String() string

String returns a human-readable representation of the Expression, e.g., "3d6" or "2d10+2".

Jump to

Keyboard shortcuts

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