"""This module contains the Square class.""" class Square: """A Square object represents a square on the board. The square's values will consist of a set of possible values for that square. The grid_id attribute identifies in which 9x9 grid the square belongs to. """ def __init__(self, line: int, column: int, values: set): self.line: int = line self.column: int = column self.grid: int = self.compute_grid() self.coordinates: tuple = (self.line, self.column) self.values: set = values def compute_grid(self) -> int: """Given the coordinates, determine which grid the Square belongs to. The grids are numbered from 0 to 8, in the following configuration: 0 1 2 3 4 5 6 7 8 """ grid_mappings = [ (0, 0), # grid 0 (0, 1), # grid 1 (0, 2), # grid 2 (1, 0), # grid 3 (1, 1), # grid 4 (1, 2), # grid 5 (2, 0), # grid 6 (2, 1), # grid 7 (2, 2), # grid 8 ] grid_coordinates = (self.line // 3, self.column // 3) grid_number = 0 while grid_mappings[grid_number] != grid_coordinates: grid_number += 1 if grid_number == 9: raise AssertionError("Board is invalid") return grid_number