A colorful terminal Battleship game in C with random fleets, live statistics, and a clean firing map.
Sea Battle is a compact C project that turns the classic guessing game into a polished terminal experience. The computer places a fleet, you fire by coordinates, and the map tracks every hit and miss.
| What you get | Why it matters |
|---|---|
| Random fleet placement | Every game is different. Ships never touch, even diagonally. |
| Adaptive board and fleet | Choose a board from 5×5 to 20×20; the fleet scales to fit. |
| Clear terminal UI | Colored map, readable status, and immediate hit or miss feedback. |
| Defensive input handling | Invalid values and duplicate shots do not break the game. |
You need a C compiler such as gcc or clang.
make
./sea_battleOr compile directly:
gcc game.c -o sea_battle
./sea_battleThe interface uses ANSI colors and looks best in a modern terminal.
Coordinates start at 0. On a 10×10 board, enter values from 0 to 9.
Number of rows (5-20): 10
Number of columns (5-20): 10
Reveal ships? (yes/no): no
Row: 4
Column: 7
✹ Hit!
Answer yes to reveal the fleet — useful for testing the placement logic. In a normal game, choose no and hunt blind.
| Symbol | Meaning |
|---|---|
. |
not fired at yet |
* |
miss |
X |
hit |
S |
ship, shown only in reveal mode |
On boards at least 10×10, the game uses the classic fleet:
| Ship | Count |
|---|---|
■■■■ |
1 |
■■■ |
2 |
■■ |
3 |
■ |
4 |
On smaller boards, the largest ship length is reduced so the fleet fits. Ships always have at least one empty cell between them.
make # build the game
make run # build and run
make check # build with AddressSanitizer and UndefinedBehaviorSanitizer
make clean # remove the executablegame.c # game logic and terminal interface
Makefile # build, run, and verification commands
docs/readme-assets/logo.svg # README identity mark
docs/readme-assets/terminal-preview.svg # README interface preview
README.md # English documentation
README.ru.md # Russian documentation