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;
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';
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;
}
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)
#include "latin.h"
-static void assert_f(p)
-{
- assert(p);
-}
-
/* --------------------------------------------------------
* Solver.
*/
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.
#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 */
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. */
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++;
}
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},
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;
#include "puzzles.h"
#include "latin.h" /* contains typedef for digit */
-static void assert_f(p)
-{
- assert(p);
-}
-
/* ----------------------------------------------------------
* Constant and structure definitions
*/
}
#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;
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)
/* 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
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));
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));
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);