mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
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]
This commit is contained in:
@ -299,7 +299,7 @@ static game_state *new_game(midend *, game_params *, char *);
|
|||||||
static void free_game(game_state *);
|
static void free_game(game_state *);
|
||||||
|
|
||||||
/* generate a random valid board; uses validate_board. */
|
/* 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;
|
int *dsf;
|
||||||
|
|
||||||
const unsigned int sz = w * h;
|
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)
|
static game_state *execute_move(game_state *state, char *move)
|
||||||
{
|
{
|
||||||
game_state *new_state;
|
game_state *new_state;
|
||||||
|
const int sz = state->shared->params.w * state->shared->params.h;
|
||||||
|
|
||||||
if (*move == 's') {
|
if (*move == 's') {
|
||||||
const int sz = state->shared->params.w * state->shared->params.h;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
new_state = dup_game(state);
|
new_state = dup_game(state);
|
||||||
for (++move; i < sz; ++i) new_state->board[i] = move[i] - '0';
|
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);
|
value = strtol(move, &endptr, 0);
|
||||||
if (endptr == move) return NULL;
|
if (endptr == move) return NULL;
|
||||||
if (*endptr != '\0') 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 = dup_game(state);
|
||||||
new_state->board[i] = value;
|
new_state->board[i] = value;
|
||||||
}
|
}
|
||||||
|
@ -298,8 +298,8 @@ static void add_assoc(game_state *state, space *tile, space *dot) {
|
|||||||
tile->dotx = dot->x;
|
tile->dotx = dot->x;
|
||||||
tile->doty = dot->y;
|
tile->doty = dot->y;
|
||||||
dot->nassoc++;
|
dot->nassoc++;
|
||||||
debug(("add_assoc sp %d %d --> dot %d,%d, new nassoc %d.\n",
|
/*debug(("add_assoc sp %d %d --> dot %d,%d, new nassoc %d.\n",
|
||||||
tile->x, tile->y, dot->x, dot->y, dot->nassoc));
|
tile->x, tile->y, dot->x, dot->y, dot->nassoc));*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct space *sp2dot(game_state *state, int x, int y)
|
static struct space *sp2dot(game_state *state, int x, int y)
|
||||||
|
14
latin.c
14
latin.c
@ -12,11 +12,6 @@
|
|||||||
|
|
||||||
#include "latin.h"
|
#include "latin.h"
|
||||||
|
|
||||||
static void assert_f(p)
|
|
||||||
{
|
|
||||||
assert(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------
|
/* --------------------------------------------------------
|
||||||
* Solver.
|
* Solver.
|
||||||
*/
|
*/
|
||||||
@ -31,7 +26,7 @@ void latin_solver_place(struct latin_solver *solver, int x, int y, int n)
|
|||||||
int i, o = solver->o;
|
int i, o = solver->o;
|
||||||
|
|
||||||
assert(n <= o);
|
assert(n <= o);
|
||||||
assert_f(cube(x,y,n));
|
assert(cube(x,y,n));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Rule out all other numbers in this square.
|
* Rule out all other numbers in this square.
|
||||||
@ -961,7 +956,7 @@ void latin_solver_debug(unsigned char *cube, int o)
|
|||||||
#ifdef STANDALONE_SOLVER
|
#ifdef STANDALONE_SOLVER
|
||||||
if (solver_show_working) {
|
if (solver_show_working) {
|
||||||
struct latin_solver ls, *solver = &ls;
|
struct latin_solver ls, *solver = &ls;
|
||||||
unsigned char *dbg;
|
char *dbg;
|
||||||
int x, y, i, c = 0;
|
int x, y, i, c = 0;
|
||||||
|
|
||||||
ls.cube = cube; ls.o = o; /* for cube() to work */
|
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);
|
tree234 *dict = newtree234(latin_check_cmp);
|
||||||
int c, r;
|
int c, r;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
lcparams *lcp, lc;
|
lcparams *lcp, lc, *aret;
|
||||||
|
|
||||||
/* Use a tree234 as a simple hash table, go through the square
|
/* Use a tree234 as a simple hash table, go through the square
|
||||||
* adding elements as we go or incrementing their counts. */
|
* adding elements as we go or incrementing their counts. */
|
||||||
@ -1193,7 +1188,8 @@ int latin_check(digit *sq, int order)
|
|||||||
lcp = snew(lcparams);
|
lcp = snew(lcparams);
|
||||||
lcp->elt = ELT(sq, c, r);
|
lcp->elt = ELT(sq, c, r);
|
||||||
lcp->count = 1;
|
lcp->count = 1;
|
||||||
assert_f(add234(dict, lcp) == lcp);
|
aret = add234(dict, lcp);
|
||||||
|
assert(aret == lcp);
|
||||||
} else {
|
} else {
|
||||||
lcp->count++;
|
lcp->count++;
|
||||||
}
|
}
|
||||||
|
2
map.c
2
map.c
@ -2532,7 +2532,7 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
|
|||||||
|
|
||||||
const float map_colours[FOUR][3] = {
|
const float map_colours[FOUR][3] = {
|
||||||
#ifdef VIVID_COLOURS
|
#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.75F, 0.25F, 0.25F},
|
||||||
{0.3F, 0.7F, 0.3F},
|
{0.3F, 0.7F, 0.3F},
|
||||||
{0.3F, 0.3F, 0.7F},
|
{0.3F, 0.3F, 0.7F},
|
||||||
|
11
pattern.c
11
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 &&
|
if (x >= 0 && x < state->w && y >= 0 && y < state->h &&
|
||||||
(button == LEFT_BUTTON || button == RIGHT_BUTTON ||
|
(button == LEFT_BUTTON || button == RIGHT_BUTTON ||
|
||||||
button == MIDDLE_BUTTON)) {
|
button == MIDDLE_BUTTON)) {
|
||||||
|
#ifdef STYLUS_BASED
|
||||||
|
int currstate = state->grid[y * state->w + x];
|
||||||
|
#endif
|
||||||
|
|
||||||
ui->dragging = TRUE;
|
ui->dragging = TRUE;
|
||||||
|
|
||||||
if (button == LEFT_BUTTON) {
|
if (button == LEFT_BUTTON) {
|
||||||
ui->drag = LEFT_DRAG;
|
ui->drag = LEFT_DRAG;
|
||||||
ui->release = LEFT_RELEASE;
|
ui->release = LEFT_RELEASE;
|
||||||
|
#ifdef STYLUS_BASED
|
||||||
|
ui->state = currstate == GRID_FULL ? GRID_UNKNOWN : GRID_FULL;
|
||||||
|
#else
|
||||||
ui->state = GRID_FULL;
|
ui->state = GRID_FULL;
|
||||||
|
#endif
|
||||||
} else if (button == RIGHT_BUTTON) {
|
} else if (button == RIGHT_BUTTON) {
|
||||||
ui->drag = RIGHT_DRAG;
|
ui->drag = RIGHT_DRAG;
|
||||||
ui->release = RIGHT_RELEASE;
|
ui->release = RIGHT_RELEASE;
|
||||||
|
#ifdef STYLUS_BASED
|
||||||
|
ui->state = currstate == GRID_EMPTY ? GRID_UNKNOWN : GRID_EMPTY;
|
||||||
|
#else
|
||||||
ui->state = GRID_EMPTY;
|
ui->state = GRID_EMPTY;
|
||||||
|
#endif
|
||||||
} else /* if (button == MIDDLE_BUTTON) */ {
|
} else /* if (button == MIDDLE_BUTTON) */ {
|
||||||
ui->drag = MIDDLE_DRAG;
|
ui->drag = MIDDLE_DRAG;
|
||||||
ui->release = MIDDLE_RELEASE;
|
ui->release = MIDDLE_RELEASE;
|
||||||
|
22
unequal.c
22
unequal.c
@ -26,11 +26,6 @@
|
|||||||
#include "puzzles.h"
|
#include "puzzles.h"
|
||||||
#include "latin.h" /* contains typedef for digit */
|
#include "latin.h" /* contains typedef for digit */
|
||||||
|
|
||||||
static void assert_f(p)
|
|
||||||
{
|
|
||||||
assert(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------
|
/* ----------------------------------------------------------
|
||||||
* Constant and structure definitions
|
* Constant and structure definitions
|
||||||
*/
|
*/
|
||||||
@ -885,7 +880,7 @@ static int gg_best_clue(game_state *state, int *scratch, digit *latin)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (i = 0; i < ls; i++) {
|
for (i = ls; i-- > 0 ;) {
|
||||||
if (!gg_place_clue(state, scratch[i], latin, 1)) continue;
|
if (!gg_place_clue(state, scratch[i], latin, 1)) continue;
|
||||||
|
|
||||||
loc = scratch[i] / 5;
|
loc = scratch[i] / 5;
|
||||||
@ -976,7 +971,8 @@ static void game_strip(game_state *new, int *scratch, digit *latin,
|
|||||||
gg_solved++;
|
gg_solved++;
|
||||||
if (solver_state(copy, difficulty) != 1) {
|
if (solver_state(copy, difficulty) != 1) {
|
||||||
/* put clue back, we can't solve without it. */
|
/* 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 {
|
} else {
|
||||||
#ifdef STANDALONE_SOLVER
|
#ifdef STANDALONE_SOLVER
|
||||||
if (solver_show_working)
|
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) */
|
/* Generate a list of 'things to strip' (randomised later) */
|
||||||
scratch = snewn(lscratch, int);
|
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:
|
generate:
|
||||||
#ifdef STANDALONE_SOLVER
|
#ifdef STANDALONE_SOLVER
|
||||||
@ -1018,7 +1015,9 @@ generate:
|
|||||||
if (sq) sfree(sq);
|
if (sq) sfree(sq);
|
||||||
sq = latin_generate(params->order, rs);
|
sq = latin_generate(params->order, rs);
|
||||||
latin_debug(sq, params->order);
|
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->nums, 0, o2 * sizeof(digit));
|
||||||
memset(state->flags, 0, o2 * sizeof(unsigned int));
|
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)
|
static game_state *execute_move(game_state *state, char *move)
|
||||||
{
|
{
|
||||||
game_state *ret = NULL;
|
game_state *ret = NULL;
|
||||||
int x, y, n, i;
|
int x, y, n, i, rc;
|
||||||
|
|
||||||
debug(("execute_move: %s", move));
|
debug(("execute_move: %s", move));
|
||||||
|
|
||||||
@ -1360,7 +1359,8 @@ static game_state *execute_move(game_state *state, char *move)
|
|||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
if (*p) goto badmove;
|
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;
|
return ret;
|
||||||
} else if (move[0] == 'H') {
|
} else if (move[0] == 'H') {
|
||||||
return solver_hint(state, NULL, DIFF_EASY, DIFF_EASY);
|
return solver_hint(state, NULL, DIFF_EASY, DIFF_EASY);
|
||||||
|
Reference in New Issue
Block a user