Minor improvement to initial loop generation.
[sgt/puzzles] / loopy.c
diff --git a/loopy.c b/loopy.c
index 4fa56e1..42e7856 100644 (file)
--- a/loopy.c
+++ b/loopy.c
@@ -764,7 +764,16 @@ static char *new_fullyclued_board(game_params *params, random_state *rs)
         square = (struct square *)index234(lightable_squares_sorted, 0);
         assert(square);
 
-        if (square->score <= 0)
+       /*
+        * We never want to _decrease_ the loop's perimeter. Making
+        * moves that leave the perimeter the same is occasionally
+        * useful: if it were _never_ done then the user would be
+        * able to deduce illicitly that any degree-zero vertex was
+        * on the outside of the loop. So we do it sometimes but
+        * not always.
+        */
+        if (square->score < 0 || (square->score == 0 &&
+                                 random_upto(rs, 2) == 0))
             break;
 
         print_tree(lightable_squares_sorted);
@@ -2459,7 +2468,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
 #define CLEAR_VL(i, j) do {                                                \
                            draw_rect(dr,                                   \
                                  BORDER + i * TILE_SIZE - CROSS_SIZE,      \
-                                 BORDER + j * TILE_SIZE + LINEWIDTH/2,     \
+                                 BORDER + j * TILE_SIZE + LINEWIDTH - LINEWIDTH/2,     \
                                  CROSS_SIZE * 2,                           \
                                  TILE_SIZE - LINEWIDTH,                    \
                                  COL_BACKGROUND);                          \
@@ -2472,7 +2481,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
 
 #define CLEAR_HL(i, j) do {                                                \
                            draw_rect(dr,                                   \
-                                 BORDER + i * TILE_SIZE + LINEWIDTH/2,     \
+                                 BORDER + i * TILE_SIZE + LINEWIDTH - LINEWIDTH/2,     \
                                  BORDER + j * TILE_SIZE - CROSS_SIZE,      \
                                  TILE_SIZE - LINEWIDTH,                    \
                                  CROSS_SIZE * 2,                           \
@@ -2499,7 +2508,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
                         CLEAR_VL(i, j);
                         draw_rect(dr,
                                   BORDER + i * TILE_SIZE - LINEWIDTH/2,
-                                  BORDER + j * TILE_SIZE + LINEWIDTH/2,
+                                  BORDER + j * TILE_SIZE + LINEWIDTH - LINEWIDTH/2,
                                   LINEWIDTH, TILE_SIZE - LINEWIDTH, 
                                   line_colour);
                     }
@@ -2540,7 +2549,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
                         flash_changed) {
                         CLEAR_HL(i, j);
                         draw_rect(dr,
-                                  BORDER + i * TILE_SIZE + LINEWIDTH/2,
+                                  BORDER + i * TILE_SIZE + LINEWIDTH - LINEWIDTH/2,
                                   BORDER + j * TILE_SIZE - LINEWIDTH/2,
                                   TILE_SIZE - LINEWIDTH, LINEWIDTH, 
                                   line_colour);