1066 Commits

Author SHA1 Message Date
0b93de904a Add 'const' to the game_params arguments in validate_desc and
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]
2013-04-12 17:11:49 +00:00
383c15794a Patch from Rogier Goossens to speed up the Pattern solver.
do_recurse() now prunes early whenever it encounters a branch of the
search tree inconsistent with existing grid data (rather than the
previous naive approach of proceeding to enumerate all possibilities
anyway and then ruling them out one by one); do_recurse also tries to
split the row up into independent sections where possible; finally the
main solver loop (all three copies of which have now been factored out
into a new solve_puzzle function), instead of simply looping round and
round over all the rows and columns, heuristically looks at the ones
most changed since the last time deduction was attempted on them, on
the basis that that will probably yield the most information the
fastest.

[originally from svn r9828]
2013-04-12 16:28:55 +00:00
c94afe9cd6 Adjust Keen's grid generation to constrain the maximum size of clue
blocks, because 'make test' showed up very large blocks as an
occasional slowdown factor in game generation (takes too long to
iterate over all possibilities). This is a good idea in any case,
because really big multiplicative clue numbers have trouble fitting in
the square.

[originally from svn r9827]
2013-04-12 16:28:53 +00:00
fe6da52b26 Apply some optimisation to Undead's get_unique() function, which was
not only enumerating all possible arrangements of monsters along a
sight-line in O(3^n) time, but also allocated memory for them all and
then does a quadratic-time loop over that list to find arrangements
with a unique visibility count from both ends. Spotted by the new
'make test', which observed that 7x7dn#517035041807425 took 45 seconds
to generate.

This revised version still does the initial O(3^n) enumeration, which
can probably be got rid of as well with a bit more thought, but it now
doesn't allocate nearly so much memory and it spots uniques
efficiently. The above random seed now generates the same game ID in
less than a second, which drops this puzzle off the 'make test' hit
list of things most obviously needing speedup.

[originally from svn r9826]
2013-04-12 16:28:52 +00:00
120f6de605 Introduce some extra testing and benchmarking command-line options to
the GTK front end, plus a 'make test' target in the GTK makefile which
uses them to automatically generate 100 puzzles for each game at each
preset configuration, test-run them back through the solver without
their aux_info to ensure that can cope, and produce an HTML box plot
of game generation times for each preset.

As part of this work I've removed the TESTSOLVE mechanism from r9549,
since the new --test-solve option does the same thing better (in that
when something goes wrong it prints the random seed that caused the
problem).

[originally from svn r9825]
[r9549 == 5a095b8a08fa9f087b93c86aea0fa027138b028d]
2013-04-11 12:51:06 +00:00
ed82ef5c0e Revamp the triangular grid generation in Loopy, which I've been
meaning to revisit for a while. The new version generates more nicely
symmetric grids (best at even heights, but still improved even at odd
heights), and avoids any 'ears' on the grid (triangles at the corners
connected to only one other triangle, which tend to be boringly easy
places to start solving).

I've reused the grid-description-string mechanism invented for the
Penrose tilings as a versioning mechanism for the triangular grids, so
that old game descriptions should still be valid, and new triangular-
grid game descriptions begin with an "0_" prefix to indicate that they
are based on the new-style construction.

[originally from svn r9824]
2013-04-11 12:51:05 +00:00
8cfcbac027 Split Untangle's background colour into two. COL_BACKGROUND is still
defined the same way and used to draw the normal background of the
puzzle, but there's a new slightly darker COL_SYSBACKGROUND which is
not used for anything at all in the puzzle backend but which occupies
colour slot #0 so that the system will use it to fill around the
playable area if the puzzle is imprecisely resized.

This doesn't _sensibly fix_ the annoyance in Untangle where a non-
square window gives rise to unusable dead space, but it at least works
around it by making the dead space obviously something to stay away
from.

[originally from svn r9823]
2013-04-07 10:44:56 +00:00
c0fff857fd Add a draggable resize handle to the JS puzzles.
Rather than design an ersatz 'window frame' surrounding the puzzle
canvas, I've simply overlaid the resize handle on the corner of the
puzzle itself (canvas or status bar, depending on whether the latter
exists), trusting that all games in my collection provide a reasonable
border within their drawing area. (OS X already does this with its
resize handle, so it's not as if there's no precedent.)

Unlike the desktop versions, I control the resize behaviour completely
in this environment, so I can constrain the canvas to only ever be
sensible sizes with no dead space round the edges (and, in particular,
preserve the aspect ratio).

Right-clicking the resize handle will restore the puzzle's default
tile size. I had intended to implement a maximise-to-browser-window
button too, but was annoyingly foiled by scrollbars - if you maximise
to the current window width, and as a result the text below the puzzle
scrolls off the bottom, then a vertical scrollbar appears and eats
into the width you just maximised to. Gah.

[originally from svn r9822]
2013-04-07 10:24:37 +00:00
9799ff0e2a Fix a typo I noticed in passing.
[originally from svn r9821]
2013-04-07 10:24:36 +00:00
c55e954854 Add a new midend function to reset the tile size to the puzzle's
default (but still counting the <puzzle>_TILESIZE user preference
environment variables, where available).

[originally from svn r9820]
2013-04-07 10:24:35 +00:00
ea25b606cb Small refactor to relative_mouse_coords: now the functionality which
returns an element's absolute position on the web page is split out
into a subfunction that can be called directly.

[originally from svn r9819]
2013-04-07 10:24:34 +00:00
b341d0544d Fix the 'puzzle doesn't work' apology, which I'd accidentally moved
inside the top-level display:none puzzle container as a side effect of
r9809.

Also, while I'm at it, reword the apology to mention typed arrays as
the most likely cause of failure (AFAIK that's the most modern feature
required by the JS front end), and fix indecision between singular and
plural ('this puzzle' doesn't work, perhaps a feature 'they depend on'
is missing).

[originally from svn r9818]
[r9809 == 5dc559c8be1b8f6ed15f560433f25c952c874f93]
2013-04-06 12:28:21 +00:00
be6bb379bb Don't forget to NULL out the new game id notification callback, or
else it might start off accidentally initialised to nonsense in front
ends which don't use it.

[originally from svn r9817]
2013-04-06 08:08:15 +00:00
ce604aa68d Mention Safari in the list of tested browsers.
[originally from svn r9816]
2013-04-05 19:27:55 +00:00
aea60465a4 Update the list of tested browsers.
[originally from svn r9812]
2013-04-05 15:49:31 +00:00
36f35f5db8 Regretfully remove my trickery with a hidden <option> element inside
the game-type <select>, since IE turns out to ignore display:none on
options. Oh well.

Instead I now do a more transparent thing: when custom game params are
in use, there's a "Custom" option selected in the dropdown, and a
separate 'Re-customise' option which brings the config box back up.
When an ordinary preset is selected, the Custom option is missing, and
there's just a 'Customise'.

In the process I've tinkered a bit to arrange that the custom 'preset'
is always represented by a negative number rather than one past the
last real preset; that seems more consistent overall.

[originally from svn r9811]
2013-04-05 15:49:29 +00:00
2360b77812 Rewrite the JS keyboard handling to cope with IE and Chrome.
Unlike Firefox, IE and Chrome don't generate keypress events at all if
you suppress the default handling of keydowns. Therefore, we have to
figure out everything from the keydown event, because if we unsuppress
the default handling of any keydowns then we'll get annoyances like ^R
going back to meaning reload-page rather than redo-move.

[originally from svn r9810]
2013-04-05 15:49:27 +00:00
5dc559c8be Assorted HTML/CSS fiddlings to make things work better in IE. I've
added a trivial doctype (IE complained without it), but that caused a
gap to appear between the puzzle and the status bar, so I tinkered a
bit more and ended up removing the <table> completely (no great loss)
as well as adding display:block to the canvas and explicitly setting
the width of not only the status bar div but also its parent div.
Meanwhile, I'm putting the "px" on the end of a lot of properties I
set from JS, because IE complains about that too if I don't.

[originally from svn r9809]
2013-04-05 15:49:25 +00:00
7479c2882d Stop accidentally subtracting onscreen_canvas.offset{Left,Top} from
the return value of relative_mouse_coords! I only got away with that
error because the canvas was at offset zero compared to its immediate
parent element.

[originally from svn r9808]
2013-04-05 15:49:24 +00:00
33b3947d1f Implement debug_printf() in the Emscripten front end, since that's the
easiest way to call js_debug with formatted parameters.

[originally from svn r9807]
2013-04-05 15:49:22 +00:00
e6afc02942 IE doesn't default to giving focus to the puzzle canvas on a mouse
click, so manually implement that behaviour. (Without it, it's quite
hard to focus the canvas at all in IE.)

[originally from svn r9806]
2013-04-05 15:49:21 +00:00
8f87f2ce89 I've just realised that the JS puzzles' permalinks were not updating
when the user pressed 'n' for a new game, because all the front end
knows is that it passed a keystroke to the puzzle, and it has no way
of hearing back that a particular keypress resulted in a game id
change.

To fix this, I've renamed midend_request_desc_changes to
midend_request_id_changes and expanded its remit to cover _any_ change
to the game ids. So now that callback in the Emscripten front end is
the only place from which update_permalinks is called (apart from
initialising them at setup time), and that should handle everything.

[originally from svn r9805]
2013-04-05 15:49:20 +00:00
841c9318f3 Remove trailing commas at the ends of initialiser lists. IE 8 and 9
didn't like them, which doesn't matter as such since they won't run
these JS puzzles anyway (no TypedArray support) but it hints that
other JS implementations might be picky about this too.

[originally from svn r9804]
2013-04-05 15:49:19 +00:00
3bc0e5cc24 Clarify header comments in the Emscripten frontend's source files to
mention that the HTML pages generated by html/jspage.pl are also an
integral part of this front end. (The NestedVM frontend is more
self-contained, needing only an appropriate <applet> tag, but this one
expects quite a few components to exist on the page and have the right
ids.)

[originally from svn r9803]
2013-04-05 15:49:18 +00:00
a752e73720 Try to give a more friendly message if anything goes wrong during
puzzle startup. The puzzle web pages now enclose the whole puzzle
(buttons, canvas, permalinks) in a div set to display:none, and
instead display an apologetic message saying 'sorry, it didn't work';
then, if we get through the whole init function without crashing, we
show the puzzle and hide the apology.

[originally from svn r9802]
2013-04-03 19:04:00 +00:00
bd8c594197 Fix a grammatical confusion on the Unruly web page.
[originally from svn r9801]
2013-04-02 10:58:52 +00:00
01471b5dc9 Rewrite trim_rect() for robustness.
The previous version dealt adequately with rectangles _partially_
overlapping the edge of the canvas, but doesn't correctly handle a
rectangle that's completely out of bounds in one direction. Replace
with a complete rewrite which is more easily seen to be correct. Also,
while I'm at it, add a missing condition to draw_update() so that we
don't even bother calling the Javascript half of it on any rectangle
that's been trimmed into nonexistence.

[originally from svn r9800]
2013-04-01 16:23:03 +00:00
bce3f1bd26 Greg Hewgill points out a code path on which the angle parameter to
the Penrose grid generation function can fail to be initialised.

[originally from svn r9798]
2013-04-01 09:38:04 +00:00
76824e1692 Fix the icon makefile in the wake of r9795.
[originally from svn r9797]
[r9795 == 3fc5a644a72e747b1f88125b38b2f178a9bc7ed3]
2013-03-31 22:06:07 +00:00
742cf3a443 A UI suggestion from Ben: label the Custom element in the dropdown
with a trailing "..." to hint that it opens a further dialog box.
However, the _invisible_ Custom option is merely indicating what you
_do_ have selected, so we leave that one as it is. (So now they're no
longer exact twins of each other, of course.)

[originally from svn r9796]
2013-03-31 18:36:03 +00:00
3fc5a644a7 Undead was not ever actually draw_update()ing to the edges of its
rectangle, which showed up on the Javascript front end since the JS
canvas doesn't start out defaulting to COL_BACKGROUND. Fixed it to
draw_update to the edge of its area, and while I'm at it, narrowed the
border (since this proves we didn't really need that much space
anyway).

[originally from svn r9795]
2013-03-31 18:25:25 +00:00
52d4dae0a9 Make sure the right element of the game-type dropdown starts off
selected. Previously we were leaving the first element on the list
selected, which is _usually_ right, but not right for Slant.

In the process of doing this, I've also reorganised to fix a crash
which shows up with non-configurable games (admittedly currently only
Nullgame :-) when we still try to call js_select_preset in spite of
not having any preset options to select.

[originally from svn r9794]
2013-03-31 11:50:46 +00:00
bb14689b4a Introduce a mechanism by which calls to midend_supersede_game_desc()
can trigger a call to a front end notification function. Use this to
update the game ID permalink when Mines supersedes its game ID.

[originally from svn r9793]
2013-03-31 09:58:52 +00:00
bf696f83fc Reinstate a missing semicolon.
[originally from svn r9792]
2013-03-31 09:58:50 +00:00
75137adf8c Oops. I consistently misspelled my desired lineCap and lineJoin values
as "1" rather than "round". Must have had my Postscript brain in,
and/or been confused by lineWidth = "1" just beforehand. This fixes a
display glitch in Towers, where there's a tiny spike at the top left
corner of each tower due to a very sharp mitred line join.

[originally from svn r9791]
2013-03-31 09:58:48 +00:00
2d2afe9ad4 Fix a crash when changing presets in Inertia. Turns out that my
Javascript-side blitter creation function had forgotten to return the
new blitter's id, so the C code was still trying to use blitter #0
after it had been thrown away and replaced.

[originally from svn r9790]
2013-03-31 09:58:47 +00:00
3603131ac1 Don't forget to restore the correct selection in the dropdown list if
the user cancels a configuration dialog.

[originally from svn r9789]
2013-03-31 09:58:47 +00:00
9826ecd5c3 Apply a bodge to arrange that if the user selects Custom from the game
type dropdown, we still get an 'onchange' event if they select it a
second time. Normally this wouldn't happen, because onchange means
what it says and we only get it if a _different_ element is selected.

My solution is to create two list items called Custom, set one of them
as display:none to stop it showing up when the list is dropped down,
and to select it after the configuration box closes.

[originally from svn r9788]
2013-03-31 09:58:46 +00:00
3e39f6b80b Stop using the dangerously unescaped 'innerHTML' for <option>
contents; use document.createTextNode like I do everywhere else.

[originally from svn r9787]
2013-03-31 09:58:45 +00:00
1264bccf40 Forgot to make the web-page-building scripts executable.
[originally from svn r9786]
2013-03-31 08:55:21 +00:00
49fba922ea New front end! To complement the webification of my puzzles via Java
applets, here's an alternative webification in Javascript, using
Emscripten in asm.js mode (so that as browsers incorporate asm.js
optimisation, the game generation should run really fast).

[originally from svn r9781]
2013-03-30 20:16:21 +00:00
e2c84a5fd2 Introduce a mechanism in this source tree for building the container
web pages for the Java applets. Previously, those have all been
maintained by hand in my website's svn area, which is a bit silly. Now
we have a file per puzzle in the 'html' subdirectory which contains
the puzzle's name, one or two attributes, and the instructions snippet
to go below the puzzle applet; and then there's a Perl script that
builds all the real web pages out of that by adding in the parts
common across all files: the header, footer, and middle fragment with
the <applet> tag and resizing bits and pieces.

One piece _not_ checked in here is the footer text specific to my
hosting at chiark, which I think does still belong in the www area. So
Buildscr doesn't actually build the web pages; it just delivers the
bits and pieces by which my nightly snapshot script will be able to
run the program that _does_ build them, passing that footer as an
extra argument.

[originally from svn r9780]
2013-03-30 20:04:10 +00:00
6920d97c09 Edit the paragraph in the midend_deserialise() docs which I forgot to
fix in r9777 when I added documentation of the function it wistfully
imagined might one day exist.

[originally from svn r9779]
[r9777 == 1fdafb6abf2d3ea0d37e79b5dfd9daf8eed28f22]
2013-03-30 18:03:15 +00:00
e6026d9d8e Add a midend function to return the current random seed, parallel to
the existing one that returns the game id. No front end has so far
needed this, but one is about to.

[originally from svn r9778]
2013-03-30 16:59:19 +00:00
1fdafb6abf Add documentation for the identify_game() function which I introduced
in r9749 and forgot to write up.

[originally from svn r9777]
[r9749 == 6b6442b16c5de9f5f9479b736bf865a4236047cb]
2013-03-30 16:59:18 +00:00
d11691ec4a Found a bug in nullgame! Its vestigial game_redraw lacked a
draw_update, which isn't really setting a good example for people
cloning it :-) Add the missing draw_update call.

[originally from svn r9776]
2013-03-30 16:59:17 +00:00
b5756838f3 Remove a redundant and also erroneous memset.
(If you're going to memset a struct to 0 before filling in the fields
you care about, do use sizeof the struct rather than sizeof the
pointer; but also, if you're filling in _every_ field, there's no need
to bother anyway.)

[originally from svn r9773]
2013-03-11 19:58:28 +00:00
48f9d92f6f Clarify instructions for 'Range' -- I initially read the last point as
meaning the maximum white squares in any direction, rather than the total of
all directions.

[originally from svn r9771]
2013-03-10 13:56:12 +00:00
9dcba6a8cf Make Unruly's keyboard controls match the documentation and other puzzles in
the collection -- now Enter = black and Space = white.

[originally from svn r9770]
2013-03-10 12:49:06 +00:00
0d62b4a688 Fix entering pencil marks from the keyboard; the cursor is no longer removed
(this brings Undead into line with Solo, etc).

[originally from svn r9769]
2013-03-10 12:28:13 +00:00