Welcome to the Battleship Game implemented in Rust! Engage in a thrilling game of strategy and skill against an AI opponent on the high seas. Sink your opponent's fleet before they sink yours!
- Interactive Gameplay: Command your fleet and take turns attacking your opponent's ships.
- Dynamic Opponent: The AI makes decisions based on a heatmap and hit tracking.
- Visual Feedback: Colored output to indicate hits, misses, and your ships' status.
- Automatic Ship Placement: Ships are randomly placed on the grid, ensuring a unique experience each time.
- Player-Friendly Input: Intuitive position input system using coordinates (e.g., A1, J10).
- CLI or TUI: Choose between two UI modes
- Objective: Destroy all enemy ships before they destroy yours.
- Turn-Based Gameplay:
- You make your move by selecting a coordinate to attack (e.g., A5) or use arrows in TUI mode.
- The AI then makes its move, with a smart strategy for targeting ships.
- Win Condition: The game ends when all ships of either player are sunk.
- The board is a 10x10 grid labeled with letters (A-J) for columns and numbers (0-9) for rows.
- Your board and the opponent's board are displayed side by side:
: Empty cell- #: Missed shot
- #: Hit shot
- X: Visible ship (your ship or ship sunk by you)
- Run in your shell:
cargo install simple_battleship - Once installed you can play the game by running:
simple_battleshiporsimple_battleship --tui
- Install Rust from Rust's official website.
- Clone this repository:
git clone https://github.com/mzums/battleship cd battleship - Build and run the game:
cargo run
- tui mode:
cargo run -- --tui
- tui mode:
-
Ship Placement: Ships of varying lengths (5, 4, 3, 3, 2) are randomly placed on the board without overlap or adjacency.
-
AI Strategy: The AI utilizes a heatmap to determine optimal moves and targets ships intelligently by continuing hits on partially discovered ships.
-
Player Input: Input coordinates in the format
[Letter][Digit](e.g., A1). Invalid inputs prompt re-entry.
- Multiplayer support.
- Customizable board sizes and ship configurations.
rand: For generating random numbers.regex: For validating player input.colored: For colorful terminal output.
Contributions are welcome! Feel free to submit issues or pull requests to improve the game.
This project is licensed under the MIT License. See the LICENSE file for details.
