This repository contains the same technical test implemented in two languages: Python and Java.
Implement a method that determines whether the stone at position x, y on a goban (Go board) is taken (i.e. the entire shape it belongs to has no liberties).
- Goban: the board on which stones are placed.
- Shape: one or more orthogonally adjacent stones (
up,down,left,right) of the same color. Diagonals do not count. - Liberty: an empty point orthogonally adjacent to any stone in a shape.
- The goban size is arbitrary (handled by the provided data structure).
- Two players: Black (
#) and White (o). - Stones are placed one per turn; positions outside the provided grid are considered
OUT. - A shape is taken when it has no liberties.
Write the function that returns whether the stone at (x, y) is taken:
- Python: implement
Goban.is_taken(self, x, y)inpython/goban.py. - Java: implement
Goban.isTaken(int x, int y)injava/src/main/java/com/example/goban/Goban.java.
Return True / true only if the stone exists at (x, y) and the entire connected shape of that color has zero liberties.
You may add helper functions / parameters if needed while keeping clear, idiomatic code.
Make use of the provided status accessors:
- Python:
get_status(x, y)returnsStatus.BLACK,Status.WHITE,Status.EMPTY, orStatus.OUT. - Java:
getStatus(x, y)returns the equivalentStatusenum values.
The return values are:
Status.BLACK: when the stone at position x, y is blackStatus.WHITE: when the stone at the x position, y is whiteStatus.EMPTY: when there is no stone at position x, yStatus.OUT: when the position x, y is out of the goban
# = black
o = white
. = empty
.#.
#o# <= o is taken: no adjacent empty points
.#.
...
#o# <= o is not taken: liberty above
.#.
o# <= o is taken: top and left are OUT (not liberties)
#.
oo.
##o <= black shape (#) is taken: no liberties
o#o
.o.
oo.
##. <= black shape (#) is not taken: liberty at x=2, y=1 (0,0 top-left)
o#o
.o.
From repository root:
git clone https://github.com/lumapps/test-goban.git
cd test-goban/python
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
PYTHONPATH=. pytest test_goban.py
(Tests use direct module import goban; running inside python/ ensures it is on the module search path.)
From repository root:
git clone https://github.com/lumapps/test-goban.git
cd test-goban/java
./gradlew test
- Python implementation:
python/goban.py - Python tests:
python/test_goban.py - Java implementation:
java/src/main/java/com/example/goban/Goban.java - Java tests:
java/src/test/java/com/example/goban/GobanTest.java
Focus only on implementing the capture logic; no additional features required.