[gnome-games] Sudoku: Only generate puzzles of the selected difficulty



commit 83c693e398afd46a482c73fd3ea1f80fa4ed9061
Author: Thomas Hindoe Paaboel Andersen <phomes gmail com>
Date:   Sat Apr 10 13:10:38 2010 +0200

    Sudoku: Only generate puzzles of the selected difficulty
    
    Patch by ultramancool gmail com
    
    GNOME bug #392960

 gnome-sudoku/src/lib/sudoku_generator_gui.py |   30 ++++++++-----------------
 gnome-sudoku/src/lib/sudoku_maker.py         |   11 +++------
 2 files changed, 14 insertions(+), 27 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/sudoku_generator_gui.py b/gnome-sudoku/src/lib/sudoku_generator_gui.py
index ebbef80..af067a7 100644
--- a/gnome-sudoku/src/lib/sudoku_generator_gui.py
+++ b/gnome-sudoku/src/lib/sudoku_generator_gui.py
@@ -113,7 +113,7 @@ class GameGenerator (gconf_wrapper.GConfWrapper):
         self.paused = False
         self.prog.set_text(_('Working...'))
         gobject.timeout_add(100, self.update_status)
-        self.worker = threading.Thread(target=lambda *args: self.sudoku_maker.work(limit=None, diff_min=self.get_diff_min(), diff_max=self.get_diff_max()))
+        self.worker = threading.Thread(target=lambda *args: self.sudoku_maker.work(limit=None, diffs=self.get_diffs()))
         self.worker.start()
 
     def pause_cb (self, widg):
@@ -214,27 +214,17 @@ class GameGenerator (gconf_wrapper.GConfWrapper):
         if self.paused:
             txt = txt + ' (' + _('Paused') + ')'
         self.prog.set_text(txt)
-
-    def get_diff_min (self):
+    
+    def get_diffs(self):
         if self.generateEndlesslyRadio.get_active():
-            return None
+            return ['easy', 'medium', 'hard', 'very hard']
+        diffs = []
         if self.easyCheckButton.get_active():
-            return None
+            diffs.append('easy')
         if self.mediumCheckButton.get_active():
-            return sudoku.DifficultyRating.medium_range[0]
+            diffs.append('medium')
         if self.hardCheckButton.get_active():
-            return sudoku.DifficultyRating.hard_range[0]
-        if self.veryHardCheckButton.get_active():
-            return sudoku.DifficultyRating.very_hard_range[0]
-
-    def get_diff_max (self):
-        if self.generateEndlesslyRadio.get_active():
-            return None
+            diffs.append('hard')
         if self.veryHardCheckButton.get_active():
-            return None
-        if self.hardCheckButton.get_active():
-            return sudoku.DifficultyRating.hard_range[1]
-        if self.mediumCheckButton.get_active():
-            return sudoku.DifficultyRating.medium_range[1]
-        if self.easyCheckButton.get_active():
-            return sudoku.DifficultyRating.easy_range[1]
+            diffs.append('very hard')
+        return diffs
diff --git a/gnome-sudoku/src/lib/sudoku_maker.py b/gnome-sudoku/src/lib/sudoku_maker.py
index 1a41e72..360c8ba 100644
--- a/gnome-sudoku/src/lib/sudoku_maker.py
+++ b/gnome-sudoku/src/lib/sudoku_maker.py
@@ -481,7 +481,7 @@ class SudokuMaker:
 
     # Methods for creating new puzzles
 
-    def make_batch (self, diff_min = None, diff_max = None):
+    def make_batch (self, diffs = None):
         self.new_generator = InterruptibleSudokuGenerator(**self.generator_args)
         key = self.new_generator.start_grid.to_string()
         #while
@@ -495,9 +495,7 @@ class SudokuMaker:
             #print 'start next item...',n
             puz, diff = ug.next()
             #print "GENERATED ",puz,diff
-            if ((not diff_min or diff.value >= diff_min)
-                and
-                (not diff_max or diff.value <= diff_max)):
+            if (diffs == None or diff.value_category() in diffs):
                 puzstring = puz.to_string()
                 # self.puzzles_by_solution[key].append((puzstring,diff))
                 # self.solutions_by_puzzle[puzstring]=key
@@ -538,7 +536,7 @@ class SudokuMaker:
                 break
             time.sleep(1)
 
-    def work (self, limit = None, diff_min = None, diff_max = None):
+    def work (self, limit = None, diffs = None):
         """Intended to be called as a worker thread, make puzzles!"""
         self.terminated = False
         if hasattr(self, 'new_generator'):
@@ -551,8 +549,7 @@ class SudokuMaker:
             if self.paused:
                 self.hesitate()
             try:
-                self.make_batch(diff_min = diff_min,
-                                diff_max = diff_max)
+                self.make_batch(diffs = diffs)
             except:
                 raise
             else:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]