battleship.logic package

Submodules

battleship.logic.ai module

AI features.

class battleship.logic.ai.BotThread(game, screen)

Bases: Thread

Playing 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.Bot

Bases: Player

Player subclass to describe an AI.

class battleship.logic.game.Field

Bases: object

Class 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: object

Class 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.

class battleship.logic.game.Player(name)

Bases: object

Class to describe the player.

update_field(coord)

Update player’s field.

Parameters:

coord – Coordinate to update.

update_status()

Update player status.

class battleship.logic.game.Ship(size)

Bases: object

Class to describe the ship.

hit(coord)

Record hit at the ship.

Parameters:

coord – Coordinate of the shot.

place(coords)

Save ship coordinates.

Parameters:

coords – Ship coordinates.

battleship.logic.network module

Multiplayer features.

class battleship.logic.network.AsyncioThread(game, screen)

Bases: Thread

Thread 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.