mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 23:51:29 -07:00
Refactor latin.c to make it easier to reuse. Instead of client
programs having to clone the latin_solver() function and insert their own extra deduction routines, they can now just _call_ latin_solver with enough parameters to let it fit its own deductions into their difficulty framework and call a set of provided function pointers to do user deductions. Modified Unequal to work in the new world, of course. [originally from svn r8791]
This commit is contained in:
24
latin.h
24
latin.h
@ -88,17 +88,27 @@ int latin_solver_diff_set(struct latin_solver *solver,
|
||||
struct latin_solver_scratch *scratch,
|
||||
int extreme);
|
||||
|
||||
typedef int (latin_solver_callback)(digit *, int, int, void*);
|
||||
/* Use to provide a standard way of dealing with solvers which can recurse;
|
||||
* pass in your enumeration for 'recursive diff' and your solver
|
||||
* callback. Returns #solutions (0 == already solved). */
|
||||
int latin_solver_recurse(struct latin_solver *solver, int recdiff,
|
||||
latin_solver_callback cb, void *ctx);
|
||||
typedef int (*usersolver_t)(struct latin_solver *solver, void *ctx);
|
||||
typedef void *(*ctxnew_t)(void *ctx);
|
||||
typedef void (*ctxfree_t)(void *ctx);
|
||||
|
||||
/* Individual puzzles should use their enumerations for their
|
||||
* own difficulty levels, ensuring they don't clash with these. */
|
||||
enum { diff_impossible = 10, diff_ambiguous, diff_unfinished };
|
||||
int latin_solver(digit *grid, int order, int maxdiff, void *unused);
|
||||
|
||||
/* Externally callable function that allocates and frees a latin_solver */
|
||||
int latin_solver(digit *grid, int o, int maxdiff,
|
||||
int diff_simple, int diff_set_0, int diff_set_1,
|
||||
int diff_forcing, int diff_recursive,
|
||||
usersolver_t const *usersolvers, void *ctx,
|
||||
ctxnew_t ctxnew, ctxfree_t ctxfree);
|
||||
|
||||
/* Version you can call if you want to alloc and free latin_solver yourself */
|
||||
int latin_solver_main(struct latin_solver *solver, int maxdiff,
|
||||
int diff_simple, int diff_set_0, int diff_set_1,
|
||||
int diff_forcing, int diff_recursive,
|
||||
usersolver_t const *usersolvers, void *ctx,
|
||||
ctxnew_t ctxnew, ctxfree_t ctxfree);
|
||||
|
||||
void latin_solver_debug(unsigned char *cube, int o);
|
||||
|
||||
|
Reference in New Issue
Block a user