forked from paviad/GoSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSGFGameTree.cs
44 lines (41 loc) · 1.27 KB
/
SGFGameTree.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Go
{
/// <summary>
/// Represents an SGF game-tree, see the SGF specification at
/// <a href="http://www.red-bean.com/sgf">http://www.red-bean.com/sgf</a>
/// </summary>
public class SGFGameTree
{
/// <summary>
/// Contains the SGF sequence.
/// </summary>
public SGFSequence Sequence = new SGFSequence();
/// <summary>
/// Contains a list of SGF game-tree objects.
/// </summary>
public List<SGFGameTree> GameTrees = new List<SGFGameTree>();
internal void Read(TextReader sr)
{
char c = (char)sr.Read();
if (c != '(')
throw new InvalidDataException("Game-tree doesn't begin with a '('.");
Sequence.Read(sr);
sr.EatWS();
while ((char)sr.Peek() == '(')
{
SGFGameTree gameTree = new SGFGameTree();
gameTree.Read(sr);
GameTrees.Add(gameTree);
sr.EatWS();
}
c = (char)sr.Read();
if (c != ')')
throw new InvalidDataException("Game-tree doesn't end with a ')'.");
}
}
}