eval

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Mate score to be adjusted by the ply that it is found on by subtracting the ply to favor shorter mates.
	CheckmateScore int16 = 8192
	// ply adjusted adjusted mates scores should not exceed this value and anything above this should be considered a mate instead of normal eval.
	CheckmateThreshold = CheckmateScore - 1024
	Inf                = 2 * CheckmateScore
)
View Source
const (
	// Mobility related weights.
	W_MOVE    int = 2
	W_CAPTURE int = 4

	// Pawn.
	W_P_PASSED    int = 10
	W_P_PROTECTED int = 15
	W_P_DOUBLED   int = -15
	W_P_ISOLATED  int = -20
)

Variables

View Source
var PST = [2][2][6][64]int{
	{{pawnPST, bishopPST, knightPST, rookPST, queenPST, kingPST}},
	{{pawnEGPST, bishopEGPST, knightEGPST, rookEGPST, queenEGPST, kingEGPST}},
}
View Source
var PiecePawnBonus = [6][9]int{
	{},
	{},
	{-25, -19, -13, -6, 0, 6, 13, 19, 25},
	{50, 37, 25, 12, 0, -12, -25, -37, -50},
	{},
	{},
}

Based on L. Kaufman - rook and knight values are adjusted by the number of pawns on the board.

View Source
var PieceWeights = [6]int{100, 325, 325, 500, 975, 10000}

Functions

func IsDoubled

func IsDoubled(b *board.Board, sq board.Square, side int) bool

TODO: create a lookup table for files to avoid branching.

func IsIsolated

func IsIsolated(b *board.Board, sq board.Square, side int) bool

Has no friendly pawns on neighboring files.

func IsPassed

func IsPassed(b *board.Board, sq board.Square, side int) bool

Has no opponent opposing pawns in front (same or neighbor files) TODO: stub.

func IsProtected

func IsProtected(b *board.Board, sq board.Square, side int) bool

TODO: combine all pawn functions in one with multi value return Piece protected a pawn.

Types

type Clock

type Clock struct {
	Wtime     int
	Btime     int
	Winc      int
	Binc      int
	Overhead  int
	Movetime  int
	Movestogo int
	Infinite  bool
}

func (*Clock) GetContext

func (c *Clock) GetContext(fmCounter, side int) (context.Context, context.CancelFunc)

func (*Clock) GetMovetime

func (c *Clock) GetMovetime(fmCounter, side int) time.Duration

type EntryData added in v1.1.0

type EntryData uint64

LSB 0..31 move, 32..38 depth 39..40 type 41..47 age 48..63 score MSB.

func NewEntry added in v1.1.0

func NewEntry(move board.Move, depth int8, eType EntryType, age int8, score int16) EntryData

func (EntryData) Age added in v1.3.0

func (ed EntryData) Age() int8

func (EntryData) Depth added in v1.1.0

func (ed EntryData) Depth() int8

func (EntryData) Get added in v1.1.0

func (ed EntryData) Get() (board.Move, int8, EntryType, int16)

func (EntryData) GetScore added in v1.1.0

func (ed EntryData) GetScore(depth, ply int8, alpha, beta int16) (int16, bool)

func (EntryData) Move added in v1.1.0

func (ed EntryData) Move() board.Move

func (EntryData) Score added in v1.1.0

func (ed EntryData) Score() int16

func (EntryData) Type added in v1.1.0

func (ed EntryData) Type() EntryType

type EntryType added in v1.3.0

type EntryType uint8
const (
	TT_UPPER EntryType = iota
	TT_LOWER
	TT_EXACT
)

func (EntryType) String added in v1.3.0

func (et EntryType) String() string

type EvalEngine

type EvalEngine struct {
	Board       *board.Board
	TTable      *TTable
	WG          sync.WaitGroup
	Stats       EvalStats
	Ponder      bool
	OwnBook     bool
	MateFound   bool
	KillerMoves [100][2]board.Move
	History     HistoryHeuristic
	Ply         int
	Plys        [512]uint64
	SearchDepth int
	Clock       Clock
	Stop        context.CancelFunc
}

func NewEvalEngine

func NewEvalEngine() *EvalEngine

func (*EvalEngine) AddKillerMove

func (e *EvalEngine) AddKillerMove(ply int8, move board.Move)

func (*EvalEngine) AddPly added in v1.1.0

func (e *EvalEngine) AddPly()

func (*EvalEngine) AgeHistory added in v1.1.0

func (e *EvalEngine) AgeHistory()

func (*EvalEngine) ConvertEvalToScore

func (e *EvalEngine) ConvertEvalToScore(eval int16) string

Display centipawn score. If the eval is in the checkmate score threshold convert to mate score.

func (*EvalEngine) DecrementHistory

func (e *EvalEngine) DecrementHistory(move board.Move)

func (*EvalEngine) GetEvaluation

func (e *EvalEngine) GetEvaluation(b *board.Board) int

func (*EvalEngine) GetHistory added in v1.1.0

func (e *EvalEngine) GetHistory(move board.Move) int

func (*EvalEngine) GetMove

func (e *EvalEngine) GetMove(ctx context.Context, depth int, infinite bool) (board.Move, board.Move)

Returns the best move and best opponent response - ponder.

func (*EvalEngine) GetMoveSelector added in v1.1.0

func (e *EvalEngine) GetMoveSelector(hashMove board.Move, moves, pvOrder []board.Move, ply int8) MoveSelector

Move ordering 1. PV 2. hash move 3. Captures orderd by MVVLVA, 4. killer moves 5. History Heuristic.

func (*EvalEngine) GetMoveSelectorQ added in v1.1.0

func (e *EvalEngine) GetMoveSelectorQ(moves []board.Move) MoveSelector

func (*EvalEngine) IDSearch

func (e *EvalEngine) IDSearch(ctx context.Context, depth int, infinite bool) (board.Move, board.Move, bool)

Iterative deepening search. Returns best move, ponder and ok if search succeeded.

func (*EvalEngine) IncrementHistory

func (e *EvalEngine) IncrementHistory(depth int8, move board.Move)

func (*EvalEngine) IsDrawByRepetition

func (e *EvalEngine) IsDrawByRepetition() bool

IsDrawByRepetition checks if the current position has been seen before.

func (*EvalEngine) MvvLva added in v1.1.0

func (e *EvalEngine) MvvLva(move board.Move) int

Estimate the potential strength of the move for move ordering.

func (*EvalEngine) PVS

func (e *EvalEngine) PVS(ctx context.Context, pvOrder []board.Move, line *[]board.Move, depth, ply int8, alpha, beta int16, nmp bool, side int16) int16

func (*EvalEngine) PlayMovesUCI

func (e *EvalEngine) PlayMovesUCI(uciMoves string) bool

PlayMovesUCI plays a list of moves in UCI format and updates game history.

func (*EvalEngine) RemovePly added in v1.1.0

func (e *EvalEngine) RemovePly()

func (*EvalEngine) ReportMove

func (e *EvalEngine) ReportMove(move, ponder board.Move, allowPonder bool)

type EvalStats

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

func (*EvalStats) Clear

func (es *EvalStats) Clear()

func (*EvalStats) Start

func (es *EvalStats) Start()

func (*EvalStats) String

func (es *EvalStats) String() string

type HistoryHeuristic added in v1.1.0

type HistoryHeuristic [2][64][64]int

type MoveSelector added in v1.3.0

type MoveSelector func(k int) board.Move

type PickBookMove

type PickBookMove func(*board.Board) board.Move

type SearchEntry

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

type TTable

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

func NewTTable

func NewTTable(sizeInMb int) *TTable

func (*TTable) Clear

func (tt *TTable) Clear()

func (*TTable) Hashfull

func (tt *TTable) Hashfull() uint64

func (*TTable) Probe

func (tt *TTable) Probe(hash uint64) (*EntryData, bool)

func (*TTable) Store

func (tt *TTable) Store(hash uint64, entryType EntryType, eval int16, depth int8, move board.Move)

Jump to

Keyboard shortcuts

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