Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 4f47f6b

Browse files
committed
docs: added readme for battleship v2
1 parent 095aa0d commit 4f47f6b

8 files changed

Lines changed: 193 additions & 1 deletion

File tree

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# Battleship 2.0
2+
3+
## Description
4+
5+
Modular Battleship Game. This application is an attempt to modularize the
6+
first implementation of the Battleship game
7+
by [Robert Lent](https://github.com/ca20110820/python-beginner-projects/tree/spike/battleship/projects/Battleship).
8+
9+
## Requirements and Installation
10+
11+
- Python >= 3.9+
12+
13+
Clone the original
14+
repository [Mrinank-Bhowmick/python-beginner-projects](https://github.com/Mrinank-Bhowmick/python-beginner-projects)
15+
to your local machine and go to the directory `projects/Battleship/battleship_v2/`. From here, you can extend this
16+
application, write your scripts own with the components, or play the game on the command-line.
17+
18+
## Features
19+
20+
- Closely Resembles the Battleship Boardgame
21+
- Modular
22+
- Extendable for GUI
23+
- CLI Game
24+
- Random Bot Player
25+
- Supports 2 Players
26+
27+
## Usage
28+
29+
### CLI
30+
31+
To play the command-line Battleship, simply run:
32+
33+
```bash
34+
python game.py
35+
```
36+
37+
The game would prompt the user for:
38+
39+
- Board Size (`5 <= board_size <= 15`)
40+
- Player 1's Name
41+
- Play with a Random Bot or Not
42+
- Player 2' Name
43+
44+
The CLI Game would display 2 boards: Your _Hit or Miss_ on the Enemy Board when you attack:
45+
46+
- `X` - _Hit_
47+
- `O` - _Missed_
48+
- `-` - _No Attack_
49+
50+
and the status of your board when the enemy attacks:
51+
52+
- `S` - _Ship_
53+
- `H` - _Hit_
54+
- `M` - _Missed_
55+
- `-` - _No Attack_
56+
57+
When entering an attack coordinate, simply enter the row and column indexes separated
58+
by space.
59+
For example:
60+
61+
```text
62+
Please Enter the Attack Coordinates Admiral P1 >>> 0 4
63+
```
64+
65+
would attack the coordinate `(0, 4)`. This is different from the first
66+
Battleship implementation where the index starts at 1. This version starts at `0`.
67+
68+
The board would print the valid indexes:
69+
```text
70+
0 1 2 3 4
71+
0 - | - | - | - | -
72+
1 - | - | - | - | -
73+
2 - | - | - | - | -
74+
3 - | - | - | - | -
75+
4 - | - | - | - | -
76+
```
77+
78+
<details>
79+
<summary><b>Sneak peek - CLI</b></summary>
80+
81+
```
82+
Enter Board Size >>> 5
83+
Please Enter the Name for Player 1 >>> P1
84+
Do you want to play with a bot? (yes/no) >>> yes
85+
Please Enter the Name for Player 2 >>> Bot
86+
Randomly placing ship ...
87+
Player Bot moves first.
88+
Bot (Bot) is attacking on (0, 0) ...
89+
90+
91+
Please Enter the Attack Coordinates Admiral P1 >>> 1 5
92+
Attack Coordinates must be in [0, 5)
93+
Invalid Attack Coordinate
94+
Please Enter the Attack Coordinates Admiral P1 >>> 1 1
95+
P1 Battlefield Situation
96+
0 1 2 3 4
97+
0 H | - | S | - | S
98+
1 S | - | S | S | S
99+
2 S | - | S | S | S
100+
3 S | S | S | - | -
101+
4 - | - | S | - | -
102+
103+
P1 Targets
104+
0 1 2 3 4
105+
0 - | - | - | - | -
106+
1 - | O | - | - | -
107+
2 - | - | - | - | -
108+
3 - | - | - | - | -
109+
4 - | - | - | - | -
110+
111+
112+
Bot (Bot) is attacking on (0, 1) ...
113+
114+
115+
Please Enter the Attack Coordinates Admiral P1 >>> asd asd
116+
Invalid Attack Coordinate
117+
Please Enter the Attack Coordinates Admiral P1 >>> 4 4
118+
P1 Battlefield Situation
119+
0 1 2 3 4
120+
0 H | M | S | - | S
121+
1 S | - | S | S | S
122+
2 S | - | S | S | S
123+
3 S | S | S | - | -
124+
4 - | - | S | - | -
125+
126+
P1 Targets
127+
0 1 2 3 4
128+
0 - | - | - | - | -
129+
1 - | O | - | - | -
130+
2 - | - | - | - | -
131+
3 - | - | - | - | -
132+
4 - | - | - | - | O
133+
134+
135+
Bot (Bot) is attacking on (2, 4) ...
136+
137+
138+
Please Enter the Attack Coordinates Admiral P1 >>> 0 4
139+
P1 Battlefield Situation
140+
0 1 2 3 4
141+
0 H | M | S | - | S
142+
1 S | - | S | S | S
143+
2 S | - | S | S | H
144+
3 S | S | S | - | -
145+
4 - | - | S | - | -
146+
147+
P1 Targets
148+
0 1 2 3 4
149+
0 - | - | - | - | X
150+
1 - | O | - | - | -
151+
2 - | - | - | - | -
152+
3 - | - | - | - | -
153+
4 - | - | - | - | O
154+
155+
156+
Bot (Bot) is attacking on (4, 0) ...
157+
158+
159+
Please Enter the Attack Coordinates Admiral P1 >>> 3 3
160+
P1 Battlefield Situation
161+
0 1 2 3 4
162+
0 H | M | S | - | S
163+
1 S | - | S | S | S
164+
2 S | - | S | S | H
165+
3 S | S | S | - | -
166+
4 M | - | S | - | -
167+
168+
P1 Targets
169+
0 1 2 3 4
170+
0 - | - | - | - | X
171+
1 - | O | - | - | -
172+
2 - | - | - | - | -
173+
3 - | - | - | X | -
174+
4 - | - | - | - | O
175+
176+
177+
Bot (Bot) is attacking on (1, 4) ...
178+
179+
180+
Please Enter the Attack Coordinates Admiral P1 >>>
181+
```
182+
183+
</details>
184+
185+
## Developer
186+
187+
[ca20110820](https://github.com/ca20110820)
File renamed without changes.
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,8 @@ def place_ships(self):
291291
"""Randomly place ships for both players."""
292292
self.player_1.generate_random_ship_arrangements()
293293
self.player_2.generate_random_ship_arrangements()
294+
295+
296+
if __name__ == '__main__':
297+
cli_game = CLIGame()
298+
cli_game.run()
File renamed without changes.

projects/Battleship/test_battleship.py renamed to projects/Battleship/battleship_v2/test_battleship.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class TestBoard(unittest.TestCase):
9393

9494
def setUp(self):
9595
"""Set up with a predefined board and ship positions."""
96-
96+
9797
self.board = Board(5)
9898

9999
# Player's POV Board
File renamed without changes.

0 commit comments

Comments
 (0)