sgf

package
v0.0.0-...-e9bdced Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2017 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package sgf parses and decodes generic game tree collection

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection []*Tree

Collection game trees

func Parse

func Parse(sgf string) Collection

Parse SGF

Example (NoVariation)

No Variation

package main

import (
	"fmt"

	"github.com/dgf/gotv/sgf"
)

func main() {
	s := "(;GM[1]SZ[19]FF[4];B[aa];W[bb];B[cc])"
	fmt.Println(sgf.Parse(s))
}
Output:

(;FF[4]GM[1]SZ[19];B[aa];W[bb];B[cc])
Example (OneVariationAtMove3)

One variation at move 3

package main

import (
	"fmt"

	"github.com/dgf/gotv/sgf"
)

func main() {
	s := `(;FF[4]GM[1]SZ[19];B[aa];W[bb]
	        (;B[cc];W[dd];B[ad];W[bd])
	        (;B[hh];W[hg]))`
	fmt.Println(sgf.Parse(s))
}
Output:

(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc];W[dd];B[ad];W[bd])(;B[hh];W[hg]))
Example (TwoVariationAtDifferentMoves)

Two variations at different moves

package main

import (
	"fmt"

	"github.com/dgf/gotv/sgf"
)

func main() {
	s := `(;FF[4]GM[1]SZ[19];B[aa];W[bb]
	        (;B[cc];W[dd]
	          (;B[ad];W[bd])
	          (;B[ee];W[ff])
	        )
	        (;B[hh];W[hg]))`
	fmt.Println(sgf.Parse(s))
}
Output:

(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc];W[dd](;B[ad];W[bd])(;B[ee];W[ff]))(;B[hh];W[hg]))
Example (TwoVariationAtMove3)

Two variations at move 3

package main

import (
	"fmt"

	"github.com/dgf/gotv/sgf"
)

func main() {
	s := `(;FF[4]GM[1]SZ[19];B[aa];W[bb]
	        (;B[cc]N[A];W[dd];B[ad];W[bd])
	        (;B[hh]N[B];W[hg])
	        (;B[gg]N[C];W[gh];B[hh];W[hg];B[kk]))`
	fmt.Println(sgf.Parse(s))
}
Output:

(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc]N[A];W[dd];B[ad];W[bd])(;B[hh]N[B];W[hg])(;B[gg]N[C];W[gh];B[hh];W[hg];B[kk]))
Example (VariationOfVariation)

Variation of a variation

package main

import (
	"fmt"

	"github.com/dgf/gotv/sgf"
)

func main() {
	s := `(;FF[4]GM[1]SZ[19];B[aa];W[bb]
	        (;B[cc]N[A];W[dd];B[ad];W[bd])
	          (;B[hh]N[B];W[hg])
	          (;B[gg]N[C];W[gh];B[hh]
	            (;W[hg]N[A];B[kk])
	            (;W[kl]N[B])))`
	fmt.Println(sgf.Parse(s))
}
Output:

(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc]N[A];W[dd];B[ad];W[bd])(;B[hh]N[B];W[hg])(;B[gg]N[C];W[gh];B[hh](;N[A]W[hg];B[kk])(;N[B]W[kl])))

func (Collection) String

func (c Collection) String() string

String tree collection (encode SGF Collection)

type Node

type Node map[string]string

Node properties

func (Node) String

func (n Node) String() string

String properties sorted by ident (encode SGF Node)

type Tree

type Tree struct {
	Parent     *Tree
	Sequence   []Node
	Collection []*Tree
}

Tree with parent reference, node sequence and subtree slice

func (*Tree) Decode

func (t *Tree) Decode() (g model.Game)

Decode game tree

func (Tree) String

func (t Tree) String() string

String game tree (encode SGF GameTree)

Jump to

Keyboard shortcuts

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