X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/e30d39f6f3df08ea9c8a91df5db31d0346d1c5ad..b0a2ee969ddd95665e0cbfd18b50c9d69e6346e0:/loopy.c diff --git a/loopy.c b/loopy.c index 07f17a9..64c45da 100644 --- a/loopy.c +++ b/loopy.c @@ -254,7 +254,9 @@ static void check_caches(const solver_state* sstate); A(Great-Hexagonal,grid_new_greathexagonal,3,3) \ A(Octagonal,grid_new_octagonal,3,3) \ A(Kites,grid_new_kites,3,3) \ - A(Floret,grid_new_floret,1,2) + A(Floret,grid_new_floret,1,2) \ + A(Dodecagonal,grid_new_dodecagonal,2,2) \ + A(Great-Dodecagonal,grid_new_greatdodecagonal,2,2) #define GRID_NAME(title,fn,amin,omin) #title, #define GRID_CONFIG(title,fn,amin,omin) ":" #title @@ -301,7 +303,7 @@ static void params_generate_grid(game_params *params) ((field) &= ~(1<<(bit)), TRUE) : FALSE) #define CLUE2CHAR(c) \ - ((c < 0) ? ' ' : c + '0') + ((c < 0) ? ' ' : c < 10 ? c + '0' : c - 10 + 'A') /* ---------------------------------------------------------------------- * General struct manipulation and other straightforward code @@ -506,6 +508,8 @@ static const game_params presets[] = { { 5, 5, DIFF_HARD, 6, NULL }, { 5, 5, DIFF_HARD, 7, NULL }, { 3, 3, DIFF_HARD, 8, NULL }, + { 3, 3, DIFF_HARD, 9, NULL }, + { 3, 3, DIFF_HARD, 10, NULL }, #else { 7, 7, DIFF_EASY, 0, NULL }, { 10, 10, DIFF_EASY, 0, NULL }, @@ -521,6 +525,8 @@ static const game_params presets[] = { { 7, 7, DIFF_HARD, 6, NULL }, { 5, 5, DIFF_HARD, 7, NULL }, { 5, 5, DIFF_HARD, 8, NULL }, + { 5, 4, DIFF_HARD, 9, NULL }, + { 5, 4, DIFF_HARD, 10, NULL }, #endif }; @@ -705,7 +711,7 @@ static char *validate_desc(game_params *params, char *desc) g = params->game_grid; for (; *desc; ++desc) { - if (*desc >= '0' && *desc <= '9') { + if ((*desc >= '0' && *desc <= '9') || (*desc >= 'A' && *desc <= 'Z')) { count++; continue; } @@ -1822,6 +1828,7 @@ static char *new_game_desc(game_params *params, random_state *rs, grid *g; game_state *state = snew(game_state); game_state *state_new; + int count = 0; params_generate_grid(params); state->game_grid = g = params->game_grid; g->refcount++; @@ -1843,6 +1850,7 @@ static char *new_game_desc(game_params *params, random_state *rs, * preventing games smaller than 4x4 seems to stop this happening */ do { add_full_clues(state, rs); + if (++count%100 == 0) printf("tried %d times to make a unique board\n", count); } while (!game_has_unique_soln(state, params->diff)); state_new = remove_clues(state, rs, params->diff); @@ -1871,7 +1879,7 @@ static game_state *new_game(midend *me, game_params *params, char *desc) int i; game_state *state = snew(game_state); int empties_to_make = 0; - int n; + int n,n2; const char *dp = desc; grid *g; int num_faces, num_edges; @@ -1899,8 +1907,11 @@ static game_state *new_game(midend *me, game_params *params, char *desc) assert(*dp); n = *dp - '0'; + n2 = *dp - 'A' + 10; if (n >= 0 && n < 10) { state->clues[i] = n; + } else if (n2 >= 10 && n2 < 36) { + state->clues[i] = n2; } else { n = *dp - 'a' + 1; assert(n > 0); @@ -2534,7 +2545,7 @@ static int dline_deductions(solver_state *sstate) * on that. We check this with an assertion, in case someone decides to * make a grid which has larger faces than this. Note, this algorithm * could get quite expensive if there are many large faces. */ -#define MAX_FACE_SIZE 8 +#define MAX_FACE_SIZE 12 for (i = 0; i < g->num_faces; i++) { int maxs[MAX_FACE_SIZE][MAX_FACE_SIZE]; @@ -3356,10 +3367,14 @@ static void game_redraw_clue(drawing *dr, game_drawstate *ds, grid *g = state->game_grid; grid_face *f = g->faces + i; int x, y; - char c[2]; + char c[3]; - c[0] = CLUE2CHAR(state->clues[i]); - c[1] = '\0'; + if (state->clues[i] < 10) { + c[0] = CLUE2CHAR(state->clues[i]); + c[1] = '\0'; + } else { + sprintf(c, "%d", state->clues[i]); + } face_text_pos(ds, g, f, &x, &y); draw_text(dr, x, y, @@ -3369,8 +3384,13 @@ static void game_redraw_clue(drawing *dr, game_drawstate *ds, ds->clue_satisfied[i] ? COL_SATISFIED : COL_FOREGROUND, c); } +static const int loopy_line_redraw_phases[] = { + COL_FAINT, COL_LINEUNKNOWN, COL_FOREGROUND, COL_HIGHLIGHT, COL_MISTAKE +}; +#define NPHASES lenof(loopy_line_redraw_phases) + static void game_redraw_line(drawing *dr, game_drawstate *ds, - game_state *state, int i) + game_state *state, int i, int phase) { grid *g = state->game_grid; grid_edge *e = g->edges + i; @@ -3388,6 +3408,8 @@ static void game_redraw_line(drawing *dr, game_drawstate *ds, line_colour = COL_HIGHLIGHT; else line_colour = COL_FOREGROUND; + if (line_colour != loopy_line_redraw_phases[phase]) + return; /* Convert from grid to screen coordinates */ grid_to_screen(ds, g, e->dot1->x, e->dot1->y, &x1, &y1); @@ -3434,7 +3456,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate, grid *g = state->game_grid; int border = BORDER(ds->tilesize); - int i; + int i, phase; int flash_changed; int redraw_everything = FALSE; @@ -3537,8 +3559,9 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate, for (i = 0; i < g->num_faces; i++) game_redraw_clue(dr, ds, state, i); - for (i = 0; i < g->num_edges; i++) - game_redraw_line(dr, ds, state, i); + for (phase = 0; phase < NPHASES; phase++) + for (i = 0; i < g->num_edges; i++) + game_redraw_line(dr, ds, state, i, phase); for (i = 0; i < g->num_dots; i++) game_redraw_dot(dr, ds, state, i); @@ -3564,8 +3587,10 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate, draw_rect(dr, x, y, w, h, COL_BACKGROUND); game_redraw_clue(dr, ds, state, faces[i]); - for (j = 0; j < f->order; j++) - game_redraw_line(dr, ds, state, f->edges[j] - g->edges); + for (phase = 0; phase < NPHASES; phase++) + for (j = 0; j < f->order; j++) + game_redraw_line(dr, ds, state, f->edges[j] - g->edges, + phase); for (j = 0; j < f->order; j++) game_redraw_dot(dr, ds, state, f->dots[j] - g->dots); unclip(dr); @@ -3599,17 +3624,19 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate, if (e->face2) game_redraw_clue(dr, ds, state, e->face2 - g->faces); - game_redraw_line(dr, ds, state, edges[i]); - for (j = 0; j < e->dot1->order; j++) { - ee = e->dot1->edges[j]; - if (ee != e) - game_redraw_line(dr, ds, state, ee - g->edges); - } - for (j = 0; j < e->dot2->order; j++) { - ee = e->dot2->edges[j]; - if (ee != e) - game_redraw_line(dr, ds, state, ee - g->edges); - } + for (phase = 0; phase < NPHASES; phase++) { + game_redraw_line(dr, ds, state, edges[i], phase); + for (j = 0; j < e->dot1->order; j++) { + ee = e->dot1->edges[j]; + if (ee != e) + game_redraw_line(dr, ds, state, ee - g->edges, phase); + } + for (j = 0; j < e->dot2->order; j++) { + ee = e->dot2->edges[j]; + if (ee != e) + game_redraw_line(dr, ds, state, ee - g->edges, phase); + } + } game_redraw_dot(dr, ds, state, e->dot1 - g->dots); game_redraw_dot(dr, ds, state, e->dot2 - g->dots);