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
};
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;
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);
#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 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)
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;
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;
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;
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,
const game_state *oldstate, const game_state *state,
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;
}
}
}
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]);
}
}