GithubHelp home page GithubHelp logo

wklchris / python-sgfutil Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 453 KB

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

License: MIT License

Python 100.00%
python3 chess-games sgf par

python-sgfutil's Introduction

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

python-sgfutil's People

Contributors

wklchris avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

yumjelly

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.