aboutsummaryrefslogtreecommitdiff
path: root/latin.h (follow)
Commit message (Collapse)AuthorAge
* latin_solver_alloc: handle clashing numbers in input grid.Simon Tatham2023-02-05
| | | | | | | | | | | | | | | | | | | | | In the setup phase of the centralised latin.c solver, we start by going over the input grid containing already-placed clue numbers, and calling latin_solver_place to enter each on into the solver's data structure. This has the side effect of ruling out each number from the rest of the row and column, and _also_ checking by assertion that the number being placed is not ruled out. Those are a bad combination, because it means that if you give an obviously inconsistent input grid to latin_solver_alloc (e.g. with two identical numbers in a row already), it will fail an assertion. In that situation, you want the solver run as a whole to return diff_impossible so that the error is reported cleanly. This assertion failure could be provoked by giving either Towers or Group a manually-constructed game description inconsistent in that way, and hitting Solve. Worse, it could be provoked during live play in Unequal, by filling in a number clashing with a clue and then pressing 'h' to get hints.
* latin.c: call a user-provided validator function. [NFC]Simon Tatham2020-05-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I've only just realised that there's a false-positive bug in the latin.c solver framework. It's designed to solve puzzles in which the solution is a latin square but with some additional constraints provided by the individual puzzle, and so during solving, it runs a mixture of its own standard deduction functions that apply to any latin-square puzzle and extra functions provided by the client puzzle to do deductions based on the extra clues or constraints. But what happens if the _last_ move in the solving process is performed by one of the latin.c built-in methods, and it causes a violation of the client puzzle's extra constraints? Nothing will ever notice, and so the solver will report that the puzzle has a solution when it actually has none. An example is the Group game id 12i:m12b9a1zd9i6d10c3y2l11q4r . This was reported by 'groupsolver -g' as being ambiguous. But if you look at the two 'solutions' reported in the verbose diagnostics, one of them is arrant nonsense: it has no identity element at all, and therefore, it fails associativity all over the place. Actually that puzzle _does_ have a unique solution. This bug has been around for ages, and nobody has reported a problem. For recursive solving, that's not much of a surprise, because it would cause a spurious accusation of ambiguity, so that at generation time some valid puzzles would be wrongly discarded, and you'd never see them. But at non-recursive levels, I can't see a reason why this bug _couldn't_ have led one of the games to present an actually impossible puzzle believing it to be soluble. Possibly this never came up because the other clients of latin.c are more forgiving of this error in some way. For example, they might all be very likely to use their extra clues early in the solving process, so that the requirements are already baked in by the time the final grid square is filled. I don't know! Anyway. The fix is to introduce last-minute client-side validation: whenever the centralised latin_solver thinks it's come up with a filled grid, it should present it to a puzzle-specific validator function and check that it's _really_ a legal solution. This commit does the plumbing for all of that: it introduces the new validator function as one of the many parameters to latin_solver, and arranges to call it in an appropriate way during the solving process. But all the per-puzzle validation functions are empty, for the moment.
* Replace TRUE/FALSE with C99 true/false throughout.Simon Tatham2018-11-13
| | | | | | This commit removes the old #defines of TRUE and FALSE from puzzles.h, and does a mechanical search-and-replace throughout the code to replace them with the C99 standard lowercase spellings.
* Adopt C99 bool in the shared Latin-square API.Simon Tatham2018-11-13
| | | | | latin_check now returns bool, and latin_solver_diff_set takes a bool 'extreme' flag. Should be non-disruptive.
* Fix an inaccurate comment.Simon Tatham2018-11-06
| | | | | | | | | latin_solver_diff_set takes a boolean input parameter to indicate whether the 'Extreme'-level variant of set elimination is permitted. But it's commented in the header file as having a boolean _output_ parameter which it sets if it _ended up_ using that variant. Probably the latter was how it worked in an early draft, and I changed my mind later without changing the comment.
* Make the code base clean under -Wwrite-strings.Simon Tatham2017-10-01
| | | | | I've also added that warning option and -Werror to the build script, so that I'll find out if I break this property in future.
* New puzzle from James Harvey: 'Singles', an implementation ofSimon Tatham2010-01-11
| | | | | | | | Hitori. One infrastructure change in the process: latin.c has acquired a utility function to generate a latin rectangle rather than a full square. [originally from svn r8828]
* Retire the YTRANS and YUNTRANS macros in latin.[ch]. They wereSimon Tatham2010-01-11
| | | | | | | | | introduced to mimic similar macros in solo.c, in case Solo ever moved over to being based on the latin.c solver framework; but even Solo has long since lost those macros, so latin.c has no need to keep them. [originally from svn r8827]
* Add a facility in the latin.c solver diagnostics to allow a puzzleSimon Tatham2010-01-05
| | | | | | to call the digit values by custom names. [originally from svn r8811]
* I've never trusted common variables. Take those bare ints out ofSimon Tatham2009-12-27
| | | | | | | latin.h and put them in latin.c with 'extern' declarations in the header. [originally from svn r8794]
* Refactor latin.c to make it easier to reuse. Instead of clientSimon Tatham2009-12-27
| | | | | | | | | | | 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]
* latin_generate_quick is long gone, so remove it from the header file.Simon Tatham2009-12-23
| | | | [originally from svn r8789]
* Patch from James H to fix the occasional generation of puzzlesSimon Tatham2007-01-15
| | | | | | harder than requested. [originally from svn r7113]
* Add James H's new puzzle, `Unequal' (otherwise known as theSimon Tatham2007-01-13
Guardian's `Futoshiki'). [originally from svn r7100]