A C-based command-line implementation of the classic Battleship game featuring dynamic memory management and a computer opponent.
This project recreates Battleship as a single-player experience where users compete against an AI opponent with randomized targeting.
It emphasizes low-level memory control, struct-based architecture, and clean system design in C.
- Interactive ship placement
- Computer opponent with randomized AI
- Three-board display system:
- Player shots
- Enemy shots
- Player ships
- Win detection system
- Dynamic memory allocation (
malloc/free) - Struct-based state management
- Modular design with header files
- Memory safety (Valgrind clean)
main.c
battleship.c
battleship.h
gcc -g main.c battleship.c -o battleship
./battleshipvalgrind ./battleship- No global state — uses structured game state passing
- Efficient grid representation
- Clean separation between logic and interface
- Memory-leak-free implementation
- Smarter AI (hunt/target strategy)
- Multiplayer support
- GUI version
Ahmed Al-Mashraie