opening

package
v0.0.0-...-b7d8144 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: MIT Imports: 7 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/notnil/chess"
    "github.com/notnil/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

NewBookECO returns a new BookECO. This operation has to parse 2k rows of CSV data and insert it into a graph so it can take some time.

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

Game returns the opening as a game.

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