aboutsummaryrefslogtreecommitdiff
path: root/solo.c (follow)
Commit message (Collapse)AuthorAge
* Add method for frontends to query the backend's cursor location.Franklin Wei2020-12-07
| | | | | | | | | | | | | | | | The Rockbox frontend allows games to be displayed in a "zoomed-in" state targets with small displays. Currently we use a modal interface -- a "viewing" mode in which the cursor keys are used to pan around the rendered bitmap; and an "interaction" mode that actually sends keys to the game. This commit adds a midend_get_cursor_location() function to allow the frontend to retrieve the backend's cursor location or other "region of interest" -- such as the player location in Cube or Inertia. With this information, the Rockbox frontend can now intelligently follow the cursor around in the zoomed-in state, eliminating the need for a modal interface.
* Add missing 'static' to game-internal declarations.Simon Tatham2018-11-13
| | | | | | | | | Another thing I spotted while trawling the whole source base was that a couple of games had omitted 'static' on a lot of their internal functions. Checking with nm, there turned out to be quite a few more than I'd spotted by eye, so this should fix them all. Also added one missing 'const', on the lookup table nbits[] in Tracks.
* Use C99 bool within source modules.Simon Tatham2018-11-13
| | | | | | | | | | This is the main bulk of this boolification work, but although it's making the largest actual change, it should also be the least disruptive to anyone interacting with this code base downstream of me, because it doesn't modify any interface between modules: all the inter-module APIs were updated one by one in the previous commits. This just cleans up the code within each individual source file to use bool in place of int where I think that makes things clearer.
* 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 game backend API.Simon Tatham2018-11-13
| | | | | | | | | | | encode_params, validate_params and new_desc now take a bool parameter; fetch_preset, can_format_as_text_now and timing_state all return bool; and the data fields is_timed, wants_statusbar and can_* are all bool. All of those were previously typed as int, but semantically boolean. This commit changes the API declarations in puzzles.h, updates all the games to match (including the unfinisheds), and updates the developer docs as well.
* Add a request_keys() function with a midend wrapper.Franklin Wei2018-04-22
| | | | | | | | This function gives the front end a way to find out what keys the back end requires; and as such it is mostly useful for ports without a keyboard. It is based on changes originally found in Chris Boyle's Android port, though some modifications were needed to make it more flexible.
* Solo: add a missing params constraint for X puzzles.Simon Tatham2018-04-08
| | | | | | | | | | Michael Quevillon points out that neither 2x1 nor 3x1 Solo can be made into an X Sudoku puzzle, on the grounds that whatever number goes in one corner of the grid is ruled out from both ends (and the centre, if any) of the opposing diagonal, and hence the X constraint can't be satisfied. (Also fixed a spurious full stop on a neighbouring line.)
* Fix false-positive completion detection in X Solo.Simon Tatham2018-03-25
| | | | | | | | | | Spotted by Michael Quevillon. After checking the set of digits appearing in one of the two main grid diagonals, we weren't clearing the used[] array before using it to check the same thing about the other diagonal. So if the first diagonal we check has one of everything, then the second will be misidentified as correct (for the purposes of game-completion detection, although not error highlighting) even if it doesn't have one of everything.
* Solo: remove some overzealous assertions in the solver.Simon Tatham2017-10-28
| | | | | | | | | | | | | | | | | | | | There were a couple of places where we enforced by assertion that our solver state had not become inconsistent, on the assumption that some previous piece of solver would have detected that the puzzle was impossible before getting to that place in the code. But in fact the combination of Killer and Unreasonable modes falsified at least two of those assumptions: 'solo --test-solve --generate 100 3x3kdu#12345' triggered an assertion failure in solver_set, and with that one fixed, the same command triggered a second failure in solver_killer_sums. In both cases, the fix is simply to return -1 for 'puzzle is inconsistent', which will cause the Unreasonable recursive solver to abandon that branch of its search tree, backtrack, and try a different guess at some previous square. Thanks to Anders Höglund for the report.
* 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.
* Return error messages as 'const char *', not 'char *'.Simon Tatham2017-10-01
| | | | | They're never dynamically allocated, and are almost always string literals, so const is more appropriate.
* Use a proper union in struct config_item.Simon Tatham2017-10-01
| | | | | | This allows me to use different types for the mutable, dynamically allocated string value in a C_STRING control and the fixed constant list of option names in a C_CHOICES.
* New name UI_UPDATE for interpret_move's return "".Simon Tatham2017-10-01
| | | | | | | | | | | | | Now midend.c directly tests the returned pointer for equality to this value, instead of checking whether it's the empty string. A minor effect of this is that games may now return a dynamically allocated empty string from interpret_move() and treat it as just another legal move description. But I don't expect anyone to be perverse enough to actually do that! The main purpose is that it avoids returning a string literal from a function whose return type is a pointer to _non-const_ char, i.e. we are now one step closer to being able to make this code base clean under -Wwrite-strings.
* Rework the preset menu system to permit submenus.Simon Tatham2017-04-26
| | | | | | | | | | | | | | | | | | | | To do this, I've completely replaced the API between mid-end and front end, so any downstream front end maintainers will have to do some rewriting of their own (sorry). I've done the necessary work in all five of the front ends I keep in-tree here - Windows, GTK, OS X, Javascript/Emscripten, and Java/NestedVM - and I've done it in various different styles (as each front end found most convenient), so that should provide a variety of sample code to show downstreams how, if they should need it. I've left in the old puzzle back-end API function to return a flat list of presets, so for the moment, all the puzzle backends are unchanged apart from an extra null pointer appearing in their top-level game structure. In a future commit I'll actually use the new feature in a puzzle; perhaps in the further future it might make sense to migrate all the puzzles to the new API and stop providing back ends with two alternative ways of doing things, but this seemed like enough upheaval for one day.
* Fix completion checking in Killer Solo.Simon Tatham2016-10-28
| | | | | | The check_valid() function was not verifying that each Killer cage summed to the right thing! Thanks to Chris Goodyer for spotting it. I wonder how nobody else has, in 8 years.
* Solo, Undead: support 'm' to fill in all pencils.Simon Tatham2015-07-13
| | | | | | | | | | Keen, Towers and Unequal (and Group) already have this feature in common: pressing m while no square is selected, causes a full set of pencil marks to be filled in for every square without a real number/ letter/whatever in it. Solo and Undead share the basic UI principles (left-click to select a square then type a thing to go in it, vs right-click to select a square then type things to pencil-mark in it), but did not have that same feature. Now they do.
* Remove an inappropriate assertion in validation context.Simon Tatham2014-11-26
| | | | | | | | | | spec_to_dsf() should not report invalid input by failing an assertion, because one of the contexts it's called from is validate_desc(), in which the whole point is to present a useful error message to the user before getting to the point where an assertion might go off at all. Game description 5j:c1_5o4_3c,c___aba___cca_a_a_aca now fails validation cleanly, where previously it would trigger this bug.
* Fix a decoding bug in Solo block-structure descriptions.Simon Tatham2014-11-26
| | | | | | | | Due to a copy-and-paste error, I was accidentally treating 'y' as the special-case character which puts no 1 bit after the run of 0s, which should have been 'z'. Game id 9jk#12345-5994 failed an assertion as a result (because it generates a y which was accidentally treated as special).
* Giant const patch of doom: add a 'const' to every parameter in everySimon Tatham2013-04-13
| | | | | | | | | | | | | | puzzle backend function which ought to have it, and propagate those consts through to per-puzzle subroutines as needed. I've recently had to do that to a few specific parameters which were being misused by particular puzzles (r9657, r9830), which suggests that it's probably a good idea to do the whole lot pre-emptively before the next such problem shows up. [originally from svn r9832] [r9657 == 3b250baa02a7332510685948bf17576c397b8ceb] [r9830 == 0b93de904a98f119b1a95d3a53029f1ed4bfb9b3]
* Add 'const' to the game_params arguments in validate_desc andSimon Tatham2013-04-12
| | | | | | | | | | | | new_desc. Oddities in the 'make test' output brought to my attention that a few puzzles have been modifying their input game_params for various reasons; they shouldn't do that, because that's the game_params held permanently by the midend and it will affect subsequent game generations if they modify it. So now those arguments are const, and all the games which previously modified their game_params now take a copy and modify that instead. [originally from svn r9830]
* New rule: interpret_move() is passed a pointer to the game_drawstateSimon Tatham2012-09-09
| | | | | | | | | | | | | | | | basically just so that it can divide mouse coordinates by the tile size, but is definitely not expected to _write_ to it, and it hadn't previously occurred to me that anyone might try. Therefore, interpret_move() now gets a pointer to a _const_ game_drawstate instead of a writable one. All existing puzzles cope fine with this API change (as long as the new const qualifier is also added to a couple of subfunctions to which interpret_move delegates work), except for the just-committed Undead, which somehow had ds->ascii and ui->ascii the wrong way round but is otherwise unproblematic. [originally from svn r9657]
* Don't fail an assertion when setting up the provided clues at theSimon Tatham2012-07-29
| | | | | | | start of the solver, if they contradict each other. (Could trigger on user-provided grids.) [originally from svn r9594]
* Correct kdiff setting.Simon Tatham2012-02-02
| | | | [originally from svn r9403]
* Don't try to run solver_killer_sums on a Killer cage with only oneSimon Tatham2012-02-02
| | | | | | | | | | square. It isn't equipped for it, and will try to handle it with the 4-square case and get confused. This can come up if the DIFF_KINTERSECT pass before that split a cage, and will cause the solver to miss valid solutions; e.g. 3x3kadu#802065940985372 would generate an ambiguous puzzle before this change. [originally from svn r9402]
* Fix a couple of typos in messages.Simon Tatham2012-02-02
| | | | [originally from svn r9401]
* Changed my mind about midend_is_solved: I've now reprototyped it asSimon Tatham2011-06-19
| | | | | | | | | | | | | | | | midend_status(), and given it three return codes for win, (permanent) loss and game-still-in-play. Depending on what the front end wants to use it for, it may find any or all of these three states worth distinguishing from each other. (I suppose a further enhancement might be to add _non_-permanent loss as a fourth distinct status, to describe situations in which you can't play further without pressing Undo but doing so is not completely pointless. That might reasonably include dead-end situations in Same Game and Pegs, and blown-self-up situations in Mines and Inertia. However, I haven't done this at present.) [originally from svn r9179]
* Fix mismatch between printf format strings and arguments in someSimon Tatham2011-04-11
| | | | | | | | | | | solosolver verbose diagnostics in X mode. Also added gcc-specific prototypes with __attribute__((format)) to ensure they all get checked in future. Spotted by Arun Giridhar; segfault without this fix is reproducible by 'solosolver -v 3x3x:7_9e4_1c7d3e3d1b2_4e2c6e5_6b1d8e5d9c8_2e9_5'. [originally from svn r9151]
* Add a function to every game backend which indicates whether a gameSimon Tatham2011-04-02
| | | | | | | | | | | state is in a solved position, and a midend function wrapping it. (Or, at least, a situation in which further play is pointless. The point is, given that game state, would it be a good idea for a front end that does that sort of thing to proactively provide the option to start a fresh game?) [originally from svn r9140]
* Jonas Koelker points out that the backspace key didn't work in GTKSimon Tatham2009-12-20
| | | | | | | | | | Guess, because Guess expected ^H whereas GTK generated ^?. Other puzzles that use Backspace do it by being prepared to see either, which seems wasteful. Now the midend normalises both into ^H, so front ends can generate whichever they like while puzzles can safely just look for ^H. [originally from svn r8786]
* Memory management and other fixes from James H.Simon Tatham2009-06-17
| | | | [originally from svn r8596]
* Fix a misdesign I must have missed when I reviewed the Killer patch:Simon Tatham2009-04-30
| | | | | | | | | | | | | | | | | merge_some_cages() was written in the assumption that it would always be able to do something, in that it returned void on success and if it couldn't find anything to do it would just loop round forever trying the same things over and over again. Now it makes a methodical list of the pairs of cages which are merge candidates, goes through them in a random order until it finds a viable one, and returns a boolean indicating whether it succeeded or ran out of candidates. A test case which previously hung and now does not is "solo --generate 1 7jxkdt#12345-10". [originally from svn r8541]
* check_valid() wasn't checking that Killer cages contain at most oneSimon Tatham2009-04-29
| | | | | | | of each digit, and - perhaps more importantly - the display code wasn't highlighting violations of that rule as an error. Fix both. [originally from svn r8540]
* Patch from James H to provide 16-bit-int cleanliness in Killer Solo.Simon Tatham2009-03-02
| | | | [originally from svn r8489]
* Fix cosmetic glitch in the interaction between Killer and JigsawSimon Tatham2009-02-24
| | | | | | modes. [originally from svn r8463]
* A substantial patch to Solo from Bernd Schmidt, adding support forSimon Tatham2009-02-22
| | | | | | | | the 'Killer Sudoku' puzzle type. As a side effect I've had to increase the default tile size of Solo, so that the extra numbers drawn in the squares in Killer mode were still legible. [originally from svn r8455]
* Keyboard control patch for Solo, from James H.Simon Tatham2009-01-19
| | | | [originally from svn r8418]
* Patch from Chris Boyle to prevent Solo's inter-block dividing linesSimon Tatham2008-11-02
| | | | | | | from becoming indistinguishable from the intra-block ones at low tile sizes. [originally from svn r8259]
* New infrastructure feature. Games are now permitted to beSimon Tatham2008-09-06
| | | | | | | | | | | | | | | | | | | | | | _conditionally_ able to format the current puzzle as text to be sent to the clipboard. For instance, if a game were to support playing on a square grid and on other kinds of grid such as hexagonal, then it might reasonably feel that only the former could be sensibly rendered in ASCII art; so it can now arrange for the "Copy" menu item to be greyed out depending on the game_params. To do this I've introduced a new backend function (can_format_as_text_now()), and renamed the existing static backend field "can_format_as_text" to "can_format_as_text_ever". The latter will cause compile errors for anyone maintaining a third-party front end; if any such person is reading this, I apologise to them for the inconvenience, but I did do it deliberately so that they'd know to update their front end. As yet, no checked-in game actually uses this feature; all current games can still either copy always or copy never. [originally from svn r8161]
* Shamelessly pander to compilers whose data flow warning systemsSimon Tatham2008-04-14
| | | | | | | insist that a variable should be initialised in all branches of an if, instead of just all the non-assertion-failing ones. [originally from svn r7989]
* Having got Jigsaw mode generation working at reasonable speed, weSimon Tatham2008-04-08
| | | | | | can now productise it. [originally from svn r7979]
* Improvements to filled-grid generation. Introduced a cunning ideaSimon Tatham2008-04-08
| | | | | | | | | | | | | | | suggested by IWJ last night: grid generation can immediately choose an entire grid row randomly, since all that's doing is nailing down the names of the numbers, and that gets the whole thing started more efficiently. But the main difference is that now grid generation is given only area^2 steps to come up with a filled grid, and then cut off unceremoniously, causing grid generation to fail and be retried from scratch. This seems to prevent hangups on jigsaw layouts that admit few useful solutions, by changing layout constantly. 9j puzzles now generate at a sensible rate, and as an added bonus so do 5x5 normal puzzles, which they never used to. [originally from svn r7978]
* Revise the printing colour framework so that we can explicitlySimon Tatham2008-04-07
| | | | | | | request either of hatching or halftoning, and also choose which to supply as a fallback when printing in colour. [originally from svn r7976]
* Pedantic tweaks to allow successful compilation on Windows. (gccSimon Tatham2008-04-07
| | | | | | | | failed to point out a declaration after a statement, and gcc's linker was clever enough to optimise the call to divvy_rectangle() out of solosolver so that I didn't have to include divvy.c in that.) [originally from svn r7975]
* Substantial reworking of Solo so that it implements both Sudoku-XSimon Tatham2008-04-07
| | | | | | | | | | | | | | | | | | | | | | | | | | (require both main diagonals to have one of every digit in addition to all the usual constraints) and Jigsaw Sudoku (replace the array of rectangular sub-blocks with the sub-blocks being random polyominoes). To implement the latter, I've moved my `divvy.c' library routine out of the `unfinished' subdirectory. Jigsaw mode is currently an undocumented feature: you enable it by setting the rows parameter to 1 (and the columns parameter to your desired grid size, which unlike normal Sudoku can be anything you like including a prime number). The reason it's undocumented is because generation times are not yet reliably short: sometimes generating a jigsaw-type puzzle can hang for hours and still get nowhere. (The algorithm should terminate in principle, but not in any time you're prepared to wait.) I _think_ I know how to solve this, but have yet to try it. Until then, jigsaw mode will remain a hidden feature. Printing of X-type puzzles is also substandard at present, because the current print-colour API replaces the desired light shading of the X-cells with heavy diagonal hatching. I plan to adjust the API imminently to address this. [originally from svn r7974]
* Gary Wong observes that solo's decode_params() is overenthusiasticSimon Tatham2007-03-11
| | | | | | | | | | | about eating the letter `d' (for `diagonal') when it appears in a symmtery description: it should only be used after `m', because mirror symmetry is the only type that can be diagonal. This was causing parsing of the parameter description `3x3adu' to produce the wrong answer: the d would be swallowed, then the u ignored for being incomprehensible, and you'd get default Trivial difficulty. [originally from svn r7386]
* Gary Wong points out that solosolver's verbose output isSimon Tatham2007-03-11
| | | | | | | inconsistent in whether it numbers rows and columns from zero or from one. Standardise on one. [originally from svn r7385]
* Dariusz Olszewski's changes to support compiling for PocketPC. ThisSimon Tatham2007-02-26
| | | | | | | | | | | | is mostly done with ifdefs in windows.c; so mkfiles.pl generates a new makefile (Makefile.wce) and Recipe enables it, but it's hardly any different from Makefile.vc apart from a few definitions at the top of the files. Currently the PocketPC build is not enabled in the build script, but with any luck I'll be able to do so reasonably soon. [originally from svn r7337]
* Phil Bordelon points out an off-by-one error: since Solo doesn't useSimon Tatham2007-01-15
| | | | | | | | zero as a valid puzzle symbol, it can support at most 35 symbols, not 36. (This is largely academic since IME anything above about 25 is impractical to generate, but there we go.) [originally from svn r7115]
* HTML Help support for Puzzles, with the same kind of automaticSimon Tatham2006-12-24
| | | | | | fallback behaviour as PuTTY's support. [originally from svn r7009]
* Cleanup: it was absolutely stupid for game_wants_statusbar() to be aSimon Tatham2005-10-22
| | | | | | | | | function, since it took no parameters by which to vary its decision, and in any case it's hard to imagine a game which only _conditionally_ wants a status bar. Changed it into a boolean data field in the backend structure. [originally from svn r6417]