I'm trying to create a 2 players Go-like game. Unfortunately I can't get the capturing system to act correctly. At the moment the system is half done, however I cannot think of a perfect way for it to recognize a circle correctly. This is the logic that I'm planning at the moment (let say it's currently White's turn):

1.Using the newest placed piece as the starting point, run a flood fill (Up, Down, Left, Right) code to find all the affected nodes/Black piece, and place them in a "suspects list".

2.Using the suspects list, find any White piece that is near them (Up, Down, Left, Right, UpLeft, UpRight, DownLeft, DownRight). Adds those pieces into a "circle candidate list".

3.Run through the circle candidate list and remove any piece that doesn't connect to at least 2 other candidates. Keep doing this until all candidate are connected to at least 2 other candidates or the number of candidates are less than 4 (which won't be possible to make a circle).

4.Using a recursive method checks whether we can make a circle using all the candidates. The last piece must be connected to the first one.

5.If a circle is identified, get all the nodes that are between the candidates, first checks from top-to-down then left-to-right. Records all the nodes that were identified in both checks as dead zones. Kill any Black piece inside the dead zone and any Black piece that is place inside there after this will automatically die.

Here's where the problem is, I noticed that 3 pieces that are next to each other will still be connected to 2 other piece. Which means the system will still see them as a legitimate candidate even if they aren't part of a circle. And secondly the way I use to check if there is a circle can easily fail if there are more than necessary pieces to make the circle since it could turn the wrong way and then unable to get back to the starting point.

I've been struggling with this capturing process for a week now, and tested a number of different ways. All of it will have a problem in certain scenario which resulted in a bug (either they're not capturing piece that should be captured, or capturing piece that should not be captured). So any help are greatly appreciated. Thank you.


1 Answer 1


Instead of trying to recognize the circle, recognize the islands.
Every island is enclosed by a circle.

  • \$\begingroup\$ I did think of that. However, the designer wanted to change the rules where even if there's a space beside the Black piece. As long as White surrounds the Black piece and the space, the Black piece will still be capture. \$\endgroup\$
    – rabbit87
    Commented Nov 6, 2014 at 6:41
  • \$\begingroup\$ @rabbit87 in that case, look for both black pieces and spaces when flood filling the islands. \$\endgroup\$ Commented Nov 6, 2014 at 7:29
  • \$\begingroup\$ @congusbongus I am. In the suspect list, both black pieces and affected nodes (a.k.a spaces) are listed as suspects. But since spaces are also being used, any white pieces which are not actually parts of the circle may also get listed as a candidate of the circle member since they will be next to the space. Come to think of it, it's the whole 'space' thing that's giving me problems. \$\endgroup\$
    – rabbit87
    Commented Nov 6, 2014 at 7:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .