Skip to content

wklchris/python-sgfutil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sgfutil

>> Languages: 中文

sgfutil is a Python library (see Github repo) for utilizing SGF (Smart Game Format) files. It supports SGF FF4.0 syntax.

sgfutil logo

Logo drawn by myself using TikZ

If you are willing to know more about the SGF format, please visit the SGF official site.

Table of Contents:

  1. Installation & Dependency
  2. Usage
  3. Known issues & Future Plan
  4. License

Installation & Dependency

Installation:

python -m pip install sgfutil 

Dependency:

  • Python >= 3.6

  • ply library:This library is no longer maintained on pip. Users can visit its official Github repo dabeza/ply for the latest version.

    However, a stable yet a little older version (3.11) of ply is still accessible through pip installation:

    python -m pip install ply

Usage

This section is semi-automatically generated by the ReadMe-auto.py.

Here is an example.

You can pass an SGF filepath to the sgf_parse() function. Please read tree.py for the data types defined for this SgfParser() class.

>>> from sgfutil import SgfParserNative, SgfParser
>>> parser = SgfParser()
>>> parser.sgf_parse('demo/Eg-multiple-branches.sgf')
>>> print(parser)

--- Branch #0 ---
@000-000 ~ CA: utf-8 (ROOT); 
           AP: MultiGo:4.4.4 (ROOT); 
           SZ: 19 (ROOT); 
           C: Multiple branch test (NODEANNO); 
           MULTIGOGM: 0 (PROP)
@000-000 ~ B: pd (MOVE)
@000-000 ~ W: nc (MOVE)

--- Branch #1 ---
@000-000 ~ B: qf (MOVE); 
           C: Branch A. (NODEANNO)
@000-000 ~ W: pb (MOVE)
@000-000 ~ B: qc (MOVE)
@000-000 ~ W: kc (MOVE)

--- Branch #2 ---
@000-000 ~ B: pf (MOVE); 
           C: Branch B. (NODEANNO)
@000-000 ~ W: pb (MOVE)
@000-000 ~ B: qc (MOVE)
@000-000 ~ W: kc (MOVE)

Or you can use SgfParseNative() class instead. In this case, the parsed results are saved with native Python data structures (a combination of lists, tuples, etc.):

>>> parser = SgfParserNative()
>>> parser.sgf_parse('(;CA[utf-8]SZ[19];B[ab](;W[cd]C[Good move])(;W[ef];B[gh]))')
>>> print(parser)

--- Branch #0 ---
(('CA', 'utf-8', 'ROOT'), ('SZ', 19, 'ROOT'))
(('B', 'ab', 'MOVE'),)

--- Branch #1 ---
(('W', 'cd', 'MOVE'), ('C', 'Good move', 'NODEANNO'))

--- Branch #2 ---
(('W', 'ef', 'MOVE'),)
(('B', 'gh', 'MOVE'),)

Known issues & Future Plan

Known issues:

  • Bugs:
    • Ply's function redefined (overriding) warning.
    • It seems to still have shift/reduce conflict.
  • Issues:
    • GameNode parent/children relation needs to be built.
    • Branch numbering hasn't been implemented.

Future plan:

  • Rewrite parsed data as Tree & Node class.
  • Syntax check for the input SGF string.
  • SGF nodes editing.
  • Visualization.

License

MIT

About

为棋类爱好者开发的一个 SGF 操作库。| An SGF utilization library for Go/chess game players.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages