The goteam program is a Go engine implementing the GTP(Go Text Protocol).
It manages the board state, validates moves, handles stone capturing via recursive flood-fill, and generates legal moves for the computer to play.
-
play <color> <coordinate>Places a stone of the specified color at the given coordinate -
genmove <color>Generates a random legal move for the specified color -
showboardDisplays the current state of the board in the terminal -
clear_boardResets the board to an empty stateCOMPILE WITH
gcc -static -Wall -Wextra -Werror -pedantic -O3 -o goteam src/goteam.c src/board.c
Or if using Make:
make
COMMAND GUIDE
./goteam
Starts the engine. Type commands manually (e.g play black D4)
play black D4
Places a black stone at D4
Returns = on success or ? on failure
genmove white
The engine picks a random legal coordinate for White and returns the coordinate
showboard
Prints the 19x19 grid with X (Black) and O (White) stones.
INPUT FORMAT
The program expects GTP commands via standard input (stdin):
<command_name> [arguments]
Example (Sequence of commands):
play black Q16
genmove white
showboard
quit
Why Recursive Flood Fill was chosen for captures:
After analyzing the requirements for game rules, Recursive Flood Fill was selected as the core algorithm for capturing stones.
-
Accuracy: Go rules state that a group of stones is captured when it has no "liberties" (empty slots). Flood fill naturally traverses connected stones to count these liberties
-
Simplicity: Unlike iterative approaches which require complex stack management the recursive approach (
has_liberties) is cleaner and easier to read -
Suicide Safety: The same algorithm allows us to perform a check before finalizing a move, therefore ensuring the engine never plays an illegal self-capture move
Example of Suicide Safety:
LOGIC TRANSLATION
Implementing Go Rules to C Code
The assignment required translating board coordinates and capture rules into C logic:
Coordinate Parsing
The GTP standard uses letters 'A' through 'T' (excluding 'I') for columns
parse_coord translates "D4" to:
- Column: 'D' - 'A' = Index 3
- Row: 4 - 1 = Index 3
- Result:
board[3][3]
The Capture Recursion
The logical relation for a stone having "air" (liberties) was implemented in has_liberties:
has_liberties(r, c) = is_empty(r,c) OR (is_same_color(r,c) AND has_liberties(neighbors))
That was implemented inside the board.c file using the visited array to prevent infinite loops during the recursive search
Visualizing the Capture Logic:
Random Generation
The gen_move function uses a brute-force approach with a safety check
1.Pick a random coordinate (r, c)
2.Check if play_move(r, c) returns true (meaning the move is not suicide and the spot is empty)
3.If valid then return the move otherwise retry
[0] GTP – Go Text Protocol Specification
[1] GTP – Go Text Protocol Specification (Draft 2)
[2] Wikipedia – Flood Fill Algorithm
[3] Wikipedia – Go (Game) Rules