chiark / gitweb /
Fix a memory error in Guess cursor handling.
[sgt-puzzles.git] / range.c
diff --git a/range.c b/range.c
index 391bdc858dfaa020eeba484e704584272d912a85..f2ea1b77f5124b1bfdc31c5313af220ed3237fd7 100644 (file)
--- a/range.c
+++ b/range.c
@@ -1167,7 +1167,7 @@ static char *game_text_format(const game_state *state)
     cellsize = 0; /* or may be used uninitialized */
 
     for (c = 0; c < w; ++c) {
-        for (r = 1; r < h; ++r) {
+        for (r = 0; r < h; ++r) {
             puzzle_size k = state->grid[idx(r, c, w)];
             int d;
             for (d = 0; k; k /= 10, ++d);
@@ -1273,6 +1273,8 @@ static char *interpret_move(const game_state *state, game_ui *ui,
     enum {none, forwards, backwards, hint};
     int const w = state->params.w, h = state->params.h;
     int r = ui->r, c = ui->c, action = none, cell;
+    int shift = button & MOD_SHFT;
+    button &= ~shift;
 
     if (IS_CURSOR_SELECT(button) && !ui->cursor_show) return NULL;
 
@@ -1330,7 +1332,36 @@ static char *interpret_move(const game_state *state, game_ui *ui,
             int i;
             for (i = 0; i < 4 && cursors[i] != button; ++i);
             assert (i < 4);
-            if (!out_of_bounds(ui->r + dr[i], ui->c + dc[i], w, h)) {
+            if (shift) {
+                int pre_r = r, pre_c = c, do_pre, do_post;
+                cell = state->grid[idx(r, c, state->params.w)];
+                do_pre = (cell == EMPTY);
+
+                if (out_of_bounds(ui->r + dr[i], ui->c + dc[i], w, h)) {
+                    if (do_pre)
+                        return nfmtstr(40, "W,%d,%d", pre_r, pre_c);
+                    else
+                        return NULL;
+                }
+
+                ui->r += dr[i];
+                ui->c += dc[i];
+
+                cell = state->grid[idx(ui->r, ui->c, state->params.w)];
+                do_post = (cell == EMPTY);
+
+                /* (do_pre ? "..." : "") concat (do_post ? "..." : "") */
+                if (do_pre && do_post)
+                    return nfmtstr(80, "W,%d,%dW,%d,%d",
+                                   pre_r, pre_c, ui->r, ui->c);
+                else if (do_pre)
+                    return nfmtstr(40, "W,%d,%d", pre_r, pre_c);
+                else if (do_post)
+                    return nfmtstr(40, "W,%d,%d", ui->r, ui->c);
+                else
+                    return "";
+
+            } else if (!out_of_bounds(ui->r + dr[i], ui->c + dc[i], w, h)) {
                 ui->r += dr[i];
                 ui->c += dc[i];
             }
@@ -1451,7 +1482,7 @@ static int find_errors(const game_state *state, int *report)
         int biggest, canonical;
 
         if (!report) {
-            printf("dfs fail at %d\n", any_white_cell);
+            sfree(dsf);
             goto found_error;
         }