eval

package
v0.91.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package eval contains position evaluation logic and utilities.

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidScore = Score{Type: Invalid}
	ZeroScore    = Score{Type: Heuristic}
	InfScore     = Score{Type: Inf}
	NegInfScore  = Score{Type: NegInf}
)

Functions

func FindCapture added in v0.90.1

func FindCapture(pos *board.Position, side board.Color, sq board.Square) []board.Placement

FindCapture returns the pieces of the given color that directly target the square.

func SortByNominalValue added in v0.90.1

func SortByNominalValue(pieces []board.Placement) []board.Placement

SortByNominalValue orders the placement list by nominal material value, low to high.

Types

type Evaluator

type Evaluator interface {
	// Evaluate returns the position score in Pawns.
	Evaluate(ctx context.Context, b *board.Board) Pawns
}

Evaluator is a static position evaluator.

type Material

type Material struct{}

Material returns the nominal material advantage balance for the side to move.

func (Material) Evaluate

func (Material) Evaluate(ctx context.Context, b *board.Board) Pawns

type Pawns

type Pawns float32

Pawns presents a fractional number of pawns.

func Limit

func Limit(pawns, limit Pawns) Pawns

Limit crops the value to +/- limit.

func NominalValue

func NominalValue(p board.Piece) Pawns

NominalValue the absolute nominal value in pawns of a piece. The King has an arbitrary value of 100 pawns.

func NominalValueGain

func NominalValueGain(m board.Move) Pawns

NominalValueGain is the nominal material gain for a move.

func (Pawns) String

func (p Pawns) String() string

type Pin

type Pin struct {
	Attacker, Pinned, Target board.Square
}

Pin represents a pinned piece. A pinned piece cannot attack anything but the attacker itself, if the relative value of attacker/target is high enough.

func FindPins

func FindPins(pos *board.Position, side board.Color, piece board.Piece) []Pin

FindPins returns all pins targeting the given piece.

type Random added in v0.89.2

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

Random is a randomized noise generator. It is used to a small amount of randomness to evaluations. The limit specifies how many millipawns to add/remove in the range [-limit/2; limit/2]. The default value always returns zero.

func NewRandom added in v0.89.2

func NewRandom(limit int, seed int64) Random

func (Random) Evaluate added in v0.89.2

func (n Random) Evaluate(ctx context.Context, b *board.Board) Pawns

type Score

type Score struct {
	Type  ScoreType
	Mate  int8 // Non-zero ply to forced mate. Negative if being mated.
	Pawns Pawns
}

Score is signed position score in "pawns", unless decided or mate-in-X. Positive favors the side to move. If all pawns become queens and the opponent has only the king left, the standard material advantage score is: 9*8 (p) + 9 (q) + 2*5 (r) + 2*3 (k) + 2*3 (b) = 103. The score can be arbitrary, but is reported as centi-pawns to humans. 64bits.

func HeuristicScore

func HeuristicScore(pawns Pawns) Score

HeuristicScore returns a Heuristic score with the given evaluation.

func IncrementMateDistance

func IncrementMateDistance(s Score) Score

IncrementMateDistance adds 1 ply to a MateInX or Inf/NegInf. Heuristic scores are unchanged.

func MateInXScore

func MateInXScore(mate int8) Score

MateInXScore returns a MateInX score with the given evaluation.

func Max

func Max(a, b Score) Score

Max returns the largest of the given scores.

func Min

func Min(a, b Score) Score

Min returns the smallest of the given scores.

func (Score) IsHeuristic

func (s Score) IsHeuristic() bool

func (Score) IsInf

func (s Score) IsInf() bool

func (Score) IsInvalid

func (s Score) IsInvalid() bool

func (Score) IsMateInX

func (s Score) IsMateInX() bool

func (Score) IsNegInf

func (s Score) IsNegInf() bool

func (Score) Less

func (s Score) Less(o Score) bool

Less implements < Score ordering. The group ordering is: -inf < negative mate < heuristic < positive mate < inf. Mates are ordered by closeness to checkmate within each mate group, e.g., M2 < M1 and M-1 < M-2.

func (Score) MateDistance

func (s Score) MateDistance() (int8, bool)

MateDistance returns the ply distance to CheckMate, if known. If a forced mate is possible, there is generally no reason to search deeper.

func (Score) Negate

func (s Score) Negate() Score

Negate returns the negative score, as viewed from the opponent.

func (Score) String

func (s Score) String() string

type ScoreType

type ScoreType int8

ScoreType represents the type of score.

const (
	Invalid ScoreType = iota
	Heuristic
	MateInX
	Inf    // Won position (= opponent checkmate)
	NegInf // Lost position (= in checkmate)
)

Jump to

Keyboard shortcuts

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