-1

I am making a game based of the asian board game called "go". I am currently trying to implement the capturing system. Basically once all of the liberties a stone has have been surrounded by the enemy the stone is taken. In the screenshot the black stone should be removed. https://i.stack.imgur.com/bO563.jpg

enter image description here

As well, if you connect stone together the liberties are combined, for example this is how you would capture two stones. https://i.stack.imgur.com/DU3mb.jpg also here is another example of black being captured. /lbg8BsC

enter image description here

I have a 2D array thats 19x19 that stores all my stone locations. Black is represented by 1 while white is 2. This is my array print out from the first image.

0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000002000000000
0000000021200000000
0000000002000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000

As you can see the black stone in the middle is surrounded by white stones. In this case it easy to check if that stone is surrounded, but I don't know how to do it once you have multiple stones like in the two other screen shots above. Any help is greatly appreciated.

Smit
  • 4,685
  • 1
  • 24
  • 28
user2457344
  • 53
  • 1
  • 9
  • I cant tell as we cant see any code in post, it would be help. However here is pointer, first check for black stone is surrounded by whites and if you encounter another black (lets say bottom side) then go to that position and check for remaining (ie left right and bottom) procedure for that location, make sure that you have checked whites for first black. – Smit Jun 06 '13 at 18:50

2 Answers2

0

You can do it recursively, I think.

Say you run through the array, and you get to a 1. You check all around that 1, you check up (2), you check left (2), you check down (1). When you get to that additional 1, you call a check on that position. I would use a temp array that changed the previous 1 to a 2 for simplicity. So now you check up (2), left (2), down (2), right(2), etc and if both 1s are satisfied with being surrounded, you turn them into 2s.

On the off chance you don't know about recursion, this explanation is very good: Understanding recursion

Community
  • 1
  • 1
Cereal
  • 3,699
  • 2
  • 23
  • 36
0

One thing you could is go through all pieces of the same color counting liberties and keeping track of which ones have been checked and if you run out of pieces to check and there are no liberties then the group of pieces have been captured.

So essentially:

  1. Start at a piece (x,y)
  2. Check left of piece (x-1, y)
    • If same color (and not already checked) check that pieces liberties (Could do this recursively)
    • If empty increase liberties count
    • If opposite color do nothing
  3. Repeat for below (x,y+1),right(x+1,y) and top(x,y-1) pieces
  4. Once we have checked all pieces mark it as 'checked' (Can be a separate boolean array or something)
Josh Maggard
  • 419
  • 3
  • 9