Documentation
¶
Index ¶
- func GetAutocompleteFunc(words []string) func(string) []string
- func GetAutocompleteItemsFunc(items []Item) func(string) []string
- type Item
- type Relation
- type Riddle
- type Rule
- type Setup
- type Solver
- func (solver *Solver) FindAssociatedItems(item Item) map[string][]string
- func (solver *Solver) FindEntriesWithItem(item Item) (entries []SolverEntry)
- func (solver *Solver) GuessPrimaryItemType() string
- func (solver *Solver) IsSolved() bool
- func (solver *Solver) Solve(primaryItemType string) (steps int, err error)
- type SolverEntry
- func (entry SolverEntry) Contains(item Item) bool
- func (entry SolverEntry) GetExcludedItems(setup Setup) (excluded []Item)
- func (entry SolverEntry) GetValue(itemType string) (result interface{})
- func (entry SolverEntry) IsSolved() bool
- func (entry SolverEntry) OnlyContains(item Item) bool
- func (entry SolverEntry) Set(item Item) bool
- func (entry SolverEntry) Unset(item Item) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAutocompleteFunc ¶
Types ¶
type Riddle ¶
Riddle contains the setup and rules of the riddle
func LoadRiddle ¶
LoadRiddle loads the riddle from a byte slice in JSON format
func LoadRiddleFromFile ¶
LoadRiddleFromFile loads the riddle from a JSON file
func NewEinsteinRiddle ¶
func NewEinsteinRiddle() *Riddle
NewEinsteinRiddle returns Einstein's 5 house riddle
func (*Riddle) SaveToFile ¶
SaveToFile saves the riddle to a JSON file
type Rule ¶
type Rule struct {
ItemA Item
ItemB Item
Relation Relation
Condition string `json:",omitempty"`
ConditionItemType string `json:",omitempty"`
IsReversible bool `json:",omitempty"`
}
Rule is used by the riddle solver algorithm
func (*Rule) ApplyConditional ¶
func (rule *Rule) ApplyConditional(entryA SolverEntry, others []SolverEntry) bool
ApplyConditional tries to apply a conditional rule to a SolverEntry
func (*Rule) ApplySimple ¶
func (rule *Rule) ApplySimple(entry SolverEntry) bool
ApplySimple tries to apply a simple (non-conditional) rule to a SolverEntry
func (*Rule) HasCondition ¶
HasCondition returns whether a rule has a condition
type Setup ¶
Setup is a map of riddle item types and their possible values
func (Setup) GetItemCountPerType ¶
GetItemCountPerType returns the number of possible values under an item type
func (Setup) GetItemTypes ¶
GetItemTypes returns all item types in a slice
type Solver ¶
type Solver struct {
Entries []SolverEntry
// contains filtered or unexported fields
}
Solver can solve a riddle based on the setup and rules
func (*Solver) FindAssociatedItems ¶
FindAssociatedItems returns a map of items that possible belong to the provided item
func (*Solver) FindEntriesWithItem ¶
func (solver *Solver) FindEntriesWithItem(item Item) (entries []SolverEntry)
FindEntriesWithItem returns the entries that contain the specified item
func (*Solver) GuessPrimaryItemType ¶
GuessPrimaryItemType tries to guess the primary item type as it's important for conditional rules
type SolverEntry ¶
SolverEntry is a unit of riddle items that belong together
func NewSolverEntry ¶
func NewSolverEntry(setup Setup) SolverEntry
NewSolverEntry returns a new SolverEntry
func (SolverEntry) Contains ¶
func (entry SolverEntry) Contains(item Item) bool
Contains returns whether the entry contains the specified item
func (SolverEntry) GetExcludedItems ¶
func (entry SolverEntry) GetExcludedItems(setup Setup) (excluded []Item)
GetExcludedItems returns the excluded items compared to the setup
func (SolverEntry) GetValue ¶
func (entry SolverEntry) GetValue(itemType string) (result interface{})
GetValue returns the value of an item type or nil if there are multiple choices
func (SolverEntry) IsSolved ¶
func (entry SolverEntry) IsSolved() bool
IsSolved return true if the entry contains one value for each item type
func (SolverEntry) OnlyContains ¶
func (entry SolverEntry) OnlyContains(item Item) bool
OnlyContains returns whether the entry only contains the specified item of that item type
func (SolverEntry) Set ¶
func (entry SolverEntry) Set(item Item) bool
Set sets an item as the only possible value for that type
func (SolverEntry) Unset ¶
func (entry SolverEntry) Unset(item Item) bool
Unset removes an item from the possible values for that type