Documentation
¶
Index ¶
- Constants
- Variables
- func Advantages(positions string) (string, string)
- func AppDir() string
- func AtScale(idx, tot int, val float64) bool
- func ConfigJSON(config Config) string
- func DownloadFile(url string, filepath string) error
- func DrawMsgLabel(s tcell.Screen, msg string, t Theme)
- func EmojiForPlayer(playerType string) string
- func EngMove(game *chess.Game, us UCIState, config Config) string
- func EngScore(game *chess.Game, us UCIState, config Config) int
- func FetchStockfish() string
- func FileExists(path string) bool
- func FindStockfish() string
- func HasTheme(name string, themes []ThemeHex) bool
- func ImportEngines(uciWhite string, uciBlack string, uciHint string, engines []UCIEngine) (*UCIEngine, *UCIEngine, *UCIEngine)
- func InCheck(game *chess.Game) (bool, bool)
- func InitEngines(config Config) (*uci.Engine, *uci.Engine, *uci.Engine)
- func IsCPU(player chess.Color, config Config) bool
- func IsFile(path string) bool
- func IsInteractive(config Config) bool
- func IsWindows() bool
- func MatchStockfishWin(file string) bool
- func ProcessCmd(cmd string, gs *GameState) (string, *chess.Game)
- func Render(gs *GameState)
- func RoundNearest(x, unit float64) float64
- func ScoreStr(positions string) (string, string)
- func SearchDirForStockfish(dir string) string
- func StockfishFilename() string
- func Timestamp() string
- func WinProb(cp int) float64
- type Config
- type GameState
- type Input
- type Option
- type Theme
- type ThemeHex
- type UCIEngine
- type UCIState
- type WriteCounter
Constants ¶
const MaxLength = 10
MaxLength defines the MaxWidth of the input buffer
Variables ¶
var DefStyle = tcell.StyleDefault.Background(tcell.ColorReset).Foreground(tcell.ColorReset)
DefStyle is the default style for tcell rendering
var DefaultOptions = []Option{
{"skill level", "3"},
}
DefaultOptions defines any default UCI options
var ThemeBasic = Theme{
"basic",
tcell.Color252,
tcell.ColorBlack,
tcell.Color188,
tcell.Color230,
tcell.Color226,
tcell.Color223,
tcell.Color218,
tcell.Color232,
tcell.Color232,
tcell.Color160,
tcell.Color247,
tcell.Color247,
tcell.Color160,
tcell.Color240,
tcell.ColorDefault,
tcell.Color45,
tcell.Color122,
tcell.Color167,
tcell.ColorDefault,
tcell.Color247,
tcell.ColorDefault,
tcell.ColorDefault,
tcell.ColorDefault,
tcell.Color247,
}
ThemeBasic is the default theme
Functions ¶
func Advantages ¶
Advantages returns the white/black advantage strings
func AtScale ¶
AtScale returns a boolean value indicating whether the given value (val) has crossed the threshold (idx) established by dividing total (tot) into equal increments
func ConfigJSON ¶
ConfigJSON returns the JSON encoded representation of the config
func DownloadFile ¶
DownloadFile will download a url and store it in local filepath. It writes to the destination file as it downloads it, without loading the entire file into memory. We pass an io.TeeReader into Copy() to report progress on the download.
func DrawMsgLabel ¶
DrawMsgLabel displays the current message from the command
func EmojiForPlayer ¶
EmojiForPlayer returns an emoji corresponding to the player type
func EngScore ¶
EngScore provides the current board score in centipawns for whomever the current game position identifies as active
func FetchStockfish ¶
func FetchStockfish() string
FetchStockfish attempts to load Stockfish via the path and attempts to download the binary for a limited number of platforms
func FileExists ¶
FileExists returns a bool indicating whether the specified file exists
func FindStockfish ¶
func FindStockfish() string
FindStockfish attempts to find Stockfish in the PATH and config dir A string with the path is returned when found, an empty string is returned otherwise
func HasTheme ¶
HasTheme returns a bool indicating whether the config contains a theme of the name provided
func ImportEngines ¶
func ImportEngines(uciWhite string, uciBlack string, uciHint string, engines []UCIEngine) (*UCIEngine, *UCIEngine, *UCIEngine)
ImportEngines returns a UCIEngine config for white and black
func InCheck ¶
InCheck returns two booleans indicating if either player is in check. The first boolean represents white and the second boolean represents black
func InitEngines ¶
InitEngines configures UCI engines if the config dictates that they are required. The white and black engines are returned respectively
func IsInteractive ¶
IsInteractive returns a bool indicating whether the game is interactive with interactive meaning a human is involved
func IsWindows ¶
func IsWindows() bool
IsWindows returns a boolean indicating whether windows is the OS
func MatchStockfishWin ¶
MatchStockfishWin returns a boolean indicating whether a given file looks like the stockfish executable (Windows). Fuzzy matching is applied
func ProcessCmd ¶
ProcessCmd processes a move request or command
func RoundNearest ¶
RoundNearest rounds to the nearest unit
func SearchDirForStockfish ¶
SearchDirForStockfish scans a directory and looks for a stockfish binary. Upon matching, a string with the binary name is returned. If no match is found, an empty string is returned
func StockfishFilename ¶
func StockfishFilename() string
StockfishFilename returns a platform specific filename for the Stockfish binary
Types ¶
type Config ¶
type Config struct { UCIWhite string `json:"uciWhite"` UCIBlack string `json:"uciBlack"` UCIHint string `json:"uciHint"` UCIEngines []UCIEngine `json:"uciEngines"` FEN string `json:"fen"` ActiveTheme string `json:"activeTheme"` Themes []ThemeHex `json:"theme"` WhitePiece string `json:"whitePiece"` BlackPiece string `json:"blackPiece"` WhiteName string `json:"whiteName"` BlackName string `json:"blackName"` }
Config defines the configurable parameters for UCI
func ReadConfig ¶
ReadConfig reads the specified JSON file into a config struct
type GameState ¶
type GameState struct { S tcell.Screen // Screen Input *Input // Input Game *chess.Game // Chess Board UCI UCIState // UCI State Config Config // Global Config Theme Theme // Theme Score int // Score in centipawns CheckWhite bool // White is in check CheckBlack bool // Black is in check Hint *chess.Move // Hint when available }
GameState encapsulates everything needed to run the game
type Input ¶
type Input struct {
// contains filtered or unexported fields
}
Input stores the input buffer
type Theme ¶
type Theme struct { Name string `json:"name"` MoveLabelBg tcell.Color `json:"moveLabelBg"` MoveLabelFg tcell.Color `json:"moveLabelFg"` SquareDark tcell.Color `json:"squareDark"` SquareLight tcell.Color `json:"squareLight"` SquareHigh tcell.Color `json:"squareHigh"` SquareHint tcell.Color `json:"squareHint"` SquareCheck tcell.Color `json:"squareCheck"` White tcell.Color `json:"white"` Black tcell.Color `json:"black"` Msg tcell.Color `json:"msg"` Rank tcell.Color `json:"rank"` File tcell.Color `json:"file"` Prompt tcell.Color `json:"prompt"` MeterBase tcell.Color `json:"meterBase"` MeterMid tcell.Color `json:"meterMid"` MeterNeutral tcell.Color `json:"meterNeutral"` MeterWin tcell.Color `json:"meterWin"` MeterLose tcell.Color `json:"meterLose"` PlayerNames tcell.Color `json:"playerNames"` Score tcell.Color `json:"score"` MoveBox tcell.Color `json:"moveBox"` Emoji tcell.Color `json:"emoji"` Input tcell.Color `json:"input"` Advantage tcell.Color `json:"advantage"` }
Theme is used for dynamically coloring the UI
func ImportThemes ¶
ImportThemes returns a converted Theme from a slice of ThemeHex entities if its name matches the want argument
type ThemeHex ¶
type ThemeHex struct { Name string `json:"name"` MoveLabelBg string `json:"moveLabelBg"` MoveLabelFg string `json:"moveLabelFg"` SquareDark string `json:"squareDark"` SquareLight string `json:"squareLight"` SquareHigh string `json:"squareHigh"` SquareHint string `json:"squareHint"` SquareCheck string `json:"squareCheck"` White string `json:"white"` Black string `json:"black"` Msg string `json:"msg"` Rank string `json:"rank"` File string `json:"file"` Prompt string `json:"prompt"` MeterBase string `json:"meterBase"` MeterMid string `json:"meterMid"` MeterNeutral string `json:"meterNeutral"` MeterWin string `json:"meterWin"` MeterLose string `json:"meterLose"` PlayerNames string `json:"playerNames"` Score string `json:"score"` MoveBox string `json:"moveBox"` Emoji string `json:"emoji"` Input string `json:"input"` Advantage string `json:"advantage"` }
ThemeHex is used for dynamically coloring the UI
func ReadThemes ¶
func ReadThemes() []ThemeHex
ReadThemes reads packaged theme data into a ThemeHex data slice
type UCIEngine ¶
type UCIEngine struct { Name string `json:"name"` Path string `json:"engine"` Hash int `json:"hash"` Ponder bool `json:"ponder"` OwnBook bool `json:"ownBook"` MultiPV int `json:"multiPV"` Depth int `json:"depth"` SearchMoves string `json:"searchMoves"` MoveTime time.Duration `json:"moveTime"` Options []Option `json:"options"` }
UCIEngine defines a UCIEngine configuration
type UCIState ¶
type UCIState struct { UciWhite *uci.Engine // UCI Engine UciBlack *uci.Engine // UCI Engine UciHint *uci.Engine // UCI Engine CfgWhite *UCIEngine // UCI Engine Config CfgBlack *UCIEngine // UCI Engine Config CfgHint *UCIEngine // UCI Engine Config }
UCIState holds the UCI engine state
type WriteCounter ¶
type WriteCounter struct {
Total uint64
}
WriteCounter counts the number of bytes written to it. By implementing the Write method, it is of the io.Writer interface and we can pass this into io.TeeReader() Every write to this writer, will print the progress of the file write
func (WriteCounter) PrintProgress ¶
func (wc WriteCounter) PrintProgress()
PrintProgress prints the progress of a file write