Question: Help writing a go capture function in java. The function needs to be able to search a game board represented as a 19x19 2D array,

Help writing a go capture function in java. The function needs to be able to search a game board represented as a 19x19 2D array, find all chains of "stones" that are surrounded and set their locations to empty then pass the array back in order to update the game board. A chain of stones is 1 or more stones that are adjacent to one another (up, down, left, right). In go a given stone or chain of stones (represented as a char in this case) is surrounded if all the positions adjacent to it, up, down, left, right (diagonals do not need to be considered), are all filled by a stone of the opposing color. The function should receive a 2D array and the color of the stone ('b' or 'w'), search the array for chains of stones, store the coordinates of the chains of stones in a data structure such as a linked list or array, then search the spaces around those coordinates (up, down, left, right), if none of those spaces are empty then the coordinates stored in the data structure should be set to empty so that those pieces are captured and removed from the board.

For example if the function were to find a set 'b' stones surrounded by a 'w', it would take the locations of 'b' stones and place them into the data structure and search the surrounding area, it would find that all of the spaces next to it are filed with enemy stones and remove the 'b' stones from play, then update the board. The search method used to find chains of stones can be recursive or iterative. Ideally the function logic should be self contained so that you only have to call the capture function in order to update the game state.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!