Go Board Game in Java

CSCI 152- Java

Assignment Requirements

  • Place black and white pieces in alternating turns.
  • Detect out-of-bounds moves.
  • Display a 9×9 Go board with crosshatch format.
  • Implement capture logic (remove surrounded groups).
  • Implement scoring (including controlled territory).
  • Use recursion in either capture or scoring logic.

My Implementation

I created a class goBoard_SFry with methods for turn-taking, board rendering, capture logic, and scoring. Recursion is used to:

  • Check for liberties of groups (hasLiberty)
  • Remove captured stones recursively (removeGroup)
  • Flood-fill empty regions for territory scoring (countTerritory)

Note: Suicide moves are currently not prevented — stones placed in captured areas without liberties can survive. Scoring works, but may count those cases incorrectly.

Sample Code Snippet


public void placePiece() {
    if (!gameOn) return;

    int playerColor = currentPlayer.equals("black(X)") ? 1 : 2;
    int opponentColor = playerColor == 1 ? 2 : 1;

    board[moveY][moveX] = playerColor;

    for (int[] dir : directions) {
        int ny = moveY + dir[0];
        int nx = moveX + dir[1];
        if (ny >= 0 && ny < boardSize && nx >= 0 && nx < boardSize && board[ny][nx] == opponentColor) {
            boolean[][] visited = new boolean[boardSize][boardSize];
            if (!hasLiberty(ny, nx, opponentColor, visited)) {
                removeGroup(ny, nx, opponentColor);
            }
        }
    }
}
                

Technologies Used

  • Java (OOP and recursion)
  • Console-based user interface

Reflection

This project helped me understand recursive group traversal and territory control logic in Go. Handling edge cases like suicide moves and correct scoring requires further refinement.