return self._grid._boxes[box_idx]
box = property(_get_box)
+ def _get_constraints(self):
+ return [ self.row, self.column, self.box ]
+ constraints = property(_get_constraints)
+
+ def _get_groups(self):
+ return self._groups
+
def __init__(self, grid, row, column):
self._grid = proxy(grid)
self._row = row
return
# Elimination time
- for group_type in 'row', 'column', 'box':
- group = getattr(self, group_type)
+ for group in self.constraints:
for cell in group.cells:
if cell == self:
continue
return self._size
size = property(_get_size)
- def _get_cell_groups(self):
+ def _get_constraints(self):
return self._rows + self._columns + self._boxes
- cell_groups = property(_get_cell_groups)
+ constraints = property(_get_constraints)
### Constructors
self.normalize_cells()
# Step 1: Find values that can only go in one cell in a group
- for group in self.cell_groups:
+ for group in self.constraints:
group.resolve_uniques()
from weakref import proxy
-class CellGroup(object):
- """Represents any group of cells in a grid."""
+class CellConstraint(object):
+ """Represents any group of cells in a grid that cannot repeat a digit."""
### Accessors
target_cell.set(value)
-class Box(CellGroup):
+class Box(CellConstraint):
def _get_box_row(self):
return self._pos // self._grid._box_width
box_row = property(_get_box_row)
self._pos = position
-class Row(CellGroup):
+class Row(CellConstraint):
def _get_cells(self):
# XXX generator + docstring
cells = []
self._pos = position
-class Column(CellGroup):
+class Column(CellConstraint):
def _get_cells(self):
# XXX generator + docstring
cells = []