Expand description
Data structures and utilities for parsing SGF FF[4] files.
§Quick Start
Most common use case - parsing a Go game and iterating through its moves:
use sgf_parse::{parse, go::Prop, go::Move};
let sgf = "(;FF[4]GM[1]B[aa];W[ab])";
let collection = parse(sgf).unwrap();
let root_node = collection.first().unwrap().as_go_node().unwrap();
// Iterate through the main variation
for node in root_node.main_variation() {
if let Some(prop) = node.get_move() {
println!("Move: {}", prop);
}
}
Working with multi-game collections:
let sgf = "(;FF[4]GM[1];B[aa])(;FF[4]GM[1];B[dd])";
let collection = parse(sgf).unwrap();
for gametree in &collection {
let root_node = gametree.as_go_node().unwrap();
println!("Game has {} nodes", root_node.main_variation().count());
}
For reading SGFs your starting point will likely be go::parse
. For parsing non-go games
check out the parse
function.
For writing SGFs check out SgfNode::serialize
for writing single game trees or
serialize
for writing whole collections.
Modules§
- go
- Types specific to the game of Go.
- unknown_
game - Generic types for SGFs without a known game.
Structs§
- Parse
Options - Options for parsing SGF files.
- SgfNode
- A node in an SGF Game Tree.
- Simple
Text - An SGF SimpleText value.
- Text
- An SGF Text value.
Enums§
- Color
- An SGF Color value.
- Double
- An SGF Double value.
- Game
Tree - An SGF GameTree value.
- Game
Type - The game recorded in a
GameTree
. - Invalid
Node Error - Err type for
SgfNode::validate
. - Lexer
Error - Error type for failures to tokenize text.
- Property
Type - An SGF property type.
- SgfParse
Error - Error type for failures parsing sgf from text.