X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/d68762325555dfb025d58f77f95557098fadf0c8..75bed5b2d4b955c4f9cbed006ca00feb40842f27:/solo.c diff --git a/solo.c b/solo.c index fc2ac04..7062194 100644 --- a/solo.c +++ b/solo.c @@ -582,7 +582,6 @@ static struct block_structure *dup_block_structure(struct block_structure *b) nb->blocks[i] = nb->blocks_data + i*nb->max_nr_squares; #ifdef STANDALONE_SOLVER - nb->blocknames = (char **)smalloc(b->c * b->r *(sizeof(char *)+80)); memcpy(nb->blocknames, b->blocknames, b->c * b->r *(sizeof(char *)+80)); { int i; @@ -831,6 +830,24 @@ static void solver_place(struct solver_usage *usage, int x, int y, int n) } } +#if defined STANDALONE_SOLVER && defined __GNUC__ +/* + * Forward-declare the functions taking printf-like format arguments + * with __attribute__((format)) so as to ensure the argument syntax + * gets debugged. + */ +struct solver_scratch; +static int solver_elim(struct solver_usage *usage, int *indices, + char *fmt, ...) __attribute__((format(printf,3,4))); +static int solver_intersect(struct solver_usage *usage, + int *indices1, int *indices2, char *fmt, ...) + __attribute__((format(printf,4,5))); +static int solver_set(struct solver_usage *usage, + struct solver_scratch *scratch, + int *indices, char *fmt, ...) + __attribute__((format(printf,4,5))); +#endif + static int solver_elim(struct solver_usage *usage, int *indices #ifdef STANDALONE_SOLVER , char *fmt, ... @@ -1456,7 +1473,7 @@ static int solver_killer_sums(struct solver_usage *usage, int b, } assert(nsquares > 0); - if (nsquares > 4) + if (nsquares < 2 || nsquares > 4) return 0; if (!cage_is_region) { @@ -1697,7 +1714,10 @@ static void solver(int cr, struct block_structure *blocks, usage->cube = snewn(cr*cr*cr, unsigned char); usage->grid = grid; /* write straight back to the input */ if (kgrid) { - int nclues = kblocks->nr_blocks; + int nclues; + + assert(kblocks); + nclues = kblocks->nr_blocks; /* * Allow for expansion of the killer regions, the absolute * limit is obviously one region per square. @@ -2021,7 +2041,7 @@ static void solver(int cr, struct block_structure *blocks, ); if (ret > 0) { changed = TRUE; - kdiff = max(kdiff, DIFF_KINTERSECT); + kdiff = max(kdiff, DIFF_KSUMS); } else if (ret < 0) { diff = DIFF_IMPOSSIBLE; goto got_result; @@ -2237,7 +2257,7 @@ static void solver(int cr, struct block_structure *blocks, #ifdef STANDALONE_SOLVER , "intersectional analysis," " %d in \\-diagonal vs block %s", - n, 1+x, usage->blocks->blocknames[b] + n, usage->blocks->blocknames[b] #endif ) || solver_intersect(usage, scratch->indexlist2, @@ -2245,7 +2265,7 @@ static void solver(int cr, struct block_structure *blocks, #ifdef STANDALONE_SOLVER , "intersectional analysis," " %d in block %s vs \\-diagonal", - n, usage->blocks->blocknames[b], 1+x + n, usage->blocks->blocknames[b] #endif )) { diff = max(diff, DIFF_INTERSECT); @@ -2270,7 +2290,7 @@ static void solver(int cr, struct block_structure *blocks, #ifdef STANDALONE_SOLVER , "intersectional analysis," " %d in /-diagonal vs block %s", - n, 1+x, usage->blocks->blocknames[b] + n, usage->blocks->blocknames[b] #endif ) || solver_intersect(usage, scratch->indexlist2, @@ -2278,7 +2298,7 @@ static void solver(int cr, struct block_structure *blocks, #ifdef STANDALONE_SOLVER , "intersectional analysis," " %d in block %s vs /-diagonal", - n, usage->blocks->blocknames[b], 1+x + n, usage->blocks->blocknames[b] #endif )) { diff = max(diff, DIFF_INTERSECT); @@ -2382,7 +2402,7 @@ static void solver(int cr, struct block_structure *blocks, scratch->indexlist[i*cr+n-1] = cubepos2(diag1(i), n); ret = solver_set(usage, scratch, scratch->indexlist #ifdef STANDALONE_SOLVER - , "set elimination, \\-diagonal" + , "set elimination, /-diagonal" #endif ); if (ret < 0) { @@ -2589,6 +2609,8 @@ static void solver(int cr, struct block_structure *blocks, "one solution"); #endif + sfree(usage->sq2region); + sfree(usage->regions); sfree(usage->cube); sfree(usage->row); sfree(usage->col); @@ -2598,6 +2620,7 @@ static void solver(int cr, struct block_structure *blocks, free_block_structure(usage->extra_cages); sfree(usage->extra_clues); } + if (usage->kclues) sfree(usage->kclues); sfree(usage); solver_free_scratch(scratch); @@ -3551,13 +3574,8 @@ static char *new_game_desc(game_params *params, random_state *rs, blocks = alloc_block_structure (c, r, area, cr, cr); - if (params->killer) { - kblocks = alloc_block_structure (c, r, area, cr, area); - kgrid = snewn(area, digit); - } else { - kblocks = NULL; - kgrid = NULL; - } + kblocks = NULL; + kgrid = (params->killer) ? snewn(area, digit) : NULL; #ifdef STANDALONE_SOLVER assert(!"This should never happen, so we don't need to create blocknames"); @@ -3587,6 +3605,7 @@ static char *new_game_desc(game_params *params, random_state *rs, make_blocks_from_whichblock(blocks); if (params->killer) { + if (kblocks) free_block_structure(kblocks); kblocks = gen_killer_cages(cr, rs, params->kdiff > DIFF_KSINGLE); } @@ -3753,6 +3772,11 @@ static char *new_game_desc(game_params *params, random_state *rs, desc = encode_puzzle_desc(params, grid, blocks, kgrid, kblocks); sfree(grid); + free_block_structure(blocks); + if (params->killer) { + free_block_structure(kblocks); + sfree(kgrid); + } return desc; } @@ -4150,6 +4174,7 @@ static void free_game(game_state *state) sfree(state->immutable); sfree(state->pencil); sfree(state->grid); + if (state->kgrid) sfree(state->kgrid); sfree(state); } @@ -4544,13 +4569,13 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds, ((button >= '0' && button <= '9' && button - '0' <= cr) || (button >= 'a' && button <= 'z' && button - 'a' + 10 <= cr) || (button >= 'A' && button <= 'Z' && button - 'A' + 10 <= cr) || - button == CURSOR_SELECT2 || button == '\010' || button == '\177')) { + button == CURSOR_SELECT2 || button == '\b')) { int n = button - '0'; if (button >= 'A' && button <= 'Z') n = button - 'A' + 10; if (button >= 'a' && button <= 'z') n = button - 'a' + 10; - if (button == CURSOR_SELECT2 || button == '\010' || button == '\177') + if (button == CURSOR_SELECT2 || button == '\b') n = 0; /* @@ -5162,6 +5187,11 @@ static float game_flash_length(game_state *oldstate, game_state *newstate, return 0.0F; } +static int game_status(game_state *state) +{ + return state->completed ? +1 : 0; +} + static int game_timing_state(game_state *state, game_ui *ui) { if (state->completed) @@ -5481,6 +5511,7 @@ const struct game thegame = { game_redraw, game_anim_length, game_flash_length, + game_status, TRUE, FALSE, game_print_size, game_print, FALSE, /* wants_statusbar */ FALSE, game_timing_state, @@ -5547,7 +5578,7 @@ int main(int argc, char **argv) dlev.diff==DIFF_IMPOSSIBLE ? "Impossible (no solution exists)": "INTERNAL ERROR: unrecognised difficulty code"); if (p->killer) - printf("Killer diffculty: %s\n", + printf("Killer difficulty: %s\n", dlev.kdiff==DIFF_KSINGLE ? "Trivial (single square cages only)": dlev.kdiff==DIFF_KMINMAX ? "Simple (maximum sum analysis required)": dlev.kdiff==DIFF_KSUMS ? "Intermediate (sum possibilities)":