openingbook

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: 17 Imported by: 0

Documentation

Overview

Package openingbook The OpeningBook reads game databases of different formats into an internal data structure. It can then be queried for a book move on a certain position.

Supported formats are currently:

BookFormat::SIMPLE for files storing a game per line with from-square and to-square notation

BookFormat::SAN for files with lines of moves in SAN notation

BookFormat::PGN for PGN formatted games<br/>

Index

Constants

This section is empty.

Variables

View Source
var (
	FormatFromString = map[string]BookFormat{
		"Simple": Simple,
		"San":    San,
		"Pgn":    Pgn,
	}
)

Functions

This section is empty.

Types

type Book

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

Book represents a structure for chess opening books which can be read from different file formats into an internal data structure.

Create new book instance with NewBook()

func NewBook

func NewBook() *Book

NewBook create as new opening book instance.

func (*Book) GetEntry

func (b *Book) GetEntry(key position.Key) (BookEntry, bool)

GetEntry returns a copy of the entry with the corresponding key

func (*Book) Initialize

func (b *Book) Initialize(bookPath string, bookFile string, bookFormat BookFormat, useCache bool, recreateCache bool) error

Initialize reads game data from the given file into the internal data structure. A binary cache file will be created in the same folder (postfix .cache) to speedup subsequent loading if the opening book. Initialization only occurs once multiple calls will be ignored. To re-initialize call Reset() first.

func (*Book) NumberOfEntries

func (b *Book) NumberOfEntries() int

NumberOfEntries returns the number of entries in the opening book

func (*Book) Reset

func (b *Book) Reset()

Reset resets the opening book so it can/must be initialized again

type BookEntry

type BookEntry struct {
	ZobristKey uint64
	Counter    int
	Moves      []Successor
}

BookEntry represents a data structure for a move in the opening book data structure. It describes exactly one position defined by a zobrist key and has links to other entries representing moves and successor positions.

type BookFormat

type BookFormat uint8

BookFormat represent the supported book formats defined as constants.

const (
	Simple BookFormat = iota
	San    BookFormat = iota
	Pgn    BookFormat = iota
)

Supported book formats.

type Successor

type Successor struct {
	Move      uint32
	NextEntry uint64
}

Successor represents a tuple of a move and a zobrist key of the position the move leads to.

Jump to

Keyboard shortcuts

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