Couple of solving-related mid-end tweaks. Firstly, when we generate
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 16 Nov 2008 15:28:28 +0000 (15:28 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 16 Nov 2008 15:28:28 +0000 (15:28 +0000)
a game which comes with an aux string, we immediately self-test that
string by passing it to solve() and test by assertion that it
succeeded. So a bug in a back end which intermittently generates
malformed aux strings will be detected as soon as it occurs, instead
of only if the user happens to use the Solve operation on a
particular game in which it happened.

Secondly, Ctrl-S now (undocumentedly) triggers the Solve operation,
on the general principle that keyboard shortcuts tend to come in
handy, and on the specific principle that if you want to look at
lots of solved grids in quick succession (say, when observing their
general shape and nature to see if your generation algorithm was
good or not) it's handy to have a quick way of getting to them.

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

midend.c

index 5229935..22d823b 100644 (file)
--- a/midend.c
+++ b/midend.c
@@ -383,6 +383,25 @@ void midend_new_game(midend *me)
     me->states[me->nstates].state =
        me->ourgame->new_game(me, me->params, me->desc);
 
+    /*
+     * As part of our commitment to self-testing, test the aux
+     * string to make sure nothing ghastly went wrong.
+     */
+    if (me->ourgame->can_solve && me->aux_info) {
+       game_state *s;
+       char *msg, *movestr;
+
+       msg = NULL;
+       movestr = me->ourgame->solve(me->states[0].state,
+                                    me->states[0].state,
+                                    me->aux_info, &msg);
+       assert(movestr && !msg);
+       s = me->ourgame->execute_move(me->states[0].state, movestr);
+       assert(s);
+       me->ourgame->free_game(s);
+       sfree(movestr);
+    }
+
     me->states[me->nstates].movestr = NULL;
     me->states[me->nstates].movetype = NEWGAME;
     me->nstates++;
@@ -538,6 +557,9 @@ static int midend_really_process_key(midend *me, int x, int y, int button)
            midend_stop_anim(me);
            if (!midend_redo(me))
                goto done;
+       } else if (button == '\x13' && me->ourgame->can_solve) {
+           if (midend_solve(me))
+               goto done;
        } else if (button == 'q' || button == 'Q' || button == '\x11') {
            ret = 0;
            goto done;