Note that there are some explanatory texts on larger screens.

plurals
  1. POCapturing stones in Go board game
    text
    copied!<p>I am trying recreate the board game "go" in Java. I am currently working on the capturing system. Basically once a stone has been surrounded by the enemy stone on all four sides (diagonal don't count) you remove that stone. Like in the screenshot below. </p> <p><img src="https://i.stack.imgur.com/lFU64.png" alt="enter image description here"></p> <p>Or if multiple of the same stones are connected you have to surround all the open sides. Like in the screenshot below. </p> <p><img src="https://i.stack.imgur.com/3Qras.png" alt="enter image description here"></p> <p>In both cases the black stones should be removed at this point. This link explains more on the rules of capturing stones. societies.cam. ac. uk /cugos/go/rules_03.html</p> <p>I was told it would be best to use recursion to do this. After doing some research on recursion I managed to write some code. But it's not working. It only seems to detect the enemy stone on the second move of the game. I call my method every time a stone is placed in my mouseReleased. </p> <pre><code>public static boolean checkCapture(int x, int y) { { if ((board[x][y + 1] != move) &amp;&amp; (board[x][y + 1] != 0)) //bellow { System.out.println("enemy is bellow"); if (checkCapture(x, y + 1)) board[x][y] = 0; } else if (board[x][y + 1] == 0) { return false; } if ((board[x][y - 1] != move) &amp;&amp; (board[x][y - 1] != 0)) //above { System.out.println("enemy is above"); if (checkCapture(x, y - 1)) board[x][y] = 0; } else if (board[x][y - 1] == 0) { return false; } if ((board[x + 1][y] != move) &amp;&amp; (board[x + 1][y] != 0)) // right { System.out.println("enemy is right"); if (checkCapture(x + 1, y)) board[x][y] = 0; } else if (board[x + 1][y] == 0) { return false; } if ((board[x - 1][y] != move) &amp;&amp; (board[x - 1][y] != 0)) //left { System.out.println("enemy is left"); if (checkCapture(x - 1, y)) board[x][y] = 0; } else if (board[x - 1][y] == 0) { return false; } } return true; } </code></pre> <p>My int x is my column and my int y is my row, move is my variable that holds whose turn it is( 1 = black , 2 = white) board is my 2d array that holds the position of all the stones on the board. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload