opening

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 6 Imported by: 0

README

opening

opening provides interactivity to opening books such as Encyclopaedia of Chess Openings (ECO) which is loadable from the package. Source: https://github.com/lichess-org/chess-openings

Visual

Advance Variation subtree of the French Defense:

subtree

Example

package main

import (
    "fmt"

    "github.com/0x5844/chess"
    "github.com/0x5844/chess/opening"
)

func main(){
    g := chess.NewGame()
 g.MoveStr("e4")
 g.MoveStr("e6")

 // print French Defense
 book := opening.NewBookECO()
 o := book.Find(g.Moves())
 fmt.Println(o.Title())
}

Documentation

Overview

Package opening implements chess opening determination and exploration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

type Book interface {
	// Find returns the most specific opening for the list of moves.  If no opening is found, Find returns nil.
	Find(moves []*chess.Move) *Opening
	// Possible returns the possible openings after the moves given.  If moves is empty or nil all openings are returned.
	Possible(moves []*chess.Move) []*Opening
}

Book is an opening book that returns openings for move sequences

type BookECO

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

BookECO represents the Encyclopedia of Chess Openings https://en.wikipedia.org/wiki/Encyclopaedia_of_Chess_Openings BookECO is safe for concurrent use.

func NewBookECO

func NewBookECO() (*BookECO, error)

NewBookECO creates and initializes a new BookECO from the embedded ECO data. It parses the TSV data and builds the opening tree.

func (*BookECO) Find

func (b *BookECO) Find(moves []*chess.Move) *Opening

Find implements the Book interface

func (*BookECO) Possible

func (b *BookECO) Possible(moves []*chess.Move) []*Opening

Possible implements the Book interface

type Opening

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

A Opening represents a specific sequence of moves from the staring position.

func (*Opening) Code

func (o *Opening) Code() string

Code returns the Encyclopaedia of Chess Openings (ECO) code.

func (*Opening) Game

func (o *Opening) Game() (*chess.Game, error)

Game returns the opening as a playable chess.Game instance.

func (*Opening) Moves added in v0.1.1

func (o *Opening) Moves() []*chess.Move

Moves returns the sequence of chess moves defining the opening.

func (*Opening) PGN

func (o *Opening) PGN() string

PGN returns the opening in PGN format.

func (*Opening) Title

func (o *Opening) Title() string

Title returns the Encyclopaedia of Chess Openings (ECO) title of the opening.

Jump to

Keyboard shortcuts

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