Hi I am creating a board game for 2 players.
Each player takes turn to place a piece on the grid.
The objective is to circle-up the opponent's pieces with your own.
The problem is creating a function that knows when a circle is complete so that the program knows when and where to connect the pieces on the board.
What methods can I use to create this function?
I have created a function called Adjacent, it will scan similar pieces that are adjacent to a particular coordinate. But I find it hard to implement this to achieve the required task.
Any suggestions?
Since I cannot place a snapshot of my program here, I will type it out.
Assume below as a grid. Star (*) player has circled up the opponent - hash (#).
So I need the function to determine if a "circle" is completed.
This is only a simple example. "Circling" can be more complex consisting more than one pieces.
______________________
________*#____#_______
_______*#*____________
___#____*_____________
______________________
__*___
_*#*__
_*##*_
__**__
Is this a valid way to circle something?
If yes, then to find similar 'circles' I suggest you make a recursive function
bool IsCircled(int x, int y){
for each adjacent tile
if it is * it's ok
if it is # then
if IsCircled(position of the adjacent tile) it's ok
else return 0
if it is _ return 0
}
You'll also have to prevent it from going forever ( if you have two adjacent # then first one will call a check on the second one, and the second one will call a check on the first one). You have to have a way of marking tiles that you've already checked.
Good luck