Commit 8411224f authored by Adam Blank's avatar Adam Blank
Browse files

Initial commit

parents
No related merge requests found
Showing with 247 additions and 0 deletions
+247 -0
assets/2-horizontal-op.png

330 Bytes

assets/2-horizontal.png

321 Bytes

assets/2-vertical-op.png

321 Bytes

assets/2-vertical.png

325 Bytes

assets/3-horizontal-op.png

427 Bytes

assets/3-horizontal.png

389 Bytes

assets/3-vertical-op.png

437 Bytes

assets/3-vertical.png

459 Bytes

assets/4-horizontal.png

406 Bytes

assets/4-vertical.png

458 Bytes

assets/5-horizontal.png

411 Bytes

assets/5-vertical.png

474 Bytes

assets/logo.png

1.28 MB

from support.placement import PlacementUI
from support.computer import ComputerGameUI
from support.mode import ModeUI
from textual.coordinate import Coordinate
from src.computer_placement import place_ships
from src.easy_computer import easy_computer
from src.harder_computer import harder_computer
app = ModeUI()
mode = app.run()
app = PlacementUI()
output = place_ships()
comp_offsets = dict()
comp_coords = set()
comp_ships = dict()
for i, ship in enumerate(reversed(output)):
if ship[0][0] == ship[1][0]:
dir = 0
else:
dir = 1
comp_offsets["s" + str(i + 1)] = (dir, (ship[0][0] * 10 + 2, ship[0][1] * 5 + 1))
comp_ships["s" + str(i + 1)] = set()
for coord in ship:
comp_coords.add(Coordinate(coord[1], coord[0]))
comp_ships["s" + str(i + 1)].add(Coordinate(coord[1], coord[0]))
if mode == "ec":
(player_offsets, player_coords, player_ships) = app.run()
app = ComputerGameUI(player_offsets, player_coords, player_ships, comp_offsets, comp_coords, comp_ships, easy_computer)
outcome = app.run()
print(outcome)
if mode == "hc":
(player_offsets, player_coords, player_ships) = app.run()
app = ComputerGameUI(player_offsets, player_coords, player_ships, comp_offsets, comp_coords, comp_ships, harder_computer)
outcome = app.run()
print(outcome)
import random
BOARD_SIZE = 8
SHIP_SIZES = [5, 4, 3, 3, 2]
def place_ships():
"""
Generates a valid placement of all ships onto the board for use by the computer.
Returns:
list[list[tuple(x, y)]]: valid list of ships.
"""
return None
def is_conflict(ship, ships):
"""
Checks if any of the coordinates of the given ship conflict with
any previously placed ships.
Args:
ship (list[tuple(x, y)]): coordinates of the ship
ships (list[list[tuple(x, y)]]): list of lists of coordinates of all previously placed ships
Returns:
bool: boolean value representing if a coordinate conflict was found
"""
return False
def place_ship(size):
"""
Generates a ship of given size not considering conflicts
with previously placed ships.
Args:
size (int): size of the ship being generated
Returns:
list[tuple(x,y)]: coordinates of generated ship
"""
orientation, location = choose_orientation_and_location(size)
ship = generate_ship_coordinates(location, size, orientation)
return ship
def generate_ship_coordinates(location, size, orientation):
"""
Generates the coordinates of a ship with the given size at the given location
with the given orientation.
Args:
location (tuple(x,y)): Top-left most coordinate of the ship being generated
size (int): size, also known as length, of ship that is being generated
orientation (bool): represents whether the ship being generated is horizontal (False)
or vertical (True)
Returns:
list[tuple(x,y)]: coordinates of generated ship
"""
return None
def choose_orientation_and_location(size):
"""
Chooses a random orientation and coordinate for a ship, taking into account the given
size to make sure all coordinates placed with the chosen orientation would exist on
a board with size BOARD_SIZE.
Args:
size (int): size, also known as length, of ship that is being generated
Returns:
tuple(bool, tuple(x,y)): tuple where the first value represents the random
orientation chosen for the ship
(True = vertical, False = horizontal) and the second
value represents the top-left most random coordinate
chosen for the ship
"""
return None
import random
BOARD_SIZE = 8
def get_all_shots(previous_shots):
"""
Finds all shots from the log regardless of the OUTCOME.
Args:
previous_shots (list[tuple(tuple(x,y), OUTCOME)]): list of all previous shot
records
Returns:
list[tuple(x,y)]: all shots from the log.
"""
return None
def easy_computer(previous_shots):
"""
Returns a random coordinate pair on a board with size BOARD_SIZE that hasn't
been shot before regardless of OUTCOME.
Args:
previous_shots (list[tuple(tuple(x,y), OUTCOME)]): list of all previous shot
records
Returns:
tuple(x,y): coordinate pair that represents the computer's shot
"""
return None
from .easy_computer import easy_computer, get_all_shots
from .shot import HIT
DIRECTIONS = [(0, 1), (1, 0), (0, -1), (-1, 0)]
def get_hits(previous_shots):
"""
Finds all shots from the list that resulted in a OUTCOME of HIT.
Args:
previous_shots (list[tuple(tuple(x,y), OUTCOME)]): list of all previous shot
records
Returns:
list[tuple(x,y)]: all shots from the list that resulted in a HIT.
"""
return None
def is_valid_shot(shot, processed_shots):
"""
Returns whether the given shot is valid or not based on the BOARD_SIZE and
the processed list of previous shots.
Args:
shot (tuple(x,y)): coordinate pair of given shot being considered
processed_shots (list[tuple(x,y)]): list of all previous shots returned
from get_all_shots
Returns:
bool: boolean value representing the shot's validity
"""
return False
def apply_direction(coords, direction):
"""
Returns a new coordinate pair made up by adding together the components of coords and direction.
Args:
coords (tuple(x,y)): coordinate pair of the given shot being modified
direction (tuple(x,y)): coordinate pair of the delta to be applied to the shot
Returns:
tuple(x,y): the new coordinate pair with direction applied to coords
"""
return None
def find_opposite_shot(coords, direction):
"""
Returns a new coordinate pair made up by adding together the components of coords and
the opposite of direction.
Args:
coords (tuple(x,y)): coordinate pair of the given shot being modified
direction (tuple(x,y)): coordinate pair of the negative delta to be applied to the shot
Returns:
tuple(x,y): the new coordinate pair with negative direction applied to coords
"""
return None
def harder_computer(previous_shots):
"""
Returns a coordinate pair that is a valid shot that continues in the direction of an unsunk previously found ship whenever possible.
Args:
previous_shots (list[tuple(tuple(x,y), OUTCOME)]): list of all previous shot
records
Returns:
tuple(x,y): coordinate pair that represents the computer's shot
"""
return None
from enum import Enum
class Shot(Enum):
MISS = 0
HIT = 1
SUNK = 2
globals().update(Shot.__members__)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment