diff --git a/inertia.c b/inertia.c index a1ad50a..6531b98 100644 --- a/inertia.c +++ b/inertia.c @@ -734,6 +734,18 @@ static char *solve_game(game_state *state, game_state *currstate, int head, tail, pass, i, j, n, x, y, d, dd; 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