enum {
COL_BACKGROUND, COL_HIGHLIGHT, COL_LOWLIGHT,
- COL_TEXT, COL_ERROR, COL_CURSOR,
+ COL_TEXT, COL_ERROR, COL_CURSOR, COL_DONE,
COL_NEUTRAL, COL_NEGATIVE, COL_POSITIVE, COL_NOT,
NCOLOURS
};
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 buf[256];
sprintf(buf, "%dx%d", params->w, params->h);
return dupstr(buf);
}
-static config_item *game_configure(game_params *params)
+static config_item *game_configure(const game_params *params)
{
config_item *ret;
char buf[64];
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)
{
if (params->w < 2) return "Width must be at least one";
if (params->h < 2) return "Height must be at least one";
int *grid; /* size w*h, for cell state (pos/neg) */
unsigned int *flags; /* size w*h */
int solved, completed, numbered;
+ unsigned char *counts_done;
struct game_common *common; /* domino layout never changes. */
};
memset(ret->common->rowcount, 0, ret->h*3*sizeof(int));
memset(ret->common->colcount, 0, ret->w*3*sizeof(int));
+ memset(ret->counts_done, 0, (ret->h + ret->w) * 2 * sizeof(unsigned char));
for (i = 0; i < ret->wh; i++) {
ret->grid[i] = EMPTY;
ret->grid = snewn(ret->wh, int);
ret->flags = snewn(ret->wh, unsigned int);
+ ret->counts_done = snewn((ret->h + ret->w) * 2, unsigned char);
ret->common = snew(struct game_common);
ret->common->refcount = 1;
return ret;
}
-static game_state *dup_game(game_state *src)
+static game_state *dup_game(const game_state *src)
{
game_state *dest = snew(game_state);
dest->grid = snewn(dest->wh, int);
memcpy(dest->grid, src->grid, dest->wh*sizeof(int));
+ dest->counts_done = snewn((dest->h + dest->w) * 2, unsigned char);
+ memcpy(dest->counts_done, src->counts_done,
+ (dest->h + dest->w) * 2 * sizeof(unsigned char));
+
dest->flags = snewn(dest->wh, unsigned int);
memcpy(dest->flags, src->flags, dest->wh*sizeof(unsigned int));
sfree(state->common->colcount);
sfree(state->common);
}
+ sfree(state->counts_done);
sfree(state->flags);
sfree(state->grid);
sfree(state);
return -1;
}
-static char *readrow(char *desc, int n, int *array, int off, const char **prob)
+static const char *readrow(const char *desc, int n, int *array, int off,
+ const char **prob)
{
int i, num;
char c;
return NULL;
}
-static game_state *new_game_int(const game_params *params, char *desc,
+static game_state *new_game_int(const game_params *params, const char *desc,
const char **prob)
{
game_state *state = new_state(params->w, params->h);
return state;
}
-static char *validate_desc(const game_params *params, char *desc)
+static char *validate_desc(const game_params *params, const char *desc)
{
const char *prob;
game_state *st = new_game_int(params, desc, &prob);
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)
{
const char *prob;
game_state *st = new_game_int(params, desc, &prob);
return desc;
}
-static void game_text_hborder(game_state *state, char **p_r)
+static void game_text_hborder(const game_state *state, char **p_r)
{
char *p = *p_r;
int x;
*p_r = p;
}
-static int game_can_format_as_text_now(game_params *params)
+static int game_can_format_as_text_now(const game_params *params)
{
return TRUE;
}
-static char *game_text_format(game_state *state)
+static char *game_text_format(const game_state *state)
{
int len, x, y, i;
char *ret, *p;
const char *name;
} rowcol;
-static rowcol mkrowcol(game_state *state, int num, int roworcol)
+static rowcol mkrowcol(const game_state *state, int num, int roworcol)
{
rowcol rc;
return rc;
}
-static int count_rowcol(game_state *state, int num, int roworcol, int which)
+static int count_rowcol(const game_state *state, int num, int roworcol,
+ int which)
{
int i, count = 0;
rowcol rc = mkrowcol(state, num, roworcol);
}
-static char *game_state_diff(game_state *src, game_state *dst, int issolve)
+static char *game_state_diff(const game_state *src, const game_state *dst,
+ int issolve)
{
char *ret = NULL, buf[80], c;
int retlen = 0, x, y, i, k;
return ret;
}
-static void solve_from_aux(game_state *state, char *aux)
+static void solve_from_aux(const game_state *state, const char *aux)
{
int i;
assert(strlen(aux) == state->wh);
}
}
-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)
{
game_state *solved = dup_game(currstate);
char *move = NULL;
int cur_x, cur_y, cur_visible;
};
-static game_ui *new_ui(game_state *state)
+static game_ui *new_ui(const game_state *state)
{
game_ui *ui = snew(game_ui);
ui->cur_x = ui->cur_y = 0;
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)
{
if (!oldstate->completed && newstate->completed)
ui->cur_visible = 0;
#define DS_ERROR 0x10
#define DS_CURSOR 0x20
#define DS_SET 0x40
-#define DS_FULL 0x80
-#define DS_NOTPOS 0x100
-#define DS_NOTNEG 0x200
-#define DS_NOTNEU 0x400
-#define DS_FLASH 0x800
+#define DS_NOTPOS 0x80
+#define DS_NOTNEG 0x100
+#define DS_NOTNEU 0x200
+#define DS_FLASH 0x400
#define PREFERRED_TILE_SIZE 32
#define TILE_SIZE (ds->tilesize)
#define COORD(x) ( (x+1) * TILE_SIZE + BORDER )
#define FROMCOORD(x) ( (x - BORDER) / TILE_SIZE - 1 )
-static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
- int x, int y, int button)
+static int is_clue(const game_state *state, int x, int y)
+{
+ int h = state->h, w = state->w;
+
+ if (((x == -1 || x == w) && y >= 0 && y < h) ||
+ ((y == -1 || y == h) && x >= 0 && x < w))
+ return TRUE;
+
+ return FALSE;
+}
+
+static int clue_index(const game_state *state, int x, int y)
+{
+ int h = state->h, w = state->w;
+
+ if (y == -1)
+ return x;
+ else if (x == w)
+ return w + y;
+ else if (y == h)
+ return 2 * w + h - x - 1;
+ else if (x == -1)
+ return 2 * (w + h) - y - 1;
+
+ return -1;
+}
+
+static char *interpret_move(const game_state *state, game_ui *ui,
+ const game_drawstate *ds,
+ int x, int y, int button)
{
int gx = FROMCOORD(x), gy = FROMCOORD(y), idx, curr;
char *nullret = NULL, buf[80], movech;
nullret = "";
}
action = (button == LEFT_BUTTON) ? CYCLE_MAGNET : CYCLE_NEUTRAL;
+ } else if (button == LEFT_BUTTON && is_clue(state, gx, gy)) {
+ sprintf(buf, "D%d,%d", gx, gy);
+ return dupstr(buf);
} else
return NULL;
return dupstr(buf);
}
-static game_state *execute_move(game_state *state, char *move)
+static game_state *execute_move(const game_state *state, const char *move)
{
game_state *ret = dup_game(state);
int x, y, n, idx, idx2;
ret->flags[idx] |= GS_SET;
ret->flags[idx2] |= GS_SET;
}
+ } else if (c == 'D' && sscanf(move, "%d,%d%n", &x, &y, &n) == 2 &&
+ is_clue(ret, x, y)) {
+ ret->counts_done[clue_index(ret, x, y)] ^= 1;
} else
goto badmove;
* 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)
{
/* Ick: fake up `ds->tilesize' for macro expansion purposes */
struct { int tilesize; } ads, *ds = &ads;
}
static void game_set_size(drawing *dr, game_drawstate *ds,
- game_params *params, int tilesize)
+ const game_params *params, int tilesize)
{
ds->tilesize = tilesize;
}
ret[COL_TEXT * 3 + i] = 0.0F;
ret[COL_NEGATIVE * 3 + i] = 0.0F;
ret[COL_CURSOR * 3 + i] = 0.9F;
+ ret[COL_DONE * 3 + i] = ret[COL_BACKGROUND * 3 + i] / 1.5F;
}
ret[COL_POSITIVE * 3 + 0] = 0.8F;
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)
{
struct game_drawstate *ds = snew(struct game_drawstate);
sfree(ds);
}
-static void draw_num_col(drawing *dr, game_drawstate *ds, int rowcol, int which,
+static void draw_num(drawing *dr, game_drawstate *ds, int rowcol, int which,
int idx, int colbg, int col, int num)
{
char buf[32];
draw_update(dr, cx, cy, TILE_SIZE, TILE_SIZE);
}
-static void draw_num(drawing *dr, game_drawstate *ds, int rowcol, int which,
- int idx, unsigned long c, int num)
-{
- draw_num_col(dr, ds, rowcol, which, idx, COL_BACKGROUND,
- (c & DS_ERROR) ? COL_ERROR : COL_TEXT, num);
-}
-
static void draw_sym(drawing *dr, game_drawstate *ds, int x, int y, int which, int col)
{
int cx = COORD(x), cy = COORD(y);
draw_update(dr, cx, cy, TILE_SIZE, TILE_SIZE);
}
+static int get_count_color(const game_state *state, int rowcol, int which,
+ int index, int target)
+{
+ int idx;
+ int count = count_rowcol(state, index, rowcol, which);
+
+ if ((count > target) ||
+ (count < target && !count_rowcol(state, index, rowcol, -1))) {
+ return COL_ERROR;
+ } else if (rowcol == COLUMN) {
+ idx = clue_index(state, index, which == POSITIVE ? -1 : state->h);
+ } else {
+ idx = clue_index(state, which == POSITIVE ? -1 : state->w, index);
+ }
+
+ if (state->counts_done[idx]) {
+ return COL_DONE;
+ }
+
+ return COL_TEXT;
+}
-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 x, y, w = state->w, h = state->h, which, i, j, flash;
- unsigned long c = 0;
flash = (int)(flashtime * 5 / FLASH_TIME) % 2;
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
int idx = y*w+x;
-
- c = state->grid[idx];
+ unsigned long c = state->grid[idx];
if (state->flags[idx] & GS_ERROR)
c |= DS_ERROR;
}
/* Draw counts around side */
for (which = POSITIVE, j = 0; j < 2; which = OPPOSITE(which), j++) {
- int target, count;
for (i = 0; i < w; i++) {
- target = state->common->colcount[i*3+which];
- count = count_rowcol(state, i, COLUMN, which);
- c = 0;
- if ((count > target) ||
- (count < target && !count_rowcol(state, i, COLUMN, -1)))
- c |= DS_ERROR;
- if (count == target) c |= DS_FULL;
- if (c != ds->colwhat[i*3+which] || !ds->started) {
- draw_num(dr, ds, COLUMN, which, i, c,
- state->common->colcount[i*3+which]);
- ds->colwhat[i*3+which] = c;
+ int index = i * 3 + which;
+ int target = state->common->colcount[index];
+ int color = get_count_color(state, COLUMN, which, i, target);
+
+ if (color != ds->colwhat[index] || !ds->started) {
+ draw_num(dr, ds, COLUMN, which, i, COL_BACKGROUND, color, target);
+ ds->colwhat[index] = color;
}
}
for (i = 0; i < h; i++) {
- target = state->common->rowcount[i*3+which];
- count = count_rowcol(state, i, ROW, which);
- c = 0;
- if ((count > target) ||
- (count < target && !count_rowcol(state, i, ROW, -1)))
- c |= DS_ERROR;
- if (count == target) c |= DS_FULL;
- if (c != ds->rowwhat[i*3+which] || !ds->started) {
- draw_num(dr, ds, ROW, which, i, c,
- state->common->rowcount[i*3+which]);
- ds->rowwhat[i*3+which] = c;
+ int index = i * 3 + which;
+ int target = state->common->rowcount[index];
+ int color = get_count_color(state, ROW, which, i, target);
+
+ if (color != ds->rowwhat[index] || !ds->started) {
+ draw_num(dr, ds, ROW, which, i, COL_BACKGROUND, color, target);
+ ds->rowwhat[index] = color;
}
}
}
ds->started = 1;
}
-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->solved && !newstate->solved)
return 0.0F;
}
-static int game_status(game_state *state)
+static int game_status(const game_state *state)
{
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;
*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->w, h = state->h;
int ink = print_mono_colour(dr, 0);
draw_sym(dr, ds, state->w, state->h, NEGATIVE, ink);
for (which = POSITIVE, j = 0; j < 2; which = OPPOSITE(which), j++) {
for (i = 0; i < w; i++) {
- draw_num_col(dr, ds, COLUMN, which, i, paper, ink,
+ draw_num(dr, ds, COLUMN, which, i, paper, ink,
state->common->colcount[i*3+which]);
}
for (i = 0; i < h; i++) {
- draw_num_col(dr, ds, ROW, which, i, paper, ink,
+ draw_num(dr, ds, ROW, which, i, paper, ink,
state->common->rowcount[i*3+which]);
}
}
goto done;
}
s = new_game(NULL, p, desc);
- printf("%s:%s (seed %ld)\n", id, desc, seed);
+ printf("%s:%s (seed %ld)\n", id, desc, (long)seed);
if (aux) {
/* We just generated this ourself. */
if (verbose || print) {