Files
battleship/battleship/board.py

23 lines
528 B
Python

from .bs_types import Coordinate
class Board:
"""
Represents the shape of a board and provides utility functions related its coordinate space.
"""
def __init__(self, width, height):
self.width = width
self.height = height
@property
def rows(self):
return range(self.height)
@property
def columns(self):
return range(self.width)
def valid(self, coordinate: Coordinate) -> bool:
x, y = coordinate
return x in self.columns and y in self.rows