All Projects → toomasr → sgf4j

toomasr / sgf4j

Licence: Apache-2.0 license
Simple SGF Parser for Java

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to sgf4j

lizgoban
Leela Zero & KataGo visualizer
Stars: ✭ 131 (+385.19%)
Mutual labels:  baduk, weiqi, sgf
immutable-gametree
An immutable game tree data type.
Stars: ✭ 18 (-33.33%)
Mutual labels:  baduk, weiqi, sgf
besogo
Embeddable SGF editor/viewer for the game of Go (aka Weiqi, Baduk)
Stars: ✭ 82 (+203.7%)
Mutual labels:  baduk, weiqi, sgf
Sabaki
An elegant Go board and SGF editor for a more civilized age.
Stars: ✭ 1,768 (+6448.15%)
Mutual labels:  baduk, weiqi, sgf
sgf to gif
SGF file --> GIF
Stars: ✭ 32 (+18.52%)
Mutual labels:  baduk, weiqi, sgf
agagd
American Go Association Games Database (AGAGD)
Stars: ✭ 44 (+62.96%)
Mutual labels:  baduk, weiqi
pyDLGO
基於深度學習的 GTP 圍棋(围棋)引擎,KGS 指引文件以及演算法教學。
Stars: ✭ 33 (+22.22%)
Mutual labels:  baduk, weiqi
GoAIRatings
Estimate Go AI ratings by real games
Stars: ✭ 118 (+337.04%)
Mutual labels:  baduk, weiqi
computer-go-dataset
datasets for computer go
Stars: ✭ 133 (+392.59%)
Mutual labels:  sgf
Goban
Adaptive Go board for flutter. Fully customisable & easy to interface with your game logic.
Stars: ✭ 30 (+11.11%)
Mutual labels:  baduk
LeelaMasterWeight
Leela Master weight is training from leela zero self-play sgf and human sgf file
Stars: ✭ 49 (+81.48%)
Mutual labels:  sgf
sgfmill
Python library for Smart Game Format (SGF) files
Stars: ✭ 50 (+85.19%)
Mutual labels:  sgf
gomill
Python tools for the game of Go (GTP and SGF)
Stars: ✭ 69 (+155.56%)
Mutual labels:  sgf

SGF4J

I've been doing some serious yak shaving. Instead of solving Go problems to improve my game I've been writing a SGF viewer to make it easier to go through my problem files.

As a side result of that viewer I had to do some SGF parsing. Hence this project. You can use this library to parse SGF files and then actually play it out on a virtual board and then write out the SGF if you want to. I test the library with bunch of databases to make sure it is able to parse enough different SGF files and also when writing those out no data is lost.

I use this parser on a weekly basis when I solve Go problems and haven't found any parsing or serialising issues for some time. I also test the library with 90 000+ SGF files that I parse with this library to make sure the lib is mature enough to parse most of the games out there. I also write the games out again to SGF format to re-parse them and make sure that by writing them out again we are not losing any data. If you find SGF files that don't parse with this library then please let me know.

Include in your project

The project is synced to Maven Central and to use it just include it in your pom.xml.

<dependencies>
  <dependency>
    <groupId>com.toomasr</groupId>
    <artifactId>sgf4j-parser</artifactId>
    <version>0.0.3</version>
  </dependency>
<dependencies>

Parsing from file

Simple parsing looks like this. You either have a SGF file in a String or a Path of the location of the file. You create a Game object of it and then start walking the nodes from the root node. There are methods to start from the end too.

    Game game = Sgf.createFromPath(Paths.get("location-of-your.sgf"));

    GameNode node = game.getRootNode();
    do {
      System.out.println(node);
    }
    while ((node = node.getNextNode()) != null);

Remember that not every node is an actual move. Also note that a node might have multiple children. I have built it in a way that node.getNextMove() returns the next move in the main line of play while getChildren() will return the rest of the possible next moves.

Writing to file

Once you have parsed a file into a Game object you can also write it back to a SGF file.

Game game = Sgf.createFromPath(sgfPath);
//... add/remove/update nodes
game.saveToFile(Paths.get("/tmp/output.sgf"))

This project writes the SGF string of the game to the output.sgf file. This code path uses the Game.getGeneratedSgf() method that returns the SGF string of the current Game object.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].