I've just noticed a bug in the Inertia solver: if you call it on an
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 26 Dec 2005 11:26:34 +0000 (11:26 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 26 Dec 2005 11:26:34 +0000 (11:26 +0000)
already-solved grid (i.e. no gems), it will still attempt to show
you a move you can make. Eliminate that special case.

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

inertia.c

index a1ad50a..6531b98 100644 (file)
--- a/inertia.c
+++ b/inertia.c
@@ -735,6 +735,18 @@ static char *solve_game(game_state *state, game_state *currstate,
     char *err, *soln, *p;
 
     /*
+     * Before anything else, deal with the special case in which
+     * all the gems are already collected.
+     */
+    for (i = 0; i < wh; i++)
+       if (currstate->grid[i] == GEM)
+           break;
+    if (i == wh) {
+       *error = "Game is already solved";
+       return NULL;
+    }
+
+    /*
      * Solving Inertia is a question of first building up the graph
      * of where you can get to from where, and secondly finding a
      * tour of the graph which takes in every gem.