chiark / gitweb /
General cleanups patch from James H:
authorSimon Tatham <anakin@pobox.com>
Wed, 28 Feb 2007 21:19:15 +0000 (21:19 +0000)
committerSimon Tatham <anakin@pobox.com>
Wed, 28 Feb 2007 21:19:15 +0000 (21:19 +0000)
 - missing static in filling.c
 - better robustness in execute_move() in filling.c
 - remove side effects in assert statements
 - remove rogue diagnostic in galaxies.c
 - remove // comment in map.c
 - add more stylus-friendly UI to Pattern
 - bias Unequal towards generating inequality clues rather than numeric

[originally from svn r7344]

filling.c
galaxies.c
latin.c
map.c
pattern.c
unequal.c

index 1ce04eb3aadcba5d0504cf24a90dd298ba1dddfa..b9dff73099624c070377b14b03c896ce0c0769c3 100644 (file)
--- a/filling.c
+++ b/filling.c
@@ -299,7 +299,7 @@ static game_state *new_game(midend *, game_params *, char *);
 static void free_game(game_state *);
 
 /* generate a random valid board; uses validate_board.  */
-void make_board(int *board, int w, int h, random_state *rs) {
+static void make_board(int *board, int w, int h, random_state *rs) {
     int *dsf;
 
     const unsigned int sz = w * h;
@@ -974,9 +974,9 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
 static game_state *execute_move(game_state *state, char *move)
 {
     game_state *new_state;
+    const int sz = state->shared->params.w * state->shared->params.h;
 
     if (*move == 's') {
-        const int sz = state->shared->params.w * state->shared->params.h;
         int i = 0;
         new_state = dup_game(state);
         for (++move; i < sz; ++i) new_state->board[i] = move[i] - '0';
@@ -991,6 +991,7 @@ static game_state *execute_move(game_state *state, char *move)
         value = strtol(move, &endptr, 0);
         if (endptr == move) return NULL;
         if (*endptr != '\0') return NULL;
+        if (i < 0 || i >= sz || value < 0 || value > 9) return NULL;
         new_state = dup_game(state);
         new_state->board[i] = value;
     }
index 4c69de0b44ccaca50ae51a095f85fb904325007a..6989fe360fd46a275b8c2ba7469eea1d9a8ae8ec 100644 (file)
@@ -298,8 +298,8 @@ static void add_assoc(game_state *state, space *tile, space *dot) {
     tile->dotx = dot->x;
     tile->doty = dot->y;
     dot->nassoc++;
-    debug(("add_assoc sp %d %d --> dot %d,%d, new nassoc %d.\n",
-           tile->x, tile->y, dot->x, dot->y, dot->nassoc));
+    /*debug(("add_assoc sp %d %d --> dot %d,%d, new nassoc %d.\n",
+           tile->x, tile->y, dot->x, dot->y, dot->nassoc));*/
 }
 
 static struct space *sp2dot(game_state *state, int x, int y)
diff --git a/latin.c b/latin.c
index dc2af8f9dc8ded5b9655ca0d4d67a1fa00bd8ebd..bfed6714ec07d3f5cc09f8c91a8ccaa94c356375 100644 (file)
--- a/latin.c
+++ b/latin.c
 
 #include "latin.h"
 
-static void assert_f(p)
-{
-    assert(p);
-}
-
 /* --------------------------------------------------------
  * Solver.
  */
@@ -31,7 +26,7 @@ void latin_solver_place(struct latin_solver *solver, int x, int y, int n)
     int i, o = solver->o;
 
     assert(n <= o);
-    assert_f(cube(x,y,n));
+    assert(cube(x,y,n));
 
     /*
      * Rule out all other numbers in this square.
@@ -961,7 +956,7 @@ void latin_solver_debug(unsigned char *cube, int o)
 #ifdef STANDALONE_SOLVER
     if (solver_show_working) {
         struct latin_solver ls, *solver = &ls;
-        unsigned char *dbg;
+        char *dbg;
         int x, y, i, c = 0;
 
         ls.cube = cube; ls.o = o; /* for cube() to work */
@@ -1181,7 +1176,7 @@ int latin_check(digit *sq, int order)
     tree234 *dict = newtree234(latin_check_cmp);
     int c, r;
     int ret = 0;
-    lcparams *lcp, lc;
+    lcparams *lcp, lc, *aret;
 
     /* Use a tree234 as a simple hash table, go through the square
      * adding elements as we go or incrementing their counts. */
@@ -1193,7 +1188,8 @@ int latin_check(digit *sq, int order)
                lcp = snew(lcparams);
                lcp->elt = ELT(sq, c, r);
                lcp->count = 1;
-               assert_f(add234(dict, lcp) == lcp);
+                aret = add234(dict, lcp);
+               assert(aret == lcp);
            } else {
                lcp->count++;
            }
diff --git a/map.c b/map.c
index b6b61947372c23605c545949518c7b29786f8635..da3c4bacb2dd013fc377905e033b5e5a34847a87 100644 (file)
--- a/map.c
+++ b/map.c
@@ -2532,7 +2532,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
 
 const float map_colours[FOUR][3] = {
 #ifdef VIVID_COLOURS
-    // Use more vivid colours (e.g. on the Pocket PC)
+    /* Use more vivid colours (e.g. on the Pocket PC) */
     {0.75F, 0.25F, 0.25F},
     {0.3F,  0.7F,  0.3F},
     {0.3F,  0.3F,  0.7F},
index 2c24ad259a493f14782a231344d13d7cdcc96852..740f434bbdb11d6e69002b9e48a30e209a120fc3 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -789,17 +789,28 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
     if (x >= 0 && x < state->w && y >= 0 && y < state->h &&
         (button == LEFT_BUTTON || button == RIGHT_BUTTON ||
          button == MIDDLE_BUTTON)) {
+#ifdef STYLUS_BASED
+        int currstate = state->grid[y * state->w + x];
+#endif
 
         ui->dragging = TRUE;
 
         if (button == LEFT_BUTTON) {
             ui->drag = LEFT_DRAG;
             ui->release = LEFT_RELEASE;
+#ifdef STYLUS_BASED
+            ui->state = currstate == GRID_FULL ? GRID_UNKNOWN : GRID_FULL;
+#else
             ui->state = GRID_FULL;
+#endif
         } else if (button == RIGHT_BUTTON) {
             ui->drag = RIGHT_DRAG;
             ui->release = RIGHT_RELEASE;
+#ifdef STYLUS_BASED
+            ui->state = currstate == GRID_EMPTY ? GRID_UNKNOWN : GRID_EMPTY;
+#else
             ui->state = GRID_EMPTY;
+#endif
         } else /* if (button == MIDDLE_BUTTON) */ {
             ui->drag = MIDDLE_DRAG;
             ui->release = MIDDLE_RELEASE;
index 8006ea1f1a3614917678cd0f1466270e1c630e20..c8059758e973814ea6da4e243aedefe8250c6ddb 100644 (file)
--- a/unequal.c
+++ b/unequal.c
 #include "puzzles.h"
 #include "latin.h" /* contains typedef for digit */
 
-static void assert_f(p)
-{
-    assert(p);
-}
-
 /* ----------------------------------------------------------
  * Constant and structure definitions
  */
@@ -885,7 +880,7 @@ static int gg_best_clue(game_state *state, int *scratch, digit *latin)
     }
 #endif
 
-    for (i = 0; i < ls; i++) {
+    for (i = ls; i-- > 0 ;) {
         if (!gg_place_clue(state, scratch[i], latin, 1)) continue;
 
         loc = scratch[i] / 5;
@@ -976,7 +971,8 @@ static void game_strip(game_state *new, int *scratch, digit *latin,
         gg_solved++;
         if (solver_state(copy, difficulty) != 1) {
             /* put clue back, we can't solve without it. */
-            assert_f(gg_place_clue(new, scratch[i], latin, 0) == 1);
+            int ret = gg_place_clue(new, scratch[i], latin, 0);
+            assert(ret == 1);
         } else {
 #ifdef STANDALONE_SOLVER
             if (solver_show_working)
@@ -1007,7 +1003,8 @@ static char *new_game_desc(game_params *params, random_state *rs,
 
     /* Generate a list of 'things to strip' (randomised later) */
     scratch = snewn(lscratch, int);
-    for (i = 0; i < lscratch; i++) scratch[i] = i;
+    /* Put the numbers (4 mod 5) before the inequalities (0-3 mod 5) */
+    for (i = 0; i < lscratch; i++) scratch[i] = (i%o2)*5 + 4 - (i/o2);
 
 generate:
 #ifdef STANDALONE_SOLVER
@@ -1018,7 +1015,9 @@ generate:
     if (sq) sfree(sq);
     sq = latin_generate(params->order, rs);
     latin_debug(sq, params->order);
-    shuffle(scratch, lscratch, sizeof(int), rs);
+    /* Separately shuffle the numeric and inequality clues */
+    shuffle(scratch, lscratch/5, sizeof(int), rs);
+    shuffle(scratch+lscratch/5, 4*lscratch/5, sizeof(int), rs);
 
     memset(state->nums, 0, o2 * sizeof(digit));
     memset(state->flags, 0, o2 * sizeof(unsigned int));
@@ -1324,7 +1323,7 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
 static game_state *execute_move(game_state *state, char *move)
 {
     game_state *ret = NULL;
-    int x, y, n, i;
+    int x, y, n, i, rc;
 
     debug(("execute_move: %s", move));
 
@@ -1360,7 +1359,8 @@ static game_state *execute_move(game_state *state, char *move)
             p++;
         }
         if (*p) goto badmove;
-       assert_f(check_complete(ret->nums, ret, 1) > 0);
+        rc = check_complete(ret->nums, ret, 1);
+       assert(rc > 0);
         return ret;
     } else if (move[0] == 'H') {
         return solver_hint(state, NULL, DIFF_EASY, DIFF_EASY);