Skip to content

Commit

Permalink
Count only distinct captured groups (was counting the same group twic…
Browse files Browse the repository at this point in the history
…e occasionally)
  • Loading branch information
paviad committed Nov 19, 2017
1 parent 088981d commit 4c7a2d5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
20 changes: 13 additions & 7 deletions Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,14 @@ public void SetContentAt(Point p, Content content)
/// <param name="c">The new content at the position.</param>
public void SetContentAt(int x, int y, Content c)
{
if (x < 0) {
throw new ArgumentOutOfRangeException ("x", "Invalid x coordinate.");
if (x < 0)
{
throw new ArgumentOutOfRangeException("x", "Invalid x coordinate.");
}
if (y < 0)
{
throw new ArgumentOutOfRangeException("y", "Invalid y coordinate.");
}
if (y < 0) {
throw new ArgumentOutOfRangeException ("y", "Invalid y coordinate.");
}
content[x, y] = c;
ClearGroupCache();
}
Expand Down Expand Up @@ -390,9 +392,13 @@ internal List<Group> GetCapturedGroups(int x, int y)
{
if (GetContentAt(n) != Content.Empty)
{
Group ngroup = GetGroupAt(n);
Group ngroup = GetGroupAt(n);
if (ngroup.ContainsPoint(x, y)) continue; // Don't consider self group
if (GetLiberties(ngroup) == 0) captures.Add(ngroup);
if (GetLiberties(ngroup) == 0)
{
if (!captures.Any(g => g.Points.Intersect(ngroup.Points).Any()))
captures.Add(ngroup);
}
}
}
return captures;
Expand Down
36 changes: 22 additions & 14 deletions ConsoleTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,34 @@ static void Main(string[] args)
{
var gi = new GameInfo();
var g = new Game(gi);
g.SetupMove(1, 3, Content.Black);
g.SetupMove(1, 4, Content.Black);
g.SetupMove(2, 2, Content.Black);
g.SetupMove(2, 5, Content.Black);

g.SetupMove(1, 0, Content.Black);
g.SetupMove(1, 1, Content.Black);
g.SetupMove(1, 2, Content.Black);
g.SetupMove(2, 3, Content.Black);
g.SetupMove(3, 0, Content.Black);
g.SetupMove(3, 3, Content.Black);
g.SetupMove(3, 1, Content.Black);
g.SetupMove(4, 1, Content.Black);
g.SetupMove(4, 2, Content.Black);
g.SetupMove(5, 2, Content.Black);
g.SetupMove(6, 2, Content.Black);
g.SetupMove(7, 0, Content.Black);
g.SetupMove(7, 1, Content.Black);
g.SetupMove(7, 2, Content.Black);

g.SetupMove(2, 3, Content.White);
g.SetupMove(2, 4, Content.White);
g.SetupMove(2, 0, Content.White);
g.SetupMove(2, 1, Content.White);
g.SetupMove(2, 2, Content.White);
g.SetupMove(3, 2, Content.White);
g.SetupMove(3, 4, Content.White);
g.SetupMove(3, 5, Content.White);
g.SetupMove(4, 2, Content.White);
g.SetupMove(4, 4, Content.White);
g.SetupMove(5, 3, Content.White);
g.SetupMove(4, 0, Content.White);
g.SetupMove(4, 1, Content.White);
g.SetupMove(5, 0, Content.White);
g.SetupMove(5, 1, Content.White);
g.SetupMove(6, 0, Content.White);
g.SetupMove(6, 1, Content.White);


Console.WriteLine("{0}", g.Board);
var result = g.MakeMove(4, 3);
var result = g.MakeMove(3, 1);
Console.WriteLine("{0}", result.Board);
}
}
Expand Down
6 changes: 0 additions & 6 deletions Go.XML

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit 4c7a2d5

@paviad
Copy link
Owner Author

@paviad paviad commented on 4c7a2d5 Nov 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closes #11

Please sign in to comment.