X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/1a960a48298c0eb3832704bbd5bb72023d2873a0..HEAD:/loopy.c diff --git a/loopy.c b/loopy.c index 2173dcd..0ee1098 100644 --- a/loopy.c +++ b/loopy.c @@ -208,7 +208,6 @@ struct game_params { int w, h; int diff; int type; - int dual; }; /* line_drawstate is the same as line_state, but with the extra ERROR @@ -257,7 +256,7 @@ static void check_caches(const solver_state* sstate); A(Dodecagonal,GRID_DODECAGONAL,2,2) \ A(Great-Dodecagonal,GRID_GREATDODECAGONAL,2,2) \ A(Penrose (kite/dart),GRID_PENROSE_P2,3,3) \ - A(Penrose (rhombs),GRID_PENROSE_P3,3,3) \ + A(Penrose (rhombs),GRID_PENROSE_P3,3,3) #define GRID_NAME(title,type,amin,omin) #title, #define GRID_CONFIG(title,type,amin,omin) ":" #title @@ -267,7 +266,6 @@ static void check_caches(const solver_state* sstate); "Width and height for this grid type must both be at least " #amin, \ "At least one of width and height for this grid type must be at least " #omin,}, static char const *const gridnames[] = { GRIDLIST(GRID_NAME) }; -static char const *const dualnames[] = { "", "(dual) " }; #define GRID_CONFIGS GRIDLIST(GRID_CONFIG) static grid_type grid_types[] = { GRIDLIST(GRID_TYPE) }; #define NUM_GRID_TYPES (sizeof(grid_types) / sizeof(grid_types[0])) @@ -281,7 +279,7 @@ static const struct { * generated. */ static grid *loopy_generate_grid(game_params *params, char *grid_desc) { - return grid_new(grid_types[params->type], params->w, params->h, params->dual, grid_desc); + return grid_new(grid_types[params->type], params->w, params->h, grid_desc); } /* ---------------------------------------------------------------------- @@ -477,7 +475,6 @@ static game_params *default_params(void) #endif ret->diff = DIFF_EASY; ret->type = 0; - ret->dual = 0; return ret; } @@ -492,42 +489,40 @@ static game_params *dup_params(game_params *params) static const game_params presets[] = { #ifdef SMALL_SCREEN - { 7, 7, DIFF_EASY, 0, 0 }, - { 7, 7, DIFF_NORMAL, 0, 0 }, - { 7, 7, DIFF_HARD, 0, 0 }, - { 7, 7, DIFF_HARD, 1, 0 }, - { 7, 7, DIFF_HARD, 2, 0 }, - { 5, 5, DIFF_HARD, 3, 0 }, - { 7, 7, DIFF_HARD, 4, 0 }, - { 5, 4, DIFF_HARD, 5, 0 }, - { 5, 5, DIFF_HARD, 6, 0 }, - { 5, 5, DIFF_HARD, 7, 0 }, - { 3, 3, DIFF_HARD, 8, 0 }, - { 3, 3, DIFF_HARD, 8, 1 }, - { 3, 3, DIFF_HARD, 9, 0 }, - { 3, 3, DIFF_HARD, 10, 0 }, - { 6, 6, DIFF_HARD, 11, 0 }, - { 6, 6, DIFF_HARD, 12, 0 }, + { 7, 7, DIFF_EASY, 0 }, + { 7, 7, DIFF_NORMAL, 0 }, + { 7, 7, DIFF_HARD, 0 }, + { 7, 7, DIFF_HARD, 1 }, + { 7, 7, DIFF_HARD, 2 }, + { 5, 5, DIFF_HARD, 3 }, + { 7, 7, DIFF_HARD, 4 }, + { 5, 4, DIFF_HARD, 5 }, + { 5, 5, DIFF_HARD, 6 }, + { 5, 5, DIFF_HARD, 7 }, + { 3, 3, DIFF_HARD, 8 }, + { 3, 3, DIFF_HARD, 9 }, + { 3, 3, DIFF_HARD, 10 }, + { 6, 6, DIFF_HARD, 11 }, + { 6, 6, DIFF_HARD, 12 }, #else - { 7, 7, DIFF_EASY, 0, 0 }, - { 10, 10, DIFF_EASY, 0, 0 }, - { 7, 7, DIFF_NORMAL, 0, 0 }, - { 10, 10, DIFF_NORMAL, 0, 0 }, - { 7, 7, DIFF_HARD, 0, 0 }, - { 10, 10, DIFF_HARD, 0, 0 }, - { 10, 10, DIFF_HARD, 1, 0 }, - { 12, 10, DIFF_HARD, 2, 0 }, - { 7, 7, DIFF_HARD, 3, 0 }, - { 9, 9, DIFF_HARD, 4, 0 }, - { 5, 4, DIFF_HARD, 5, 0 }, - { 7, 7, DIFF_HARD, 6, 0 }, - { 5, 5, DIFF_HARD, 7, 0 }, - { 5, 5, DIFF_HARD, 8, 0 }, - { 5, 5, DIFF_HARD, 8, 1 }, - { 5, 4, DIFF_HARD, 9, 0 }, - { 5, 4, DIFF_HARD, 10, 0 }, - { 10, 10, DIFF_HARD, 11, 0 }, - { 10, 10, DIFF_HARD, 12, 0 } + { 7, 7, DIFF_EASY, 0 }, + { 10, 10, DIFF_EASY, 0 }, + { 7, 7, DIFF_NORMAL, 0 }, + { 10, 10, DIFF_NORMAL, 0 }, + { 7, 7, DIFF_HARD, 0 }, + { 10, 10, DIFF_HARD, 0 }, + { 10, 10, DIFF_HARD, 1 }, + { 12, 10, DIFF_HARD, 2 }, + { 7, 7, DIFF_HARD, 3 }, + { 9, 9, DIFF_HARD, 4 }, + { 5, 4, DIFF_HARD, 5 }, + { 7, 7, DIFF_HARD, 6 }, + { 5, 5, DIFF_HARD, 7 }, + { 5, 5, DIFF_HARD, 8 }, + { 5, 4, DIFF_HARD, 9 }, + { 5, 4, DIFF_HARD, 10 }, + { 10, 10, DIFF_HARD, 11 }, + { 10, 10, DIFF_HARD, 12 } #endif }; @@ -542,9 +537,8 @@ static int game_fetch_preset(int i, char **name, game_params **params) tmppar = snew(game_params); *tmppar = presets[i]; *params = tmppar; - sprintf(buf, "%dx%d %s %s- %s", tmppar->h, tmppar->w, - gridnames[tmppar->type], dualnames[tmppar->dual], - diffnames[tmppar->diff]); + sprintf(buf, "%dx%d %s - %s", tmppar->h, tmppar->w, + gridnames[tmppar->type], diffnames[tmppar->diff]); *name = dupstr(buf); return TRUE; @@ -557,10 +551,8 @@ static void free_params(game_params *params) static void decode_params(game_params *params, char const *string) { - debug(("Decoding params '%s'\n",string)); params->h = params->w = atoi(string); params->diff = DIFF_EASY; - params->dual = 0; while (*string && isdigit((unsigned char)*string)) string++; if (*string == 'x') { string++; @@ -572,10 +564,6 @@ static void decode_params(game_params *params, char const *string) params->type = atoi(string); while (*string && isdigit((unsigned char)*string)) string++; } - if (*string == 'l') { - string++; - params->dual = 1; - } if (*string == 'd') { int i; string++; @@ -589,11 +577,9 @@ static void decode_params(game_params *params, char const *string) static char *encode_params(game_params *params, int full) { char str[80]; - sprintf(str, "%dx%dt%d%s", params->w, params->h, params->type, - params->dual ? "l" : ""); + sprintf(str, "%dx%dt%d", params->w, params->h, params->type); if (full) sprintf(str + strlen(str), "d%c", diffchars[params->diff]); - debug(("Encoded to '%s'\n",str)); return dupstr(str); } @@ -602,7 +588,7 @@ static config_item *game_configure(game_params *params) config_item *ret; char buf[80]; - ret = snewn(6, config_item); + ret = snewn(5, config_item); ret[0].name = "Width"; ret[0].type = C_STRING; @@ -626,15 +612,10 @@ static config_item *game_configure(game_params *params) ret[3].sval = DIFFCONFIG; ret[3].ival = params->diff; - ret[4].name = "Dual"; - ret[4].type = C_BOOLEAN; + ret[4].name = NULL; + ret[4].type = C_END; ret[4].sval = NULL; - ret[4].ival = params->dual; - - ret[5].name = NULL; - ret[5].type = C_END; - ret[5].sval = NULL; - ret[5].ival = 0; + ret[4].ival = 0; return ret; } @@ -647,7 +628,6 @@ static game_params *custom_params(config_item *cfg) ret->h = atoi(cfg[1].sval); ret->type = cfg[2].ival; ret->diff = cfg[3].ival; - ret->dual = cfg[4].ival; return ret; } @@ -742,15 +722,12 @@ static char *validate_desc(game_params *params, char *desc) /* It's pretty inefficient to do this just for validation. All we need to * know is the precise number of faces. */ grid_desc = extract_grid_desc(&desc); - ret = grid_validate_desc(grid_types[params->type], params->w, params->h, params->dual, grid_desc); + ret = grid_validate_desc(grid_types[params->type], params->w, params->h, grid_desc); if (ret) return ret; g = loopy_generate_grid(params, grid_desc); if (grid_desc) sfree(grid_desc); - debug(("Validating '%s' type %d %dx%d dual: %d\n", - desc, params->type, params->w, params->h, params->dual)); - for (; *desc; ++desc) { if ((*desc >= '0' && *desc <= '9') || (*desc >= 'A' && *desc <= 'Z')) { count++; @@ -1396,7 +1373,7 @@ static char *new_game_desc(game_params *params, random_state *rs, game_state *state = snew(game_state); game_state *state_new; - grid_desc = grid_new_desc(grid_types[params->type], params->w, params->h, params->dual, rs); + grid_desc = grid_new_desc(grid_types[params->type], params->w, params->h, rs); state->game_grid = g = loopy_generate_grid(params, grid_desc); state->clues = snewn(g->num_faces, signed char); @@ -2836,7 +2813,7 @@ static char *solve_game(game_state *state, game_state *currstate, * Drawing and mouse-handling */ -static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds, +static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds, int x, int y, int button) { grid *g = state->game_grid; @@ -3216,60 +3193,63 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate, * what needs doing, and the second actually does it. */ - if (!ds->started) + if (!ds->started) { redraw_everything = TRUE; - else { - - /* First, trundle through the faces. */ - for (i = 0; i < g->num_faces; i++) { - grid_face *f = g->faces + i; - int sides = f->order; - int clue_mistake; - int clue_satisfied; - int n = state->clues[i]; - if (n < 0) - continue; - - clue_mistake = (face_order(state, i, LINE_YES) > n || - face_order(state, i, LINE_NO ) > (sides-n)); - clue_satisfied = (face_order(state, i, LINE_YES) == n && - face_order(state, i, LINE_NO ) == (sides-n)); - - if (clue_mistake != ds->clue_error[i] || - clue_satisfied != ds->clue_satisfied[i]) { - ds->clue_error[i] = clue_mistake; - ds->clue_satisfied[i] = clue_satisfied; - if (nfaces == REDRAW_OBJECTS_LIMIT) - redraw_everything = TRUE; - else - faces[nfaces++] = i; - } - } + /* + * But we must still go through the upcoming loops, so that we + * set up stuff in ds correctly for the initial redraw. + */ + } - /* Work out what the flash state needs to be. */ - if (flashtime > 0 && - (flashtime <= FLASH_TIME/3 || - flashtime >= FLASH_TIME*2/3)) { - flash_changed = !ds->flashing; - ds->flashing = TRUE; - } else { - flash_changed = ds->flashing; - ds->flashing = FALSE; - } + /* First, trundle through the faces. */ + for (i = 0; i < g->num_faces; i++) { + grid_face *f = g->faces + i; + int sides = f->order; + int clue_mistake; + int clue_satisfied; + int n = state->clues[i]; + if (n < 0) + continue; - /* Now, trundle through the edges. */ - for (i = 0; i < g->num_edges; i++) { - char new_ds = - state->line_errors[i] ? DS_LINE_ERROR : state->lines[i]; - if (new_ds != ds->lines[i] || - (flash_changed && state->lines[i] == LINE_YES)) { - ds->lines[i] = new_ds; - if (nedges == REDRAW_OBJECTS_LIMIT) - redraw_everything = TRUE; - else - edges[nedges++] = i; - } - } + clue_mistake = (face_order(state, i, LINE_YES) > n || + face_order(state, i, LINE_NO ) > (sides-n)); + clue_satisfied = (face_order(state, i, LINE_YES) == n && + face_order(state, i, LINE_NO ) == (sides-n)); + + if (clue_mistake != ds->clue_error[i] || + clue_satisfied != ds->clue_satisfied[i]) { + ds->clue_error[i] = clue_mistake; + ds->clue_satisfied[i] = clue_satisfied; + if (nfaces == REDRAW_OBJECTS_LIMIT) + redraw_everything = TRUE; + else + faces[nfaces++] = i; + } + } + + /* Work out what the flash state needs to be. */ + if (flashtime > 0 && + (flashtime <= FLASH_TIME/3 || + flashtime >= FLASH_TIME*2/3)) { + flash_changed = !ds->flashing; + ds->flashing = TRUE; + } else { + flash_changed = ds->flashing; + ds->flashing = FALSE; + } + + /* Now, trundle through the edges. */ + for (i = 0; i < g->num_edges; i++) { + char new_ds = + state->line_errors[i] ? DS_LINE_ERROR : state->lines[i]; + if (new_ds != ds->lines[i] || + (flash_changed && state->lines[i] == LINE_YES)) { + ds->lines[i] = new_ds; + if (nedges == REDRAW_OBJECTS_LIMIT) + redraw_everything = TRUE; + else + edges[nedges++] = i; + } } /* Pass one is now done. Now we do the actual drawing. */