~ubuntu-branches/ubuntu/maverick/sgt-puzzles/maverick

« back to all changes in this revision

Viewing changes to debian/patches/204_loopy-show-more-errors.diff

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-05-03 14:54:23 UTC
  • mfrom: (1.1.7 upstream) (3.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090503145423-o4d0ubd8ocykbad8
Tags: 8446-1ubuntu1
* Merge from debian unstable, remaining changes:
  - typos in debian/desktop/netslide.desktop (Exec=netslide)
  - xpm icons files for the menus
  - debian/rules adapted to install desktop and icons files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
--- trunk.orig/loopy.c
2
 
+++ trunk/loopy.c
3
 
@@ -149,6 +149,7 @@
4
 
     int flashing;
5
 
     char *hl, *vl;
6
 
     char *clue_error;
7
 
+    char *hl_error, *vl_error;
8
 
 };
9
 
 
10
 
 static char *game_text_format(game_state *state);
11
 
@@ -838,17 +839,21 @@
12
 
     ds->hl = snewn(HL_COUNT(state), char);
13
 
     ds->vl = snewn(VL_COUNT(state), char);
14
 
     ds->clue_error = snewn(SQUARE_COUNT(state), char);
15
 
+    ds->hl_error = snewn(LINE_COUNT(state), char);
16
 
+    ds->vl_error = ds->hl_error + HL_COUNT(state);
17
 
     ds->flashing = 0;
18
 
 
19
 
     memset(ds->hl, LINE_UNKNOWN, HL_COUNT(state));
20
 
     memset(ds->vl, LINE_UNKNOWN, VL_COUNT(state));
21
 
     memset(ds->clue_error, 0, SQUARE_COUNT(state));
22
 
+    memset(ds->hl_error, 0, LINE_COUNT(state));
23
 
 
24
 
     return ds;
25
 
 }
26
 
 
27
 
 static void game_free_drawstate(drawing *dr, game_drawstate *ds)
28
 
 {
29
 
+    sfree(ds->hl_error);
30
 
     sfree(ds->clue_error);
31
 
     sfree(ds->hl);
32
 
     sfree(ds->vl);
33
 
@@ -3264,6 +3269,37 @@
34
 
  * Drawing and mouse-handling
35
 
  */
36
 
 
37
 
+static int follow_line(game_state *state, int *prevdir, int *x, int *y,
38
 
+                       int *looplen)
39
 
+{
40
 
+    if (dot_order(state, *x, *y, LINE_YES) != 2) {
41
 
+        *looplen = 0;
42
 
+        return FALSE;
43
 
+    }
44
 
+
45
 
+    if (LEFTOF_DOT(state, *x, *y) == LINE_YES && *prevdir != 'L') {
46
 
+        (*x)--;
47
 
+        *prevdir = 'R';
48
 
+    } else if (RIGHTOF_DOT(state, *x, *y) == LINE_YES &&
49
 
+               *prevdir != 'R') {
50
 
+        (*x)++;
51
 
+        *prevdir = 'L';
52
 
+    } else if (ABOVE_DOT(state, *x, *y) == LINE_YES &&
53
 
+               *prevdir != 'U') {
54
 
+        (*y)--;
55
 
+        *prevdir = 'D';
56
 
+    } else if (BELOW_DOT(state, *x, *y) == LINE_YES && 
57
 
+               *prevdir != 'D') {
58
 
+        (*y)++;
59
 
+        *prevdir = 'U';
60
 
+    } else {
61
 
+        assert(!"Can't happen");   /* dot_order guarantees success */
62
 
+    }
63
 
+
64
 
+    (*looplen)++;
65
 
+    return TRUE;
66
 
+}
67
 
+
68
 
 static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
69
 
                             int x, int y, int button)
70
 
 {
71
 
@@ -3443,38 +3479,9 @@
72
 
          * to see if it's part of a loop.
73
 
          */
74
 
         looplen = 0;
75
 
-        while (1) {
76
 
-            int order = dot_order(newstate, x, y, LINE_YES);
77
 
-            if (order != 2)
78
 
-                goto completion_check_done;
79
 
-
80
 
-            if (LEFTOF_DOT(newstate, x, y) == LINE_YES && prevdir != 'L') {
81
 
-                x--;
82
 
-                prevdir = 'R';
83
 
-            } else if (RIGHTOF_DOT(newstate, x, y) == LINE_YES &&
84
 
-                       prevdir != 'R') {
85
 
-                x++;
86
 
-                prevdir = 'L';
87
 
-            } else if (ABOVE_DOT(newstate, x, y) == LINE_YES &&
88
 
-                       prevdir != 'U') {
89
 
-                y--;
90
 
-                prevdir = 'D';
91
 
-            } else if (BELOW_DOT(newstate, x, y) == LINE_YES && 
92
 
-                       prevdir != 'D') {
93
 
-                y++;
94
 
-                prevdir = 'U';
95
 
-            } else {
96
 
-                assert(!"Can't happen");   /* dot_order guarantees success */
97
 
-            }
98
 
-
99
 
-            looplen++;
100
 
-
101
 
-            if (x == i && y == j)
102
 
-                break;
103
 
-        }
104
 
-
105
 
-        if (x != i || y != j || looplen == 0)
106
 
-            goto completion_check_done;
107
 
+        while (follow_line(newstate, &prevdir, &x, &y, &looplen) &&
108
 
+               !(x == i && y == j))
109
 
+            ;
110
 
 
111
 
         /*
112
 
          * We've traced our way round a loop, and we know how many
113
 
@@ -3529,6 +3536,8 @@
114
 
     char c[2];
115
 
     int line_colour, flash_changed;
116
 
     int clue_mistake;
117
 
+    int has_loop;
118
 
+    char *old_hl_error, *old_vl_error;
119
 
 
120
 
     if (!ds->started) {
121
 
         /*
122
 
@@ -3575,6 +3584,69 @@
123
 
         line_colour = COL_FOREGROUND;
124
 
     }
125
 
 
126
 
+    old_hl_error = ds->hl_error;
127
 
+    old_vl_error = ds->vl_error;
128
 
+    ds->hl_error = snewn(LINE_COUNT(state), char);
129
 
+    ds->vl_error = ds->hl_error + HL_COUNT(state);
130
 
+    memset(ds->hl_error, 0, LINE_COUNT(state));
131
 
+
132
 
+    if (state->solved) {
133
 
+        has_loop = TRUE;
134
 
+    } else {
135
 
+        /* Highlight non-solution loops as errors */
136
 
+        has_loop = FALSE;
137
 
+        for (j = 0; j <= state->h; j++) {
138
 
+            for (i = 0; i < state->w; i++) {
139
 
+                if (!ds->hl_error[HL_INDEX(state, i, j)] &&
140
 
+                    RIGHTOF_DOT(state, i, j) == LINE_YES) {
141
 
+                    int prevdir = 'R';
142
 
+                    int x = i, y = j;
143
 
+                    int looplen = 0;
144
 
+
145
 
+                    while (follow_line(state, &prevdir, &x, &y, &looplen) &&
146
 
+                           !(x == i && y == j))
147
 
+                        ;
148
 
+                    if (looplen != 0) {
149
 
+                        has_loop = TRUE;
150
 
+                        do {
151
 
+                            follow_line(state, &prevdir, &x, &y, &looplen);
152
 
+                            switch (prevdir) {
153
 
+                            case 'R':
154
 
+                                ds->hl_error[HL_INDEX(state, x, y)] = TRUE;
155
 
+                                break;
156
 
+                            case 'L':
157
 
+                                ds->hl_error[HL_INDEX(state, x - 1, y)] = TRUE;
158
 
+                                break;
159
 
+                            case 'D':
160
 
+                                ds->vl_error[VL_INDEX(state, x, y)] = TRUE;
161
 
+                                break;
162
 
+                            case 'U':
163
 
+                                ds->vl_error[VL_INDEX(state, x, y - 1)] = TRUE;
164
 
+                                break;
165
 
+                            }
166
 
+                        } while (!(x == i && y == j));
167
 
+                    }
168
 
+                }
169
 
+            }
170
 
+        }
171
 
+
172
 
+        /* Highlight dots with >2 lines as errors */
173
 
+        for (j = 0; j <= state->h; j++) {
174
 
+            for (i = 0; i <= state->w; i++) {
175
 
+                if (dot_order(state, i, j, LINE_YES) > 2) {
176
 
+                    if (RIGHTOF_DOT(state, i, j) == LINE_YES)
177
 
+                        ds->hl_error[HL_INDEX(state, i, j)] = TRUE;
178
 
+                    if (LEFTOF_DOT(state, i, j) == LINE_YES)
179
 
+                        ds->hl_error[HL_INDEX(state, i - 1, j)] = TRUE;
180
 
+                    if (BELOW_DOT(state, i, j) == LINE_YES)
181
 
+                        ds->vl_error[VL_INDEX(state, i, j)] = TRUE;
182
 
+                    if (ABOVE_DOT(state, i, j) == LINE_YES)
183
 
+                        ds->vl_error[VL_INDEX(state, i, j - 1)] = TRUE;
184
 
+                }
185
 
+            }
186
 
+        }
187
 
+    }
188
 
+
189
 
 #define CROSS_SIZE (3 * LINEWIDTH / 2)
190
 
     
191
 
     /* Redraw clue colours if necessary */
192
 
@@ -3588,8 +3660,11 @@
193
 
         c[0] = CLUE2CHAR(CLUE_AT(state, i, j));
194
 
         c[1] = '\0';
195
 
 
196
 
-        clue_mistake = (square_order(state, i, j, LINE_YES) > n ||
197
 
-                        square_order(state, i, j, LINE_NO ) > (4-n));
198
 
+        if (has_loop)
199
 
+            clue_mistake = square_order(state, i, j, LINE_YES) != n;
200
 
+        else
201
 
+            clue_mistake = (square_order(state, i, j, LINE_YES) > n ||
202
 
+                            square_order(state, i, j, LINE_NO ) > (4-n));
203
 
 
204
 
         if (clue_mistake != ds->clue_error[SQUARE_INDEX(state, i, j)]) {
205
 
             draw_rect(dr, 
206
 
@@ -3610,10 +3685,6 @@
207
 
         }
208
 
     }
209
 
 
210
 
-    /* I've also had a request to colour lines red if they make a non-solution
211
 
-     * loop, or if more than two lines go into any point.  I think that would
212
 
-     * be good some time. */
213
 
-
214
 
 #define CLEAR_VL(i, j) \
215
 
     do { \
216
 
        draw_rect(dr, \
217
 
@@ -3654,13 +3725,16 @@
218
 
                 break;
219
 
             case LINE_YES:
220
 
                 if (ds->vl[VL_INDEX(state, i, j)] != BELOW_DOT(state, i, j) ||
221
 
+                    ds->vl_error[VL_INDEX(state, i, j)] !=
222
 
+                    old_vl_error[VL_INDEX(state, i, j)] ||
223
 
                     flash_changed) {
224
 
                     CLEAR_VL(i, j);
225
 
                     draw_rect(dr,
226
 
                               BORDER + i * TILE_SIZE - LINEWIDTH/2,
227
 
                               BORDER + j * TILE_SIZE + LINEWIDTH - LINEWIDTH/2,
228
 
                               LINEWIDTH, TILE_SIZE - LINEWIDTH, 
229
 
-                              line_colour);
230
 
+                              ds->vl_error[VL_INDEX(state, i, j)] ?
231
 
+                              COL_MISTAKE : line_colour);
232
 
                 }
233
 
                 break;
234
 
             case LINE_NO:
235
 
@@ -3694,13 +3768,16 @@
236
 
                 break;
237
 
             case LINE_YES:
238
 
                 if (ds->hl[HL_INDEX(state, i, j)] != RIGHTOF_DOT(state, i, j) ||
239
 
+                    ds->hl_error[HL_INDEX(state, i, j)] !=
240
 
+                    old_hl_error[HL_INDEX(state, i, j)] ||
241
 
                     flash_changed) {
242
 
                     CLEAR_HL(i, j);
243
 
                     draw_rect(dr,
244
 
                               BORDER + i * TILE_SIZE + LINEWIDTH - LINEWIDTH/2,
245
 
                               BORDER + j * TILE_SIZE - LINEWIDTH/2,
246
 
                               TILE_SIZE - LINEWIDTH, LINEWIDTH, 
247
 
-                              line_colour);
248
 
+                              ds->hl_error[HL_INDEX(state, i, j)] ?
249
 
+                              COL_MISTAKE : line_colour);
250
 
                 }
251
 
                 break; 
252
 
             case LINE_NO:
253
 
@@ -3723,6 +3800,8 @@
254
 
         }
255
 
         ds->hl[HL_INDEX(state, i, j)] = RIGHTOF_DOT(state, i, j);
256
 
     }
257
 
+
258
 
+    sfree(old_hl_error);
259
 
 }
260
 
 
261
 
 static float game_flash_length(game_state *oldstate, game_state *newstate,