aboutsummaryrefslogtreecommitdiff
path: root/grid.h
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2011-04-24 09:10:52 +0000
committerSimon Tatham <anakin@pobox.com>2011-04-24 09:10:52 +0000
commit62c20496bf106b1034f4be95bdb7723c3ec78d00 (patch)
tree28ab54312b25f9ccf288c553a74db0fea5646ba0 /grid.h
parentf390d0d7ff4972e4cb8aa778c2eb44452067d6d0 (diff)
downloadpuzzles-62c20496bf106b1034f4be95bdb7723c3ec78d00.zip
puzzles-62c20496bf106b1034f4be95bdb7723c3ec78d00.tar.gz
puzzles-62c20496bf106b1034f4be95bdb7723c3ec78d00.tar.bz2
puzzles-62c20496bf106b1034f4be95bdb7723c3ec78d00.tar.xz
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]
Diffstat (limited to 'grid.h')
-rw-r--r--grid.h43
1 files changed, 32 insertions, 11 deletions
diff --git a/grid.h b/grid.h
index 65ced86..d1c260e 100644
--- a/grid.h
+++ b/grid.h
@@ -9,6 +9,8 @@
#ifndef PUZZLES_GRID_H
#define PUZZLES_GRID_H
+#include "puzzles.h" /* for random_state */
+
/* Useful macros */
#define SQ(x) ( (x) * (x) )
@@ -89,22 +91,41 @@ typedef struct grid {
int refcount;
} grid;
-grid *grid_new_square(int width, int height);
-grid *grid_new_honeycomb(int width, int height);
-grid *grid_new_triangular(int width, int height);
-grid *grid_new_snubsquare(int width, int height);
-grid *grid_new_cairo(int width, int height);
-grid *grid_new_greathexagonal(int width, int height);
-grid *grid_new_octagonal(int width, int height);
-grid *grid_new_kites(int width, int height);
-grid *grid_new_floret(int width, int height);
-grid *grid_new_dodecagonal(int width, int height);
-grid *grid_new_greatdodecagonal(int width, int height);
+/* Grids are specified by type: GRID_SQUARE, GRID_KITE, etc. */
+
+#define GRIDGEN_LIST(A) \
+ A(SQUARE,square) \
+ A(HONEYCOMB,honeycomb) \
+ A(TRIANGULAR,triangular) \
+ A(SNUBSQUARE,snubsquare) \
+ A(CAIRO,cairo) \
+ A(GREATHEXAGONAL,greathexagonal) \
+ A(OCTAGONAL,octagonal) \
+ A(KITE,kites) \
+ A(FLORET,floret) \
+ A(DODECAGONAL,dodecagonal) \
+ A(GREATDODECAGONAL,greatdodecagonal) \
+ A(PENROSE_P2,penrose_p2_kite) \
+ A(PENROSE_P3,penrose_p3_thick)
+
+#define ENUM(upper,lower) GRID_ ## upper,
+typedef enum grid_type { GRIDGEN_LIST(ENUM) GRID_TYPE_MAX } grid_type;
+#undef ENUM
+
+/* Free directly after use if non-NULL. Will never contain an underscore
+ * (so clients can safely use that as a separator). */
+char *grid_new_desc(grid_type type, int width, int height, random_state *rs);
+char *grid_validate_desc(grid_type type, int width, int height, char *desc);
+
+grid *grid_new(grid_type type, int width, int height, char *desc);
void grid_free(grid *g);
grid_edge *grid_nearest_edge(grid *g, int x, int y);
+void grid_compute_size(grid_type type, int width, int height,
+ int *tilesize, int *xextent, int *yextent);
+
void grid_find_incentre(grid_face *f);
#endif /* PUZZLES_GRID_H */