chiark / gitweb /
New infrastructure feature. Games are now permitted to be
[sgt-puzzles.git] / slant.c
diff --git a/slant.c b/slant.c
index fd7adad9b784d78175065e7374e675ace1abec11..000d880dc3ae587d2bde20b6d14e66ec7fd50468 100644 (file)
--- a/slant.c
+++ b/slant.c
@@ -287,7 +287,10 @@ struct solver_scratch {
      *    below it might form a <-shape between them
      * 
      * Any starting 1 or 3 clue rules out four bits in this array
-     * immediately; we can rule out further bits during play using
+     * immediately; a 2 clue propagates any ruled-out bit past it
+     * (if the two squares on one side of a 2 cannot be a v-shape,
+     * then neither can the two on the other side be the same
+     * v-shape); we can rule out further bits during play using
      * partially filled 2 clues; whenever a pair of squares is
      * known not to be _either_ kind of v-shape, we can mark them
      * as equivalent.
@@ -465,15 +468,13 @@ static int slant_solve(int w, int h, const signed char *clues,
      * Establish a disjoint set forest for tracking connectedness
      * between grid points.
      */
-    for (i = 0; i < W*H; i++)
-       sc->connected[i] = i;          /* initially all distinct */
+    dsf_init(sc->connected, W*H);
 
     /*
      * Establish a disjoint set forest for tracking which squares
      * are known to slant in the same direction.
      */
-    for (i = 0; i < w*h; i++)
-       sc->equiv[i] = i;              /* initially all distinct */
+    dsf_init(sc->equiv, w*h);
 
     /*
      * Clear the slashval array.
@@ -486,7 +487,7 @@ static int slant_solve(int w, int h, const signed char *clues,
     memset(sc->vbitmap, 0xF, w*h);
 
     /*
-     * Initialise the `exits' and `border' arrays. Theses is used
+     * Initialise the `exits' and `border' arrays. These are used
      * to do second-order loop avoidance: the dual of the no loops
      * constraint is that every point must be somehow connected to
      * the border of the grid (otherwise there would be a solid
@@ -1003,9 +1004,7 @@ static void slant_generate(int w, int h, signed char *soln, random_state *rs)
      * Establish a disjoint set forest for tracking connectedness
      * between grid points.
      */
-    connected = snewn(W*H, int);
-    for (i = 0; i < W*H; i++)
-       connected[i] = i;                      /* initially all distinct */
+    connected = snew_dsf(W*H);
 
     /*
      * Prepare a list of the squares in the grid, and fill them in
@@ -1386,8 +1385,7 @@ static int check_completion(game_state *state)
      * edge is visited at most twice.
      */
     dsf = state->clues->tmpdsf;
-    for (i = 0; i < W*H; i++)
-        dsf[i] = i;                   /* initially all distinct */
+    dsf_init(dsf, W*H);
     for (y = 0; y < h; y++)
         for (x = 0; x < w; x++) {
             int i1, i2;
@@ -1617,6 +1615,11 @@ static char *solve_game(game_state *state, game_state *currstate,
     return move;
 }
 
+static int game_can_format_as_text_now(game_params *params)
+{
+    return TRUE;
+}
+
 static char *game_text_format(game_state *state)
 {
     int w = state->p.w, h = state->p.h, W = w+1, H = h+1;
@@ -2188,7 +2191,7 @@ static void game_print(drawing *dr, game_state *state, int tilesize)
 #endif
 
 const struct game thegame = {
-    "Slant", "games.slant",
+    "Slant", "games.slant", "slant",
     default_params,
     game_fetch_preset,
     decode_params,
@@ -2203,7 +2206,7 @@ const struct game thegame = {
     dup_game,
     free_game,
     TRUE, solve_game,
-    TRUE, game_text_format,
+    TRUE, game_can_format_as_text_now, game_text_format,
     new_ui,
     free_ui,
     encode_ui,