0

I'm trying to make a game I'm finding myself trying to reinvent a wheel that probably already exists.

Here is a sample of the problem I'm trying to solve. I'm trying to check if any board pieces fall within the territory of another player, in this case, the black piece is captured.

W W - - 
- - W - 
- B W - 
- - W - 

Any advice to go about solving this would be appreciated.

6
  • 3
    What is considered "within the territory of another player"? Commented Aug 27, 2012 at 14:58
  • 1
    Sensei's Library has a list of algorithms that tackle this problem. Commented Aug 27, 2012 at 15:00
  • 1
    That looks like a variation of a flood-fill algorithm (v en.wikipedia.org/wiki/Flood_fill) often used in image segmentation. Commented Aug 27, 2012 at 15:07
  • Determining what constitutes the territory of a player is a very difficult problem, even for humans, since it requires you to determine which stones are dead or alive. Commented Aug 27, 2012 at 15:09
  • Thanks, Mark - Flood-fill was exactly what I was looking for. Commented Aug 27, 2012 at 18:07

2 Answers 2

2

Oh well, if one of my comments is taken as an answer, might as well whore for rep:

It looks as if a variation of a flood-fill algorithm (often used in image segmentation) would be useful to you.

Sign up to request clarification or add additional context in comments.

Comments

0

This sounds like a reachability problem to me.

The position the black piece is on is obviously reachable. It could move up, down or to the left, but not to the right. Moreover, it could never reach the top right position (unless it can move diagonally).

  1. A queue of open positions contains the position of the piece itself.

  2. While there are open positions:

    • mark the position as reachable, and
    • add neighbor positions to queue of open positions.
  3. If there are still unreachable positions, you could consider the piece "trapped".

1 Comment

If the black piece was outside white's territory, the positions inside white's territory would be unreachable and your algorithm would consider the piece to be trapped.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.