[][src]Struct sgf_parser::GameTree

pub struct GameTree {
    pub nodes: Vec<GameNode>,
    pub variations: Vec<GameTree>,
}

A game tree, containing it's nodes and possible variations following the last node

Fields

nodes: Vec<GameNode>variations: Vec<GameTree>

Methods

impl GameTree[src]

pub fn count_max_nodes(&self) -> usize[src]

Counts number of nodes in the longest variation

pub fn get_unknown_nodes(&self) -> Vec<&GameNode>[src]

Gets a vector of all nodes that contain a SgfToken::Unknown token

use sgf_parser::*;

let tree: GameTree = parse("(;B[dc];W[ef]TMP[foobar](;B[aa])(;B[cc];W[ee]))").unwrap();

let unknown_nodes = tree.get_unknown_nodes();
unknown_nodes.iter().for_each(|node| {
    let unknown_tokens = node.get_unknown_tokens();
    assert_eq!(unknown_tokens.len(), 1);
    if let SgfToken::Unknown((identifier, value)) = unknown_tokens[0] {
        assert_eq!(identifier, "TMP");
        assert_eq!(value, "foobar");
    }
});

pub fn get_invalid_nodes(&self) -> Vec<&GameNode>[src]

Gets a vector of all nodes that contain a SgfToken::Invalid token

use sgf_parser::*;

let tree: GameTree = parse("(;B[dc];W[foobar];B[aa])(;B[cc];W[ee]))").unwrap();

let invalid_nodes = tree.get_invalid_nodes();
invalid_nodes.iter().for_each(|node| {
    let invalid_tokens = node.get_invalid_tokens();
    if let SgfToken::Invalid((identifier, value)) = invalid_tokens[0] {
        assert_eq!(identifier, "W");
        assert_eq!(value, "foobar");
    }
});

pub fn has_variations(&self) -> bool[src]

Checks if this GameTree has any variations

pub fn count_variations(&self) -> usize[src]

Counts number of variations in the GameTree

pub fn get_varation_length(&self, variation: usize) -> Result<usize, SgfError>[src]

Get max length of a variation

use sgf_parser::*;

let tree: GameTree = parse("(;B[dc];W[ef](;B[aa])(;B[cc];W[ee]))").unwrap();

assert_eq!(tree.get_varation_length(0).unwrap(), 1);
assert_eq!(tree.get_varation_length(1).unwrap(), 2);

pub fn iter(&self) -> GameTreeIterator[src]

Gets an iterator for the GameTree

use sgf_parser::*;

let tree: GameTree = parse("(;B[dc];W[ef](;B[aa])(;B[cc];W[ee]))").unwrap();

let mut iter = tree.iter();

assert_eq!(iter.count_variations(), 2);
assert!(iter.pick_variation(1).is_ok());

let mut count = 0;
iter.for_each(|node| {
    assert!(!node.tokens.is_empty());
    count += 1;
});

assert_eq!(count, tree.count_max_nodes());

Trait Implementations

impl PartialEq<GameTree> for GameTree[src]

impl Default for GameTree[src]

fn default() -> Self[src]

Creates an empty GameTree

impl Debug for GameTree[src]

Auto Trait Implementations

impl Send for GameTree

impl Sync for GameTree

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]