aboutsummaryrefslogtreecommitdiff
path: root/filling.c (follow)
Commit message (Collapse)AuthorAge
* Centralise initial clearing of the puzzle window.Simon Tatham2021-04-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | I don't know how I've never thought of this before! Pretty much every game in this collection has to have a mechanism for noticing when game_redraw is called for the first time on a new drawstate, and if so, start by covering the whole window with a filled rectangle of the background colour. This is a pain for implementers, and also awkward because the drawstate often has to _work out_ its own pixel size (or else remember it from when its size method was called). The backends all do that so that the frontends don't have to guarantee anything about the initial window contents. But that's a silly tradeoff to begin with (there are way more backends than frontends, so this _adds_ work rather than saving it), and also, in this code base there's a standard way to handle things you don't want to have to do in every backend _or_ every frontend: do them just once in the midend! So now that rectangle-drawing operation happens in midend_redraw, and I've been able to remove it from almost every puzzle. (A couple of puzzles have other approaches: Slant didn't have a rectangle-draw because it handles even the game borders using its per-tile redraw function, and Untangle clears the whole window on every redraw _anyway_ because it would just be too confusing not to.) In some cases I've also been able to remove the 'started' flag from the drawstate. But in many cases that has to stay because it also triggers drawing of static display furniture other than the background.
* Filling grid gen: slightly randomise neighbour selection.Simon Tatham2021-03-29
| | | | | | | | | | | | | | | | | | This is another modification to the same piece of code as the previous commit. Previously, a square with a neighbour in a same-sized region was fixed by choosing a neighbour to merge it with that was part of the smallest region. Now, it's _usually_ that, but sometimes it can be a larger neighbour instead. Partly, I hope this might remove a potential source of regularity in the random grids. But mostly, it prevents the grid generator from hanging completely on 2x2 grids (e.g. if you gave "2x2#12345" in the previous state of the code), because with the previous 'always minimal' rule, the generator would merge together two squares of the 2x2 grid, then the other two, and then (due to maxsize==3) it would have no merge remaining to clear the final error. Now, every so often, it will take the unusual option of making a size-3 region instead, which allows game generation to succeed.
* Filling: remove directional bias in grid generation.Simon Tatham2021-03-29
| | | | | | | | | | | | | The method of generating a solved Filling grid (before winnowing clues) is to loop over every square of the board, and for each one, if it has a neighbour which is part of a different region of the same size (i.e. the board is not currently legal), fix it by merging with one of its neighbours. We pick a neighbour to merge with based on the size of its region - but we always loop over the four possible neighbours in the same order, which introduces a directional bias into the breaking of ties in that comparison. Now we iterate over the four directions in random order.
* Filling: fix assertion failure in 3x1 game generation.Simon Tatham2021-03-29
| | | | | | | | | | | | | | | | This would come up on the game id "3x1#12345", for example. The failing assertion was (s->board[f] != EMPTY) in expand(), called in turn from learn_expand_or_one(). It looks as if the problem was that the #define SENTINEL was set too small. It was intended to be a value that can't coincide with the true size of any region - and it was set to precisely the area of the whole board. But on a 3x1 grid, that _can_ coincide with the size of a region! So a board entry was set to a real region size, and then mistaken for SENTINEL by another part of the code. Easy fix: set SENTINEL to be sz+1. Now it really can't coincide with a region area.
* 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.
* 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.
* C89 build fixes.Simon Tatham2018-04-25
| | | | | Recent changes introduced a couple of non-C89-compatible mixed declarations and code.
* 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.
* Standardise character encoding of source tree on UTF-8.Simon Tatham2017-11-18
| | | | | | | | | Editing LICENCE just now, I happened to notice that the accented letter in Jonas Kölker's name was encoded in ISO 8859-1, as is the occurrence of the same name in filling.c - but _not_ the one in guess.c, which was in UTF-8 already. That seems needlessly confusing, so let's sort it out. Now every text file in this git repository is suitable for interpreting as UTF-8.
* 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 array overruns in the new Filling solver pass.Simon Tatham2015-10-21
| | | | | | | | | | | | | Probably because I wrote a couple of loops up to the maximum cell value using the non-idiomatic <= for their termination test, I also managed to use <= inappropriately for iterating over every cell of the grid, leading to a couple of references just off the end of arrays. Amusingly, it was the Emscripten front end which pointed this out to me by actually crashing as a result! Though valgrind found it just fine too, once I thought to run that. But it comes to something when running your C program in Javascript detects your memory errors :-)
* Enhance Filling's solver to handle large ghost regions.Simon Tatham2015-10-20
| | | | | | | | | | | | | | | | The previous solver could cope with inferring a '1' in an empty square, but had no deductions that would enable it to infer the existence of a '4'-sized region in 5x3:52d5b1a5b3. The new solver can handle that, and I've made a companion change to the clue-stripping code so that it aims to erase whole regions where possible so as to actually present this situation to the player. Current testing suggests that at the smallest preset a nontrivial ghost region comes up in about 1/3 of games, and at the largest, more like 1/2 of games. I may yet decide to introduce a difficulty level at which it's skewed to happen more often still and one at which it doesn't happen at all; but for the moment, this at least gets the basic functionality into the code.
* Produce shorter Filling descriptions by run-length encoding 0s.Jonas Kölker2015-10-18
|
* Render Filling presets as 'WxH', not 'HxW'.Jonas Kölker2015-10-03
|
* Greatly improve and speed up the Filling instance generation.Jonas Kölker2015-10-03
|
* Greatly increase the speed of the Filling solver.Jonas Kölker2015-10-03
|
* Filling: enable keyboard-driven cursor dragging mode.Jonas Kölker2015-10-03
|
* 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]
* Fix a memory management bug in Filling: in some situations itsSimon Tatham2013-04-13
| | | | | | | | solve_game() was returning its aux parameter un-dupstr()ed, which is wrong. Also clarified the developer docs on that function to make it clearer that the returned string should be dynamic. [originally from svn r9831]
* 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]
* Patch from Jonas Koelker to improve Filling's error highlighting: asSimon Tatham2012-05-14
| | | | | | | | | well as marking a region as wrong if it has too many squares for the number written in it, this patch now causes a region to be marked wrong if it has too few squares _and no liberties_, so that it can't just be one the user is intending to enlarge later. [originally from svn r9534]
* 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]
* 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]
* Fix incorrect uses of ctype.h (passing it uncast chars, or otherSimon Tatham2010-04-17
| | | | | | things potentially not in the range 0..255). [originally from svn r8922]
* 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]
* More defensive-coding fixes from James H.Simon Tatham2009-07-01
| | | | [originally from svn r8605]
* Memory management and other fixes from James H.Simon Tatham2009-06-17
| | | | [originally from svn r8596]
* Keyboard interface for Filling, from James H.Simon Tatham2009-01-14
| | | | [originally from svn r8412]
* 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]
* UI change to Filling: allow multiple squares to be set at once.Jacob Nevins2008-02-10
| | | | | | | | | (This change adds a new possibility to the save format, such that new save files won't necessarily be loadable by old binaries. I think that's acceptable -- it's certainly happened before -- but I couldn't find anything in the developer docs explicitly blessing it.) [originally from svn r7849]
* Updates and improvements from Jonas Koelker.Simon Tatham2007-05-20
| | | | [originally from svn r7601]
* Bound edge thicknesses below so that they're always thicker than theSimon Tatham2007-03-01
| | | | | | grid lines. [originally from svn r7349]
* Fix some border drawing issues.Jacob Nevins2007-02-28
| | | | [originally from svn r7347]
* General cleanups patch from James H:Simon Tatham2007-02-28
| | | | | | | | | | | | - missing static in filling.c - better robustness in execute_move() in filling.c - remove side effects in assert statements - remove rogue diagnostic in galaxies.c - remove // comment in map.c - add more stylus-friendly UI to Pattern - bias Unequal towards generating inequality clues rather than numeric [originally from svn r7344]
* This game requires the numpad.Simon Tatham2007-02-27
| | | | [originally from svn r7338]
* 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]
* Hardwiring the grid line width to 1 is really bad for printing. UseSimon Tatham2007-02-25
| | | | | | | a slightly more conventional method of drawing the grid lines, and thereby fix printing. [originally from svn r7335]
* Don't create an undo-chain entry for a move with no effect.Simon Tatham2007-02-25
| | | | [originally from svn r7333]
* New puzzle: `Filling', a Fillomino implementation by Jonas Koelker.Simon Tatham2007-02-25
[originally from svn r7326]