engine

package
v0.0.0-...-906a36e Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

package engine defines a generic interface for communicating with chess engines.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrTimeout indicates a timeout in communicating with the engine.
	ErrTimeout = errors.New("timeout in engine communication")
	// ErrExited indicates that the engine was closed.
	ErrExited = errors.New("engine was closed")
)

Functions

This section is empty.

Types

type BoolOption

type BoolOption interface {
	Bool() bool    // current value
	SetBool(bool)  // change value
	Default() bool // default value
}

BoolOption represents a togglable option.

type Engine

type Engine interface {
	// SetPosition sets the position to search.
	SetPosition(board *chess.Board)

	// Search starts an infinite search of the position; that is, until
	// Stop is called. During the search, Info's will be sent on the
	// channel that is returned. The last Info on the channel, and only the
	// last, will either return a non-nil Info.Err or an Info.BestMove,
	// after which the channel is closed.
	Search() <-chan Info

	// SearchDepth is like Search but tells the engine to stop at a certain
	// depth.
	SearchDepth(depth int) <-chan Info

	// SearchTime is like Search but tells the engine to stop after the
	// given time.
	SearchTime(t time.Duration) <-chan Info

	// SearchClock is like Search but informs the engine of the time
	// controls of the game and lets the engine decide how much time to
	// use. movesToGo is the number of moves to the next time control.
	SearchClock(wtime, btime, winc, binc time.Duration, movesToGo int) <-chan Info

	// Stop stops a search started by one of the SearchXXX functions.
	Stop()

	// Quit quits the engine process.
	Quit()

	// Ping pings the engine process to check that it is still responding.
	Ping() error

	// Options returns the settable options of the engine.
	Options() map[string]Option
}

Engine provides a generic interface to a running chess engine.

Example
var e Engine
defer e.Quit()

e.SetPosition(chess.MustParseFen(""))
for info := range e.SearchDepth(6) {
	if err := info.Err(); err != nil {
		log.Fatal(err)
	} else if move, ok := info.BestMove(); ok {
		log.Print("the best move is", move)
	} else {
		log.Print(info.Pv(), info.Stats())
	}
}
Output:

type Info

type Info interface {
	// Err returns an error if one occured. This should be the first thing
	// to check, before calling the other methods.
	Err() error

	// BestMove returns the best move found by the engine. It returns !ok
	// if no best move has been found yet.
	BestMove() (move chess.Move, ok bool)

	BestMoveRaw() (string, bool)

	// Pv returns the principal variation of this Info. It can be nil if no
	// pv information is available.
	Pv() *Pv

	// Stats returns statistics of the search so far. Any of the Stats
	// fields can be zero, meaning the information is not present (or
	// actually zero).
	Stats() *Stats
}

Info represents a generic information "event" sent over an Info channel while an engine search is in progress.

type IntOption

type IntOption interface {
	Int() int     // current value
	SetInt(int)   // change value
	Default() int // default value
	Min() int     // minimum value
	Max() int     // maximum value (0 = no maximum)
}

IntOption represents a number option, possibly with a limited range.

type Option

type Option interface {
	String() string        // current value
	StringDefault() string // default value
	Set(value string)      // change the value
}

Option represents a generic settable engine option.

type Pv

type Pv struct {
	Moves      []chess.Move // principal variation moves
	Score      int          // centipawns or moves-to-mate; positive is good for white
	Mate       bool         // if yes then Score is moves-to-mate
	Upperbound bool         // Score is a upperbound
	Lowerbound bool         // Score is a lowerbound
	Rank       int          // 0-based rank of the pv in a MultiPV search
}

Pv holds the details of a principal variation from an engine search.

type Stats

type Stats struct {
	Depth    int           // depth in plies
	SelDepth int           // selective depth
	Nodes    int           // number of nodes searched so far
	Time     time.Duration // amount of time searched so far
}

Stats holds statistics from an engine search.

type StringOption

type StringOption interface {
	Option
}

StringOption represents string option.

Directories

Path Synopsis
Package uci (partly) implements the UCI protocol for communicating with chess engines.
Package uci (partly) implements the UCI protocol for communicating with chess engines.

Jump to

Keyboard shortcuts

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