From 4c7a2d59abaa0862409ce2a988fff823f3cc789f Mon Sep 17 00:00:00 2001 From: Aviad Pineles Date: Mon, 20 Nov 2017 00:14:03 +0200 Subject: [PATCH] Count only distinct captured groups (was counting the same group twice occasionally) --- Board.cs | 20 +++++++++++++------- ConsoleTest/Program.cs | 36 ++++++++++++++++++++++-------------- Go.XML | 6 ------ 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/Board.cs b/Board.cs index 076a25a..534388f 100644 --- a/Board.cs +++ b/Board.cs @@ -230,12 +230,14 @@ public void SetContentAt(Point p, Content content) /// The new content at the position. 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(); } @@ -390,9 +392,13 @@ internal List 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; diff --git a/ConsoleTest/Program.cs b/ConsoleTest/Program.cs index fd115df..1f94173 100644 --- a/ConsoleTest/Program.cs +++ b/ConsoleTest/Program.cs @@ -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); } } diff --git a/Go.XML b/Go.XML index 2f0e548..f0667c5 100644 --- a/Go.XML +++ b/Go.XML @@ -660,12 +660,6 @@ The source TextReader. - - - Create an SGFCollection object from a byte array. - - The source byte array. - Represents an SGF game-tree, see the SGF specification at