Snake Battle
Two snakes. One smart little rivalry.
An autonomous head-to-head snake game. Breadth-first search and predictive collision avoidance turn a familiar game into an exercise in decision-making.
Java desktop gameahead.
Java desktop game
2025 / Algorithms & desktopThe challenge.
Two autonomous agents need to reach food while avoiding walls, their own bodies, and each other in a changing board state.
02 / THE RESPONSEInside the build.
Breadth-first search finds routes to the target. Predictive safety logic checks opposing heads and obstacles, while a Swing timer updates the game loop at 150 ms intervals.
Swing game board
GameController
BFS PathFinder
- 30 × 30 game board with live scores
- Predictive collision avoidance
- Separate Snake, Ball, controller and pathfinder classes
- Collision-safe spawn and target placement
A path to
understanding.
A browser experiment illustrating the BFS principle used in Snake Battle. The original game uses Java, a 30 × 30 board, two snakes and collision prediction; this editable grid isolates the search algorithm.
Place obstacles. Move the target. Find a way through.
The original work.