shithub: puzzles

Download patch

ref: 53f6e4c6cb0b342f37e75c2686c1b542212c5f3e
parent: 1a628aebd8893001bc3a2e9dbc3e2dc7432b08e4
author: Simon Tatham <anakin@pobox.com>
date: Wed Feb 23 15:05:42 EST 2011

Patch from Chris Moore to implement an extra grid type, the 'floret'
pentagonal tiling.

[originally from svn r9107]

--- a/grid.c
+++ b/grid.c
@@ -1350,4 +1350,93 @@
     return g;
 }
 
+grid *grid_new_floret(int width, int height)
+{
+    int x, y;
+    /* Vectors for sides; weird numbers needed to keep puzzle aligned with window
+     * -py/px is close to tan(30 - atan(sqrt(3)/9))
+     * using py=26 makes everything lean to the left, rather than right
+     */
+    int px = 75, py = -26;       /* |( 75, -26)| = 79.43 */
+    int qx = 4*px/5, qy = -py*2; /* |( 60,  52)| = 79.40 */
+    int rx = qx-px, ry = qy-py;  /* |(-15,  78)| = 79.38 */
+
+    /* Upper bounds - don't have to be exact */
+    int max_faces = 6 * width * height;
+    int max_dots = 9 * (width + 1) * (height + 1);
+    
+    tree234 *points;
+
+    grid *g = grid_new();
+    g->tilesize = 2 * px;
+    g->faces = snewn(max_faces, grid_face);
+    g->dots = snewn(max_dots, grid_dot);
+
+    points = newtree234(grid_point_cmp_fn);
+
+    /* generate pentagonal faces */
+    for (y = 0; y < height; y++) {
+        for (x = 0; x < width; x++) {
+            grid_dot *d;
+            /* face centre */
+            int cx = (6*px+3*qx)/2 * x;
+            int cy = (4*py-5*qy) * y;
+            if (x % 2)
+                cy -= (4*py-5*qy)/2;
+            else if (y && y == height-1)
+                continue; /* make better looking grids?  try 3x3 for instance */
+
+            grid_face_add_new(g, 5);
+            d = grid_get_dot(g, points, cx        , cy        ); grid_face_set_dot(g, d, 0);
+            d = grid_get_dot(g, points, cx+2*rx   , cy+2*ry   ); grid_face_set_dot(g, d, 1);
+            d = grid_get_dot(g, points, cx+2*rx+qx, cy+2*ry+qy); grid_face_set_dot(g, d, 2);
+            d = grid_get_dot(g, points, cx+2*qx+rx, cy+2*qy+ry); grid_face_set_dot(g, d, 3);
+            d = grid_get_dot(g, points, cx+2*qx   , cy+2*qy   ); grid_face_set_dot(g, d, 4);
+
+            grid_face_add_new(g, 5);
+            d = grid_get_dot(g, points, cx        , cy        ); grid_face_set_dot(g, d, 0);
+            d = grid_get_dot(g, points, cx+2*qx   , cy+2*qy   ); grid_face_set_dot(g, d, 1);
+            d = grid_get_dot(g, points, cx+2*qx+px, cy+2*qy+py); grid_face_set_dot(g, d, 2);
+            d = grid_get_dot(g, points, cx+2*px+qx, cy+2*py+qy); grid_face_set_dot(g, d, 3);
+            d = grid_get_dot(g, points, cx+2*px   , cy+2*py   ); grid_face_set_dot(g, d, 4);
+
+            grid_face_add_new(g, 5);
+            d = grid_get_dot(g, points, cx        , cy        ); grid_face_set_dot(g, d, 0);
+            d = grid_get_dot(g, points, cx+2*px   , cy+2*py   ); grid_face_set_dot(g, d, 1);
+            d = grid_get_dot(g, points, cx+2*px-rx, cy+2*py-ry); grid_face_set_dot(g, d, 2);
+            d = grid_get_dot(g, points, cx-2*rx+px, cy-2*ry+py); grid_face_set_dot(g, d, 3);
+            d = grid_get_dot(g, points, cx-2*rx   , cy-2*ry   ); grid_face_set_dot(g, d, 4);
+
+            grid_face_add_new(g, 5);
+            d = grid_get_dot(g, points, cx        , cy        ); grid_face_set_dot(g, d, 0);
+            d = grid_get_dot(g, points, cx-2*rx   , cy-2*ry   ); grid_face_set_dot(g, d, 1);
+            d = grid_get_dot(g, points, cx-2*rx-qx, cy-2*ry-qy); grid_face_set_dot(g, d, 2);
+            d = grid_get_dot(g, points, cx-2*qx-rx, cy-2*qy-ry); grid_face_set_dot(g, d, 3);
+            d = grid_get_dot(g, points, cx-2*qx   , cy-2*qy   ); grid_face_set_dot(g, d, 4);
+
+            grid_face_add_new(g, 5);
+            d = grid_get_dot(g, points, cx        , cy        ); grid_face_set_dot(g, d, 0);
+            d = grid_get_dot(g, points, cx-2*qx   , cy-2*qy   ); grid_face_set_dot(g, d, 1);
+            d = grid_get_dot(g, points, cx-2*qx-px, cy-2*qy-py); grid_face_set_dot(g, d, 2);
+            d = grid_get_dot(g, points, cx-2*px-qx, cy-2*py-qy); grid_face_set_dot(g, d, 3);
+            d = grid_get_dot(g, points, cx-2*px   , cy-2*py   ); grid_face_set_dot(g, d, 4);
+
+            grid_face_add_new(g, 5);
+            d = grid_get_dot(g, points, cx        , cy        ); grid_face_set_dot(g, d, 0);
+            d = grid_get_dot(g, points, cx-2*px   , cy-2*py   ); grid_face_set_dot(g, d, 1);
+            d = grid_get_dot(g, points, cx-2*px+rx, cy-2*py+ry); grid_face_set_dot(g, d, 2);
+            d = grid_get_dot(g, points, cx+2*rx-px, cy+2*ry-py); grid_face_set_dot(g, d, 3);
+            d = grid_get_dot(g, points, cx+2*rx   , cy+2*ry   ); grid_face_set_dot(g, d, 4);
+        }
+    }
+
+    freetree234(points);
+    assert(g->num_faces <= max_faces);
+    assert(g->num_dots <= max_dots);
+    g->middle_face = g->faces + 6 * ((height/2) * width + (width/2));
+
+    grid_make_consistent(g);
+    return g;
+}
+
 /* ----------- End of grid generators ------------- */
--- a/grid.h
+++ b/grid.h
@@ -85,6 +85,7 @@
 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_floret(int width, int height);
 grid *grid_new_kites(int width, int height);
 
 void grid_free(grid *g);
--- a/loopy.c
+++ b/loopy.c
@@ -253,7 +253,8 @@
     A(Cairo,grid_new_cairo,3,4) \
     A(Great-Hexagonal,grid_new_greathexagonal,3,3) \
     A(Octagonal,grid_new_octagonal,3,3) \
-    A(Kites,grid_new_kites,3,3)
+    A(Kites,grid_new_kites,3,3) \
+    A(Floret,grid_new_floret,1,2)
 
 #define GRID_NAME(title,fn,amin,omin) #title,
 #define GRID_CONFIG(title,fn,amin,omin) ":" #title
@@ -504,6 +505,7 @@
     {  5,  4, DIFF_HARD, 5, NULL },
     {  5,  5, DIFF_HARD, 6, NULL },
     {  5,  5, DIFF_HARD, 7, NULL },
+    {  3,  3, DIFF_HARD, 8, NULL },
 #else
     {  7,  7, DIFF_EASY, 0, NULL },
     {  10,  10, DIFF_EASY, 0, NULL },
@@ -518,6 +520,7 @@
     {  5,  4, DIFF_HARD, 5, NULL },
     {  7,  7, DIFF_HARD, 6, NULL },
     {  5,  5, DIFF_HARD, 7, NULL },
+    {  5,  5, DIFF_HARD, 8, NULL },
 #endif
 };