dice

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Die

type Die struct {
	Value int  // The rolled value
	Sides int  // Number of sides on this die
	Kept  bool // Whether this die counts toward the total
}

Die represents a single rolled die

type Expression

type Expression struct {
	Count     int        // Number of dice to roll
	Sides     int        // Sides per die
	Modifier  int        // +/- modifier to add to total
	Operation *Operation // Optional keep/drop operation
	Advantage bool       // Per-die advantage (roll each die twice, keep highest)
}

Expression represents a dice notation to be rolled (input)

func Parse

func Parse(notation string) (*Expression, error)

Parse parses a dice notation string into an Expression Supports: XdY, XdY+Z, XdY!, XdYkhN, XdYdlN, etc.

type OpType

type OpType int

OpType represents the type of keep/drop operation

const (
	OpKeepHighest OpType = iota // Keep the N highest dice
	OpKeepLowest                // Keep the N lowest dice
	OpDropHighest               // Drop the N highest dice
	OpDropLowest                // Drop the N lowest dice
)

type Operation

type Operation struct {
	Type  OpType // Type of operation
	Count int    // How many dice to keep/drop
}

Operation represents a keep/drop operation on rolled dice

type Result

type Result struct {
	Expression *Expression // Original expression that created this result
	Rolls      []Die       // All dice rolled (including dropped)
	KeptTotal  int         // Sum of kept dice only
	Total      int         // Final result (kept + modifier)
}

Result represents the outcome of rolling dice (output)

func RollExpression

func RollExpression(expr *Expression) (*Result, error)

RollExpression rolls dice according to an Expression and returns a Result

func (*Result) String

func (r *Result) String() string

String returns a formatted string representation of the result

type Roll

type Roll struct {
	Notation string // e.g., "2d6"
	Count    int    // number of dice
	Sides    int    // sides per die
	Results  []int  // individual die results
	Total    int    // sum of all results
}

Roll represents the result of a dice roll (legacy/backward compatibility)

func RollDice

func RollDice(notation string) (*Roll, error)

RollDice rolls the specified dice and returns the results (backward compatibility)

func (*Roll) String

func (r *Roll) String() string

String returns a formatted string representation of the roll

Jump to

Keyboard shortcuts

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