optimization

package
v0.0.0-...-6781cc5 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: LGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

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 New2DCache(size1, size2 int) []*Cache

func NewCache

func NewCache(size int) *Cache

func (*Cache) Count

func (c *Cache) Count() int

func (*Cache) Get

func (c *Cache) Get(key uint) (GameResult, bool)

func (*Cache) IsSet

func (c *Cache) IsSet(key uint) bool

func (*Cache) LoadFromFile

func (c *Cache) LoadFromFile(filename string) error

func (*Cache) Reset

func (c *Cache) Reset()

func (*Cache) SaveToFile

func (c *Cache) SaveToFile(filename string) error

func (*Cache) Set

func (c *Cache) Set(key uint, value GameResult)

func (*Cache) Size

func (c *Cache) Size() int

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 (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

func (s *Strategy) LoadCache(filename string) error

LoadCache loads the results table for this strategy from the given filename.

func (*Strategy) Populate

func (s *Strategy) Populate()

func (*Strategy) SaveToFile

func (s *Strategy) SaveToFile(filename string) error

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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