pbn

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

README

Go-PBN Parser Library

The GO-PBN Parser Library is a specialized software tool designed for reading and interpreting data in Portable Bridge Notation (PBN) format.

Usage

go get "git.sr.ht/~klahr/go-pbn"
package main

import (
	"fmt"
	"os"

	"git.sr.ht/~klahr/go-pbn"
)

func main() {
	if data, err := os.ReadFile("my-file.pbn"); err != nil {
		panic(err)
	} else {
		if m, err := pbn.Import(data); err != nil {
			panic(err)
		} else {
			for _, g := range m.Games {
				fmt.Println(g.Event) // Print event name.
				// ...
			}
		}
	}
}

Documentation

Overview

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

SPDX-License-Identifier: GPL-3.0-only

Index

Constants

View Source
const (
	CallSuffixGoodCall         = "!"
	CallSuffixPoorCall         = "?"
	CallSuffixVeryGoodCall     = "!!"
	CallSuffixVeryPoorCall     = "??"
	CallSuffixSpeculativeCall  = "!?"
	CallSuffixQuestionableCall = "?!"
)
View Source
const (
	NAGNoAnnotation                 = "$0"
	NAGGoodCall                     = "$1"
	NAGPoorCall                     = "$2"
	NAGVeryGoodCall                 = "$3"
	NAGVeryPoorCall                 = "$4"
	NAGSpeculativeCall              = "$5"
	NAGQuestionableCall             = "$6"
	NAGGoodCard                     = "$7"
	NAGPoorCard                     = "$8"
	NAGVeryGoodCard                 = "$9"
	NAGVeryPoorCard                 = "$10"
	NAGSpeculativeCard              = "$11"
	NAGQuestionableCard             = "$12"
	NAGCallHasBeenCorrectedManually = "$13"
	NAGCardHasBeenCorrectedManually = "$14"
)
View Source
const (
	CallTokenAP   = "AP"
	CallTokenPass = "Pass"
	CallTokenX    = "X"
	CallTokenXX   = "XX"
)
View Source
const (
	RankTwo   = "2"
	RankThree = "3"
	RankFour  = "4"
	RankFive  = "5"
	RankSix   = "6"
	RankSeven = "7"
	RankEight = "8"
	RankNine  = "9"
	RankTen   = "T"
	RankJack  = "J"
	RankQueen = "Q"
	RankKing  = "K"
	RankAce   = "A"
)
View Source
const (
	SuitSpades   = "S"
	SuitHearts   = "H"
	SuitDiamonds = "D"
	SuitClubs    = "C"
)
View Source
const (
	RiskUndoubled = ""
	RiskDouble    = "X"
	RiskRedouble  = "XX"
)
View Source
const (
	DenominationSpades   = "S"
	DenominationHearts   = "H"
	DenominationDiamonds = "D"
	DenominationClubs    = "C"
	DenominationNoTrump  = "NT"
)
View Source
const (
	PairNoPair     = "None"
	PairEastWest   = "EW"
	PairNorthSouth = "NS"
	PairBoth       = "Both"
)
View Source
const (
	PlayCardSuffixGoodCard         = "!"
	PlayCardSuffixPoorCard         = "?"
	PlayCardSuffixVeryGoodCard     = "!!"
	PlayCardSuffixVeryPoorCard     = "??"
	PlayCardSuffixSpeculativeCard  = "!?"
	PlayCardSuffixQuestionableCard = "?!"
)
View Source
const (
	NoSeat = "None"
	West   = "W"
	North  = "N"
	East   = "E"
	South  = "S"
)

Variables

This section is empty.

Functions

func InheritValue added in v1.2.0

func InheritValue(g *Game, games []Game, field string) error

Types

type Auction added in v1.2.0

type Auction struct {
	Dealer Seat   `json:"dealer"`
	Calls  []Call `json:"calls"`
	Notes  []Note `json:"notes"`
}

func GetAuction added in v1.2.0

func GetAuction(dealer string, lines []string) (Auction, error)

type Call added in v1.2.0

type Call struct {
	Token            string     `json:"token"`
	SuffixAnnotation CallSuffix `json:"suffix_annotation,omitempty"`
	NoteReference    string     `json:"note_reference,omitempty"`
	NAGs             []string   `json:"nags,omitempty"`
}

type CallSuffix added in v1.2.0

type CallSuffix string

type CallToken added in v1.2.0

type CallToken string

type Card added in v1.2.0

type Card struct {
	Suit Suit `json:"suit"`
	Rank Rank `json:"rank"`
}

type Contract added in v1.2.0

type Contract struct {
	Tricks       int          `json:"tricks"`
	Denomination Denomination `json:"denomination"`
	Risk         Risk         `json:"risk"`
	Pass         bool         `json:"pass"`
}

func GetContract added in v1.2.0

func GetContract(s string) (Contract, error)

type Date added in v1.2.0

type Date struct {
	Year  int `json:"year"`
	Month int `json:"month"`
	Day   int `json:"day"`
}

func ParseDate added in v1.2.0

func ParseDate(s string) (Date, error)

type Deal added in v1.2.0

type Deal struct {
	West  []Card `json:"west"`
	North []Card `json:"north"`
	East  []Card `json:"east"`
	South []Card `json:"south"`
}

func GetDeal added in v1.2.0

func GetDeal(s string) (Deal, error)

type Declarer added in v1.2.0

type Declarer struct {
	Seat      Seat `json:"seat"`
	Irregular bool `json:"irregular"`
}

func GetDeclarer added in v1.2.0

func GetDeclarer(s string) (Declarer, error)

type Denomination added in v1.2.0

type Denomination string

type Game added in v1.2.0

type Game struct {
	// Mandatory tags.
	Event      string `json:"event"`
	Site       string `json:"site"`
	Date       Date   `json:"date"`
	Board      string `json:"board"`
	West       string `json:"west"`
	North      string `json:"north"`
	East       string `json:"east"`
	South      string `json:"south"`
	Dealer     Seat   `json:"seat"`
	Vulnerable Pair   `json:"vulnerable"`
	Deal       Deal   `json:"deal"`

	// Game related information.
	Competition string `json:"competition,omitempty"`
	DealId      string `json:"deal_id,omitempty"`
	Description string `json:"description,omitempty"`
	FrenchMP    bool   `json:"french_mp,omitempty"`
	Generator   string `json:"generator,omitempty"`
	Hidden      []Seat `json:"hidden,omitempty"`
	Room        string `json:"room,omitempty"`
	Termination string `json:"termination,omitempty"`

	// Score related information.
	Score           Score[int]     `json:"score,omitempty"`
	ScoreIMP        Score[int]     `json:"score_imp,omitempty"`
	ScoreMP         Score[int]     `json:"score_mp,omitempty"`
	ScorePercentage Score[float32] `json:"score_percentage,omitempty"`
	ScoreRubber     [2]int         `json:"score_rubber,omitempty"`

	// Player related information.
	BidSystemEW string `json:"bid_system_ew,omitempty"`
	BidSystemNS string `json:"bid_system_ns,omitempty"`
	PairEW      string `json:"pair_ew,omitempty"`
	PairNS      string `json:"pair_ns,omitempty"`
	WestNA      string `json:"west_na,omitempty"`
	NorthNA     string `json:"north_na,omitempty"`
	EastNA      string `json:"east_na,omitempty"`
	SouthNA     string `json:"south_na,omitempty"`
	WestType    string `json:"west_type,omitempty"`
	NorthType   string `json:"north_type,omitempty"`
	EastType    string `json:"east_type,omitempty"`
	SouthType   string `json:"south_type,omitempty"`

	// Event related information.
	EventDate    Date   `json:"event_date,omitempty"`
	EventSponsor string `json:"event_sponsor,omitempty"`
	HomeTeam     string `json:"home_team,omitempty"`
	Round        string `json:"round,omitempty"`
	Section      string `json:"section,omitempty"`
	Stage        string `json:"stage,omitempty"`
	Table        string `json:"table,omitempty"`
	VisitTeam    string `json:"visit_team,omitempty"`

	// Time and date related information.
	Time    Time `json:"time,omitempty"`
	UTCDate Time `json:"utc_date,omitempty"`
	UTCTime Time `json:"utc_time,omitempty"`

	// Time control.
	TimeControl TimeControl `json:"time_control,omitempty"`
	TimeCall    int         `json:"time_call,omitempty"`
	TimeCard    int         `json:"time_card,omitempty"`

	// Miscellaneous.
	Annotator   string `json:"annotator,omitempty"`
	AnnotatorNA string `json:"annotator_na,omitempty"`
	Application string `json:"application,omitempty"`
	Mode        string `json:"mode,omitempty"`

	// Auction
	Auction Auction `json:"auction"`
	Play    Play    `json:"play"`

	// Others.
	Declarer Declarer   `json:"declarer,omitempty"`
	Contract Contract   `json:"contract,omitempty"`
	Result   Score[int] `json:"result,omitempty"`
	Scoring  []string   `json:"scoring,omitempty"`
}

type MetaData added in v1.2.0

type MetaData struct {
	Version struct {
		Major int `json:"major"`
		Minor int `json:"minor"`
	} `json:"version"`
}

type NAG added in v1.2.0

type NAG string

type Note added in v1.2.0

type Note struct {
	Id   string `json:"id"`
	Text string `json:"text"`
}

type PBN added in v1.2.0

type PBN struct {
	MetaData MetaData `json:"meta_data"`
	Games    []Game   `json:"games"`
}

func Import

func Import(data []byte) (*PBN, error)

type Pair added in v1.2.0

type Pair string

type Play added in v1.2.0

type Play struct {
	Direction Seat    `json:"direction"`
	Tricks    []Trick `json:"tricks"`
	Notes     []Note  `json:"notes"`
}

func GetPlay added in v1.2.0

func GetPlay(direction string, lines []string) (Play, error)

type PlayCard added in v1.2.0

type PlayCard struct {
	Token            string         `json:"token"`
	SuffixAnnotation PlayCardSuffix `json:"suffix_annotation,omitempty"`
	NoteReference    string         `json:"note_reference,omitempty"`
	NAGs             []string       `json:"nags,omitempty"`
}

type PlayCardSuffix added in v1.2.0

type PlayCardSuffix string

type Rank added in v1.2.0

type Rank string

type Risk added in v1.2.0

type Risk string

type Score added in v1.2.0

type Score[T int | float32] struct {
	Declarer   T `json:"declarer"`
	EastWest   T `json:"east_west"`
	NorthSouth T `json:"north_south"`
}

func GetScore added in v1.2.0

func GetScore[T int | float32](s string) (Score[T], error)

type Seat added in v1.2.0

type Seat string

func GetHidden added in v1.2.0

func GetHidden(s string) ([]Seat, error)

type Suit added in v1.2.0

type Suit string

type Time added in v1.2.0

type Time struct {
	Hours   int `json:"hours"`
	Minutes int `json:"minutes"`
	Seconds int `json:"seconds"`
}

func ParseTime added in v1.2.0

func ParseTime(s string) (Time, error)

type TimeControl added in v1.2.0

type TimeControl struct {
	Games   int `json:"games,omitempty"`
	Minutes int `json:"minutes,omitempty"`
}

func GetTimeControl added in v1.2.0

func GetTimeControl(s string) (TimeControl, error)

type Trick added in v1.2.0

type Trick struct {
	PlayCards []PlayCard `json:"play_cards"`
}

Jump to

Keyboard shortcuts

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