26 Commits

Author SHA1 Message Date
2a0e91bc76 grid.c: fix size miscalculation in Floret tiling.
A Floret grid of height h usually alternates columns of h hexagonal
florets with columns of h-1. An exception is when h=1, in which case
alternating columns of 1 and 0 florets would leave the grid
disconnected. So in that situation all columns have 1 floret in them,
and the starting y-coordinate oscillates to make the grid tile
sensibly.

However, that special case wasn't taken account of when calculating
the grid height. As a result the anomalous extra florets in the
height-1 tiling fell off the bottom of the puzzle window.
2020-04-12 14:37:47 +01:00
5f5b284c0b Use C99 bool within source modules.
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.
2018-11-13 21:48:24 +00:00
a550ea0a47 Replace TRUE/FALSE with C99 true/false throughout.
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.
2018-11-13 21:48:24 +00:00
8af0c29615 New grid type: the trihexagonal tiling, or 'kagome lattice'.
Regular hexagons and equilateral triangles in strict alternation, with
two of each interleaved around each vertex.
https://en.wikipedia.org/wiki/Trihexagonal_tiling

Thanks to Michael Quevillon for the patch.
2017-11-18 15:26:13 +00:00
a58c1b216b Make the code base clean under -Wwrite-strings.
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.
2017-10-01 16:35:40 +01:00
e37d915f44 New Loopy tiling: 'Great Great Dodecagonal'.
Officially known as the '3-4-6-12 tiling', according to, e.g.,
https://en.wikipedia.org/wiki/3-4-6-12_tiling .

Thanks to Michael Quevillon for contributing this patch (and for
choosing a less hard-to-remember name for the tiling :-).
2017-04-24 17:09:39 +01:00
7f64f4a50e Sort out abs/fabs confusion.
My Mac has just upgraded itself to include a version of clang which
warns if you use abs() on a floating-point value, or fabs() on an
integer. Fixed the two occurrences that came up in this build (and
which were actual build failures, because of -Werror), one in each
direction.

I think both were benign. The potentially dangerous one was using abs
in place of fabs in grid_find_incentre(), because that could actually
lose precision, but I think that function had plenty of precision to
spare (grid point separation being of the order of tens of pixels) so
nothing should have gone seriously wrong with the old code.
2015-04-10 07:58:26 +01:00
b6ee9debcf Fix grid generation crashes at Penrose 3x3 sizes. What seemed to be
happening was that at the point of calling grid_make_consistent, the
grid had no faces or vertices, probably because grid_trim_vigorously
had removed them all, causing grid_make_consistent to try to allocate
a negative amount of memory and die in snewn.

Fixed by detecting this case in new_desc_penrose and retrying until
generation is successful. (It wasn't happening 100% of the time, just
_most_ of the time.) The same verification step is also used in
validate_desc_penrose in case a user manages to manually construct a
set of parameters leading to this failure mode.

[originally from svn r9840]
2013-05-10 17:56:00 +00:00
251b21c418 Giant const patch of doom: add a 'const' to every parameter in every
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]
2013-04-13 10:37:32 +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
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
4a172274f2 Apply the rotation in Penrose grid descriptions by rotating in the
4-vector representation, rather than mucking about with sines and
cosines after grid generation. _Should_ make no difference in the
generated grids (there's a theoretical risk of an unlucky rounding
error just about managing to push some point in or out of bounds, but
I think it's vanishingly small), but simplifies the coordinate-
flattening procedure, and in particular increases its chance of
getting vertical lines actually vertical.

(Prior to this change, the game ID
10x10t12:G2554,-31,108_a3b12h0a212a3d102b2a23a2e3b01b0a2c2a0c0 was
generating a not-quite-vertical edge at top left, in the Java port but
not on Linux; I suspect differences in sin and cos as the cause of the
discrepancy. With the rotation done like this, the points'
x-coordinates are now computed without reference to their
y-coordinates.)

[originally from svn r9168]
2011-05-06 17:09:03 +00:00
89bfecaa5a Portability fixes, mostly from James for Palm purposes. Mostly
additions of missing 'static' and explicit 'void' in parameter lists,
plus one or two other things like explicitly casting chars in variadic
argument lists to int and using DBL_MAX if HUGE_VAL isn't available.

[originally from svn r9166]
2011-05-04 18:41:21 +00:00
4bab5e531b Fix two memory leaks reported by Tiago Dionizio in recent Loopy
development.

[originally from svn r9163]
2011-04-26 13:44:27 +00:00
8266b71475 Forgot to set 'has_incentre' on triangular grids, which don't use
grid_face_add_new(). Oops.

[originally from svn r9161]
2011-04-25 22:41:54 +00:00
62c20496bf From James Harvey (via a period of collaborative polishing), a patch
to add two kinds of Penrose tiling to the grid types supported by
Loopy.

This has involved a certain amount of infrastructure work, because of
course the whole point of Penrose tilings is that they don't have to
be the same every time: so now grid.c has grown the capacity to
describe its grids as strings, and reconstitute them from those string
descriptions. Hence a Penrose Loopy game description consists of a
string identifying a particular piece of Penrose tiling, followed by
the normal Loopy clue encoding.

All the existing grid types decline to provide a grid description
string, so their Loopy game descriptions have not changed encoding.

[originally from svn r9159]
2011-04-24 09:10:52 +00:00
f390d0d7ff Oops: initialise that new 'has_incentre' flag to false, otherwise the
game will sometimes pick random incentres in place of the carefully
computed ones. Ahem.

[originally from svn r9158]
2011-04-23 13:03:38 +00:00
5e3de7d95b Move most of face_text_pos() into grid.c, leaving in loopy.c only the
part that converts from abstract grid coordinates into screen
coordinates. This should speed up window-resizing by eliminating
pointless reiteration of the complicated part of the algorithm: now
when a game_drawstate is renewed, only the conversion into screen
coordinates has to be redone.

[originally from svn r9157]
2011-04-23 11:44:43 +00:00
7b2b742be8 Another patch from Chris Moore implementing two more grid types, both
involving dodecagons.

[originally from svn r9109]
2011-02-24 19:06:49 +00:00
621649491d Retire the 'middle_face' field in 'struct grid', together with the
overly complicated algorithm that uses it to home in on the grid edge
closest to a mouse click. That algorithm is being stressed beyond its
limit by the new grid type, and it's unnecessary anyway given that no
sensibly sized puzzle grid is going to be big enough to make it
prohibitively expensive just to do the trivial approach of iterating
over all edges and finding the closest of the eligible ones.

[originally from svn r9108]
2011-02-24 19:06:48 +00:00
53f6e4c6cb Patch from Chris Moore to implement an extra grid type, the 'floret'
pentagonal tiling.

[originally from svn r9107]
2011-02-23 20:05:42 +00:00
1a628aebd8 Patch from Chris Moore to improve the generality of
grid_nearest_edge(), by having it search harder for a better dot to
move to in the first loop.

[originally from svn r9106]
2011-02-23 20:05:40 +00:00
fe1b91ac49 Since the lack of this has caused portability issues in the past:
add "-ansi -pedantic" to the main Unix makefile, and clean up a few
minor problems pointed out thereby.

[originally from svn r8175]
2008-09-13 18:25:19 +00:00
acf5c55d35 Patch from James H to make new-Loopy port more easily.
[originally from svn r8174]
2008-09-10 21:44:23 +00:00
4033458aff How did I manage to check this in without actually trying to build
on Windows at all?! Fix some departures from the C standard, mostly
declaring variables after a statement has already been issued in the
same block. MSVC is picky about this where gcc is forgiving, and TBH
I'd change the latter given the choice.

[originally from svn r8166]
2008-09-07 08:35:52 +00:00
f38b711c73 Completely re-engineered version of Loopy, courtesy of Lambros
Lambrou. Now capable of handling triangular and hexagonal grids as
well as square ones, and then a number of semiregular plane tilings
and duals of semiregular ones. In fact, most of the solver code
supports an _arbitrary_ planar graph (well, provided both the graph
and its dual have no self-edges), so it could easily be extended
further with only a little more effort.

[originally from svn r8162]
2008-09-06 15:19:47 +00:00