This repository was archived by the owner on Apr 24, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from dataclasses import dataclass
2+
3+ from utils import generate_random_ships_arrangements
4+ from board import Board
5+
6+
7+ @dataclass
8+ class Player :
9+ """
10+ Represents a player in the Battleship game.
11+
12+ Attributes:
13+ name (str): The name of the player.
14+ enemy_board (Board): The board representing the opponent's board.
15+ """
16+
17+ name : str
18+ enemy_board : Board
19+
20+ def attack (self , row : int , col : int ):
21+ """
22+ Attack a specific location on the opponent's board.
23+
24+ Args:
25+ row (int): The row index of the target location.
26+ col (int): The column index of the target location.
27+ """
28+ self .enemy_board .enemy_move (row , col )
29+
30+ def generate_random_ship_arrangements (self ) -> None :
31+ """Generate random ship arrangements for the opponent's board and place them."""
32+ ships = generate_random_ships_arrangements (self .enemy_board .board_size )
33+ for ship in ships :
34+ self .enemy_board .place_ship (ship .coordinates )
35+
36+ def place_ship (self , ship_coordinates ):
37+ """
38+ Place a ship on the opponent's board.
39+
40+ Args:
41+ ship_coordinates: Coordinates representing the ship's position.
42+ """
43+ # Remind that this is for the enemy's ships not this player.
44+ self .enemy_board .place_ship (ship_coordinates )
You can’t perform that action at this time.
0 commit comments