pgn

PGN

A Go module for parsing and working with chess games in PGN format

go get github.com/Shobhit-Nagpal/pgn

Features

Usage

package main

import (
    "fmt"
    "github.com/Shobhit-Nagpal/pgn"
)

func main() {
    // Parse a PGN string
    gameStr := `[Event "F/S Return Match"]
[Site "Belgrade, Serbia JUG"]
[Date "1992.11.04"]
[Round "29"]
[White "Fischer, Robert J."]
[Black "Spassky, Boris V."]
[Result "1/2-1/2"]

1. e4 e5 2. Nf3 Nc6 3. Bb5 1/2-1/2`
    
    game, err := pgn.New(gameStr)
    if err != nil {
        panic(err)
    }
    
    // Access game information
    fmt.Println("Event:", game.Event())
    fmt.Println("White Player:", game.White())
    fmt.Println("Black Player:", game.Black())
    fmt.Println("Result:", game.Result())
}

Methods

New(pgn string) (*Game, error)
Create a new game from PGN string
GetTag(name string) string
Get the value of a specific tag
SetTag(tag, value string)
Set a tag
Event() string
Get the event name
Site() string
Get the site/location
White() string
Get the white player's name
Black() string
Get the black player's name
Result() string
Get the game result
Winner() string
Get the winner ("White", "Black", "Draw", or "Unknown")
IsDraw() bool
Check if the game ended in a draw
Moves() map[int]*Move
Get all moves
GetMove(number int) *Move
Get a specific move by number