ref: 9287d95d0810e6fc76625aa270ecdff297934c55
parent: de5ccc9352d0156600c0ed1e87daac28015e8c01
author: Simon Tatham <[email protected]>
date: Wed Feb 28 16:19:15 EST 2007
General cleanups patch from James H: - 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]
--- a/filling.c
+++ b/filling.c
@@ -299,7 +299,7 @@
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 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 @@
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;
}
--- a/galaxies.c
+++ b/galaxies.c
@@ -298,8 +298,8 @@
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)
--- a/latin.c
+++ b/latin.c
@@ -12,11 +12,6 @@
#include "latin.h"
-static void assert_f(p)
-{
- assert(p);
-}
-
/* --------------------------------------------------------
* Solver.
*/
@@ -31,7 +26,7 @@
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 @@
#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 @@
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 @@
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++;
}
--- a/map.c
+++ b/map.c
@@ -2532,7 +2532,7 @@
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},
--- a/pattern.c
+++ b/pattern.c
@@ -789,6 +789,9 @@
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;
@@ -795,11 +798,19 @@
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;
--- a/unequal.c
+++ b/unequal.c
@@ -26,11 +26,6 @@
#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 @@
}
#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 @@
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 @@
/* 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 @@
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 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 @@
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);