vi

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMoves = errors.New("vi: no moves are possible from the given position")
)

Functions

func DumpAnalyticsCsv

func DumpAnalyticsCsv(vi VI, w io.Writer) error

func Game

func Game(
	white, black VI,
	turnTimer time.Duration,
) <-chan state.Board

Makes two VIs play against each other, updating the board state through the returned channel. The channel is closed when the game is over. In this case, the winner of the game can be determined by which player is set to make the next move. That is, if White is the active player when the channel closes, that means that White had no moves left and Black is the winner.

Types

type Arrow

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

Arrow is a program that was created by Martin Müller and Theodore Tegos, described in their paper "Experiments in Computer Amazons." They describe two versions of Arrow, one which is non-selective (no move ordering) and another which is selective (a beam search where moves are ordered by the same evaluation function used for leaf nodes). This implementation is non-selective. That is, it's just normal alpha-beta search which uses QMinDist to evaluate leaf nodes.

func (*Arrow) AllAnalytics

func (a *Arrow) AllAnalytics() []map[string]float64

func (*Arrow) Analytics

func (a *Arrow) Analytics() map[string]float64

func (*Arrow) Consult

func (a *Arrow) Consult(
	board state.Board,
	timeLimit time.Duration,
) (state.Move, error)

func (*Arrow) Id

func (arrow *Arrow) Id() string

type EDI

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

EDI is the flagship VI for this project. At the time of writing it uses alpha-beta search with the History Heuristic for move ordering and the KMinDist function for leaf node evaluation.

func (*EDI) AllAnalytics

func (e *EDI) AllAnalytics() []map[string]float64

func (*EDI) Analytics

func (e *EDI) Analytics() map[string]float64

func (*EDI) Consult

func (e *EDI) Consult(
	board state.Board,
	timeLimit time.Duration,
) (state.Move, error)

func (*EDI) Id

func (e *EDI) Id() string

type Random

type Random struct{}

This VI picks moves completely at random.

func (*Random) AllAnalytics

func (r *Random) AllAnalytics() []map[string]float64

func (*Random) Analytics

func (r *Random) Analytics() map[string]float64

func (*Random) Consult

func (r *Random) Consult(
	board state.Board, timeLimit time.Duration,
) (state.Move, error)

func (*Random) Id

func (r *Random) Id() string

type Sparrow

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

Sparrow uses a simple alpha-beta search with the k-mindist evaluation function and no move ordering.

func (*Sparrow) AllAnalytics

func (s *Sparrow) AllAnalytics() []map[string]float64

func (*Sparrow) Analytics

func (s *Sparrow) Analytics() map[string]float64

func (*Sparrow) Consult

func (s *Sparrow) Consult(
	board state.Board,
	timeLimit time.Duration,
) (state.Move, error)

func (*Sparrow) Id

func (arrow *Sparrow) Id() string

type VI

type VI interface {

	// Determines the best move and returns it within the given time limit.
	//
	// If an error is returned, it will be [ErrNoMoves].
	Consult(board state.Board, timeLimit time.Duration) (state.Move, error)

	// Returns the analytics from the most recent call to [Consult]. The
	// specific fields depends on the VI model. E.g., a VI using alpha-beta
	// might describe its effective branching factor and the number of cutoffs,
	// while a Monte Carlo model would have entirely different metrics. If
	// [Consult] has not yet been successfully called, this function will
	// return nil.
	Analytics() map[string]float64

	// Returns all analytics from past calls to ConsultWithAnalytics, ordered
	// so that the last element is from the most recent call. This value will
	// be a slice of the same type that GetAnalytics() returns.
	AllAnalytics() []map[string]float64

	// Returns a string that represents the VI's model.
	Id() string
}

We use VI, short for "virtual intelligence," to refer to a program that can recommend a move from a given board state within a certain amount of time. In contrast with a search function, which is defined to be stateless, a VI may "remember" certain things between searches.

The term VI is borrowed from a videogame: https://masseffect.fandom.com/wiki/Virtual_Intelligence. Traditionally we would call such a program "AI," but that term has been diluted in recent years.

func NewArrow

func NewArrow() VI

func NewEDI

func NewEDI() VI

func NewRandom

func NewRandom() VI

func NewSparrow

func NewSparrow() VI

Jump to

Keyboard shortcuts

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