Documentation ¶
Index ¶
- type Cache
- func (c *Cache) Count() int
- func (c *Cache) Get(key uint) (GameResult, bool)
- func (c *Cache) IsSet(key uint) bool
- func (c *Cache) LoadFromFile(filename string) error
- func (c *Cache) Reset()
- func (c *Cache) SaveToFile(filename string) error
- func (c *Cache) Set(key uint, value GameResult)
- func (c *Cache) Size() int
- type ExpectedValue
- type ExpectedWork
- func (ew ExpectedWork) Add(gr GameResult, weight float32) GameResult
- func (ew ExpectedWork) Close()
- func (ew ExpectedWork) Copy() GameResult
- func (ew ExpectedWork) GetValue(score int) float32
- func (ew ExpectedWork) Max(gr GameResult) GameResult
- func (ew ExpectedWork) Shift(offset int) GameResult
- func (ew ExpectedWork) String() string
- func (ew ExpectedWork) Zero() GameResult
- type GameResult
- type ScoreDistribution
- func (sd ScoreDistribution) Add(gr GameResult, weight float32) GameResult
- func (sd ScoreDistribution) Close()
- func (sd ScoreDistribution) Copy() GameResult
- func (sd ScoreDistribution) GetProbability(score int) float32
- func (sd ScoreDistribution) Max(gr GameResult) GameResult
- func (sd ScoreDistribution) Shift(offset int) GameResult
- func (sd ScoreDistribution) Zero() GameResult
- type Strategy
- type TurnOptimizer
- func (t *TurnOptimizer) Close()
- func (t *TurnOptimizer) GetBestFill(roll yahtzee.Roll) GameResult
- func (t *TurnOptimizer) GetBestHold1(roll1 yahtzee.Roll) GameResult
- func (t *TurnOptimizer) GetBestHold2(roll2 yahtzee.Roll) GameResult
- func (t *TurnOptimizer) GetFillOutcomes(roll yahtzee.Roll) map[yahtzee.Box]GameResult
- func (t *TurnOptimizer) GetHold1Outcomes(roll1 yahtzee.Roll) map[yahtzee.Roll]GameResult
- func (t *TurnOptimizer) GetHold2Outcomes(roll2 yahtzee.Roll) map[yahtzee.Roll]GameResult
- func (t *TurnOptimizer) GetOptimalTurnOutcome() GameResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache memoizes computed values. It is designed to be efficiently reusable by resetting the isSet array (which uses an efficient memset). Values for which isSet[i] == false are not defined.
func New2DCache ¶
func (*Cache) LoadFromFile ¶
func (*Cache) SaveToFile ¶
func (*Cache) Set ¶
func (c *Cache) Set(key uint, value GameResult)
type ExpectedValue ¶
type ExpectedValue float32
ExpectedValue implements GameResult, and represents maximizing your expected score.
func NewExpectedValue ¶
func NewExpectedValue() ExpectedValue
func (ExpectedValue) Add ¶
func (ev ExpectedValue) Add(other GameResult, weight float32) GameResult
func (ExpectedValue) Close ¶
func (ev ExpectedValue) Close()
func (ExpectedValue) Copy ¶
func (ev ExpectedValue) Copy() GameResult
func (ExpectedValue) Max ¶
func (ev ExpectedValue) Max(other GameResult) GameResult
func (ExpectedValue) Shift ¶
func (ev ExpectedValue) Shift(offset int) GameResult
func (ExpectedValue) Zero ¶
func (ev ExpectedValue) Zero() GameResult
type ExpectedWork ¶
type ExpectedWork struct { // The expected work at the start of a game. E0 float32 // [W(start + 1), W(start + 2), ..., W(start + N)] // where W(start + N) is the largest integer such that W(start + N) < E0. Values []float32 }
ExpectedWork implements GameResult, and represents minimizing the work required to achieve a desired score.
func NewExpectedWork ¶
func NewExpectedWork(e0 float32) ExpectedWork
func (ExpectedWork) Add ¶
func (ew ExpectedWork) Add(gr GameResult, weight float32) GameResult
func (ExpectedWork) Close ¶
func (ew ExpectedWork) Close()
func (ExpectedWork) Copy ¶
func (ew ExpectedWork) Copy() GameResult
func (ExpectedWork) GetValue ¶
func (ew ExpectedWork) GetValue(score int) float32
func (ExpectedWork) Max ¶
func (ew ExpectedWork) Max(gr GameResult) GameResult
func (ExpectedWork) Shift ¶
func (ew ExpectedWork) Shift(offset int) GameResult
func (ExpectedWork) String ¶
func (ew ExpectedWork) String() string
func (ExpectedWork) Zero ¶
func (ew ExpectedWork) Zero() GameResult
type GameResult ¶
type GameResult interface { Close() Zero() GameResult Copy() GameResult Add(other GameResult, weight float32) GameResult Max(other GameResult) GameResult Shift(offset int) GameResult }
GameResult is an observable to maximize.
type ScoreDistribution ¶
type ScoreDistribution []float32
ScoreDistribution implements GameResult, and represents minimizing the work required to achieve a desired score.
func NewScoreDistribution ¶
func NewScoreDistribution() ScoreDistribution
func (ScoreDistribution) Add ¶
func (sd ScoreDistribution) Add(gr GameResult, weight float32) GameResult
func (ScoreDistribution) Close ¶
func (sd ScoreDistribution) Close()
func (ScoreDistribution) Copy ¶
func (sd ScoreDistribution) Copy() GameResult
func (ScoreDistribution) GetProbability ¶
func (sd ScoreDistribution) GetProbability(score int) float32
func (ScoreDistribution) Max ¶
func (sd ScoreDistribution) Max(gr GameResult) GameResult
func (ScoreDistribution) Shift ¶
func (sd ScoreDistribution) Shift(offset int) GameResult
func (ScoreDistribution) Zero ¶
func (sd ScoreDistribution) Zero() GameResult
type Strategy ¶
type Strategy struct {
// contains filtered or unexported fields
}
Strategy maximizes an observable GameResult through retrograde analysis.
func NewStrategy ¶
func NewStrategy(observable GameResult) *Strategy
func (*Strategy) Compute ¶
func (s *Strategy) Compute(game yahtzee.GameState) GameResult
Compute calculates the value of the given GameState for the observable that is maximized by this Strategy.
func (*Strategy) LoadCache ¶
LoadCache loads the results table for this strategy from the given filename.
func (*Strategy) SaveToFile ¶
SaveToFile serializes the results table for this strategy to the given filename.
type TurnOptimizer ¶
type TurnOptimizer struct {
// contains filtered or unexported fields
}
TurnOptimizer computes optimal choices for a single turn. Once the strategy results table is fully populated, TurnOptimizer is thread-safe as long as the caches are not shared.
func NewTurnOptimizer ¶
func NewTurnOptimizer(strategy *Strategy, game yahtzee.GameState) *TurnOptimizer
func (*TurnOptimizer) Close ¶
func (t *TurnOptimizer) Close()
func (*TurnOptimizer) GetBestFill ¶
func (t *TurnOptimizer) GetBestFill(roll yahtzee.Roll) GameResult
func (*TurnOptimizer) GetBestHold1 ¶
func (t *TurnOptimizer) GetBestHold1(roll1 yahtzee.Roll) GameResult
func (*TurnOptimizer) GetBestHold2 ¶
func (t *TurnOptimizer) GetBestHold2(roll2 yahtzee.Roll) GameResult
func (*TurnOptimizer) GetFillOutcomes ¶
func (t *TurnOptimizer) GetFillOutcomes(roll yahtzee.Roll) map[yahtzee.Box]GameResult
func (*TurnOptimizer) GetHold1Outcomes ¶
func (t *TurnOptimizer) GetHold1Outcomes(roll1 yahtzee.Roll) map[yahtzee.Roll]GameResult
func (*TurnOptimizer) GetHold2Outcomes ¶
func (t *TurnOptimizer) GetHold2Outcomes(roll2 yahtzee.Roll) map[yahtzee.Roll]GameResult
func (*TurnOptimizer) GetOptimalTurnOutcome ¶
func (t *TurnOptimizer) GetOptimalTurnOutcome() GameResult