Stop the analysis pass in Loopy's redraw routine from being
[sgt/puzzles] / pearl.c
diff --git a/pearl.c b/pearl.c
index a06ecc2..ed1ee16 100644 (file)
--- a/pearl.c
+++ b/pearl.c
@@ -1161,9 +1161,17 @@ void pearl_loopgen(int w, int h, char *lines, random_state *rs)
 static int new_clues(game_params *params, random_state *rs,
                      char *clues, char *grid)
 {
-    int w = params->w, h = params->h;
+    int w = params->w, h = params->h, diff = params->difficulty;
     int ngen = 0, x, y, d, ret, i;
 
+
+    /*
+     * Difficulty exception: 5x5 Tricky is not generable (the
+     * generator will spin forever trying) and so we fudge it to Easy.
+     */
+    if (w == 5 && h == 5 && diff > DIFF_EASY)
+        diff = DIFF_EASY;
+
     while (1) {
         ngen++;
        pearl_loopgen(w, h, grid, rs);
@@ -1245,7 +1253,7 @@ static int new_clues(game_params *params, random_state *rs,
             /*
              * See if we can solve the puzzle just like this.
              */
-            ret = pearl_solve(w, h, clues, grid, params->difficulty, FALSE);
+            ret = pearl_solve(w, h, clues, grid, diff, FALSE);
             assert(ret > 0);          /* shouldn't be inconsistent! */
             if (ret != 1)
                 continue;                     /* go round and try again */
@@ -1253,8 +1261,8 @@ static int new_clues(game_params *params, random_state *rs,
             /*
              * Check this puzzle isn't too easy.
              */
-            if (params->difficulty > DIFF_EASY) {
-                ret = pearl_solve(w, h, clues, grid, params->difficulty-1, FALSE);
+            if (diff > DIFF_EASY) {
+                ret = pearl_solve(w, h, clues, grid, diff-1, FALSE);
                 assert(ret > 0);
                 if (ret == 1)
                     continue; /* too easy: try again */
@@ -1321,7 +1329,7 @@ static int new_clues(game_params *params, random_state *rs,
                 clue = clues[y*w+x];
                 clues[y*w+x] = 0;             /* try removing this clue */
 
-                ret = pearl_solve(w, h, clues, grid, params->difficulty, FALSE);
+                ret = pearl_solve(w, h, clues, grid, diff, FALSE);
                 assert(ret > 0);
                 if (ret != 1)
                     clues[y*w+x] = clue;   /* oops, put it back again */
@@ -1632,8 +1640,6 @@ static void check_completion(game_state *state, int mark)
     if (!had_error && loopclass != -1) {
         state->completed = TRUE;
         state->loop_length = dsfsize[loopclass];
-    } else {
-        state->completed = FALSE;
     }
 
     sfree(dsf);
@@ -1954,7 +1960,7 @@ static char *mark_in_direction(game_state *state, int x, int y, int dir,
     (btn) == CURSOR_DOWN ? D : (btn) == CURSOR_UP ? U :\
     (btn) == CURSOR_LEFT ? L : R)
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int w = state->shared->w, h = state->shared->h /*, sz = state->shared->sz */;
@@ -2442,8 +2448,8 @@ static float game_anim_length(game_state *oldstate, game_state *newstate,
 static float game_flash_length(game_state *oldstate, game_state *newstate,
                               int dir, game_ui *ui)
 {
-    if (!oldstate->completed &&
-        newstate->completed && !newstate->used_solve)
+    if (!oldstate->completed && newstate->completed &&
+        !oldstate->used_solve && !newstate->used_solve)
         return FLASH_TIME;
     else
         return 0.0F;