forked from paviad/GoSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SGFPropValue.cs
112 lines (98 loc) · 2.95 KB
/
SGFPropValue.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Go
{
/// <summary>
/// Represents an SGF property-value, see the SGF specification at
/// <a href="http://www.red-bean.com/sgf">http://www.red-bean.com/sgf</a>
/// </summary>
public class SGFPropValue
{
/// <summary>
/// Contains the property value.
/// </summary>
public string Value;
/// <summary>
/// Returns true if the property value is a composed value (value ':' value).
/// </summary>
public bool IsComposed { get { return Value.Contains(':'); } }
/// <summary>
/// Gets the first value of a composed value.
/// </summary>
public string ValX { get { return Value.Split(':')[0]; } }
/// <summary>
/// Gets the second value of a composed value.
/// </summary>
public string ValY { get { return Value.Split(':')[1]; } }
/// <summary>
/// Gets the first integer of a composed value.
/// </summary>
public int NumX { get { return int.Parse(ValX); } }
/// <summary>
/// Gets the second integer of a composed value.
/// </summary>
public int NumY { get { return int.Parse(ValY); } }
/// <summary>
/// Gets the property value as an integer.
/// </summary>
public int Num { get { return int.Parse(Value); } }
/// <summary>
/// Gets the property value as a real number.
/// </summary>
public double Double { get { return double.Parse(Value); } }
/// <summary>
/// Gets the property value as a move object (Point).
/// </summary>
public Point Move
{
get
{
return Point.ConvertFromSGF(Value);
}
}
/// <summary>
/// Gets the first move object of a composed value.
/// </summary>
public Point MoveA
{
get
{
return Point.ConvertFromSGF(ValX);
}
}
/// <summary>
/// Gets the second move object of a composed value.
/// </summary>
public Point MoveB
{
get
{
return Point.ConvertFromSGF(ValY);
}
}
/// <summary>
/// Gets the property value as a color object (Content enum).
/// </summary>
public Content Turn
{
get
{
return Value=="W" ? Content.White : Content.Black;
}
}
/// <summary>
/// Construct an SGFPropValue object using the specified value.
/// </summary>
/// <param name="v">The value of the SGFPropValue.</param>
public SGFPropValue(string v)
{
Value = v;
}
public override string ToString ()
{
return Value;
}
}
}