transpositiontable

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package transpositiontable implements a transposition table (cache) data structure and functionality for a chess engine search. The TtTable class is not thread safe and needs to be synchronized externally if used from multiple threads. Is especially relevant for Resize and Clear which should not be called in parallel while searching.

Index

Constants

View Source
const (
	// TtEntrySize is the size in bytes for each TtEntry
	TtEntrySize = 16 // 16 bytes

	// MaxSizeInMB maximal memory usage of tt
	MaxSizeInMB = 65_536
)

Variables

This section is empty.

Functions

This section is empty.

Types

type TtEntry

type TtEntry struct {
	Key        position.Key // 64-bit Zobrist Key
	Move       Move         // 32-bit Move and value
	Depth      int8         // 7-bit 0-127 0b01111111
	Age        int8         // 3-bit 0-7   0b00000111 0=used 1=generated, not used, >1 older generation
	Type       ValueType    // 2-bit None, Exact, Alpha (upper), Beta (lower)
	MateThreat bool         // 1-bit
}

TtEntry struct is the data structure for each entry in the transposition table. Each entry has 16-bytes (128-bits)

type TtStats

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

TtStats holds statistical data on tt usage

type TtTable

type TtTable struct {
	Stats TtStats
	// contains filtered or unexported fields
}

TtTable is the actual transposition table object holding data and state. Create with NewTtTable()

func NewTtTable

func NewTtTable(sizeInMByte int) *TtTable

NewTtTable creates a new TtTable with the given number of bytes as a maximum of memory usage. actual size will be determined by the number of elements fitting into this size which need to be a power of 2 for efficient hashing/addressing via bit masks

func (*TtTable) AgeEntries

func (tt *TtTable) AgeEntries()

AgeEntries ages each entry in the tt Creates a number of go routines with processes each a certain slice of data to process

func (*TtTable) Clear

func (tt *TtTable) Clear()

Clear clears all entries of the tt The TtTable class is not thread safe and needs to be synchronized externally if used from multiple threads. Is especially relevant for Resize and Clear which should not be called in parallel while searching.

func (*TtTable) GetEntry

func (tt *TtTable) GetEntry(key position.Key) *TtEntry

GetEntry returns a pointer to the corresponding tt entry. Given key is checked against the entry's key. When equal pointer to entry will be returned. Otherwise nil will be returned. Does not change statistics.

func (*TtTable) Hashfull

func (tt *TtTable) Hashfull() int

Hashfull returns how full the transposition table is in permill as per UCI

func (*TtTable) Len

func (tt *TtTable) Len() uint64

Len returns the number of non empty entries in the tt

func (*TtTable) Probe

func (tt *TtTable) Probe(key position.Key) *TtEntry

Probe returns a pointer to the corresponding tt entry or nil if it was not found. Decreases TtEntry.Age by 1

func (*TtTable) Put

func (tt *TtTable) Put(key position.Key, move Move, depth int8, value Value, valueType ValueType, mateThreat bool)

Put an TtEntry into the tt. Encodes value into the move.

func (*TtTable) Resize

func (tt *TtTable) Resize(sizeInMByte int)

Resize resizes the tt table. All entries will be cleared. The TtTable class is not thread safe and needs to be synchronized externally if used from multiple threads. Is especially relevant for Resize and Clear which should not be called in parallel while searching.

func (*TtTable) String

func (tt *TtTable) String() string

String returns a string representation of this TtTable instance

Jump to

Keyboard shortcuts

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