~mdw
/
sgt
/
puzzles
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Slight solver speedup by tracking more carefully which block merges
[sgt/puzzles]
/
loopy.c
diff --git
a/loopy.c
b/loopy.c
index
798e54e
..
f0344fe
100644
(file)
--- a/
loopy.c
+++ b/
loopy.c
@@
-512,10
+512,12
@@
static const game_params presets[] = {
{ 15, 15, DIFF_EASY, 0 },
{ 15, 15, DIFF_NORMAL, 0 },
{ 15, 15, DIFF_HARD, 0 },
{ 15, 15, DIFF_EASY, 0 },
{ 15, 15, DIFF_NORMAL, 0 },
{ 15, 15, DIFF_HARD, 0 },
+#ifndef SMALL_SCREEN
{ 30, 20, DIFF_EASY, 0 },
{ 30, 20, DIFF_NORMAL, 0 },
{ 30, 20, DIFF_HARD, 0 }
#endif
{ 30, 20, DIFF_EASY, 0 },
{ 30, 20, DIFF_NORMAL, 0 },
{ 30, 20, DIFF_HARD, 0 }
#endif
+#endif
};
static int game_fetch_preset(int i, char **name, game_params **params)
};
static int game_fetch_preset(int i, char **name, game_params **params)
@@
-1876,10
+1878,7
@@
const static struct dline dlines[] = {
(d==DLINE_DR) ? "DLINE_DR": \
"oops")
(d==DLINE_DR) ? "DLINE_DR": \
"oops")
-static const struct dline *get_dline(enum dline_desc desc)
-{
- return &dlines[desc];
-}
+#define CHECK_DLINE_SENSIBLE(d) assert(dlines[(d)].dx != -1 && dlines[(d)].dy != -1)
/* This will fail an assertion if the directions handed to it are the same, as
* no dline corresponds to that */
/* This will fail an assertion if the directions handed to it are the same, as
* no dline corresponds to that */
@@
-1932,10
+1931,9
@@
static int set_dot_dline(game_state *state, char *dline_array,
static int get_square_dline(game_state *state, char *dline_array,
int i, int j, enum dline_desc desc)
{
static int get_square_dline(game_state *state, char *dline_array,
int i, int j, enum dline_desc desc)
{
- const struct dline *dl = get_dline(desc);
- assert(dl->dx != -1 && dl->dy != -1);
+ CHECK_DLINE_SENSIBLE(desc);
/* fprintf(stderr, "get_square_dline %p [%d,%d] %s\n", dline_array, i, j, DL2STR(desc)); */
/* fprintf(stderr, "get_square_dline %p [%d,%d] %s\n", dline_array, i, j, DL2STR(desc)); */
- return BIT_SET(dline_array[(i+dl
->dx) + (state->w + 1) * (j+dl->
dy)],
+ return BIT_SET(dline_array[(i+dl
ines[desc].dx) + (state->w + 1) * (j+dlines[desc].
dy)],
desc);
}
desc);
}
@@
-1946,10
+1944,9
@@
static int set_square_dline(game_state *state, char *dline_array,
#endif
)
{
#endif
)
{
- const struct dline *dl = get_dline(desc);
int ret;
int ret;
-
assert(dl->dx != -1 && dl->dy != -1
);
- ret = SET_BIT(dline_array[(i+dl
->dx) + (state->w + 1) * (j+dl->
dy)], desc);
+
CHECK_DLINE_SENSIBLE(desc
);
+ ret = SET_BIT(dline_array[(i+dl
ines[desc].dx) + (state->w + 1) * (j+dlines[desc].
dy)], desc);
#ifdef SHOW_WORKING
if (ret)
fprintf(stderr, "set_square_dline %p [%d,%d] %s (%s)\n", dline_array, i, j, DL2STR(desc), reason);
#ifdef SHOW_WORKING
if (ret)
fprintf(stderr, "set_square_dline %p [%d,%d] %s (%s)\n", dline_array, i, j, DL2STR(desc), reason);
@@
-1980,10
+1977,9
@@
static int set_square_opp_dline(game_state *state, char *dline_array,
static int dline_both_unknown(const game_state *state, int i, int j,
enum dline_desc desc)
{
static int dline_both_unknown(const game_state *state, int i, int j,
enum dline_desc desc)
{
- const struct dline *dl = get_dline(desc);
return
return
- (get_line_status_from_point(state, i, j, dl
->
dir1) == LINE_UNKNOWN) &&
- (get_line_status_from_point(state, i, j, dl
->
dir2) == LINE_UNKNOWN);
+ (get_line_status_from_point(state, i, j, dl
ines[desc].
dir1) == LINE_UNKNOWN) &&
+ (get_line_status_from_point(state, i, j, dl
ines[desc].
dir2) == LINE_UNKNOWN);
}
#define SQUARE_DLINES \
}
#define SQUARE_DLINES \
@@
-2143,14
+2139,14
@@
static int square_setboth_in_dline(solver_state *sstate, enum dline_desc dd,
int i, int j, enum line_state line_new)
{
int retval = FALSE;
int i, int j, enum line_state line_new)
{
int retval = FALSE;
- const struct dline
*dl = get_dline(dd)
;
+ const struct dline
dll = dlines[dd], *dl = &dll
;
#if 0
fprintf(stderr, "square_setboth_in_dline %s [%d,%d] to %d\n",
DL2STR(dd), i, j, line_new);
#endif
#if 0
fprintf(stderr, "square_setboth_in_dline %s [%d,%d] to %d\n",
DL2STR(dd), i, j, line_new);
#endif
-
assert(dl->dx != -1 && dl->dy != -1
);
+
CHECK_DLINE_SENSIBLE(dd
);
retval |=
set_line_bydot(sstate, i+dl->dx, j+dl->dy, dl->dir1, line_new);
retval |=
set_line_bydot(sstate, i+dl->dx, j+dl->dy, dl->dir1, line_new);
@@
-2651,7
+2647,6
@@
static int hard_mode_deductions(solver_state *sstate)
enum direction dir1, dir2;
int can1, can2, inv1, inv2;
int diff = DIFF_MAX;
enum direction dir1, dir2;
int can1, can2, inv1, inv2;
int diff = DIFF_MAX;
- const struct dline *dl;
enum dline_desc dd;
FORALL_SQUARES(state, i, j) {
enum dline_desc dd;
FORALL_SQUARES(state, i, j) {
@@
-2774,7
+2769,7
@@
static int hard_mode_deductions(solver_state *sstate)
continue;
FORALL_DOT_DLINES(dd) {
continue;
FORALL_DOT_DLINES(dd) {
-
dl = get_dline(dd)
;
+
const struct dline dll = dlines[dd], *dl = &dll
;
if (i == 0 && (dl->dir1 == LEFT || dl->dir2 == LEFT))
continue;
if (i == w && (dl->dir1 == RIGHT || dl->dir2 == RIGHT))
if (i == 0 && (dl->dir1 == LEFT || dl->dir2 == LEFT))
continue;
if (i == w && (dl->dir1 == RIGHT || dl->dir2 == RIGHT))
@@
-3791,14
+3786,14
@@
static void game_print(drawing *dr, game_state *state, int tilesize)
/*
* Lines. (At the moment, I'm not bothering with crosses.)
*/
/*
* Lines. (At the moment, I'm not bothering with crosses.)
*/
- FORALL_
V
L(state, x, y) {
+ FORALL_
H
L(state, x, y) {
if (RIGHTOF_DOT(state, x, y) == LINE_YES)
draw_rect(dr, BORDER + x * TILE_SIZE,
BORDER + y * TILE_SIZE - LINEWIDTH/2,
TILE_SIZE, (LINEWIDTH/2) * 2 + 1, ink);
}
if (RIGHTOF_DOT(state, x, y) == LINE_YES)
draw_rect(dr, BORDER + x * TILE_SIZE,
BORDER + y * TILE_SIZE - LINEWIDTH/2,
TILE_SIZE, (LINEWIDTH/2) * 2 + 1, ink);
}
- FORALL_
H
L(state, x, y) {
+ FORALL_
V
L(state, x, y) {
if (BELOW_DOT(state, x, y) == LINE_YES)
draw_rect(dr, BORDER + x * TILE_SIZE - LINEWIDTH/2,
BORDER + y * TILE_SIZE,
if (BELOW_DOT(state, x, y) == LINE_YES)
draw_rect(dr, BORDER + x * TILE_SIZE - LINEWIDTH/2,
BORDER + y * TILE_SIZE,
@@
-3811,7
+3806,7
@@
static void game_print(drawing *dr, game_state *state, int tilesize)
#endif
const struct game thegame = {
#endif
const struct game thegame = {
- "Loopy", "games.loopy",
+ "Loopy", "games.loopy",
"loopy",
default_params,
game_fetch_preset,
decode_params,
default_params,
game_fetch_preset,
decode_params,