summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/spectre.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/puzzles/src/spectre.h')
-rw-r--r--apps/plugins/puzzles/src/spectre.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/apps/plugins/puzzles/src/spectre.h b/apps/plugins/puzzles/src/spectre.h
new file mode 100644
index 0000000000..97d7595e3a
--- /dev/null
+++ b/apps/plugins/puzzles/src/spectre.h
@@ -0,0 +1,72 @@
1#ifndef PUZZLES_SPECTRE_H
2#define PUZZLES_SPECTRE_H
3
4struct SpectrePatchParams {
5 /*
6 * A patch of Spectre tiling is identified by giving
7 *
8 * - the coordinates of the central Spectre, using a
9 * combinatorial coordinate system similar to the Hat tiling in
10 * hat.h
11 *
12 * - the orientation of that Spectre, as a number from 0 to 11 (a
13 * multiple of 30 degrees), with 0 representing the 'head' of
14 * the Spectre facing upwards, and numbers counting
15 * anticlockwise.
16 *
17 * Coordinates are a sequence of small non-negative integers. The
18 * valid range for each coordinate depends on the next coordinate,
19 * or on final_hex if it's the last one in the list. The largest
20 * valid range is {0,...,7}.
21 *
22 * 'final_hex' is one of the letters GDJLXPSFY.
23 * spectre_valid_hex_letter() will check that.
24 */
25 int orientation;
26 size_t ncoords;
27 unsigned char *coords;
28 char final_hex;
29};
30
31bool spectre_valid_hex_letter(char c);
32
33/*
34 * Fill in SpectrePatchParams with a randomly selected set of
35 * coordinates, in enough detail to generate a patch of tiling filling
36 * a w x h area. The unit of measurement is 1/(2*sqrt(2)) of a Spectre
37 * edge, i.e. such that a single Spectre edge at 45 degrees would
38 * correspond to the vector (2,2).
39 *
40 * The 'coords' field of the structure will be filled in with a new
41 * dynamically allocated array. Any previous pointer in that field
42 * will be overwritten.
43 */
44void spectre_tiling_randomise(struct SpectrePatchParams *params, int w, int h,
45 random_state *rs);
46
47/*
48 * Validate a SpectrePatchParams to ensure it contains no illegal
49 * coordinates. Returns NULL if it's acceptable, or an error string if
50 * not.
51 */
52const char *spectre_tiling_params_invalid(
53 const struct SpectrePatchParams *params);
54
55/*
56 * Generate the actual set of Spectre tiles from a SpectrePatchParams,
57 * passing each one to a callback. The callback receives the vertices
58 * of each point, in the form of an array of 4*14 integers. Each
59 * vertex is represented by four consecutive integers in this array,
60 * with the first two giving the x coordinate and the last two the y
61 * coordinate. Each pair of integers a,b represent a single coordinate
62 * whose value is a + b*sqrt(3). The unit of measurement is as above.
63 */
64typedef void (*spectre_tile_callback_fn)(void *ctx, const int *coords);
65
66#define SPECTRE_NVERTICES 14
67
68void spectre_tiling_generate(
69 const struct SpectrePatchParams *params, int w, int h,
70 spectre_tile_callback_fn cb, void *cbctx);
71
72#endif