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 */
params->unique = FALSE;
}
-static char *encode_params(game_params *params, int full)
+static char *encode_params(const game_params *params, int full)
{
char buf[80];
sprintf(buf, "%d", params->n);
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[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)
{
if (params->n < 1)
return "Maximum face number must be at least one";
* End of solver code.
*/
-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 n = params->n, w = n+2, h = n+1, wh = w*h;
return ret;
}
-static char *validate_desc(game_params *params, char *desc)
+static char *validate_desc(const game_params *params, const char *desc)
{
int n = params->n, w = n+2, h = n+1, wh = w*h;
int *occurrences;
return ret;
}
-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 n = params->n, w = n+2, h = n+1, wh = w*h;
game_state *state = snew(game_state);
return state;
}
-static game_state *dup_game(game_state *state)
+static game_state *dup_game(const game_state *state)
{
int n = state->params.n, w = n+2, h = n+1, wh = w*h;
game_state *ret = snew(game_state);
sfree(state);
}
-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 n = state->params.n, w = n+2, h = n+1, wh = w*h;
int *placements;
return ret;
}
-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)
{
return NULL;
}
-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 = 0;
+ 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)
{
+ if (!oldstate->completed && newstate->completed)
+ ui->cur_visible = 0;
}
#define PREFERRED_TILESIZE 32
#define DOMINO_GUTTER (TILESIZE / 16)
#define DOMINO_RADIUS (TILESIZE / 8)
#define DOMINO_COFFSET (DOMINO_GUTTER + DOMINO_RADIUS)
+#define CURSOR_RADIUS (TILESIZE / 4)
#define COORD(x) ( (x) * TILESIZE + BORDER )
#define FROMCOORD(x) ( ((x) - BORDER + TILESIZE) / TILESIZE - 1 )
unsigned long *visible;
};
-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->w, h = state->h;
char buf[80];
(state->grid[d1] != d1 || state->grid[d2] != d2))
return NULL;
+ ui->cur_visible = 0;
sprintf(buf, "%c%d,%d", (int)(button == RIGHT_BUTTON ? 'E' : 'D'), d1, d2);
return dupstr(buf);
+ } else if (IS_CURSOR_MOVE(button)) {
+ ui->cur_visible = 1;
+
+ move_cursor(button, &ui->cur_x, &ui->cur_y, 2*w-1, 2*h-1, 0);
+
+ return "";
+ } else if (IS_CURSOR_SELECT(button)) {
+ int d1, d2;
+
+ if (!((ui->cur_x ^ ui->cur_y) & 1))
+ return NULL; /* must have exactly one dimension odd */
+ d1 = (ui->cur_y / 2) * w + (ui->cur_x / 2);
+ d2 = ((ui->cur_y+1) / 2) * w + ((ui->cur_x+1) / 2);
+
+ /*
+ * We can't mark an edge next to any domino.
+ */
+ if (button == CURSOR_SELECT2 &&
+ (state->grid[d1] != d1 || state->grid[d2] != d2))
+ return NULL;
+
+ sprintf(buf, "%c%d,%d", (int)(button == CURSOR_SELECT2 ? 'E' : 'D'), d1, d2);
+ return dupstr(buf);
}
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 n = state->params.n, w = n+2, h = n+1, wh = w*h;
int d1, d2, d3, p;
* 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)
{
int n = params->n, w = n+2, h = n+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;
}
ret[COL_DOMINOTEXT * 3 + 1] = 1.0F;
ret[COL_DOMINOTEXT * 3 + 2] = 1.0F;
- ret[COL_EDGE * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 2 / 3;
+ ret[COL_EDGE * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 2 / 3;
ret[COL_EDGE * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2 / 3;
ret[COL_EDGE * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2 / 3;
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);
int i;
TYPE_MASK = 0x0F
};
-static void draw_tile(drawing *dr, game_drawstate *ds, game_state *state,
+/* These flags must be disjoint with:
+ * the above enum (TYPE_*) [0x000 -- 0x00F]
+ * EDGE_* [0x100 -- 0xF00]
+ * and must fit into an unsigned long (32 bits).
+ */
+#define DF_FLASH 0x40
+#define DF_CLASH 0x80
+
+#define DF_CURSOR 0x01000
+#define DF_CURSOR_USEFUL 0x02000
+#define DF_CURSOR_XBASE 0x10000
+#define DF_CURSOR_XMASK 0x30000
+#define DF_CURSOR_YBASE 0x40000
+#define DF_CURSOR_YMASK 0xC0000
+
+#define CEDGE_OFF (TILESIZE / 8)
+#define IS_EMPTY(s,x,y) ((s)->grid[(y)*(s)->w+(x)] == ((y)*(s)->w+(x)))
+
+static void draw_tile(drawing *dr, game_drawstate *ds, const game_state *state,
int x, int y, int type)
{
int w = state->w /*, h = state->h */;
char str[80];
int flags;
+ clip(dr, cx, cy, TILESIZE, TILESIZE);
draw_rect(dr, cx, cy, TILESIZE, TILESIZE, COL_BACKGROUND);
flags = type &~ TYPE_MASK;
* - a slight shift in the number
*/
- if (flags & 0x80)
+ if (flags & DF_CLASH)
bg = COL_DOMINOCLASH;
else
bg = COL_DOMINO;
nc = COL_DOMINOTEXT;
- if (flags & 0x40) {
+ if (flags & DF_FLASH) {
int tmp = nc;
nc = bg;
bg = tmp;
nc = COL_TEXT;
}
+ if (flags & DF_CURSOR) {
+ int curx = ((flags & DF_CURSOR_XMASK) / DF_CURSOR_XBASE) & 3;
+ int cury = ((flags & DF_CURSOR_YMASK) / DF_CURSOR_YBASE) & 3;
+ int ox = cx + curx*TILESIZE/2;
+ int oy = cy + cury*TILESIZE/2;
+
+ draw_rect_corners(dr, ox, oy, CURSOR_RADIUS, nc);
+ if (flags & DF_CURSOR_USEFUL)
+ draw_rect_corners(dr, ox, oy, CURSOR_RADIUS+1, nc);
+ }
+
sprintf(str, "%d", state->numbers->numbers[y*w+x]);
draw_text(dr, cx+TILESIZE/2, cy+TILESIZE/2, FONT_VARIABLE, TILESIZE/2,
ALIGN_HCENTRE | ALIGN_VCENTRE, nc, str);
draw_update(dr, cx, cy, TILESIZE, TILESIZE);
+ unclip(dr);
}
-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 n = state->params.n, w = state->w, h = state->h, wh = w*h;
int x, y, i;
n2 = state->numbers->numbers[state->grid[n]];
di = DINDEX(n1, n2);
if (used[di] > 1)
- c |= 0x80; /* highlight a clash */
+ c |= DF_CLASH; /* highlight a clash */
} else {
c |= state->edges[n];
}
if (flashtime != 0)
- c |= 0x40; /* we're flashing */
+ c |= DF_FLASH; /* we're flashing */
+
+ if (ui->cur_visible) {
+ unsigned curx = (unsigned)(ui->cur_x - (2*x-1));
+ unsigned cury = (unsigned)(ui->cur_y - (2*y-1));
+ if (curx < 3 && cury < 3) {
+ c |= (DF_CURSOR |
+ (curx * DF_CURSOR_XBASE) |
+ (cury * DF_CURSOR_YBASE));
+ if ((ui->cur_x ^ ui->cur_y) & 1)
+ c |= DF_CURSOR_USEFUL;
+ }
+ }
if (ds->visible[n] != c) {
draw_tile(dr, ds, state, x, y, c);
sfree(used);
}
-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->cheated && !newstate->cheated)
return 0.0F;
}
-static int game_timing_state(game_state *state, game_ui *ui)
+static int game_status(const game_state *state)
+{
+ return state->completed ? +1 : 0;
+}
+
+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 c, x, y;
game_redraw,
game_anim_length,
game_flash_length,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,