Can I use an array to determine an enclosed area and remove objects inside?
I'll be honest, I have very little experience with Arrays and I am only starting to understand them. I just want to know a basic idea as to how this would work and get a good insight as to how this would be done.
So this is the situation I have. I am currently making a 2D world domination type of game using a 10x10 grid that you move pieces onto and set it down. After so many turns of going back and forth eventually the pieces may form an enclosed area, I want to use an array, unless there is something better for this purpose, to determine that an area has been enclosed, and remove any opposing pieces within that area and then claim it as the players "territory"
so I want to try and create a visual...
0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1 1 0
0 0 0 1 0 8 8 0 1 0
0 0 0 1 0 8 8 0 1 0
0 0 0 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0
The 1's are the pieces of the player, and the 8 are the pieces of the opponent. How would I use an array, or another technique to make all the 8's and 0's inside of the enclosed 1's into 1's?
0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1 1 0
0 0 0 1 1 1 1 1 1 0
0 0 0 1 1 1 1 1 1 0
0 0 0 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0
Any help would be greatly appreciated. Thank you!
Unless I'm missing a really obvious and easy way to do this, this is actually quite complex. One way I can think off of doing this is by doing some sort of alteration of a flood fill algorithm. But you would also have to check if the edges are all of the same $$anonymous$$m. Another thing I can think of is that this re$$anonymous$$ds me a lot of the game go. You might be able to find some resources on how to program that...
Edit: Quick googling showed that Benson's Algorithm is used to deter$$anonymous$$ed which blocks belong to whom in go.
Hope this helps... Good luck
Your answer
Follow this Question
Related Questions
Array 2D of data 1 Answer
Why i can't read a Variable's Length(Array) 2 Answers
InvalidCastException 0 Answers
how to not repeat random array 1 Answer
how to not repeat random array 0 Answers