[gnome-games/sudoku-tube] Make auto_fill do change the grid
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/sudoku-tube] Make auto_fill do change the grid
- Date: Sat, 18 Jul 2009 04:48:23 +0000 (UTC)
commit 9a3d3fa81915ac31ec6c221eda05a11142270521
Author: Zhang Sen <zh jesse gmail com>
Date: Sat Jul 18 12:09:30 2009 +0800
Make auto_fill do change the grid
* Reverting aff8a591cf25bbe05a3a53711aa750928a2d95a2.
* auto_fill must change the grid, in order to work well. E.g. it can't work out
the difficulty rightly, which uses auto_fill to solve the puzzle.
gnome-sudoku/src/lib/gsudoku.py | 9 +++++++--
gnome-sudoku/src/lib/sudoku.py | 8 +++++++-
2 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/gsudoku.py b/gnome-sudoku/src/lib/gsudoku.py
index 1e99a75..95646c1 100644
--- a/gnome-sudoku/src/lib/gsudoku.py
+++ b/gnome-sudoku/src/lib/gsudoku.py
@@ -546,10 +546,15 @@ class SudokuModel:
self._signal_completeness()
def auto_fill (self):
+ result = []
+
changed = set(self.grid.auto_fill()) # there are duplicate?
for coords, val in changed:
- self.set_value(coords[0], coords[1], val)
- return changed
+ x, y = coords
+ result.append((x, y, val, None))
+
+ self._signal_observers(result)
+ self._check_for_completeness()
def auto_fill_current(self, x, y):
filled = self.grid.auto_fill_for_xy(x, y)
diff --git a/gnome-sudoku/src/lib/sudoku.py b/gnome-sudoku/src/lib/sudoku.py
index d42e105..cbbcc39 100644
--- a/gnome-sudoku/src/lib/sudoku.py
+++ b/gnome-sudoku/src/lib/sudoku.py
@@ -336,7 +336,12 @@ class SudokuSolver (SudokuGrid):
if not coords:
raise UnsolvablePuzzle('Missing a %s in %s' % (n, label))
else:
- changed.append((coords, n))
+ try:
+ self.add(coords[0], coords[1], n)
+ changed.append((coords, n))
+ except AlreadySetError:
+ raise UnsolvablePuzzle(
+ "%s,%s must be two values at once!" % (coords))
return changed
def fill_deterministically (self):
@@ -347,6 +352,7 @@ class SudokuSolver (SudokuGrid):
if self.verbose:
print 'Deterministically adding ', coords, choices
val = choices.pop()
+ self.add(coords[0], coords[1], val)
retval.append(((coords[0], coords[1]), val))
if self.verbose:
print 'deterministically returning ', retval
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]