summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
9065fe8)
So far, this is mostly just renaming some things and inching the code in that
direction.
return self._grid._boxes[box_idx]
box = property(_get_box)
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
def __init__(self, grid, row, column):
self._grid = proxy(grid)
self._row = row
return
# Elimination time
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
for cell in group.cells:
if cell == self:
continue
return self._size
size = property(_get_size)
return self._size
size = property(_get_size)
- def _get_cell_groups(self):
+ def _get_constraints(self):
return self._rows + self._columns + self._boxes
return self._rows + self._columns + self._boxes
- cell_groups = property(_get_cell_groups)
+ constraints = property(_get_constraints)
self.normalize_cells()
# Step 1: Find values that can only go in one cell in a group
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:
from weakref import proxy
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."""
+class Box(CellConstraint):
def _get_box_row(self):
return self._pos // self._grid._box_width
box_row = property(_get_box_row)
def _get_box_row(self):
return self._pos // self._grid._box_width
box_row = property(_get_box_row)
+class Row(CellConstraint):
def _get_cells(self):
# XXX generator + docstring
cells = []
def _get_cells(self):
# XXX generator + docstring
cells = []
-class Column(CellGroup):
+class Column(CellConstraint):
def _get_cells(self):
# XXX generator + docstring
cells = []
def _get_cells(self):
# XXX generator + docstring
cells = []