Documentation
¶
Overview ¶
Package opening implements chess opening determination and exploration.
Index ¶
Examples ¶
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.
// Use Find for performance-sensitive opening detection paths.
Find(moves []chess.Move) *Entry
// Possible returns the possible openings after the moves given. If moves is empty or nil all openings are returned.
// Use Possible for performance-sensitive opening exploration paths.
Possible(moves []chess.Move) []*Entry
}
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 DefaultBook ¶
DefaultBook returns the standard ECO opening book. The book is parsed lazily on first call and cached for subsequent calls. It is safe for concurrent use.
Example (Find) ¶
package main
import (
"fmt"
"github.com/corentings/chess/v3"
"github.com/corentings/chess/v3/opening"
)
func main() {
g := chess.NewGame()
_, _ = g.MoveText("e4", chess.SAN(), nil)
_, _ = g.MoveText("e6", chess.SAN(), nil)
// print French Defense
book, err := opening.DefaultBook()
if err != nil {
fmt.Println("Error:", err)
return
}
o := book.Find(g.Moves())
fmt.Println(o.Title())
}
Output: French Defense
Example (Possible) ¶
package main
import (
"fmt"
"github.com/corentings/chess/v3"
"github.com/corentings/chess/v3/opening"
)
func main() {
g := chess.NewGame()
_, _ = g.MoveText("e4", chess.SAN(), nil)
_, _ = g.MoveText("d5", chess.SAN(), nil)
// print all variantions of the Scandinavian Defense
book, err := opening.DefaultBook()
if err != nil {
fmt.Println("Error:", err)
return
}
for _, o := range book.Possible(g.Moves()) {
if o.Title() == "Scandinavian Defense" {
fmt.Println(o.Title())
}
}
}
Output: Scandinavian Defense Scandinavian Defense
func NewBook ¶
NewBook creates a new opening book from an ECO TSV reader. Use this for custom opening data or when you need isolation from the default book. NewBook validates the input during construction so malformed books fail before use. Entry.Game returns a caller-owned clone of the cached game.
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
A Entry represents a specific sequence of moves from the starting position.
