app.players module
- exception EnemyUnsetError
Bases:
Exception
- class Player(name: str = 'Unnamed', ships: list = None, side: int = 0, ui: ui.CLI | None = None)
Bases:
object
- property ships: dict[int, ships.Ship]
Returns the player’s ships
- Returns
player’s ships
- Return type
dict
- property name: str
Returns the player’s name
- Returns
player’s name
- Return type
str
- property side: str
Returns the player’s side
- Returns
player’s side
- Return type
int
- property enemy_board: Board
Returns the enemy’s board object
- Raises
EnemyUnsetError – if the enemy is not set
- Returns
enemy’s board
- Return type
- property last_attack_result: AttackResult
Returns the last attack result
- Returns
last attack result enum
- Return type
- property fleet_strength: int
Returns the player’s fleet strength (sum of all ships’ sizes)
- Returns
player’s fleet strength
- Return type
int
- _edit_board()
Edits the board using the user input. First the user selects a ship, then the ship is moved to the desired location.
If the user aborts the ship placement, the ship is not moved.
If the user selects a cell that is not a ship, the user is asked to select a ship again.
- initialize_board() None
Initializes the board using the user input
- attack_enemy() AttackResult
Attacks the enemy using the user input
- Returns
result of the attack
- Return type
- class AIPlayer(name: str = 'AI', ships: list = None, side: int = 0)
Bases:
Player
- initialize_board() None
Initializes the board with random ship placement
- attack_enemy() AttackResult
Attacks the enemy using the hunt-target strategy. Hunt mode: hitting random cells. If the last attack was a hit, the algorithm switches to target mode. Target mode: hitting cells around the last hit cell. If the ship is sunk, the algorithm switches to hunt mode.
- Returns
result of the attack
- Return type