-
Notifications
You must be signed in to change notification settings - Fork 13
/
SGFSequence.cs
47 lines (42 loc) · 1.24 KB
/
SGFSequence.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
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Go
{
/// <summary>
/// Represents an SGF sequence, see the SGF specification at
/// <a href="http://www.red-bean.com/sgf">http://www.red-bean.com/sgf</a>
/// </summary>
public class SGFSequence
{
/// <summary>
/// Contains a list of SGF nodes.
/// </summary>
public List<SGFNode> Nodes = new List<SGFNode>();
internal void Read(TextReader sr)
{
sr.EatWS();
while ((char)sr.Peek() == ';')
{
SGFNode node = new SGFNode();
node.Read(sr);
Nodes.Add(node);
sr.EatWS();
}
}
internal IEnumerable<SGFProperty> GetAllProperties()
{
return Nodes.SelectMany(x => x.Properties);
}
internal IEnumerable<SGFProperty> GetProperties()
{
return Nodes.SelectMany(x => x.Properties.Where(y => !y.IsRoot).OrderBy(y => y.Priority));
}
internal IEnumerable<SGFProperty> GetRootProperties()
{
return Nodes.SelectMany(x => x.Properties.Where(y => y.IsRoot));
}
}
}