battleship.logic package¶
Submodules¶
battleship.logic.ai module¶
AI features.
- class battleship.logic.ai.BotThread(game, screen)¶
Bases:
ThreadPlaying thread for the AI.
- get_shot()¶
Get shot by the player.
- play()¶
Start the game.
- run()¶
Start the thread.
- shoot()¶
Shoot at the player.
- update_screen(screen)¶
Get the new screen.
- battleship.logic.ai.get_coords(position, size, angle, field=None)¶
Get a list of coordinates for a ship.
- Parameters:
position – Starting coordinate of the ship.
size – Size of the ship.
angle – Angle of the ship extension.
field – Player’s field.
- Returns:
Coordinates of the ship.
- Return type:
list
- battleship.logic.ai.random_ships(cells)¶
Get coordinates of placed ships.
- Parameters:
cells – Player’s field.
- Returns:
dict
- battleship.logic.ai.random_ships_matrix()¶
Build a playing field with randomly placed ships.
- battleship.logic.ai.shot(cells)¶
Shoot at random available cell.
- Parameters:
cells – Player’s field.
- Returns:
A tuple, containing coordinates.
- battleship.logic.ai.surrounding(coords)¶
Get neighboring coordinates of a ship.
battleship.logic.game module¶
Game, field, player classes.
- class battleship.logic.game.Field¶
Bases:
objectClass to describe player’s field.
- auto_place()¶
Place ships automatically.
- check(coord)¶
Check cell status.
- Parameters:
coord – Coordinate to check.
- check_placed()¶
Check whether all ships are placed.
- clear()¶
Clear the list of placed ships.
- place(coords)¶
Place the ship on the playing field.
- Parameters:
coords – Ship coordinates.
- update(coord, status)¶
Update cell status.
- Parameters:
coord – Coordinate to update.
status – Status to apply.
- Returns:
Whether the ship was hit.
- Return type:
bool
- class battleship.logic.game.Game(mode, name)¶
Bases:
objectClass to describe ana active game.
- enemy_turn(cell)¶
Process opponent’s turn.
- Parameters:
cell – Shot coordinates.
- player_turn(cell)¶
Process player’s turn.
- Parameters:
cell – Shot coordinates.
battleship.logic.network module¶
Multiplayer features.
- class battleship.logic.network.AsyncioThread(game, screen)¶
Bases:
ThreadThread to handle networking during game.
- async connect()¶
Connect to server.
- async handle_tech_data()¶
Receive and send technical data.
- async play()¶
Start the game.
- async put_in_erqueue(data)¶
Put in error queue.
- async put_in_queue(data)¶
Put in regular queue.
- run()¶
Start the thread.
- update_screen(screen)¶
Get the new screen.
Module contents¶
Module to support game logic.