~mdw
/
sgt
/
puzzles
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix problems with arrow UI with non-square grid.
[sgt/puzzles]
/
tents.c
diff --git
a/tents.c
b/tents.c
index
b29fb22
..
de20300
100644
(file)
--- a/
tents.c
+++ b/
tents.c
@@
-415,8
+415,12
@@
static game_params *custom_params(config_item *cfg)
static char *validate_params(game_params *params, int full)
{
static char *validate_params(game_params *params, int full)
{
- if (params->w < 2 || params->h < 2)
- return "Width and height must both be at least two";
+ /*
+ * Generating anything under 4x4 runs into trouble of one kind
+ * or another.
+ */
+ if (params->w < 4 || params->h < 4)
+ return "Width and height must both be at least four";
return NULL;
}
return NULL;
}
@@
-875,7
+879,7
@@
static int tents_solve(int w, int h, const char *grid, int *numbers,
printf("%s %d forces %s at %d,%d\n",
step==1 ? "row" : "column",
step==1 ? start/w : start,
printf("%s %d forces %s at %d,%d\n",
step==1 ? "row" : "column",
step==1 ? start/w : start,
- m
row
[j] == TENT ? "tent" : "non-tent",
+ m
this
[j] == TENT ? "tent" : "non-tent",
pos % w, pos / w);
#endif
soln[pos] = mthis[j];
pos % w, pos / w);
#endif
soln[pos] = mthis[j];
@@
-916,7
+920,7
@@
static char *new_game_desc(game_params *params, random_state *rs,
char *puzzle = snewn(w*h, char);
int *numbers = snewn(w+h, int);
char *soln = snewn(w*h, char);
char *puzzle = snewn(w*h, char);
int *numbers = snewn(w+h, int);
char *soln = snewn(w*h, char);
- int *temp = snewn(2*w*h, int)
, *itemp = temp + w*h
;
+ int *temp = snewn(2*w*h, int);
int maxedges = ntrees*4 + w*h;
int *edges = snewn(2*maxedges, int);
int *capacity = snewn(maxedges, int);
int maxedges = ntrees*4 + w*h;
int *edges = snewn(2*maxedges, int);
int *capacity = snewn(maxedges, int);
@@
-962,9
+966,9
@@
static char *new_game_desc(game_params *params, random_state *rs,
* The maxflow algorithm is not randomised, so employed naively
* it would give rise to grids with clear structure and
* directional bias. Hence, I assign the network nodes as seen
* The maxflow algorithm is not randomised, so employed naively
* it would give rise to grids with clear structure and
* directional bias. Hence, I assign the network nodes as seen
- * by maxflow to be a _random_ permutation
the squares of the
- *
grid, so that any bias shown by maxflow towards low-numbered
- * nodes is turned into a random bias.
+ * by maxflow to be a _random_ permutation
of the squares of
+ *
the grid, so that any bias shown by maxflow towards
+ *
low-numbered
nodes is turned into a random bias.
*
* This generation strategy can fail at many points, including
* as early as tent placement (if you get a bad random order in
*
* This generation strategy can fail at many points, including
* as early as tent placement (if you get a bad random order in
@@
-979,16
+983,16
@@
static char *new_game_desc(game_params *params, random_state *rs,
* trouble.
*/
* trouble.
*/
+ if (params->diff > DIFF_EASY && params->w <= 4 && params->h <= 4)
+ params->diff = DIFF_EASY; /* downgrade to prevent tight loop */
+
while (1) {
/*
while (1) {
/*
- * Arrange the grid squares into a random order, and invert
- * that order so we can find a square's index as well.
+ * Arrange the grid squares into a random order.
*/
for (i = 0; i < w*h; i++)
temp[i] = i;
shuffle(temp, w*h, sizeof(*temp), rs);
*/
for (i = 0; i < w*h; i++)
temp[i] = i;
shuffle(temp, w*h, sizeof(*temp), rs);
- for (i = 0; i < w*h; i++)
- itemp[temp[i]] = i;
/*
* The first `ntrees' entries in temp which we can get
/*
* The first `ntrees' entries in temp which we can get
@@
-1562,7
+1566,7
@@
static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
ymin = min(ui->dsy, ui->dey);
ymax = max(ui->dsy, ui->dey);
assert(0 <= xmin && xmin <= xmax && xmax < w);
ymin = min(ui->dsy, ui->dey);
ymax = max(ui->dsy, ui->dey);
assert(0 <= xmin && xmin <= xmax && xmax < w);
- assert(0 <= ymin && ymin <= ymax && ymax <
w
);
+ assert(0 <= ymin && ymin <= ymax && ymax <
h
);
buflen = 0;
bufsize = 256;
buflen = 0;
bufsize = 256;
@@
-1573,8
+1577,8
@@
static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
int v = drag_xform(ui, x, y, state->grid[y*w+x]);
if (state->grid[y*w+x] != v) {
tmplen = sprintf(tmpbuf, "%s%c%d,%d", sep,
int v = drag_xform(ui, x, y, state->grid[y*w+x]);
if (state->grid[y*w+x] != v) {
tmplen = sprintf(tmpbuf, "%s%c%d,%d", sep,
- (v == BLANK ? 'B' :
- v == TENT ? 'T' : 'N'),
+ (
int)(
v == BLANK ? 'B' :
+
v == TENT ? 'T' : 'N'),
x, y);
sep = ";";
x, y);
sep = ";";
@@
-1806,7
+1810,7
@@
static void game_set_size(drawing *dr, game_drawstate *ds,
ds->tilesize = tilesize;
}
ds->tilesize = tilesize;
}
-static float *game_colours(frontend *fe,
game_state *state,
int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
{
float *ret = snewn(3 * NCOLOURS, float);
{
float *ret = snewn(3 * NCOLOURS, float);
@@
-1972,7
+1976,7
@@
static void int_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
* marginally nicer not to have the drag effects
* flickering on and off disconcertingly.
*/
* marginally nicer not to have the drag effects
* flickering on and off disconcertingly.
*/
- if (ui->drag_button >= 0)
+ if (ui
&& ui
->drag_button >= 0)
v = drag_xform(ui, x, y, v);
if (flashing && (v == TREE || v == TENT))
v = drag_xform(ui, x, y, v);
if (flashing && (v == TREE || v == TENT))
@@
-2009,11
+2013,6
@@
static float game_flash_length(game_state *oldstate, game_state *newstate,
return 0.0F;
}
return 0.0F;
}
-static int game_wants_statusbar(void)
-{
- return FALSE;
-}
-
static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
static int game_timing_state(game_state *state, game_ui *ui)
{
return TRUE;
@@
-2054,7
+2053,7
@@
static void game_print(drawing *dr, game_state *state, int tilesize)
#endif
const struct game thegame = {
#endif
const struct game thegame = {
- "Tents", "games.tents",
+ "Tents", "games.tents",
"tents",
default_params,
game_fetch_preset,
decode_params,
default_params,
game_fetch_preset,
decode_params,
@@
-2085,9
+2084,9
@@
const struct game thegame = {
game_anim_length,
game_flash_length,
TRUE, FALSE, game_print_size, game_print,
game_anim_length,
game_flash_length,
TRUE, FALSE, game_print_size, game_print,
- game_wants_statusbar,
+ FALSE, /* wants_statusbar */
FALSE, game_timing_state,
FALSE, game_timing_state,
-
0, /* mouse_prioritie
s */
+
REQUIRE_RBUTTON, /* flag
s */
};
#ifdef STANDALONE_SOLVER
};
#ifdef STANDALONE_SOLVER