[gnome-sudoku] Remove SudokuSolver, SudokuRater and DifficultyRating



commit 3f4401fef8a859027bd37f99d2655686c12a8f87
Author: Parin Porecha <parinporecha gmail com>
Date:   Tue Aug 5 11:22:46 2014 +0200

    Remove SudokuSolver, SudokuRater and DifficultyRating
    
    - Move DifficultyCategory enum to sudoku-board.vala
    - Move float difficulty ranges to SudokuBoard and make them private

 lib/Makefile.am        |    3 +-
 lib/sudoku-board.vala  |   41 ++-
 lib/sudoku-solver.vala |  878 ------------------------------------------------
 src/gnome-sudoku.vala  |    5 -
 4 files changed, 36 insertions(+), 891 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index ed3d03a..94808e1 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -3,8 +3,7 @@ noinst_LTLIBRARIES = libsudoku.la
 libsudoku_la_SOURCES = \
        sudoku-board.vala \
        sudoku-game.vala \
-       sudoku-saver.vala \
-       sudoku-solver.vala
+       sudoku-saver.vala
 
 libsudoku_la_CFLAGS = -w
 
diff --git a/lib/sudoku-board.vala b/lib/sudoku-board.vala
index cd159eb..04547ca 100644
--- a/lib/sudoku-board.vala
+++ b/lib/sudoku-board.vala
@@ -12,6 +12,13 @@ public class SudokuBoard : Object
     private bool[,] possible_in_col;            /* if specific value is possible in specific col */
     private bool[,,] possible_in_block;         /* if specific value is possible in specific block */
 
+    private const float[] VERY_HARD_RANGE = { 0.75f, 10 };
+    private const float[] HARD_RANGE = { 0.6f, 0.75f };
+    private const float[] MEDIUM_RANGE = { 0.45f, 0.6f };
+    private const float[] EASY_RANGE = { -10, 0.45f };
+
+    public double difficulty_rating;
+
     public bool[,,] earmarks;                  /* Earmarks set by the user */
 
     public double previous_played_time { set; get; default = 0; }
@@ -55,8 +62,6 @@ public class SudokuBoard : Object
         return filled == fixed;
     }
 
-    public double difficulty_rating;
-
     private bool in_range (float[] range)
     {
         return (difficulty_rating >= range[0] && difficulty_rating < range[1]);
@@ -64,13 +69,13 @@ public class SudokuBoard : Object
 
     public DifficultyCategory get_difficulty_category ()
     {
-        if (in_range(DifficultyRating.EASY_RANGE))
+        if (in_range(EASY_RANGE))
             return DifficultyCategory.EASY;
-        else if (in_range(DifficultyRating.MEDIUM_RANGE))
+        else if (in_range(MEDIUM_RANGE))
             return DifficultyCategory.MEDIUM;
-        else if (in_range(DifficultyRating.HARD_RANGE))
+        else if (in_range(HARD_RANGE))
             return DifficultyCategory.HARD;
-        else if (in_range(DifficultyRating.VERY_HARD_RANGE))
+        else if (in_range(VERY_HARD_RANGE))
             return DifficultyCategory.VERY_HARD;
         else
             return DifficultyCategory.EASY;
@@ -574,3 +579,27 @@ public struct Cell
         return (Coord.equal(a.coord, b.coord) && (a.val == b.val));
     }
 }
+
+public enum DifficultyCategory {
+    EASY,
+    MEDIUM,
+    HARD,
+    VERY_HARD;
+
+    public string to_string ()
+    {
+        switch (this)
+        {
+            case EASY:
+                return _("Easy Difficulty");
+            case MEDIUM:
+                return _("Medium Difficulty");
+            case HARD:
+                return _("Hard Difficulty");
+            case VERY_HARD:
+                return _("Very Hard Difficulty");
+            default:
+                assert_not_reached ();
+        }
+    }
+}
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index d30c9e7..5b485ad 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -164,12 +164,7 @@ public class Sudoku : Gtk.Application
 
     private void start_game (SudokuBoard board)
     {
-        var completed_board = board.clone ();
-
-        var rater = new SudokuRater(ref completed_board);
-        var rating = rater.get_difficulty ();
         var difficulty_category = board.get_difficulty_category ();
-        debug ("\n%s", rating.to_string ());
         undo_action.set_enabled (false);
         redo_action.set_enabled (false);
         clear_action.set_enabled (!board.is_empty ());


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