ai

package
v0.0.0-...-7af1aca Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 19 Imported by: 5

Documentation

Index

Constants

View Source
const (
	MaxEval int64 = 1 << 30
	MinEval       = -MaxEval

	WinThreshold = 1 << 29
	WinBase      = (WinThreshold + MaxEval) / 2

	ForcedWin = 1 << 20
)

Variables

View Source
var DefaultWeights []Weights

Functions

func CountThreats

func CountThreats(c *bitboard.Constants, p *tak.Position) (wp, wt, bp, bt int)

func EvaluateWinner

func EvaluateWinner(_ *bitboard.Constants, p *tak.Position) int64

func ExplainScore

func ExplainScore(m *MinimaxAI, out io.Writer, p *tak.Position)

Types

type EvaluationFunc

type EvaluationFunc func(c *bitboard.Constants, p *tak.Position) int64

func MakeEvaluator

func MakeEvaluator(size int, w *Weights) EvaluationFunc

type Feature

type Feature int
const (
	Tempo Feature = iota
	TopFlat
	Standing
	Capstone

	HardTopCap
	CapMobility

	FlatCaptives_Soft
	FlatCaptives_Hard
	StandingCaptives_Soft
	StandingCaptives_Hard
	CapstoneCaptives_Soft
	CapstoneCaptives_Hard

	Liberties
	GroupLiberties

	Groups
	Groups_1
	Groups_2
	Groups_3
	Groups_4
	Groups_5
	Groups_6
	Groups_7
	Groups_8

	Potential
	Threat

	EmptyControl
	FlatControl

	Center
	CenterControl

	ThrowMine
	ThrowTheirs
	ThrowEmpty

	Terminal_Plies
	Terminal_Flats
	Terminal_Reserves
	Terminal_OpponentReserves

	MaxFeature
)

func (Feature) String

func (i Feature) String() string

type MinimaxAI

type MinimaxAI struct {
	Cfg MinimaxConfig
	// contains filtered or unexported fields
}

func NewMinimax

func NewMinimax(cfg MinimaxConfig) *MinimaxAI

func (*MinimaxAI) Analyze

func (m *MinimaxAI) Analyze(ctx context.Context, p *tak.Position) ([]tak.Move, int64, Stats)

func (*MinimaxAI) AnalyzeAll

func (ai *MinimaxAI) AnalyzeAll(ctx context.Context, p *tak.Position) ([][]tak.Move, int64, Stats)

func (*MinimaxAI) Evaluate

func (m *MinimaxAI) Evaluate(p *tak.Position) int64

func (*MinimaxAI) GetMove

func (ai *MinimaxAI) GetMove(ctx context.Context, p *tak.Position) tak.Move

type MinimaxConfig

type MinimaxConfig struct {
	Size     int
	Depth    int
	MaxEvals uint64
	Debug    int
	Seed     int64

	// How much memory to allocate to the transposition
	// table. Negative means don't use a table.
	TableMem int64

	RandomizeWindow int64
	RandomizeScale  int64

	NoSort         bool
	NoNullMove     bool
	NoExtendForces bool

	NoReduceSlides bool

	MultiCut bool

	Evaluate EvaluationFunc

	DedupSymmetry bool
	CutLog        string
}

func (*MinimaxConfig) MakePrecise

func (cfg *MinimaxConfig) MakePrecise()

MakePrecise modifies a MinimaxConfig to produce a MinimaxAI that will always produce accurate game-theoretic evaluations – i.e. it disables all heuristic searches that cannot prove the correctness of their results.

In general, such configurations should be slower and weaker players, but can be useful for constructing or solving puzzles, debugging, or analyzing unusual positions.

type OpeningBook

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

func BuildOpeningBook

func BuildOpeningBook(size int, lines []string) (*OpeningBook, error)

func (*OpeningBook) GetMove

func (ob *OpeningBook) GetMove(p *tak.Position, r *rand.Rand) (tak.Move, bool)

type OpeningPlayer

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

func (*OpeningPlayer) GetMove

func (op *OpeningPlayer) GetMove(ctx context.Context, p *tak.Position) tak.Move

type RandomAI

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

func (*RandomAI) GetMove

func (r *RandomAI) GetMove(ctx context.Context, p *tak.Position) tak.Move

type Stats

type Stats struct {
	Depth    int
	Canceled bool
	Elapsed  time.Duration

	Generated uint64
	Evaluated uint64
	Scout     uint64
	Terminal  uint64
	Visited   uint64

	CutNodes   uint64
	NullSearch uint64
	NullCut    uint64
	Cut0       uint64
	Cut1       uint64
	CutSearch  uint64

	ReSearch uint64

	AllNodes uint64

	TTHits     uint64
	TTShortcut uint64

	Extensions    uint64
	ReducedSlides uint64

	MCSearch uint64
	MCCut    uint64
}

func (Stats) Merge

func (s Stats) Merge(other Stats) Stats

type TakPlayer

type TakPlayer interface {
	GetMove(ctx context.Context, p *tak.Position) tak.Move
}

func NewRandom

func NewRandom(seed int64) TakPlayer

func WithOpeningBook

func WithOpeningBook(ai TakPlayer, ob *OpeningBook) TakPlayer

type Weights

type Weights [MaxFeature]int64

func (*Weights) MarshalJSON

func (ws *Weights) MarshalJSON() ([]byte, error)

func (*Weights) UnmarshalJSON

func (ws *Weights) UnmarshalJSON(bs []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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