From: Eevee Date: Thu, 18 Dec 2008 08:57:11 +0000 (-0800) Subject: Started merging cols/rows/boxes into "constraints". X-Git-Url: http://git.veekun.com/pseudoku.git/commitdiff_plain/f331885e36c9a1ba448a798fb103fd2c48b2ce44?ds=inline Started merging cols/rows/boxes into "constraints". So far, this is mostly just renaming some things and inching the code in that direction. --- diff --git a/pseudoku/grid/__init__.py b/pseudoku/grid/__init__.py index 94d0833..ce7a701 100644 --- a/pseudoku/grid/__init__.py +++ b/pseudoku/grid/__init__.py @@ -56,6 +56,13 @@ class Cell(object): 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 @@ -92,8 +99,7 @@ class Cell(object): 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 @@ -170,9 +176,9 @@ class Grid(object): 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 @@ -282,7 +288,7 @@ class Grid(object): 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() diff --git a/pseudoku/grid/cellgroup.py b/pseudoku/grid/cellgroup.py index 863ca4e..8ff948e 100644 --- a/pseudoku/grid/cellgroup.py +++ b/pseudoku/grid/cellgroup.py @@ -2,8 +2,8 @@ from __future__ import division 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 @@ -43,7 +43,7 @@ class CellGroup(object): 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) @@ -68,7 +68,7 @@ class Box(CellGroup): self._pos = position -class Row(CellGroup): +class Row(CellConstraint): def _get_cells(self): # XXX generator + docstring cells = [] @@ -82,7 +82,7 @@ class Row(CellGroup): self._pos = position -class Column(CellGroup): +class Column(CellConstraint): def _get_cells(self): # XXX generator + docstring cells = []