1275 Commits

Author SHA1 Message Date
55683abd97 Fix a valgrind warning in the Keen DIFF_HARD solver code.
The solver's array ctx->iscratch[] is used for a completely different
purpose in the DIFF_HARD code, compared to what it's used for in
DIFF_EASY and DIFF_NORMAL. In particular, a different number of
elements of the array are used - but the code which sets up the array
was not correctly initialising all of them.

I was also unable to find any clear comment that even explained _that_
the purpose of the array was entirely different between the two cases,
let alone explaining _what_ the two purposes were. So I've written
some comments as part of this commit, which should make things a bit
less confusing next time. (Though not much, I admit.)
2016-01-03 09:51:15 +00:00
ff91d2d78d rect: Fix compiler errors about uninitialized use of variables
error: 'r2.x' may be used uninitialized in this function

Its happening when using gcc 5.3 with musl C library. its considering
the case when case falls into default and immediately after exiting
this there is a check if (r1.h > 0 && r1.w > 0) where r1 element is
used but not assigned anything.

GCC is not noticing the control flow where the initilization will
always work due to assertion call can be a function call from libc

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2015-12-31 08:28:14 +00:00
d295a8a93c Add a missing error message in Flood solve_game().
The only situation in which it actually can't find a solution is if
the puzzle is already solved, in which case it can at least fill in
*error to say so before it returns NULL.
2015-12-24 22:05:48 +00:00
f1af73319f Clarify in README that Makefile.vc is for nmake.
A user pointed out today that I hadn't actually said that!
2015-12-18 14:51:09 +00:00
786f5b18e4 New utility 'patternpicture', to build a Pattern from an xbm.
This utility works basically the same as galaxiespicture: you feed it
a .xbm bitmap on standard input, and it constructs a game ID which
solves to exactly that image. It will pre-fill some squares if that's
necessary to resolve ambiguity, or leave the grid completely blank if
it can.
2015-12-12 11:00:15 +00:00
f061101210 Pattern: add a system of immutable pre-filled grid squares.
The game previously only supported numeric clues round the edge; but
if for some reason you really want a puzzle with a specific solution
bitmap and that bitmap doesn't happen to be uniquely soluble from only
its row and column counts, then this gives you a fallback approach of
pre-filling a few grid squares to resolve the ambiguities.

(This also applies if the puzzle is uniquely soluble *in principle*
but not by Pattern's limited solver - for example, Pattern has never
been able to solve 4x4:2/1/2/1/1.1/2/1/1 and still can't, but now it
can solve 4x4:2/1/2/1/1.1/2/1/1,Ap which has the hard part done for
it.)

Immutable squares are protected from modification during play, and
used as initial information by the solver.
2015-12-12 10:56:34 +00:00
d1219cac3c Pattern: fix solver's handling of empty rows.
The algorithm for deducing how many squares in a row could be filled
in just from the initial clue set was focusing solely on _black_
squares, and forgot that if a row has a totally empty clue square then
everything in it can be filled in as white!

Now the solver can cope with puzzles such as 3x3:/1///1/ , where it
would previously have spuriously considered that it had no idea where
to start.
2015-12-12 10:54:03 +00:00
a845e6476d Pattern: make part of the game_state shared.
The game_state now includes a pointer to a game_state_common
containing all the row and column clues, which is reference-counted
and therefore doesn't have to be physically copied in every dup_game.
2015-12-12 10:53:55 +00:00
0fa7baed10 Code-sign the Windows puzzle binaries and installer.
Where facilities exist, that is. Like the approach I took with PuTTY
yesterday, Buildscr will now run a code-signing script over the binary
if you specify one in the bob config, and otherwise should fall back
to just leaving that step out.
2015-12-12 09:17:33 +00:00
7000b0c70a Implement align_label for GTK 3.[14,16).
gtk_misc_set_alignment was deprecated in GTK 3.14. But my replacement
code using gtk_label_set_{x,y}align doesn't work there, because that
function wasn't introduced until GTK 3.16, so there are two minor
versions in the middle where a third strategy is needed.

(That middle strategy doesn't permit arbitrary float alignments, but
that's OK, bceause we only actually use multiples of 0.5.)
2015-12-06 16:00:10 +00:00
346584bf6e Allow unlocking an island despite moving slightly.
Previously moving 1 pixel would be treated as a failed drag and not an unlock.

Now you only have to release the button somewhere on the island you started on.
2015-11-28 15:13:24 +00:00
2acd8baae8 Convert Buildscr to use the new "do/win" mechanism. 2015-11-17 18:47:29 +00:00
13b67b9d09 Fix loophole in Palisade completion checker.
A user pointed out that if you construct a 'solution' in which no clue
square has too _many_ borders but at least one has too few, and then
bring those clues up to their count by adding extra stray border lines
_inside_ a connected component (avoiding actually dividing any
component completely into two), then the game checker treats that as
solved for victory-flash purposes, on the grounds that (a) the grid is
divided into components of the right size and (b) all clues are
satisfied.

A small example is 4x4n4:22a2b2c33, with the non-solution of dividing
the grid into four 2x2 square blocks and then adding a spurious extra
edge between the two 3 clues. The old Palisade completion check would
flash for victory _at the same time_ as highlighting the spurious edge
in COL_ERROR.

Fixed by enforcing in is_solved() that every border line must separate
two distinct connected components.
2015-11-03 06:59:47 +00:00
d60e348aae Format Palisade solve-type moves in sensible ASCII.
The solve move stored in 'aux' by new_game_desc consists of printable
characters in the range '@' to 'O', each representing a 4-bit bitmap
of edges around a cell. But the one generated on the fly by
solve_game() was missing out the 0x40 bit and just returning
characters in the range ^@ to ^O - which would not only have been
horrible if you found such a string in a save file, but also meant
that a game with any completely borderless square would have a
solution move string terminating early due to the ^@, causing
execute_move() to reject it.

Example: ./palisade --test-solve --generate 1 5x5n5#12345-37 now
succeeds, where previously it failed an assertion.
2015-11-03 06:59:47 +00:00
ffe8639619 Fix premature completion flash in Tracks.
Commit 44e2690ab loosened check_completion's idea of what made a
square count as 'having track in it' for purposes of checking
violations of the row/column counts. Unfortunately, that loosened
notion also applied to the check for the game being complete - so the
game would announce a win as soon as you had every square shaded, even
if you hadn't actually laid all the exact track positions down.

Now we separately count up the number of track-ish squares and the
number of fully completed ones, and use the former for error checking
and the latter for completion checking.
2015-10-23 19:33:52 +01:00
3234912f92 Tents: mark squares as non-tents with {Shift,Control}-cursor keys. 2015-10-21 22:34:12 +01:00
67178751e9 Fix a comment in Tents (it said 'tents' instead of 'trees'). 2015-10-21 22:03:04 +01:00
44e2690abb Highlight clue errors in Tracks in some more situations.
- Count any square as having a track either if the square is marked
   as such (rendered as a different background), or if at least one
   adjacent edge is marked as containing a segment of train track
   (rendered as train tracks if they're placed, else as an '=').

 - Do the same counting in rows and columns.
2015-10-21 22:03:02 +01:00
80b63e6cef In Undead, mark clues as errors in a few more situations.
- Mark a clue as an error if too many monsters are seen, even if
   some squares are empty.

 - Mark a clue as an error if too few monsters are seen, taking into
   account how many more sightings are possible given the number of
   empty squares and how many times each of them are visited.
2015-10-21 22:02:59 +01:00
1cf403ceb8 Fix array overruns in the new Filling solver pass.
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 :-)
2015-10-21 18:32:15 +01:00
90af15b43e Enhance Filling's solver to handle large ghost regions.
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.
2015-10-20 20:33:53 +01:00
3c0b01114c Add the new 'fifteensolver' to .gitignore. 2015-10-18 17:53:28 +01:00
3448fe1b47 Use \q{} in place of literal quote marks in puzzles.but.
While checking over the Palisade docs for this sort of error, I
happened to notice that a few were already in the existing games'
documentation.
2015-10-18 17:53:28 +01:00
6860c65bb3 Add a new puzzle: Palisade. 2015-10-18 17:53:28 +01:00
b33b83429f Fix GTK puzzle resizing, *again*.
Jonas Kölker points out that commit a800ff16b (which fixed a bug in
the previous attempt) left in another bug: if the puzzle size was
changed while the window was maximised, the system would fail to
recompute the tile size and would redraw completely wrongly.

So it's not optional after all to run midend_size(), even if the
drawing area size hasn't changed. I've reverted that code to be
unconditional, and now only the refresh of the Cairo-side backing
store system is conditionalised - and that's conditionalised on
changes to either the size of the actual window _or_ the size of the
contained pixmap. (The latter should defend against redraw failure in
the case where the puzzle aspect ratio changes, so that neither the
window size nor the tile size changes but a recentre is still needed.)

I _think_ this now fixes all the cases of resizing: this time I've
tested making an unmaximised puzzle window bigger or smaller, and
within a maximised window, forcing the puzzle to scale up, scale down,
or change its aspect ratio without changing its tile size. All work,
on GTK2 and GTK3, and yet we still don't get the visible flicker on
status line updates that was the reason I started fiddling with this
code in the first place.

(We _do_ still call configure_area on every update of the status line,
at least under GTK3; that's going to cause a forced full redraw on
every timer tick in Mines, which is wasteful of CPU, so it would still
be nice to find a better way of identifying the cases in which no
resizing at all was necessary and we could avoid renewing the game
drawstate. But the current code at least doesn't have any display
_errors_ that I know of, which is an improvement on its previous
state.)
2015-10-18 14:55:01 +01:00
3e2dc51db0 Produce shorter Filling descriptions by run-length encoding 0s. 2015-10-18 11:19:48 +01:00
f7eb186184 Expand keyboard input options in Bridges, for faster entry.
- Lay bridges (crosess) with Control-arrow (Shift-arrow)
- Jump (non-orthogonally) to nearby islands with number keys, a..f
- Mark islands as done with a single tap on the space bar
2015-10-18 11:03:16 +01:00
96b6f55ec8 Fix two memory leaks in GTK frontend.
- The file selector for loading and saving gets a g_free().
 - The handling of saving (menu_save_event) gets an sfree().
 - It's also slightly restructured to prevent future errors.
 - menu_load_event was already structured to prevent this error.
 - The OLD_FILESEL code seems to not need a g_free().
2015-10-18 11:02:12 +01:00
2fb2774fcd Fix a typo in a Bridges error message.
'contain_ER_s' becomes 'contains'.
2015-10-18 11:01:54 +01:00
75335f199e Fix Bridges keyboard cursor vertical out-of-bounds error.
Position the cursor in the top (bottom) row, press enter and press up
(down).  The game acts as if you had pressed right, both with Enter-
and Space-based dragging.
2015-10-18 11:01:51 +01:00
fcf573c672 Update Sixteen keyboard system for faster entry.
Pressing Ctrl-arrow or Shift-arrow on a tile now moves the row or
column under the tile. With Ctrl, the cursor moves as well so you can
keep making moves that affect the same tile; with Shift, the cursor
stays put so you can keep making moves that affect the same location.
2015-10-18 10:59:50 +01:00
d0500732f7 In GTK frontend, bind mouse8/mouse9 to undo/redo.
These button codes are generated by the back/forward button pair on
the sides of some mice, and web browsers treat these as the back and
forward actions in the page history.
2015-10-14 21:22:44 +01:00
ef5c017a5f Add hinting feature to Guess.
Pressing H now suggests the lexicographically first row consistent
with all previous feedback.

The previous function of the H key to toggle a hold marker on the
current peg is now performed by Space / CURSOR_SELECT2, which is more
in line with other puzzles anyway.
2015-10-14 21:21:27 +01:00
cd67072556 Add standalone Fifteen solver, based on the hint feature.
Recall that the hint feature is really an incremental solver.  Apply
it repeatedly until the board is solved. Grade puzzles as solvable
or unsolvable by checking their parity.
2015-10-14 20:29:32 +01:00
12fabc4add Add hinting feature to Fifteen (press 'h' for a hint).
This is really an incremental solver. It alternates between solving
rows and solving columns. Each row and column is solved one piece at
a time. Except for some temporary trickery with the last two pieces
in a row or column, once a piece is solved it is never moved again.

(On non-square grids it first solves some rows or some columns until
the unsolved part is a square, then starts alternating.)
2015-10-14 20:29:32 +01:00
5ddb011a57 Invert the Fifteen cursor if FIFTEEN_INVERT_CURSOR ~= ^[yY].*$
The introduction of flip_cursor allows us to replace some hairy
hand-rolled logic with the standardised and tested move_cursor.
2015-10-14 20:29:32 +01:00
988b16a319 End victory flash on new game and restart game.
Net provides the best demonstration of why. Complete a game of net,
then press N while the victory flash is playing: then the victory
flash keeps playing on the new game board. (Tip: save a game which
but for a redo is completed, then you can reproduce this repeatedly
without having to complete a new game each time.)

The flash timer reset code is placed together with the animation
timer reset code, because the two are conceptually related. Note
that midend_restart_game resets animations via midend_finish_move.
2015-10-14 20:29:32 +01:00
bf81e9c1fa Reset midend animation counters on starting a new game.
This is already done in midend_restart_game via midend_finish_move.
If it's good enough for restarting a game, it ought to also be good
enough for starting new games.
2015-10-14 20:29:32 +01:00
af010d7283 Remove a redundant line of code.
Setting me->anim_time = 0.0 right before calling midend_finish_move is
redundant, since midend_finish_move itself sets me->anim_time = 0.
2015-10-14 20:29:32 +01:00
f3f0f009ff Don't stop animations when restarting an already restarted game.
Restarting a game that is already in the restarted state is meant to
be a no-op.  It stopped animations.  Don't do this.

Also, given that midmidend_restart_game called midend_stop_anim
twice, the invocation we remove was redundant.
2015-10-14 20:29:32 +01:00
156b0c3e23 Stop animations on a new game, no matter how it is started.
Animations were stopped if a new game was initiated with a keyboard
shortcut (n, N, Ctrl-N), but not via menu items such as presets or
custom configurations, nor (perhaps not a problem) on starting the
program. Fix this, so that animations are stopped on a new game no
matter how the new game is started.
2015-10-14 20:29:32 +01:00
11b14a5f44 GTK 3 cleanup: stop using GtkDialog for config boxes.
It's becoming annoying to keep working within the increasing
restrictions on GtkDialog, in particular the fact that not only do we
have to let it have complete control of the button area, but also it's
not clear whether we can intercept a press of the 'OK' button and
display an error message rather than ending the dialog.

So, as I did in PuTTY, I'm resorting to using an ordinary GtkWindow
with controls I laid out myself.
2015-10-04 20:10:41 +01:00
27fe1c9c49 GTK 3 cleanup: use GtkAboutDialog for the About box.
This is again easier than faffing about doing it manually, and as an
added bonus, we get to put the largest of our icons in the box as a
logo :-)
2015-10-04 19:57:25 +01:00
a94dbd27d0 GTK 3 cleanup: use GtkMessageDialog for message_box().
This is a lot easier than faffing about setting up a dialog box
ourself, and also avoids direct access to GtkDialog's action area
(deprecated in GTK 3.16).
2015-10-04 19:56:39 +01:00
2afbcdcc3c GTK 3.16 deprecation: stop using gtk_misc_set_alignment.
The new equivalent is gtk_label_set_{x,y}align. But we can't use that
in all GTK 3 builds, because it's very new.
2015-10-04 19:33:44 +01:00
5e22080bcd Improve Towers error highlighting.
Highlight clues of value n in Towers if its row/column contains an
increasing sequence of length n, the last number of which is not equal
to the number of rows/columns (i.e. such that the sequence will have
to be extended, in violation of the clue).
2015-10-03 18:17:25 +01:00
21b8323b2f Dominosa: Highlight a number when pressed on the keyboard. 2015-10-03 18:16:01 +01:00
a800ff16bb Fix switching to a larger puzzle size under GTK 2.
Commit 8b491946e had a bug: configure_area stopped doing most of its
work if the new size already matched fe->w and fe->h, but in fact the
GTK2 resize_fe() _already_ set up fe->w and fe->h for the new size. I
managed not to notice, because I checked it all worked on GTK 3 but
only tested resizing to a _smaller_ puzzle on GTK 2. Ahem.

Now we don't change fe->w and fe->h at all until configure_area is
called. Also, we initialise them to dummy values at setup time, so
that configure_area won't compare the new size with uninitialised
data.
2015-10-03 18:01:18 +01:00
e22a9c8396 build fix 2015-10-03 17:39:22 +01:00
581becc3aa Insert a manual reference in the default status bar text.
To guide developers to the resources they need.

[actual wording tweaked by SGT]
2015-10-03 17:12:20 +01:00