Documentation ¶
Index ¶
- func DiceProbability(numberOfDice, sides, H, L int64) map[int64]float64
- func FacesSliceString(faces []int64) string
- func MergeDiceTotalMaps(mapsToMerge ...map[string]float64) map[string]float64
- func PrintAST(t *AST, identation int)
- func ReStringAST(t *AST) string
- func TotalsMapString(m map[string]float64) string
- type AST
- type Dice
- type DiceSet
- type Element
- type Lexer
- type Parser
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiceProbability ¶
DiceProbability returns a map of results to probabilities (in percent) for a given roll of dice numberOfDice (int64): the number of dice in the throw. sides (int64): the sides each die has H: The number of high dice to drop (set to 0 to not drop any) L: The number of low dice to drop (set to 0 to not drop any) credit to https://stackoverflow.com/questions/50690348/calculate-probability-of-a-fair-dice-roll-in-non-exponential-time
func FacesSliceString ¶
func MergeDiceTotalMaps ¶
func ReStringAST ¶
ReStringAST is a modified inverse shunting yard which converts an AST back to an infix expression.
func TotalsMapString ¶
Types ¶
type AST ¶
type AST struct { Sym string Value string BindingPower int Children []*AST // contains filtered or unexported fields }
AST represents a node in an abstract syntax tree
func (*AST) GetDiceSet ¶
GetDiceSet returns the sum of an AST, a DiceSet, and an error
type Dice ¶
type Dice struct { Count int64 Sides int64 Total int64 Faces []int64 Max int64 Min int64 DropHighest int64 DropLowest int64 Color string }
Dice represents a a throw of a single type of die
func GetDiceSets ¶
GetDiceSets merges all statements in ...*AST and returns a merged diceTotalMap and all rolled dice.
type DiceSet ¶
type DiceSet struct { Dice []Dice TotalsByColor map[string]float64 // contains filtered or unexported fields }
DiceSet represents a collection of Dice and their totals by type
func (*DiceSet) AddToColor ¶
AddToColor increments the total result for a given color
func (*DiceSet) PushAndRoll ¶
PushAndRoll adds a dice roll to the "stack" applying any values from the set
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer steps through a source string and returns tokens
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser holds a Lexer and implements a top down operator precedence parser (https://tdop.github.io/) credit to: https://github.com/cristiandima/tdop for most of this code.
func (*Parser) Statements ¶
Statements returns all statements from the parser as []*AST