{"id":16180893,"url":"https://github.com/cqb13/terminal-battleship","last_synced_at":"2026-06-17T16:32:22.355Z","repository":{"id":214792076,"uuid":"737368521","full_name":"cqb13/terminal-battleship","owner":"cqb13","description":"A Battleship game implemented in Rust for the terminal! This game features a pass-and-play multiplayer mode and a single-player mode against a computer opponent.","archived":false,"fork":false,"pushed_at":"2024-02-12T14:06:14.000Z","size":80,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-13T14:44:17.285Z","etag":null,"topics":["battleship","battleship-bot","battleship-game","battleship-multiplayer","console-battleship","console-game","rust-game","rust-gamedev","rust-terminal-game","terminal-battleship","terminal-game"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cqb13.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-12-30T19:25:22.000Z","updated_at":"2024-06-11T15:02:34.000Z","dependencies_parsed_at":"2024-01-06T16:39:32.277Z","dependency_job_id":"c2816840-e42a-4ee9-b240-8b3cd8ca3f70","html_url":"https://github.com/cqb13/terminal-battleship","commit_stats":null,"previous_names":["cqb13/terminal-battleship"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cqb13%2Fterminal-battleship","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cqb13%2Fterminal-battleship/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cqb13%2Fterminal-battleship/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cqb13%2Fterminal-battleship/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cqb13","download_url":"https://codeload.github.com/cqb13/terminal-battleship/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648977,"owners_count":20972945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["battleship","battleship-bot","battleship-game","battleship-multiplayer","console-battleship","console-game","rust-game","rust-gamedev","rust-terminal-game","terminal-battleship","terminal-game"],"created_at":"2024-10-10T06:10:41.447Z","updated_at":"2025-10-26T12:41:12.166Z","avatar_url":"https://github.com/cqb13.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Battleship Game in Rust\n\nWelcome to the Battleship game implemented in Rust for the terminal! This game features a pass-and-play multiplayer mode and a single-player mode against a computer opponent. The computer opponent comes with three difficulty levels: easy, medium, and hard. The difficulty levels vary in their attack strategies, from random guessing to more advanced probabilistic calculations.\n\n## How to Play\n\n1. **Clone the Repository:**\n\n   ```bash\n   git clone https://github.com/cqb13/terminal-battleship.git\n   ```\n\n2. **Navigate to the Project Directory:**\n\n   ```bash\n   cd terminal-battleship\n   ```\n\n3. **Compile and Run:**\n\n   ```bash\n   cargo run\n   ```\n\n4. **Follow the On-screen Instructions:**\n   - Choose between single-player and pass-and-play multiplayer.\n   - Select the difficulty level for the computer opponent (if playing single-player).\n   - Enjoy the classic Battleship game experience!\n\n**Note:** Might not work on windows\n\n## Game Features\n\n### Game Board Legend\n\n- `⊕`: Targeted\n- `⊗`: Already Attacked\n- `🅇`: Hit\n- `⓪`: Miss\n- `•`: Unknown\n- `▧`: Carrier\n- `#`: Battleship\n- `▭`: Cruiser or Submarine\n- `△`: Destroyer\n\n### Player Options\n\n- **Single Player:**\n  - Face off against the computer with different difficulty levels.\n- **Multiplayer:**\n  - Pass and play with a friend.\n\n### Attack Strategies\n\n1. **Easy Difficulty:**\n\n   - Computer makes random guesses.\n\n2. **Medium Difficulty:**\n\n   - Computer uses a hunt-and-target strategy to find and sink ships.\n\n3. **Hard Difficulty:**\n   - Computer employs probability-based attacks to target the most likely spaces.\n\n## Code Structure\n\n- `display`: Module for displaying game-related information.\n- `game`: Module containing game logic and player/computer interactions.\n- `utils`: Utility module for common functionalities.\n\n## Implementation Details\n\n- **Game Board:**\n\n  - The game board is represented as a 2D array of `Tile` enums within the `GameBoard` struct.\n  - Each `Tile` enum represents different states of a cell, such as `Targeted`, `AlreadyAttacked`, `Hit`, `Miss`, `Unknown`, or `Ship`.\n\n- **Attack Strategies:**\n\n  - The computer's attack strategy is encapsulated within the `Computer` struct, utilizing various attack strategies based on the difficulty level.\n  - The attack strategies include:\n    - `RandomAttackStrategy`: Randomly selects attack positions.\n    - `HuntAndTargetAttackStrategy`: Seeks out nearby ship positions after a hit.\n    - `ProbabilityAttackStrategy`: Uses probability calculations for optimal attacks.\n\n- **Player and Turns:**\n\n  - Players are represented by the `Player` enum, with values `PlayerOne` and `PlayerTwo`.\n  - Turn management is implemented in the `multiplayer_game` function, where players take alternating turns.\n\n- **Game Logic:**\n\n  - The core game logic is implemented in the `singleplayer_game` and `multiplayer_game` functions.\n  - These functions handle the setup, turns, and win conditions for both single-player and multiplayer modes.\n\n- **Ships and Ship Types:**\n\n  - Ships are represented by the `Ship` struct, containing a `ShipType` enum and orientation information.\n  - The `ShipType` enum defines ship names, sizes, and symbols for display.\n\n- **Position and Board Management:**\n\n  - The `Position` struct represents a 2D position on the game board.\n  - The `GameBoard` struct manages the overall game board, providing methods for placing markers and checking game state.\n\n- **Constants:**\n\n  - `GRID_SIZE`: A constant indicating the size of the game board.\n  - `GRID_ARRAY_SIZE`: A constant representing the array size for the game board.\n\n- **Game Modes and Difficulty Levels:**\n  - The `GameMode` enum distinguishes between single-player and multiplayer modes.\n  - The `Difficulty` enum defines difficulty levels for the single-player game.\n\n## Contributions\n\nFeel free to contribute to the project by opening issues, suggesting improvements, or adding new features. Pull requests are welcome!\n\nEnjoy playing Battleship in Rust! 🚢🔥\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqb13%2Fterminal-battleship","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcqb13%2Fterminal-battleship","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqb13%2Fterminal-battleship/lists"}