Arrgh! Revert r9395,r9396,r9397,r9398, all of which I just committed
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 2 Feb 2012 07:15:48 +0000 (07:15 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 2 Feb 2012 07:15:48 +0000 (07:15 +0000)
by mistake in one go by running git-svn dcommit on the wrong branch.
Those were patches recently submitted by a user but which are not of
production quality (yet?) and I meant to keep them in my local
experimental repository. Sorry.

git-svn-id: svn://svn.tartarus.org/sgt/puzzles@9399 cda61777-01e9-0310-a592-d414129be87e

grid.c
grid.h
loopy.c
pearl.c

diff --git a/grid.c b/grid.c
index 24380d9..658fd4d 100644 (file)
--- a/grid.c
+++ b/grid.c
@@ -518,7 +518,6 @@ static void grid_make_consistent(grid *g)
      * We use "-1", not "-2" here, because Euler's formula includes the
      * infinite face, which we don't count. */
     g->num_edges = g->num_faces + g->num_dots - 1;
-    debug(("allocating room for %d edges\n", g->num_edges));
     g->edges = snewn(g->num_edges, grid_edge);
     next_new_edge = g->edges;
 
@@ -533,7 +532,6 @@ static void grid_make_consistent(grid *g)
     for (i = 0; i < g->num_faces; i++) {
         grid_face *f = g->faces + i;
         int j;
-        assert(f->order > 2);
         for (j = 0; j < f->order; j++) {
             grid_edge e; /* fake edge for searching */
             grid_edge *edge_found;
@@ -1371,70 +1369,6 @@ void grid_find_incentre(grid_face *f)
     f->iy = ybest + 0.5;
 }
 
-/* Generate the dual to a grid
- * Returns a new dynamically-allocated grid whose dots are the
- * faces of the input, and whose faces are the dots of the input.
- * A few modifications are made: dots on input that have only two
- * edges are deleted, and the infinite exterior face is also removed
- * before conversion.
- */
-static grid *grid_dual(grid *g)
-{
-    grid *new_g;
-    int i, j, k;
-    tree234* points;
-
-    new_g = grid_empty();
-    new_g->tilesize = g->tilesize;
-    new_g->faces = snewn(g->num_dots, grid_face);
-    new_g->dots = snewn(g->num_faces, grid_dot);
-    debug(("taking the dual of a grid with %d faces and %d dots\n",
-                g->num_faces,g->num_dots));
-
-    points = newtree234(grid_point_cmp_fn);
-
-    for (i=0;i<g->num_faces;i++)
-    {
-        grid_find_incentre(&(g->faces[i]));
-    }
-    for (i=0;i<g->num_dots;i++)
-    {
-        int order;
-        grid_dot *d;
-
-        d = &(g->dots[i]);
-
-        order = d->order;
-        for (j=0;j<d->order;j++)
-        {
-            if (!d->faces[j]) order--;
-        }
-        if (order>2)
-        {
-            grid_face_add_new(new_g, order);
-            for (j=0,k=0;j<d->order;j++)
-            {
-                grid_dot *new_d;
-                if (d->faces[j])
-                {
-                    new_d = grid_get_dot(new_g, points,
-                            d->faces[j]->ix, d->faces[j]->iy);
-                    grid_face_set_dot(new_g, new_d, k++);
-                }
-            }
-            assert(k==order);
-        }
-    }
-
-    freetree234(points);
-    assert(new_g->num_faces <= g->num_dots);
-    assert(new_g->num_dots <= g->num_faces);
-
-    debug(("dual has %d faces and %d dots\n",
-                new_g->num_faces,new_g->num_dots));
-    grid_make_consistent(new_g);
-    return new_g;
-}
 /* ------ Generate various types of grid ------ */
 
 /* General method is to generate faces, by calculating their dot coordinates.
@@ -2023,6 +1957,7 @@ static grid *grid_new_greathexagonal(int width, int height, char *desc)
     grid_make_consistent(g);
     return g;
 }
+
 #define OCTAGONAL_TILESIZE 40
 /* b/a approx sqrt(2) */
 #define OCTAGONAL_A 29
@@ -2771,7 +2706,7 @@ static grid *grid_new_penrose_p3_thick(int width, int height, char *desc)
 static grid *(*(grid_news[]))(int, int, char*) = { GRIDGEN_LIST(FNNEW) };
 static void(*(grid_sizes[]))(int, int, int*, int*, int*) = { GRIDGEN_LIST(FNSZ) };
 
-char *grid_new_desc(grid_type type, int width, int height, int dual, random_state *rs)
+char *grid_new_desc(grid_type type, int width, int height, random_state *rs)
 {
     if (type != GRID_PENROSE_P2 && type != GRID_PENROSE_P3)
         return NULL;
@@ -2779,7 +2714,7 @@ char *grid_new_desc(grid_type type, int width, int height, int dual, random_stat
     return grid_new_desc_penrose(type, width, height, rs);
 }
 
-char *grid_validate_desc(grid_type type, int width, int height, int dual, char *desc)
+char *grid_validate_desc(grid_type type, int width, int height, char *desc)
 {
     if (type != GRID_PENROSE_P2 && type != GRID_PENROSE_P3) {
         if (desc != NULL)
@@ -2790,25 +2725,12 @@ char *grid_validate_desc(grid_type type, int width, int height, int dual, char *
     return grid_validate_desc_penrose(type, width, height, desc);
 }
 
-grid *grid_new(grid_type type, int width, int height, int dual, char *desc)
+grid *grid_new(grid_type type, int width, int height, char *desc)
 {
-    char *err = grid_validate_desc(type, width, height, dual, desc);
+    char *err = grid_validate_desc(type, width, height, desc);
     if (err) assert(!"Invalid grid description.");
 
-    if (!dual)
-    {
-        return grid_news[type](width, height, desc);
-    }
-    else
-    {
-        grid *temp;
-        grid *g;
-
-        temp = grid_news[type](width, height, desc);
-        g = grid_dual(temp);
-        grid_free(temp);
-        return g;
-    }
+    return grid_news[type](width, height, desc);
 }
 
 void grid_compute_size(grid_type type, int width, int height,
diff --git a/grid.h b/grid.h
index 7cf4f59..d1c260e 100644 (file)
--- a/grid.h
+++ b/grid.h
@@ -114,10 +114,10 @@ typedef enum grid_type { GRIDGEN_LIST(ENUM) GRID_TYPE_MAX } grid_type;
 
 /* 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, int dual, random_state *rs);
-char *grid_validate_desc(grid_type type, int width, int height, int dual, char *desc);
+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, int dual, char *desc);
+grid *grid_new(grid_type type, int width, int height, char *desc);
 
 void grid_free(grid *g);
 
diff --git a/loopy.c b/loopy.c
index 2173dcd..85590fa 100644 (file)
--- a/loopy.c
+++ b/loopy.c
@@ -208,7 +208,6 @@ struct game_params {
     int w, h;
     int diff;
     int type;
-    int dual;
 };
 
 /* line_drawstate is the same as line_state, but with the extra ERROR
@@ -257,7 +256,7 @@ static void check_caches(const solver_state* sstate);
     A(Dodecagonal,GRID_DODECAGONAL,2,2) \
     A(Great-Dodecagonal,GRID_GREATDODECAGONAL,2,2) \
     A(Penrose (kite/dart),GRID_PENROSE_P2,3,3) \
-    A(Penrose (rhombs),GRID_PENROSE_P3,3,3) \
+    A(Penrose (rhombs),GRID_PENROSE_P3,3,3)
 
 #define GRID_NAME(title,type,amin,omin) #title,
 #define GRID_CONFIG(title,type,amin,omin) ":" #title
@@ -267,7 +266,6 @@ static void check_caches(const solver_state* sstate);
      "Width and height for this grid type must both be at least " #amin, \
      "At least one of width and height for this grid type must be at least " #omin,},
 static char const *const gridnames[] = { GRIDLIST(GRID_NAME) };
-static char const *const dualnames[] = { "", "(dual) " };
 #define GRID_CONFIGS GRIDLIST(GRID_CONFIG)
 static grid_type grid_types[] = { GRIDLIST(GRID_TYPE) };
 #define NUM_GRID_TYPES (sizeof(grid_types) / sizeof(grid_types[0]))
@@ -281,7 +279,7 @@ static const struct {
  * generated. */
 static grid *loopy_generate_grid(game_params *params, char *grid_desc)
 {
-    return grid_new(grid_types[params->type], params->w, params->h, params->dual, grid_desc);
+    return grid_new(grid_types[params->type], params->w, params->h, grid_desc);
 }
 
 /* ----------------------------------------------------------------------
@@ -477,7 +475,6 @@ static game_params *default_params(void)
 #endif
     ret->diff = DIFF_EASY;
     ret->type = 0;
-    ret->dual = 0;
 
     return ret;
 }
@@ -492,42 +489,40 @@ static game_params *dup_params(game_params *params)
 
 static const game_params presets[] = {
 #ifdef SMALL_SCREEN
-    {  7,  7, DIFF_EASY, 0, 0 },
-    {  7,  7, DIFF_NORMAL, 0, 0 },
-    {  7,  7, DIFF_HARD, 0, 0 },
-    {  7,  7, DIFF_HARD, 1, 0 },
-    {  7,  7, DIFF_HARD, 2, 0 },
-    {  5,  5, DIFF_HARD, 3, 0 },
-    {  7,  7, DIFF_HARD, 4, 0 },
-    {  5,  4, DIFF_HARD, 5, 0 },
-    {  5,  5, DIFF_HARD, 6, 0 },
-    {  5,  5, DIFF_HARD, 7, 0 },
-    {  3,  3, DIFF_HARD, 8, 0 },
-    {  3,  3, DIFF_HARD, 8, 1 },
-    {  3,  3, DIFF_HARD, 9, 0 },
-    {  3,  3, DIFF_HARD, 10, 0 },
-    {  6,  6, DIFF_HARD, 11, 0 },
-    {  6,  6, DIFF_HARD, 12, 0 },
+    {  7,  7, DIFF_EASY, 0 },
+    {  7,  7, DIFF_NORMAL, 0 },
+    {  7,  7, DIFF_HARD, 0 },
+    {  7,  7, DIFF_HARD, 1 },
+    {  7,  7, DIFF_HARD, 2 },
+    {  5,  5, DIFF_HARD, 3 },
+    {  7,  7, DIFF_HARD, 4 },
+    {  5,  4, DIFF_HARD, 5 },
+    {  5,  5, DIFF_HARD, 6 },
+    {  5,  5, DIFF_HARD, 7 },
+    {  3,  3, DIFF_HARD, 8 },
+    {  3,  3, DIFF_HARD, 9 },
+    {  3,  3, DIFF_HARD, 10 },
+    {  6,  6, DIFF_HARD, 11 },
+    {  6,  6, DIFF_HARD, 12 },
 #else
-    {  7,  7, DIFF_EASY, 0, 0 },
-    {  10,  10, DIFF_EASY, 0, 0 },
-    {  7,  7, DIFF_NORMAL, 0, 0 },
-    {  10,  10, DIFF_NORMAL, 0, 0 },
-    {  7,  7, DIFF_HARD, 0, 0 },
-    {  10,  10, DIFF_HARD, 0, 0 },
-    {  10,  10, DIFF_HARD, 1, 0 },
-    {  12,  10, DIFF_HARD, 2, 0 },
-    {  7,  7, DIFF_HARD, 3, 0 },
-    {  9,  9, DIFF_HARD, 4, 0 },
-    {  5,  4, DIFF_HARD, 5, 0 },
-    {  7,  7, DIFF_HARD, 6, 0 },
-    {  5,  5, DIFF_HARD, 7, 0 },
-    {  5,  5, DIFF_HARD, 8, 0 },
-    {  5,  5, DIFF_HARD, 8, 1 },
-    {  5,  4, DIFF_HARD, 9, 0 },
-    {  5,  4, DIFF_HARD, 10, 0 },
-    {  10, 10, DIFF_HARD, 11, 0 },
-    {  10, 10, DIFF_HARD, 12, 0 }
+    {  7,  7, DIFF_EASY, 0 },
+    {  10,  10, DIFF_EASY, 0 },
+    {  7,  7, DIFF_NORMAL, 0 },
+    {  10,  10, DIFF_NORMAL, 0 },
+    {  7,  7, DIFF_HARD, 0 },
+    {  10,  10, DIFF_HARD, 0 },
+    {  10,  10, DIFF_HARD, 1 },
+    {  12,  10, DIFF_HARD, 2 },
+    {  7,  7, DIFF_HARD, 3 },
+    {  9,  9, DIFF_HARD, 4 },
+    {  5,  4, DIFF_HARD, 5 },
+    {  7,  7, DIFF_HARD, 6 },
+    {  5,  5, DIFF_HARD, 7 },
+    {  5,  5, DIFF_HARD, 8 },
+    {  5,  4, DIFF_HARD, 9 },
+    {  5,  4, DIFF_HARD, 10 },
+    {  10, 10, DIFF_HARD, 11 },
+    {  10, 10, DIFF_HARD, 12 }
 #endif
 };
 
@@ -542,9 +537,8 @@ static int game_fetch_preset(int i, char **name, game_params **params)
     tmppar = snew(game_params);
     *tmppar = presets[i];
     *params = tmppar;
-    sprintf(buf, "%dx%d %s %s- %s", tmppar->h, tmppar->w,
-            gridnames[tmppar->type], dualnames[tmppar->dual], 
-            diffnames[tmppar->diff]);
+    sprintf(buf, "%dx%d %s - %s", tmppar->h, tmppar->w,
+            gridnames[tmppar->type], diffnames[tmppar->diff]);
     *name = dupstr(buf);
 
     return TRUE;
@@ -557,10 +551,8 @@ static void free_params(game_params *params)
 
 static void decode_params(game_params *params, char const *string)
 {
-    debug(("Decoding params '%s'\n",string));
     params->h = params->w = atoi(string);
     params->diff = DIFF_EASY;
-    params->dual = 0;
     while (*string && isdigit((unsigned char)*string)) string++;
     if (*string == 'x') {
         string++;
@@ -572,10 +564,6 @@ static void decode_params(game_params *params, char const *string)
         params->type = atoi(string);
         while (*string && isdigit((unsigned char)*string)) string++;
     }
-    if (*string == 'l') {
-        string++;
-        params->dual = 1;
-    }
     if (*string == 'd') {
         int i;
         string++;
@@ -589,11 +577,9 @@ static void decode_params(game_params *params, char const *string)
 static char *encode_params(game_params *params, int full)
 {
     char str[80];
-    sprintf(str, "%dx%dt%d%s", params->w, params->h, params->type,
-            params->dual ? "l" : "");
+    sprintf(str, "%dx%dt%d", params->w, params->h, params->type);
     if (full)
         sprintf(str + strlen(str), "d%c", diffchars[params->diff]);
-    debug(("Encoded to '%s'\n",str));
     return dupstr(str);
 }
 
@@ -602,7 +588,7 @@ static config_item *game_configure(game_params *params)
     config_item *ret;
     char buf[80];
 
-    ret = snewn(6, config_item);
+    ret = snewn(5, config_item);
 
     ret[0].name = "Width";
     ret[0].type = C_STRING;
@@ -626,15 +612,10 @@ static config_item *game_configure(game_params *params)
     ret[3].sval = DIFFCONFIG;
     ret[3].ival = params->diff;
 
-    ret[4].name = "Dual";
-    ret[4].type = C_BOOLEAN;
+    ret[4].name = NULL;
+    ret[4].type = C_END;
     ret[4].sval = NULL;
-    ret[4].ival = params->dual;
-
-    ret[5].name = NULL;
-    ret[5].type = C_END;
-    ret[5].sval = NULL;
-    ret[5].ival = 0;
+    ret[4].ival = 0;
 
     return ret;
 }
@@ -647,7 +628,6 @@ static game_params *custom_params(config_item *cfg)
     ret->h = atoi(cfg[1].sval);
     ret->type = cfg[2].ival;
     ret->diff = cfg[3].ival;
-    ret->dual = cfg[4].ival;
 
     return ret;
 }
@@ -742,15 +722,12 @@ static char *validate_desc(game_params *params, char *desc)
     /* It's pretty inefficient to do this just for validation. All we need to
      * know is the precise number of faces. */
     grid_desc = extract_grid_desc(&desc);
-    ret = grid_validate_desc(grid_types[params->type], params->w, params->h, params->dual, grid_desc);
+    ret = grid_validate_desc(grid_types[params->type], params->w, params->h, grid_desc);
     if (ret) return ret;
 
     g = loopy_generate_grid(params, grid_desc);
     if (grid_desc) sfree(grid_desc);
 
-    debug(("Validating '%s' type %d %dx%d dual: %d\n", 
-                desc, params->type, params->w, params->h, params->dual));
-
     for (; *desc; ++desc) {
         if ((*desc >= '0' && *desc <= '9') || (*desc >= 'A' && *desc <= 'Z')) {
             count++;
@@ -1396,7 +1373,7 @@ static char *new_game_desc(game_params *params, random_state *rs,
     game_state *state = snew(game_state);
     game_state *state_new;
 
-    grid_desc = grid_new_desc(grid_types[params->type], params->w, params->h, params->dual, rs);
+    grid_desc = grid_new_desc(grid_types[params->type], params->w, params->h, rs);
     state->game_grid = g = loopy_generate_grid(params, grid_desc);
 
     state->clues = snewn(g->num_faces, signed char);
diff --git a/pearl.c b/pearl.c
index ef9fdc9..248d64e 100644 (file)
--- a/pearl.c
+++ b/pearl.c
@@ -1048,7 +1048,7 @@ int pearl_loopgen_bias(void *vctx, char *board, int face)
 
 void pearl_loopgen(int w, int h, char *lines, random_state *rs)
 {
-    grid *g = grid_new(GRID_SQUARE, w-1, h-1, 0, NULL);
+    grid *g = grid_new(GRID_SQUARE, w-1, h-1, NULL);
     char *board = snewn(g->num_faces, char);
     int i, s = g->tilesize;
     struct pearl_loopgen_bias_ctx biasctx;