title: How to implement a capturing function for a group of stones on a Go board?
body: <p>I am creating a Go game application, and I am trying to figure out how to capture a group of stones on a board, not just individual stones. Below is what I have so far. I wrote out in comments my though process at each step of this function. Generally, I first make sure the stones in the chain are dead before I capture. Figuring out a function to determine if a group of stones are &quot;dead&quot; is hard, but to &quot;capture&quot; them, all I have to do is reset the state of each stone in the chain to &quot;empty&quot;. My question is: Is my implementation below correct in this case? Can it be made more efficient?</p>
  <pre class="lang-java prettyprint-override"><code>    public void killDeadNeighbours(Board board) {
          List&lt;Stone&gt; hostilesToChain = new ArrayList&lt;&gt;();
          List&lt;Stone&gt; neighbourStorage = this.getChainNeighbours(board);
          boolean dead = true;
          for (Stone neighbour : this.getNeighbours(board)) {
              for (Stone link : neighbour.getChain()) { // For every link in stoneChain...
                  for (Stone adj : link.getNeighbours(board)) { // Get the adjacents.
                      if (adj.getState().equals(EMPTY)) { // If any adjacent is empty...
                          dead = dead &amp;&amp; false; // The chain is definitely not dead.
                      } else { // Else (now adj can be BLACk or WHITE)...
                          if (adj.getState().equals(this.getState())) { // If adj is the same color...
                              neighbourStorage.remove(adj); // Then exclude it.
                          } else { // If the adj is not EMPTY and not the same state, ...
                              hostilesToChain.add(adj); // Mark it as a hostile stone
                              dead = dead &amp;&amp; true; // Conjunct the current dead with TRUE
                          }
                      }
                  }
              }
          }
          if (dead) {
              for (Stone neighbour : this.getNeighbours(board)) {
                  for (Stone link : neighbour.getChain()) { // For every link in stoneChain...
                      link.setState(EMPTY);
                  }
              }
          }
          this.hostilesToChain = hostilesToChain;
      }
  </code></pre>