-
Notifications
You must be signed in to change notification settings - Fork 13
/
Group.cs
109 lines (98 loc) · 3.45 KB
/
Group.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Go
{
/// <summary>
/// Represents a group of stones (or empty spaces) on a board object. This
/// object is context-free, i.e. it is not associated with a specific board.
/// In essence it is simply a set of board coordinates, with an associated
/// content (black, white or empty), and state (dead or alive for scoring
/// purposes).
/// </summary>
public class Group
{
private HashSet<Point> points = new HashSet<Point>(), neighbours = new HashSet<Point>();
/// <summary>
/// Gets the content of the group.
/// </summary>
public Content Content { get; private set; }
/// <summary>
/// Gets an enumerator for the neighboring coordinates of the group.
/// </summary>
public IEnumerable<Point> Neighbours
{
get
{
return neighbours;
}
}
/// <summary>
/// Gets an enumerator for the coordinates contained in this group.
/// </summary>
public IEnumerable<Point> Points
{
get
{
return points;
}
}
/// <summary>
/// Gets or sets whether this group is dead for the purposes of scoring.
/// </summary>
public bool IsDead { get; set; }
/// <summary>
/// Gets the territory ownership color of this group of empty spaces.
/// </summary>
public Content Territory { get; internal set; }
/// <summary>
/// Constructs a group object of specified content.
/// </summary>
/// <param name="c">The group content.</param>
public Group(Content c)
{
Content = c;
}
/// <summary>
/// Adds a point to the group.
/// </summary>
/// <param name="x">The X coordinate of the point.</param>
/// <param name="y">The Y coordinate of the point.</param>
public void AddPoint(int x, int y)
{
points.Add(new Point(x, y));
}
/// <summary>
/// Checks whether this group contains the specified point.
/// </summary>
/// <param name="x">The X coordinate of the point.</param>
/// <param name="y">The Y coordinate of the point.</param>
/// <returns>Returns true if the point is contained in the group.</returns>
public bool ContainsPoint(int x, int y)
{
return points.Contains(new Point(x, y));
}
/// <summary>
/// Adds a neighbour point to the group.
/// </summary>
/// <param name="x">The X coordinate of the neighbour.</param>
/// <param name="y">The Y coordinate of the neighbour.</param>
public void AddNeighbour(int x, int y)
{
neighbours.Add(new Point(x, y));
}
/// <summary>
/// Returns a string representation of the group as a list of points.
/// </summary>
/// <returns>Returns a string representation of the group as a list of points.</returns>
public override string ToString()
{
if (points.Count == 0) return Content.ToString() + ":{}";
string rc = Content.ToString() + ":{";
foreach (var p in points) rc += p.ToString() + ",";
rc = rc.Substring(0, rc.Length - 1) + "}";
return rc;
}
}
}