From 4f7b65de2e5f6387a819dd3767f5459b06f5db11 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 2 May 2005 13:17:10 +0000 Subject: Added an automatic `Solve' feature to most games. This is useful for various things: - if you haven't fully understood what a game is about, it gives you an immediate example of a puzzle plus its solution so you can understand it - in some games it's useful to compare your solution with the real one and see where you made a mistake - in the rearrangement games (Fifteen, Sixteen, Twiddle) it's handy to be able to get your hands on a pristine grid quickly so you can practise or experiment with manoeuvres on it - it provides a good way of debugging the games if you think you've encountered an unsolvable grid! [originally from svn r5731] --- midend.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'midend.c') diff --git a/midend.c b/midend.c index dbbaad4..084cd16 100644 --- a/midend.c +++ b/midend.c @@ -595,3 +595,35 @@ char *midend_text_format(midend_data *me) else return NULL; } + +char *midend_solve(midend_data *me) +{ + game_state *s; + char *msg; + + if (!me->ourgame->can_solve) + return "This game does not support the Solve operation"; + + if (me->statepos < 1) + return "No game set up to solve"; /* _shouldn't_ happen! */ + + msg = "Solve operation failed"; /* game _should_ overwrite on error */ + s = me->ourgame->solve(me->states[0], me->aux_info, &msg); + if (!s) + return msg; + + /* + * Now enter the solved state as the next move.~|~ + */ + midend_stop_anim(me); + while (me->nstates > me->statepos) + me->ourgame->free_game(me->states[--me->nstates]); + ensure(me); + me->states[me->nstates] = s; + me->statepos = ++me->nstates; + me->anim_time = 0.0; + midend_finish_move(me); + midend_redraw(me); + activate_timer(me->frontend); + return NULL; +} -- cgit v1.1