GitXplorerGitXplorer
j

sgf

public
31 stars
6 forks
6 issues

Commits

List of commits on branch master.
Unverified
5951d66a382960475245c4129e71242ed29c3f2a

Merge pull request #8 from jtauber/ready-0.5

jjtauber committed 9 years ago
Unverified
517e769eda8cbe72f1c2076cf79a66b5119fcc61

bumped version to 0.5

jjtauber committed 9 years ago
Unverified
4156577e635932c870dfa17769fa2f5b57fb7afb

Merge pull request #7 from jtauber/issue-3

jjtauber committed 9 years ago
Unverified
683d2f452a0df7c5c3adf8d9d515e7a1a74d6b4d

test game.rest when only one node

jjtauber committed 9 years ago
Unverified
9e8a3ea22a4274f6175103395292da2239ae836d

fixed flake8 complaint

jjtauber committed 9 years ago
Unverified
7bc16d3dc3c376afa952df4149fe39b1314fa619

updated README with new properties

jjtauber committed 9 years ago

README

The README file for this repository.

sgf

Build Status Coverage Status

Python implementation of Smart Game Format

After 14 years, I've extracted my old SGF code from PyGo and am in the process of cleaning it up and making it available under an MIT license.

To Install

pip install sgf==0.5

Parse

import sgf
with open("examples/ff4_ex.sgf") as f:
    collection = sgf.parse(f.read())

collection now represents the SGF collection.

Output

with open("output.sgf", "w") as f:
    collection.output(f)

The Objects

  • Collection has
    • children[] each of which is a GameTree
  • GameTree has
    • nodes[] each of which is a Node (nodes up to first variation)
    • children[] each of which is a GameTree (game tree for each variation)
    • game.root the first node of the game tree (technically this is only
      called the "root" for game trees immediately under a collection)
    • game.rest an iterable over the rest of the nodes in the mainline
  • Node has
    • properties[] dictionary with string keys and values
    • previous - previous node in SGF
    • next - next node in SGF
    • previous_variation - previous variation (if first node in a variation)
    • next_variation - next variation (if first node in a variation)
    • first - boolean indicating when first node in a variation
    • variations[] - list of variations immediately from this node

Collection is indexable and iterable. collection[0] will return the first game in a collection and for game in collection will iterate over the games. len(collection) will return the number of games it contains.

GameTree is iterable over the mainline nodes (i.e. following the first of any variations). e.g. for node in game.