rangefinder

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxEnumeratedLeaves is the default threshold for exhaustive enumeration.
	// When the number of distinct leaves drawable from the bag is at or below this
	// value, inferEnumerated is used instead of Monte Carlo sampling.
	// At ~100 ms per mini-sim and 16 threads this corresponds to roughly 30 s of wall
	// time, which is the natural knee of the tractability curve:
	//   k=1 → ≤27 leaves    (always enumerate)
	//   k=2 → ≤378 leaves   (always enumerate)
	//   k=3 → ≤3650 leaves  (enumerate when bag is modest, ≤~20 distinct tiles)
	//   k=4 → ≤27000 leaves (enumerate only when bag ≤~15 tiles total)
	// Anything above 750 typically exceeds the default 1m sampling budget and won't
	// beat MC in practice.
	DefaultMaxEnumeratedLeaves = 750
)
View Source
const (
	// SoftmaxTemperature controls how "rational" we assume the opponent to be
	// when computing P(play | leave). Lower values assume near-optimal play;
	// higher values allow more weight for sub-optimal plays.
	// Softmax is applied over log-odds of win probabilities, so tau is on the
	// log-odds scale. Typical positions (20%-80% win prob) span roughly [-1.4, 1.4];
	// strongly won/lost positions (5%-95%) reach about [-3, 3].
	SoftmaxTemperature = 0.05
)

Variables

View Source
var ErrBagEmpty = errors.New("bag is empty")
View Source
var ErrMoveTypeNotSupported = errors.New("opponent move type not suitable for inference")
View Source
var ErrNoEvents = errors.New("no events")
View Source
var ErrNoInformation = errors.New("not enough information to infer")

Functions

This section is empty.

Types

type Inference added in v0.10.2

type Inference struct {
	RackLength    int
	InferredRacks []montecarlo.InferredRack
	// contains filtered or unexported fields
}

func NewInference added in v0.10.2

func NewInference() *Inference

type LogIteration

type LogIteration struct {
	Iteration      int     `json:"iteration" yaml:"iteration"`
	Thread         int     `json:"thread" yaml:"thread"`
	Rack           string  `json:"rack" yaml:"rack"`
	TopMoveWinProb float64 `json:"topMoveWinProb" yaml:"topMoveWinProb"`
	TopMove        string  `json:"topMove" yaml:"topMove"`
	// InferredMoveWinProb is the win prob of the move we are inferring, given
	// that they drew "Rack"
	InferredMoveWinProb float64 `json:"inferredMoveWinProb" yaml:"inferredMoveWinProb"`
	// Likelihood = softmax P(play|leave) with temperature tau
	Likelihood float64 `json:"likelihood" yaml:"likelihood"`
	SimLogFile string  `json:"simLogFile,omitempty" yaml:"simLogFile,omitempty"`
}

type RangeFinder

type RangeFinder struct {
	// contains filtered or unexported fields
}

func (*RangeFinder) AnalyzeInferences

func (r *RangeFinder) AnalyzeInferences(detailed bool) string

func (*RangeFinder) BagMap added in v0.13.0

func (r *RangeFinder) BagMap() []uint8

BagMap returns a copy of the inferenceBagMap after PrepareFinder has been called. It represents the pool of tiles from which the opponent's leave was drawn (bag + both racks, minus opp's played tiles this turn).

func (*RangeFinder) ExhaustiveTotal added in v0.13.0

func (r *RangeFinder) ExhaustiveTotal() int

ExhaustiveTotal returns the total number of distinct leaves that existed when inferEnumerated was used. Zero means the MC sampling path was taken.

func (*RangeFinder) Infer

func (r *RangeFinder) Infer(ctx context.Context) error

func (*RangeFinder) InferElapsed added in v0.13.0

func (r *RangeFinder) InferElapsed() time.Duration

InferElapsed returns the wall-clock duration of the last Infer call.

func (*RangeFinder) Inferences

func (r *RangeFinder) Inferences() *Inference

func (*RangeFinder) Init

func (r *RangeFinder) Init(game *game.Game, eqCalcs []equity.EquityCalculator,
	cfg *config.Config)

func (*RangeFinder) IsBusy added in v0.8.6

func (r *RangeFinder) IsBusy() bool

func (*RangeFinder) PrepareFinder

func (r *RangeFinder) PrepareFinder(myRack []tilemapping.MachineLetter) error

func (*RangeFinder) Reset

func (r *RangeFinder) Reset()

func (*RangeFinder) SetLogStream

func (r *RangeFinder) SetLogStream(l io.Writer)

func (*RangeFinder) SetMaxEnumeratedLeaves added in v0.13.0

func (r *RangeFinder) SetMaxEnumeratedLeaves(n int)

SetMaxEnumeratedLeaves sets the maximum number of distinct leaves for which exhaustive enumeration (inferEnumerated) is used instead of Monte Carlo sampling. If 0, DefaultMaxEnumeratedLeaves is used.

func (*RangeFinder) SetSimIters added in v0.13.0

func (r *RangeFinder) SetSimIters(n int)

func (*RangeFinder) SetTau added in v0.13.0

func (r *RangeFinder) SetTau(tau float64)

SetTau sets the softmax temperature for P(play | leave). Lower values assume the opponent plays more optimally; higher values give more weight to sub-optimal plays. Must be called before PrepareFinder.

func (*RangeFinder) SetThreads

func (r *RangeFinder) SetThreads(t int)

func (*RangeFinder) SimCount added in v0.13.0

func (r *RangeFinder) SimCount() uint64

SimCount returns the total number of mini-simulations run during Infer.

func (*RangeFinder) SimIters added in v0.13.0

func (r *RangeFinder) SimIters() int

func (*RangeFinder) Tau added in v0.13.0

func (r *RangeFinder) Tau() float64

Jump to

Keyboard shortcuts

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