Documentation
¶
Overview ¶
Package bgfparser provides parsers for BGBlitz backgammon data files.
BGBlitz is a backgammon analysis software that stores data in two formats:
- TXT: Human-readable position files showing board state and analysis
- BGF: Binary match files using JSON with gzip compression and SMILE encoding
This package can parse both formats and extract position data, evaluations, match information, and move analysis.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CubeDecision ¶
type CubeDecision struct {
Action string `json:"action"` // "Double/Take", "Double/Pass", "No Double"
MWC float64 `json:"mwc"` // Match Winning Chances
MWCDiff float64 `json:"mwc_diff"`
EMG float64 `json:"emg"` // EMG (Normalized equity)
EMGDiff float64 `json:"emg_diff"`
IsBest bool `json:"is_best"`
}
CubeDecision represents a cube decision analysis
type Evaluation ¶
type Evaluation struct {
Rank int `json:"rank"`
Move string `json:"move"`
Equity float64 `json:"equity"`
Diff float64 `json:"diff"`
Win float64 `json:"win"`
WinG float64 `json:"win_g"`
WinBG float64 `json:"win_bg"`
LoseG float64 `json:"lose_g"`
LoseBG float64 `json:"lose_bg"`
IsBest bool `json:"is_best"`
}
Evaluation represents a move evaluation
type Match ¶
type Match struct {
Format string `json:"format"`
Version string `json:"version"`
Compress bool `json:"compress"`
UseSmile bool `json:"useSmile"`
// Match data will be populated from the JSON structure
Data map[string]interface{} `json:"data,omitempty"`
}
Match represents a complete backgammon match from a BGF file
func ParseBGF ¶
ParseBGF parses a BGBlitz BGF (binary match) file from disk This is a convenience wrapper around ParseBGFFromReader that handles file reading.
BGF files consist of: 1. A JSON header line with format info (uncompressed) 2. The rest of the file is gzipped JSON data (optionally SMILE encoded)
func ParseBGFFromReader ¶
ParseBGFFromReader parses a BGBlitz BGF file from an io.Reader This allows parsing BGF files from network streams, memory buffers, HTTP uploads, or any io.Reader source.
Example usage with HTTP upload:
func uploadHandler(w http.ResponseWriter, r *http.Request) {
file, _, _ := r.FormFile("bgffile")
defer file.Close()
match, err := bgfparser.ParseBGFFromReader(file)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(match)
}
func (*Match) GetMatchInfo ¶
GetMatchInfo extracts basic match information from a parsed BGF file
type ParseError ¶
ParseError represents an error during parsing
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type Position ¶
type Position struct {
// Board represents the checkers on each point (1-24), bar, and off
// Points 1-24 for both players, positive for X, negative for O
Board [26]int `json:"board"`
// Player information
PlayerX string `json:"player_x"`
PlayerO string `json:"player_o"`
ScoreX int `json:"score_x"`
ScoreO int `json:"score_o"`
// Match information
MatchLength int `json:"match_length"`
Crawford bool `json:"crawford"`
// Position identifiers
PositionID string `json:"position_id"` // BGBlitz Position-ID
MatchID string `json:"match_id"` // BGBlitz Match-ID
XGID string `json:"xgid"` // XG format ID
// Current state
OnRoll string `json:"on_roll"` // "X" or "O"
Dice [2]int `json:"dice"`
CubeValue int `json:"cube_value"`
CubeOwner string `json:"cube_owner"` // "", "X", "O"
OnBar map[string]int `json:"on_bar"`
PipCount map[string]int `json:"pip_count"`
// Evaluation data
Evaluations []Evaluation `json:"evaluations,omitempty"`
CubeDecisions []CubeDecision `json:"cube_decisions,omitempty"`
// Cube analysis summary (when present)
CubelessEquity float64 `json:"cubeless_equity,omitempty"`
CubefulEquity float64 `json:"cubeful_equity,omitempty"`
EquityStdDev float64 `json:"equity_std_dev,omitempty"`
}
Position represents a backgammon position
func ParseTXT ¶
ParseTXT parses a BGBlitz position text file from disk This is a convenience wrapper around ParseTXTFromReader that handles file reading.
func ParseTXTFromReader ¶
ParseTXTFromReader parses a BGBlitz TXT position file from an io.Reader This allows parsing TXT files from network streams, memory buffers, HTTP uploads, or any io.Reader source.
Example usage with in-memory data:
data := []byte("... TXT content ...")
pos, err := bgfparser.ParseTXTFromReader(bytes.NewReader(data))
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
batch_parse
command
|
|
|
parse_bgf
command
|
|
|
parse_txt
command
|
|
|
parse_txt_detailed
command
|
|
|
web_server
command
This example demonstrates how to use the bgfparser in HTTP handlers for uploading and analyzing BGF and TXT files via a web interface.
|
This example demonstrates how to use the bgfparser in HTTP handlers for uploading and analyzing BGF and TXT files via a web interface. |
|
internal
|
|
|
smile
Licensed under the MIT License Original source: https://gitlab.com/LeLuxNet/X/-/blob/c09411c26dfb/encoding/smile/decode.go
|
Licensed under the MIT License Original source: https://gitlab.com/LeLuxNet/X/-/blob/c09411c26dfb/encoding/smile/decode.go |