# determine if opposing pieces are captivated

Discussion in 'C' started by vril, Mar 3, 2013.

1. ### vrilNew Member

Joined:
Mar 3, 2013
Messages:
2
0
Trophy Points:
0
Hey everyone. I am trying to write a simple application in C that resembles the game "Computer Co", but I am stuck with this problem: If the board is represented by a dimensional array, with what algorithm could I tell if one player's pieces are captivated by the other's? In other words, how can I recognise whether the pieces of one colour form a circle?
Sorry for my English.

2. ### hobbyistNew Member

Joined:
Jan 7, 2012
Messages:
141
0
Trophy Points:
0
I've never heard of the game - what's it similar to? From your description, you'd probably need piece and their coordinate info.

If your board is a 2D grid, then it's pretty much

Code:
```   s2
s2 s1 s2
s2
```
Code:
```if(s1.row - 1 == s2[index].row &&
s1.col - 1 == s2[index].col &&
s1.row + 1 == s2[index].row &&
s1.col + 1 == s2[index].col)
// this s1 is encircled by s2(s)
```
I don't always interpret things the way they're intended though - it's only a guess as to what you're trying to do. This would be checking one piece against the opposing side probably through a loop of s2 pieces.

3. ### vrilNew Member

Joined:
Mar 3, 2013
Messages:
2
0
Trophy Points:
0
Thanks.
Is there any source code of the game, bacause I cannot find anything?

Joined:
Jan 7, 2012
Messages:
141