#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
COL_SLANT1,
COL_SLANT2,
COL_ERROR,
+ COL_CURSOR,
+ COL_FILLEDSQUARE,
NCOLOURS
};
typedef struct game_clues {
int w, h;
signed char *clues;
- signed char *tmpsoln;
+ int *tmpdsf;
int refcount;
} game_clues;
sfree(params);
}
-static game_params *dup_params(game_params *params)
+static game_params *dup_params(const game_params *params)
{
game_params *ret = snew(game_params);
*ret = *params; /* structure copy */
}
}
-static char *encode_params(game_params *params, int full)
+static char *encode_params(const game_params *params, int full)
{
char data[256];
return dupstr(data);
}
-static config_item *game_configure(game_params *params)
+static config_item *game_configure(const game_params *params)
{
config_item *ret;
char buf[80];
return ret;
}
-static game_params *custom_params(config_item *cfg)
+static game_params *custom_params(const config_item *cfg)
{
game_params *ret = snew(game_params);
return ret;
}
-static char *validate_params(game_params *params, int full)
+static char *validate_params(const game_params *params, int full)
{
/*
* (At least at the time of writing this comment) The grid
*/
signed char *slashval;
+ /*
+ * Stores possible v-shapes. This array is w by h in size, but
+ * not every bit of every entry is meaningful. The bits mean:
+ *
+ * - bit 0 for a square means that that square and the one to
+ * its right might form a v-shape between them
+ * - bit 1 for a square means that that square and the one to
+ * its right might form a ^-shape between them
+ * - bit 2 for a square means that that square and the one
+ * below it might form a >-shape between them
+ * - bit 3 for a square means that that square and the one
+ * below it might form a <-shape between them
+ *
+ * Any starting 1 or 3 clue rules out four bits in this array
+ * immediately; a 2 clue propagates any ruled-out bit past it
+ * (if the two squares on one side of a 2 cannot be a v-shape,
+ * then neither can the two on the other side be the same
+ * v-shape); we can rule out further bits during play using
+ * partially filled 2 clues; whenever a pair of squares is
+ * known not to be _either_ kind of v-shape, we can mark them
+ * as equivalent.
+ */
+ unsigned char *vbitmap;
+
/*
* Useful to have this information automatically passed to
* solver subroutines. (This pointer is not dynamically
ret->border = snewn(W*H, unsigned char);
ret->equiv = snewn(w*h, int);
ret->slashval = snewn(w*h, signed char);
+ ret->vbitmap = snewn(w*h, unsigned char);
return ret;
}
static void free_scratch(struct solver_scratch *sc)
{
+ sfree(sc->vbitmap);
sfree(sc->slashval);
sfree(sc->equiv);
sfree(sc->border);
}
}
+static int vbitmap_clear(int w, int h, struct solver_scratch *sc,
+ int x, int y, int vbits, char *reason, ...)
+{
+ int done_something = FALSE;
+ int vbit;
+
+ for (vbit = 1; vbit <= 8; vbit <<= 1)
+ if (vbits & sc->vbitmap[y*w+x] & vbit) {
+ done_something = TRUE;
+#ifdef SOLVER_DIAGNOSTICS
+ if (verbose) {
+ va_list ap;
+
+ printf("ruling out %c shape at (%d,%d)-(%d,%d) (",
+ "!v^!>!!!<"[vbit], x, y,
+ x+((vbit&0x3)!=0), y+((vbit&0xC)!=0));
+
+ va_start(ap, reason);
+ vprintf(reason, ap);
+ va_end(ap);
+
+ printf(")\n");
+ }
+#endif
+ sc->vbitmap[y*w+x] &= ~vbit;
+ }
+
+ return done_something;
+}
+
/*
* Solver. Returns 0 for impossibility, 1 for success, 2 for
* ambiguity or failure to converge.
* Establish a disjoint set forest for tracking connectedness
* between grid points.
*/
- for (i = 0; i < W*H; i++)
- sc->connected[i] = i; /* initially all distinct */
+ dsf_init(sc->connected, W*H);
/*
* Establish a disjoint set forest for tracking which squares
* are known to slant in the same direction.
*/
- for (i = 0; i < w*h; i++)
- sc->equiv[i] = i; /* initially all distinct */
+ dsf_init(sc->equiv, w*h);
/*
* Clear the slashval array.
memset(sc->slashval, 0, w*h);
/*
- * Initialise the `exits' and `border' arrays. Theses is used
+ * Set up the vbitmap array. Initially all types of v are possible.
+ */
+ memset(sc->vbitmap, 0xF, w*h);
+
+ /*
+ * Initialise the `exits' and `border' arrays. These are used
* to do second-order loop avoidance: the dual of the no loops
* constraint is that every point must be somehow connected to
* the border of the grid (otherwise there would be a solid
sc->exits[y*W+x] = clues[y*W+x];
}
- /*
- * Make a one-off preliminary pass over the grid looking for
- * starting-point arrangements. The ones we need to spot are:
- *
- * - two adjacent 1s in the centre of the grid imply that each
- * one's single line points towards the other. (If either 1
- * were connected on the far side, the two squares shared
- * between the 1s would both link to the other 1 as a
- * consequence of neither linking to the first.) Thus, we
- * can fill in the four squares around them.
- *
- * - dually, two adjacent 3s imply that each one's _non_-line
- * points towards the other.
- *
- * - if the pair of 1s and 3s is not _adjacent_ but is
- * separated by one or more 2s, the reasoning still applies.
- *
- * This is more advanced than just spotting obvious starting
- * squares such as central 4s and edge 2s, so we disable it on
- * DIFF_EASY.
- *
- * (I don't like this loop; it feels grubby to me. My
- * mathematical intuition feels there ought to be some more
- * general deductive form which contains this loop as a special
- * case, but I can't bring it to mind right now.)
- */
- if (difficulty > DIFF_EASY) {
- for (y = 1; y+1 < H; y++)
- for (x = 1; x+1 < W; x++) {
- int v = clues[y*W+x], s, x2, y2, dx, dy;
- if (v != 1 && v != 3)
- continue;
- /* Slash value of the square up and left of (x,y). */
- s = (v == 1 ? +1 : -1);
-
- /* Look in each direction once. */
- for (dy = 0; dy < 2; dy++) {
- dx = 1 - dy;
- x2 = x+dx;
- y2 = y+dy;
- if (x2+1 >= W || y2+1 >= H)
- continue; /* too close to the border */
- while (x2+dx+1 < W && y2+dy+1 < H && clues[y2*W+x2] == 2)
- x2 += dx, y2 += dy;
- if (clues[y2*W+x2] == v) {
-#ifdef SOLVER_DIAGNOSTICS
- if (verbose)
- printf("found adjacent %ds at %d,%d and %d,%d\n",
- v, x, y, x2, y2);
-#endif
- fill_square(w, h, x-1, y-1, s, soln,
- sc->connected, sc);
- fill_square(w, h, x-1+dy, y-1+dx, -s, soln,
- sc->connected, sc);
- fill_square(w, h, x2, y2, s, soln,
- sc->connected, sc);
- fill_square(w, h, x2-dy, y2-dx, -s, soln,
- sc->connected, sc);
- }
- }
- }
- }
-
/*
* Repeatedly try to deduce something until we can't.
*/
}
}
+ if (done_something)
+ continue;
+
+ /*
+ * Now see what we can do with the vbitmap array. All
+ * vbitmap deductions are disabled at Easy level.
+ */
+ if (difficulty <= DIFF_EASY)
+ continue;
+
+ for (y = 0; y < h; y++)
+ for (x = 0; x < w; x++) {
+ int s, c;
+
+ /*
+ * Any line already placed in a square must rule
+ * out any type of v which contradicts it.
+ */
+ if ((s = soln[y*w+x]) != 0) {
+ if (x > 0)
+ done_something |=
+ vbitmap_clear(w, h, sc, x-1, y, (s < 0 ? 0x1 : 0x2),
+ "contradicts known edge at (%d,%d)",x,y);
+ if (x+1 < w)
+ done_something |=
+ vbitmap_clear(w, h, sc, x, y, (s < 0 ? 0x2 : 0x1),
+ "contradicts known edge at (%d,%d)",x,y);
+ if (y > 0)
+ done_something |=
+ vbitmap_clear(w, h, sc, x, y-1, (s < 0 ? 0x4 : 0x8),
+ "contradicts known edge at (%d,%d)",x,y);
+ if (y+1 < h)
+ done_something |=
+ vbitmap_clear(w, h, sc, x, y, (s < 0 ? 0x8 : 0x4),
+ "contradicts known edge at (%d,%d)",x,y);
+ }
+
+ /*
+ * If both types of v are ruled out for a pair of
+ * adjacent squares, mark them as equivalent.
+ */
+ if (x+1 < w && !(sc->vbitmap[y*w+x] & 0x3)) {
+ int n1 = y*w+x, n2 = y*w+(x+1);
+ if (dsf_canonify(sc->equiv, n1) !=
+ dsf_canonify(sc->equiv, n2)) {
+ dsf_merge(sc->equiv, n1, n2);
+ done_something = TRUE;
+#ifdef SOLVER_DIAGNOSTICS
+ if (verbose)
+ printf("(%d,%d) and (%d,%d) must be equivalent"
+ " because both v-shapes are ruled out\n",
+ x, y, x+1, y);
+#endif
+ }
+ }
+ if (y+1 < h && !(sc->vbitmap[y*w+x] & 0xC)) {
+ int n1 = y*w+x, n2 = (y+1)*w+x;
+ if (dsf_canonify(sc->equiv, n1) !=
+ dsf_canonify(sc->equiv, n2)) {
+ dsf_merge(sc->equiv, n1, n2);
+ done_something = TRUE;
+#ifdef SOLVER_DIAGNOSTICS
+ if (verbose)
+ printf("(%d,%d) and (%d,%d) must be equivalent"
+ " because both v-shapes are ruled out\n",
+ x, y, x, y+1);
+#endif
+ }
+ }
+
+ /*
+ * The remaining work in this loop only works
+ * around non-edge clue points.
+ */
+ if (y == 0 || x == 0)
+ continue;
+ if ((c = clues[y*W+x]) < 0)
+ continue;
+
+ /*
+ * x,y marks a clue point not on the grid edge. See
+ * if this clue point allows us to rule out any v
+ * shapes.
+ */
+
+ if (c == 1) {
+ /*
+ * A 1 clue can never have any v shape pointing
+ * at it.
+ */
+ done_something |=
+ vbitmap_clear(w, h, sc, x-1, y-1, 0x5,
+ "points at 1 clue at (%d,%d)", x, y);
+ done_something |=
+ vbitmap_clear(w, h, sc, x-1, y, 0x2,
+ "points at 1 clue at (%d,%d)", x, y);
+ done_something |=
+ vbitmap_clear(w, h, sc, x, y-1, 0x8,
+ "points at 1 clue at (%d,%d)", x, y);
+ } else if (c == 3) {
+ /*
+ * A 3 clue can never have any v shape pointing
+ * away from it.
+ */
+ done_something |=
+ vbitmap_clear(w, h, sc, x-1, y-1, 0xA,
+ "points away from 3 clue at (%d,%d)", x, y);
+ done_something |=
+ vbitmap_clear(w, h, sc, x-1, y, 0x1,
+ "points away from 3 clue at (%d,%d)", x, y);
+ done_something |=
+ vbitmap_clear(w, h, sc, x, y-1, 0x4,
+ "points away from 3 clue at (%d,%d)", x, y);
+ } else if (c == 2) {
+ /*
+ * If a 2 clue has any kind of v ruled out on
+ * one side of it, the same v is ruled out on
+ * the other side.
+ */
+ done_something |=
+ vbitmap_clear(w, h, sc, x-1, y-1,
+ (sc->vbitmap[(y )*w+(x-1)] & 0x3) ^ 0x3,
+ "propagated by 2 clue at (%d,%d)", x, y);
+ done_something |=
+ vbitmap_clear(w, h, sc, x-1, y-1,
+ (sc->vbitmap[(y-1)*w+(x )] & 0xC) ^ 0xC,
+ "propagated by 2 clue at (%d,%d)", x, y);
+ done_something |=
+ vbitmap_clear(w, h, sc, x-1, y,
+ (sc->vbitmap[(y-1)*w+(x-1)] & 0x3) ^ 0x3,
+ "propagated by 2 clue at (%d,%d)", x, y);
+ done_something |=
+ vbitmap_clear(w, h, sc, x, y-1,
+ (sc->vbitmap[(y-1)*w+(x-1)] & 0xC) ^ 0xC,
+ "propagated by 2 clue at (%d,%d)", x, y);
+ }
+
+#undef CLEARBITS
+
+ }
+
} while (done_something);
/*
* Establish a disjoint set forest for tracking connectedness
* between grid points.
*/
- connected = snewn(W*H, int);
- for (i = 0; i < W*H; i++)
- connected[i] = i; /* initially all distinct */
+ connected = snew_dsf(W*H);
/*
* Prepare a list of the squares in the grid, and fill them in
sfree(connected);
}
-static char *new_game_desc(game_params *params, random_state *rs,
+static char *new_game_desc(const game_params *params, random_state *rs,
char **aux, int interactive)
{
int w = params->w, h = params->h, W = w+1, H = h+1;
return desc;
}
-static char *validate_desc(game_params *params, char *desc)
+static char *validate_desc(const game_params *params, const char *desc)
{
int w = params->w, h = params->h, W = w+1, H = h+1;
int area = W*H;
return NULL;
}
-static game_state *new_game(midend *me, game_params *params, char *desc)
+static game_state *new_game(midend *me, const game_params *params,
+ const char *desc)
{
int w = params->w, h = params->h, W = w+1, H = h+1;
game_state *state = snew(game_state);
state->clues->h = h;
state->clues->clues = snewn(W*H, signed char);
state->clues->refcount = 1;
- state->clues->tmpsoln = snewn(w*h, signed char);
+ state->clues->tmpdsf = snewn(W*H*2+W+H, int);
memset(state->clues->clues, -1, W*H);
while (*desc) {
int n = *desc++;
return state;
}
-static game_state *dup_game(game_state *state)
+static game_state *dup_game(const game_state *state)
{
int w = state->p.w, h = state->p.h, W = w+1, H = h+1;
game_state *ret = snew(game_state);
assert(state->clues);
if (--state->clues->refcount <= 0) {
sfree(state->clues->clues);
- sfree(state->clues->tmpsoln);
+ sfree(state->clues->tmpdsf);
sfree(state->clues);
}
sfree(state);
{
int w = state->p.w, h = state->p.h, W = w+1, H = h+1;
int x, y, err = FALSE;
- signed char *ts;
+ int *dsf;
memset(state->errors, 0, W*H);
/*
- * An easy way to do loop checking would be by means of the
- * same dsf technique we've used elsewhere (loop over all edges
- * in the grid, joining vertices together into equivalence
- * classes when connected by an edge, and raise the alarm when
- * an edge joins two already-equivalent vertices). However, a
- * better approach is to repeatedly remove the single edge
- * connecting to any degree-1 vertex, and then see if there are
- * any edges left over; if so, precisely those edges are part
- * of loops, which means we can highlight them as errors for
- * the user.
- *
- * We use the `tmpsoln' scratch space in the shared clues
+ * To detect loops in the grid, we iterate through each edge
+ * building up a dsf of connected components of the space
+ * around the edges; if there's more than one such component,
+ * we have a loop, and in particular we can then easily
+ * identify and highlight every edge forming part of a loop
+ * because it separates two nonequivalent regions.
+ *
+ * We use the `tmpdsf' scratch space in the shared clues
* structure, to avoid mallocing too often.
+ *
+ * For these purposes, the grid is considered to be divided
+ * into diamond-shaped regions surrounding an orthogonal edge.
+ * This means we have W*h vertical edges and w*H horizontal
+ * ones; so our vertical edges are indexed in the dsf as
+ * (y*W+x) (0<=y<h, 0<=x<W), and the horizontal ones as (W*h +
+ * y*w+x) (0<=y<H, 0<=x<w), where (x,y) is the topmost or
+ * leftmost point on the edge.
*/
- ts = state->clues->tmpsoln;
- memcpy(ts, state->soln, w*h);
- for (y = 0; y < H; y++)
- for (x = 0; x < W; x++) {
- int vx = x, vy = y;
- int sx, sy;
- /*
- * Every time we disconnect a vertex like this, there
- * is precisely one other vertex which might have
- * become degree 1; so we follow the trail as far as it
- * leads. This ensures that we don't have to make more
- * than one loop over the grid, because whenever a
- * degree-1 vertex comes into existence somewhere we've
- * already looked, we immediately remove it again.
- * Hence one loop over the grid is adequate; and
- * moreover, this algorithm visits every vertex at most
- * twice (once in the loop and possibly once more as a
- * result of following a trail) so it has linear time
- * in the area of the grid.
- */
- while (vertex_degree(w, h, ts, vx, vy, FALSE, &sx, &sy) == 1) {
- ts[sy*w+sx] = 0;
- vx = vx + 1 + (sx - vx) * 2;
- vy = vy + 1 + (sy - vy) * 2;
- }
+ dsf = state->clues->tmpdsf;
+ dsf_init(dsf, W*h + w*H);
+ /* Start by identifying all the outer edges with each other. */
+ for (y = 0; y < h; y++) {
+ dsf_merge(dsf, 0, y*W+0);
+ dsf_merge(dsf, 0, y*W+w);
+ }
+ for (x = 0; x < w; x++) {
+ dsf_merge(dsf, 0, W*h + 0*w+x);
+ dsf_merge(dsf, 0, W*h + h*w+x);
+ }
+ /* Now go through the actual grid. */
+ for (y = 0; y < h; y++)
+ for (x = 0; x < w; x++) {
+ if (state->soln[y*w+x] >= 0) {
+ /*
+ * There isn't a \ in this square, so we can unify
+ * the top edge with the left, and the bottom with
+ * the right.
+ */
+ dsf_merge(dsf, y*W+x, W*h + y*w+x);
+ dsf_merge(dsf, y*W+(x+1), W*h + (y+1)*w+x);
+ }
+ if (state->soln[y*w+x] <= 0) {
+ /*
+ * There isn't a / in this square, so we can unify
+ * the top edge with the right, and the bottom
+ * with the left.
+ */
+ dsf_merge(dsf, y*W+x, W*h + (y+1)*w+x);
+ dsf_merge(dsf, y*W+(x+1), W*h + y*w+x);
+ }
}
-
- /*
- * Now mark any remaining edges with ERR_SQUARE.
- */
+ /* Now go through again and mark the appropriate edges as erroneous. */
for (y = 0; y < h; y++)
- for (x = 0; x < w; x++)
- if (ts[y*w+x]) {
- state->errors[y*W+x] |= ERR_SQUARE;
- err = TRUE;
- }
+ for (x = 0; x < w; x++) {
+ int erroneous = 0;
+ if (state->soln[y*w+x] > 0) {
+ /*
+ * A / separates the top and left edges (which
+ * must already have been identified with each
+ * other) from the bottom and right (likewise).
+ * Hence it is erroneous if and only if the top
+ * and right edges are nonequivalent.
+ */
+ erroneous = (dsf_canonify(dsf, y*W+(x+1)) !=
+ dsf_canonify(dsf, W*h + y*w+x));
+ } else if (state->soln[y*w+x] < 0) {
+ /*
+ * A \ separates the top and right edges (which
+ * must already have been identified with each
+ * other) from the bottom and left (likewise).
+ * Hence it is erroneous if and only if the top
+ * and left edges are nonequivalent.
+ */
+ erroneous = (dsf_canonify(dsf, y*W+x) !=
+ dsf_canonify(dsf, W*h + y*w+x));
+ }
+ if (erroneous) {
+ state->errors[y*W+x] |= ERR_SQUARE;
+ err = TRUE;
+ }
+ }
/*
* Now go through and check the degree of each clue vertex, and
return TRUE;
}
-static char *solve_game(game_state *state, game_state *currstate,
- char *aux, char **error)
+static char *solve_game(const game_state *state, const game_state *currstate,
+ const char *aux, char **error)
{
int w = state->p.w, h = state->p.h;
signed char *soln;
return move;
}
-static char *game_text_format(game_state *state)
+static int game_can_format_as_text_now(const game_params *params)
+{
+ return TRUE;
+}
+
+static char *game_text_format(const game_state *state)
{
int w = state->p.w, h = state->p.h, W = w+1, H = h+1;
int x, y, len;
return ret;
}
-static game_ui *new_ui(game_state *state)
+struct game_ui {
+ int cur_x, cur_y, cur_visible;
+};
+
+static game_ui *new_ui(const game_state *state)
{
- return NULL;
+ game_ui *ui = snew(game_ui);
+ ui->cur_x = ui->cur_y = ui->cur_visible = 0;
+ return ui;
}
static void free_ui(game_ui *ui)
{
+ sfree(ui);
}
-static char *encode_ui(game_ui *ui)
+static char *encode_ui(const game_ui *ui)
{
return NULL;
}
-static void decode_ui(game_ui *ui, char *encoding)
+static void decode_ui(game_ui *ui, const char *encoding)
{
}
-static void game_changed_state(game_ui *ui, game_state *oldstate,
- game_state *newstate)
+static void game_changed_state(game_ui *ui, const game_state *oldstate,
+ const game_state *newstate)
{
}
#define ERR_TR 0x00008000L
#define ERR_BL 0x00010000L
#define ERR_BR 0x00020000L
+#define CURSOR 0x00040000L
struct game_drawstate {
int tilesize;
long *todraw;
};
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
- int x, int y, int button)
+static char *interpret_move(const game_state *state, game_ui *ui,
+ const game_drawstate *ds,
+ int x, int y, int button)
{
int w = state->p.w, h = state->p.h;
+ int v;
+ char buf[80];
+ enum { CLOCKWISE, ANTICLOCKWISE, NONE } action = NONE;
if (button == LEFT_BUTTON || button == RIGHT_BUTTON) {
- int v;
- char buf[80];
-
/*
* This is an utterly awful hack which I should really sort out
* by means of a proper configuration mechanism. One Slant
button = LEFT_BUTTON;
}
}
+ action = (button == LEFT_BUTTON) ? CLOCKWISE : ANTICLOCKWISE;
x = FROMCOORD(x);
y = FROMCOORD(y);
if (x < 0 || y < 0 || x >= w || y >= h)
return NULL;
+ } else if (IS_CURSOR_SELECT(button)) {
+ if (!ui->cur_visible) {
+ ui->cur_visible = 1;
+ return "";
+ }
+ x = ui->cur_x;
+ y = ui->cur_y;
+
+ action = (button == CURSOR_SELECT2) ? ANTICLOCKWISE : CLOCKWISE;
+ } else if (IS_CURSOR_MOVE(button)) {
+ move_cursor(button, &ui->cur_x, &ui->cur_y, w, h, 0);
+ ui->cur_visible = 1;
+ return "";
+ }
- if (button == LEFT_BUTTON) {
+ if (action != NONE) {
+ if (action == CLOCKWISE) {
/*
* Left-clicking cycles blank -> \ -> / -> blank.
*/
return NULL;
}
-static game_state *execute_move(game_state *state, char *move)
+static game_state *execute_move(const game_state *state, const char *move)
{
int w = state->p.w, h = state->p.h;
char c;
* Drawing routines.
*/
-static void game_compute_size(game_params *params, int tilesize,
- int *x, int *y)
+static void game_compute_size(const game_params *params, int tilesize,
+ int *x, int *y)
{
/* fool the macros */
- struct dummy { int tilesize; } dummy = { tilesize }, *ds = &dummy;
+ struct dummy { int tilesize; } dummy, *ds = &dummy;
+ dummy.tilesize = tilesize;
*x = 2 * BORDER + params->w * TILESIZE + 1;
*y = 2 * BORDER + params->h * TILESIZE + 1;
}
static void game_set_size(drawing *dr, game_drawstate *ds,
- game_params *params, int tilesize)
+ const game_params *params, int 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);
- frontend_default_colour(fe, &ret[COL_BACKGROUND * 3]);
+ /* CURSOR colour is a background highlight. */
+ game_mkhighlight(fe, ret, COL_BACKGROUND, COL_CURSOR, -1);
+
+ ret[COL_FILLEDSQUARE * 3 + 0] = ret[COL_BACKGROUND * 3 + 0];
+ ret[COL_FILLEDSQUARE * 3 + 1] = ret[COL_BACKGROUND * 3 + 1];
+ ret[COL_FILLEDSQUARE * 3 + 2] = ret[COL_BACKGROUND * 3 + 2];
ret[COL_GRID * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 0.7F;
ret[COL_GRID * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 0.7F;
return ret;
}
-static game_drawstate *game_new_drawstate(drawing *dr, game_state *state)
+static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state)
{
int w = state->p.w, h = state->p.h;
int i;
if (v < 0)
return;
- p[0] = v + '0';
+ p[0] = (char)v + '0';
p[1] = '\0';
draw_circle(dr, COORD(x), COORD(y), CLUE_RADIUS,
bg >= 0 ? bg : COL_BACKGROUND, ccol);
clip(dr, COORD(x), COORD(y), TILESIZE, TILESIZE);
draw_rect(dr, COORD(x), COORD(y), TILESIZE, TILESIZE,
- (v & FLASH) ? COL_GRID : COL_BACKGROUND);
+ (v & FLASH) ? COL_GRID :
+ (v & CURSOR) ? COL_CURSOR :
+ (v & (BACKSLASH | FORWSLASH)) ? COL_FILLEDSQUARE :
+ COL_BACKGROUND);
/*
* Draw the grid lines.
draw_update(dr, COORD(x), COORD(y), TILESIZE, TILESIZE);
}
-static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
- game_state *state, int dir, game_ui *ui,
- float animtime, float flashtime)
+static void game_redraw(drawing *dr, game_drawstate *ds,
+ const game_state *oldstate, const game_state *state,
+ int dir, const game_ui *ui,
+ float animtime, float flashtime)
{
int w = state->p.w, h = state->p.h, W = w+1, H = h+1;
int x, y;
ds->todraw[(y+2)*(w+2)+(x+1)] |= ERR_T_L | ERR_C_TL;
}
}
+ if (ui->cur_visible && ui->cur_x == x && ui->cur_y == y)
+ ds->todraw[(y+1)*(w+2)+(x+1)] |= CURSOR;
}
}
}
}
-static float game_anim_length(game_state *oldstate, game_state *newstate,
- int dir, game_ui *ui)
+static float game_anim_length(const game_state *oldstate,
+ const game_state *newstate, int dir, game_ui *ui)
{
return 0.0F;
}
-static float game_flash_length(game_state *oldstate, game_state *newstate,
- int dir, game_ui *ui)
+static float game_flash_length(const game_state *oldstate,
+ const game_state *newstate, int dir, game_ui *ui)
{
if (!oldstate->completed && newstate->completed &&
!oldstate->used_solve && !newstate->used_solve)
return 0.0F;
}
-static int game_wants_statusbar(void)
+static int game_status(const game_state *state)
{
- return FALSE;
+ return state->completed ? +1 : 0;
}
-static int game_timing_state(game_state *state, game_ui *ui)
+static int game_timing_state(const game_state *state, game_ui *ui)
{
return TRUE;
}
-static void game_print_size(game_params *params, float *x, float *y)
+static void game_print_size(const game_params *params, float *x, float *y)
{
int pw, ph;
* I'll use 6mm squares by default.
*/
game_compute_size(params, 600, &pw, &ph);
- *x = pw / 100.0;
- *y = ph / 100.0;
+ *x = pw / 100.0F;
+ *y = ph / 100.0F;
}
-static void game_print(drawing *dr, game_state *state, int tilesize)
+static void game_print(drawing *dr, const game_state *state, int tilesize)
{
int w = state->p.w, h = state->p.h, W = w+1;
int ink = print_mono_colour(dr, 0);
/* Ick: fake up `ds->tilesize' for macro expansion purposes */
game_drawstate ads, *ds = &ads;
- ads.tilesize = tilesize;
+ game_set_size(dr, ds, NULL, tilesize);
/*
* Border.
#endif
const struct game thegame = {
- "Slant", "games.slant",
+ "Slant", "games.slant", "slant",
default_params,
game_fetch_preset,
decode_params,
dup_game,
free_game,
TRUE, solve_game,
- TRUE, game_text_format,
+ TRUE, game_can_format_as_text_now, game_text_format,
new_ui,
free_ui,
encode_ui,
game_redraw,
game_anim_length,
game_flash_length,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
- game_wants_statusbar,
+ FALSE, /* wants_statusbar */
FALSE, game_timing_state,
- 0, /* mouse_priorities */
+ 0, /* flags */
};
#ifdef STANDALONE_SOLVER
}
#endif
+
+/* vim: set shiftwidth=4 tabstop=8: */