chesstools

package module
v0.0.0-...-7c97921 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: MIT Imports: 18 Imported by: 0

README

chesstools

Collection of chess related utilities

Documentation

Index

Constants

View Source
const (
	KiB = 1024
	MiB = 1024 * KiB

	DefaultEvalTimeInSec = 300
	DefaultDepth         = -1 // infinite
)
View Source
const (
	LichessDbBaseUrl = "https://explorer.lichess.ovh/lichess"
	PlayerDbBaseUrl  = "https://explorer.lichess.ovh/player"
)
View Source
const (
	LichessApiBaseUrl = "https://lichess.org/api/crosstable"
)
View Source
const LichessUrlPrefix = "https://lichess.org"

Variables

View Source
var ErrCacheMiss = errors.New("cache miss")
View Source
var ErrCacheStale = errors.New("cache stale")

Functions

func GetCrossTable

func GetCrossTable(player1 string, player2 string) (int, error)

func GetOpeningEco

func GetOpeningEco(fen string) string

func GetOpeningName

func GetOpeningName(fen string) string

func NormalizeFEN

func NormalizeFEN(fen string) (string, error)

func OpenPgn

func OpenPgn(pgnFileOrUrl string) (io.ReadCloser, error)

func Pct

func Pct(numerator int, denominator int) float64

func PctS

func PctS(numerator int, denominator int) string

func PctS2

func PctS2(pctf float64) string

Types

type CloudEvalResp

type CloudEvalResp struct {
	Error  string    `json:"error"`
	Fen    string    `json:"fen"`
	KNodes int       `json:"knodes"`
	Depth  int       `json:"depth"`
	PVs    []CloudPV `json:"pvs"`
}

type CloudPV

type CloudPV struct {
	CP    int    `json:"cp"`
	Mate  int    `json:"mate"`
	Moves string `json:"moves"`
}

type CrossTableGames

type CrossTableGames struct {
	NumGames int `json:"nbGames"`
}

type EvalCtx

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

func NewEvalCtx

func NewEvalCtx(cacheOnlyIn bool) *EvalCtx

func (*EvalCtx) Close

func (evalCtx *EvalCtx) Close()

func (*EvalCtx) Eval

func (evalCtx *EvalCtx) Eval() *EvalResult

func (*EvalCtx) GetPosition

func (evalCtx *EvalCtx) GetPosition() string

func (*EvalCtx) InitEngine

func (evalCtx *EvalCtx) InitEngine()

func (*EvalCtx) SetFEN

func (evalCtx *EvalCtx) SetFEN(fen string) *EvalCtx

func (*EvalCtx) WithCacheOnly

func (evalCtx *EvalCtx) WithCacheOnly() *EvalCtx

func (*EvalCtx) WithEvalDepth

func (evalCtx *EvalCtx) WithEvalDepth(evalDepth int) *EvalCtx

func (*EvalCtx) WithEvalTime

func (evalCtx *EvalCtx) WithEvalTime(evalTimeInSec uint) *EvalCtx

func (*EvalCtx) WithFEN

func (evalCtx *EvalCtx) WithFEN(fen string) *EvalCtx

func (*EvalCtx) WithHashSize

func (evalCtx *EvalCtx) WithHashSize(hashSizeInMiB uint64) *EvalCtx

func (*EvalCtx) WithMoveNum

func (evalCtx *EvalCtx) WithMoveNum(moveNum uint) *EvalCtx

func (*EvalCtx) WithPgnFile

func (evalCtx *EvalCtx) WithPgnFile(pgnFile string) *EvalCtx

func (*EvalCtx) WithStaleOk

func (evalCtx *EvalCtx) WithStaleOk() *EvalCtx

func (*EvalCtx) WithThreads

func (evalCtx *EvalCtx) WithThreads(numThreads uint64) *EvalCtx

func (*EvalCtx) WithTurn

func (evalCtx *EvalCtx) WithTurn(turn chess.Color) *EvalCtx

func (*EvalCtx) WithoutCloudCache

func (evalCtx *EvalCtx) WithoutCloudCache() *EvalCtx

type EvalResult

type EvalResult struct {
	CP         int
	Mate       int
	BestMove   string
	Depth      int
	EngVersion float64
	KNPS       string
}

type GameInfo

type GameInfo struct {
	Uci    string     `json:"uci"`
	Id     string     `json:"id"`
	Winner string     `json:"winner"`
	Speed  string     `json:"speed"`
	Mode   string     `json:"mode"`
	Year   int        `json:"year"`
	Month  string     `json:"month"`
	Black  PlayerInfo `json:"black"`
	White  PlayerInfo `json:"white"`
}

type MoveStats

type MoveStats struct {
	Uci       string `json:"uci"`
	San       string `json:"san"`
	WhiteWins int    `json:"white"`
	BlackWins int    `json:"black"`
	Draws     int    `json:"draws"`

	Eval *EvalResult //only valid when getEval==true
}

func (*MoveStats) Total

func (mv *MoveStats) Total() int

type Opening

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

type OpeningGame

type OpeningGame struct {
	G      *chess.Game
	Parent *OpeningGame

	Eco         string
	OpeningResp *OpeningResp
	Threshold   float64 // percent of games
	// contains filtered or unexported fields
}

func NewOpeningGame

func NewOpeningGame() *OpeningGame

func (*OpeningGame) ChoicesString

func (openingGame *OpeningGame) ChoicesString(ignoreThreshold bool) string

func (*OpeningGame) GetMoveCount

func (openingGame *OpeningGame) GetMoveCount() int

func (*OpeningGame) String

func (openingGame *OpeningGame) String() string

func (*OpeningGame) Turn

func (openingGame *OpeningGame) Turn() chess.Color

func (*OpeningGame) WithAllSpeeds

func (openingGame *OpeningGame) WithAllSpeeds(fetchAllSpeeds bool) *OpeningGame

func (*OpeningGame) WithEval

func (openingGame *OpeningGame) WithEval(doEval bool) *OpeningGame

func (*OpeningGame) WithFEN

func (openingGame *OpeningGame) WithFEN(fen string) *OpeningGame

func (*OpeningGame) WithFullRatingRange

func (openingGame *OpeningGame) WithFullRatingRange(fetchFullRatingRange bool) *OpeningGame

func (*OpeningGame) WithGame

func (openingGame *OpeningGame) WithGame(game *chess.Game) *OpeningGame

func (*OpeningGame) WithMove

func (openingGame *OpeningGame) WithMove(move string) *OpeningGame

func (*OpeningGame) WithOpponent

func (openingGame *OpeningGame) WithOpponent(playerIn string, colorIn chess.Color) *OpeningGame

func (*OpeningGame) WithParent

func (openingGame *OpeningGame) WithParent(parent *OpeningGame) *OpeningGame

func (*OpeningGame) WithThreshold

func (openingGame *OpeningGame) WithThreshold(threshold float64) *OpeningGame

func (*OpeningGame) WithTopReplies

func (openingGame *OpeningGame) WithTopReplies(fetchTop bool) *OpeningGame

type OpeningResp

type OpeningResp struct {
	WhiteWins   int         `json:"white"`
	BlackWins   int         `json:"black"`
	Draws       int         `json:"draws"`
	Moves       []MoveStats `json:"moves"`
	TopGames    []GameInfo  `json:"topGames"`
	RecentGames []GameInfo  `json:"recentGames"`
}

func (*OpeningResp) Total

func (openingResp *OpeningResp) Total() int

type PlayerInfo

type PlayerInfo struct {
	Name   string `json:"name"`
	Rating int    `json:"rating"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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