From ef1306764e6443d67612542654f252b376c5993e Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Mon, 23 Oct 2017 17:19:29 -0400 Subject: puzzles: resync with upstream There have been some improvements with regard to small screen sizes, which will be nice to have. Change-Id: I30c740514156258d2818fde325c1a751500f7611 --- apps/plugins/puzzles/src/unequal.c | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'apps/plugins/puzzles/src/unequal.c') diff --git a/apps/plugins/puzzles/src/unequal.c b/apps/plugins/puzzles/src/unequal.c index a63b7d8ed0..cb477c9e37 100644 --- a/apps/plugins/puzzles/src/unequal.c +++ b/apps/plugins/puzzles/src/unequal.c @@ -218,24 +218,21 @@ static config_item *game_configure(const game_params *params) ret[0].name = "Mode"; ret[0].type = C_CHOICES; - ret[0].sval = ":Unequal:Adjacent"; - ret[0].ival = params->adjacent; + ret[0].u.choices.choicenames = ":Unequal:Adjacent"; + ret[0].u.choices.selected = params->adjacent; ret[1].name = "Size (s*s)"; ret[1].type = C_STRING; sprintf(buf, "%d", params->order); - ret[1].sval = dupstr(buf); - ret[1].ival = 0; + ret[1].u.string.sval = dupstr(buf); ret[2].name = "Difficulty"; ret[2].type = C_CHOICES; - ret[2].sval = DIFFCONFIG; - ret[2].ival = params->diff; + ret[2].u.choices.choicenames = DIFFCONFIG; + ret[2].u.choices.selected = params->diff; ret[3].name = NULL; ret[3].type = C_END; - ret[3].sval = NULL; - ret[3].ival = 0; return ret; } @@ -244,14 +241,14 @@ static game_params *custom_params(const config_item *cfg) { game_params *ret = snew(game_params); - ret->adjacent = cfg[0].ival; - ret->order = atoi(cfg[1].sval); - ret->diff = cfg[2].ival; + ret->adjacent = cfg[0].u.choices.selected; + ret->order = atoi(cfg[1].u.string.sval); + ret->diff = cfg[2].u.choices.selected; return ret; } -static char *validate_params(const game_params *params, int full) +static const char *validate_params(const game_params *params, int full) { if (params->order < 3 || params->order > 32) return "Order must be between 3 and 32"; @@ -1198,12 +1195,12 @@ generate: } static game_state *load_game(const game_params *params, const char *desc, - char **why_r) + const char **why_r) { game_state *state = blank_game(params->order, params->adjacent); const char *p = desc; int i = 0, n, o = params->order, x, y; - char *why = NULL; + const char *why = NULL; while (*p) { while (*p >= 'a' && *p <= 'z') { @@ -1294,9 +1291,9 @@ static game_state *new_game(midend *me, const game_params *params, return state; } -static char *validate_desc(const game_params *params, const char *desc) +static const char *validate_desc(const game_params *params, const char *desc) { - char *why = NULL; + const char *why = NULL; game_state *dummy = load_game(params, desc, &why); if (dummy) { free_game(dummy); @@ -1307,7 +1304,7 @@ static char *validate_desc(const game_params *params, const char *desc) } static char *solve_game(const game_state *state, const game_state *currstate, - const char *aux, char **error) + const char *aux, const char **error) { game_state *solved; int r; @@ -1425,7 +1422,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, ui->hshow = 1; } ui->hcursor = 0; - return ""; + return UI_UPDATE; } if (button == RIGHT_BUTTON) { /* pencil highlighting for non-filled squares */ @@ -1439,7 +1436,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, ui->hshow = 1; } ui->hcursor = 0; - return ""; + return UI_UPDATE; } } @@ -1453,11 +1450,12 @@ static char *interpret_move(const game_state *state, game_ui *ui, ny != ui->hy + adjthan[i].dy); ++i); if (i == 4) - return ""; /* invalid direction, i.e. out of the board */ + return UI_UPDATE; /* invalid direction, i.e. out of + * the board */ if (!(GRID(state, flags, ui->hx, ui->hy) & adjthan[i].f || GRID(state, flags, nx, ny ) & adjthan[i].fo)) - return ""; /* no clue to toggle */ + return UI_UPDATE; /* no clue to toggle */ if (state->adjacent) self = (adjthan[i].dx >= 0 && adjthan[i].dy >= 0); @@ -1475,13 +1473,13 @@ static char *interpret_move(const game_state *state, game_ui *ui, } else { move_cursor(button, &ui->hx, &ui->hy, ds->order, ds->order, FALSE); ui->hshow = ui->hcursor = 1; - return ""; + return UI_UPDATE; } } if (ui->hshow && IS_CURSOR_SELECT(button)) { ui->hpencil = 1 - ui->hpencil; ui->hcursor = 1; - return ""; + return UI_UPDATE; } n = c2n(button, state->order); @@ -1568,7 +1566,9 @@ static game_state *execute_move(const game_state *state, const char *move) } return ret; } else if (move[0] == 'H') { - return solver_hint(state, NULL, DIFF_EASY, DIFF_EASY); + ret = solver_hint(state, NULL, DIFF_EASY, DIFF_EASY); + check_complete(ret->nums, ret, 1); + return ret; } else if (move[0] == 'F' && sscanf(move+1, "%d,%d,%d", &x, &y, &n) == 3 && x >= 0 && x < state->order && y >= 0 && y < state->order) { ret = dup_game(state); @@ -2041,7 +2041,7 @@ const char *quis = NULL; #if 0 /* currently unused */ -static void debug_printf(char *fmt, ...) +static void debug_printf(const char *fmt, ...) { char buf[4096]; va_list ap; @@ -2125,7 +2125,7 @@ static int solve(game_params *p, char *desc, int debug) static void check(game_params *p) { - char *msg = validate_params(p, 1); + const char *msg = validate_params(p, 1); if (msg) { fprintf(stderr, "%s: %s", quis, msg); exit(1); @@ -2233,7 +2233,8 @@ int main(int argc, const char *argv[]) int i; for (i = 0; i < argc; i++) { const char *id = *argv++; - char *desc = strchr(id, ':'), *err; + char *desc = strchr(id, ':'); + const char *err; p = default_params(); if (desc) { *desc++ = '\0'; -- cgit v1.2.3