bgn

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 5 Imported by: 8

README

Board Game Notation - BGN

GoDoc

Many different standards exist for simplified human and machine readable notation of games. Chess is a common example with notations such as Portable Game Notation (PGN) or Forsyth–Edwards Notation (FEN). While useful for chess, these notations have difficulties being applied to other games. Currently no single standard exists that can be applied to any game hence the introduction of Board Game Notation (BGN) as a potential solution to this problem.

Format

BGN is structured into two distinct sections, tags and actions.

Tags

Tags are key value pairs used to describe the initial game state as well as to store additional meta data about the game.

Tag Format
[Key "Value"]
Tag Example
[Game "Carcassonne"]
Tag Requirements

There are two tags necessary for any game, Game and Teams.

  • Game: the name of the game represented. Ex: [Game "Carcassonne"]
  • Teams: the list of teams playing the game. Ex: [Teams "TeamA, TeamB"]
Actions

Actions are an ordered list of actions teams take to create the current game state. Actions require the team, the action done, and any additional details needed to perform the action.

Action Format
{team index}{action character}&{action detail 1}.{action detail 2}...
Action Examples
0a&1.2 // team at index 0 of list in Teams Tag does action a with details 1 and 2
1b     // team at index 1 of list in Teams Tag does action b
BGN Example
[Game "Carcassonne"]
[Teams "TeamA, TeamB"]
[Seed "123"]
[Completed "False"]
[Date "10-31-2021"]

0c 0a&1.2 0b&1.2.k.b 1c 1c 1c 1a&0.1 1b&0.1.m {you can add
comments like so} 0a&2.2 0b&2.2.t.l

Usage

This package provides both a method of creating as well as parsing BGN text.

Create BGN
bgn := &Game{
    Tags: map[string]string{"Game": "Carcassonne", "Teams": "TeamA, TeamB", "Seed": "123"}
    Actions: []Action{
        {
            TeamIndex: 0,
            ActionType: 'a',
            Details: []string{"1", "2"}
        },
        {
            TeamIndex: 1,
            ActionType: 'c',
        },
    }
}
raw := bgn.String()
Parse BGN
raw := "[Game \"Carcassonne\"][Teams \"TeamA, TeamB\"][Seed \"123\"]0c 0a&1.2"
bgn, err := Parse(raw)

Documentation

Index

Constants

View Source
const (
	GameTag      string = "Game"
	TeamsTag     string = "Teams"
	VariantTag   string = "Variant"
	SeedTag      string = "Seed"
	CompletedTag string = "Completed"
	CreatedAtTag string = "CreatedAt"
	UpdatedAtTag string = "UpdatedAt"
)

Variables

View Source
var RequiredTags = []string{
	GameTag,
	TeamsTag,
}

RequiredTags are the list of tags any game must include

Functions

This section is empty.

Types

type Action

type Action struct {
	TeamIndex int      // the index of team in Teams Tag
	ActionKey rune     // single character key indicating the action to perform
	Details   []string // additional details that can be optionally used when describing an action
}

func (*Action) String

func (a *Action) String() string

type Game

type Game struct {
	Tags    map[string]string
	Actions []Action
}

Game is a representation of a game in Board Game Notation (BGN)

func Parse

func Parse(raw string) (*Game, error)

func (*Game) String

func (g *Game) String() string

Jump to

Keyboard shortcuts

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