return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- /*
- * We return true whenever the solution has been revealed, even
- * (on spoiler grounds) if it wasn't guessed correctly.
- */
- return state->reveal;
+ if (state->reveal) {
+ /*
+ * We return nonzero whenever the solution has been revealed,
+ * even (on spoiler grounds) if it wasn't guessed correctly.
+ */
+ if (state->nwrong == 0 &&
+ state->nmissed == 0 &&
+ state->nright >= state->minballs)
+ return +1;
+ else
+ return -1;
+ }
+ return 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
FALSE, game_timing_state,
to achieve this, its \cw{flash_length()} function has to store a
flag in the \c{game_ui} to indicate which flash type is required.)
-\S{backend-is-solved} \cw{is_solved()}
+\S{backend-status} \cw{status()}
-\c int (*is_solved)(game_state *state);
+\c int (*status)(game_state *state);
-This function returns \cw{TRUE} if the game represented by \cw{state}
-is currently in a solved state. The mid-end uses this to implement
-\cw{midend_is_solved()} (\k{midend-is-solved}).
+This function returns a status value indicating whether the current
+game is still in play, or has been won, or has been conclusively lost.
+The mid-end uses this to implement \cw{midend_status()}
+(\k{midend-status}).
-Front ends may wish to use this as a cue to proactively offer the
-option of starting a new game. Therefore, back ends should consider
-returning \cw{TRUE} in situations where the game is \e{lost} as well
-as won, if losing makes it unlikely that the player would play on.
+The return value should be +1 if the game has been successfully
+solved. If the game has been lost in a situation where further play is
+unlikely, the return value should be -1. If neither is true (so play
+is still ongoing), return zero.
+
+Front ends may wish to use a non-zero status as a cue to proactively
+offer the option of starting a new game. Therefore, back ends should
+not return -1 if the game has been \e{technically} lost but undoing
+and continuing is still a realistic possibility.
(For instance, games with hidden information such as Guess or Mines
-might well set this flag whenever they reveal the solution, whether or
-not the player guessed it correctly, on the grounds that a player
-would be unlikely to hide the solution and continue playing after the
-answer was spoiled. On the other hand, games where you can merely get
-into a dead end such as Same Game or Inertia might choose not to, on
-the grounds that the player would quite likely press Undo and carry on
-playing.)
+might well return a non-zero status whenever they reveal the solution,
+whether or not the player guessed it correctly, on the grounds that a
+player would be unlikely to hide the solution and continue playing
+after the answer was spoiled. On the other hand, games where you can
+merely get into a dead end such as Same Game or Inertia might choose
+to return 0 in that situation, on the grounds that the player would
+quite likely press Undo and carry on playing.)
\S{backend-redraw} \cw{redraw()}
\cw{activate_timer()} to be called from within a call to this
function.
-\H{midend-is-solved} \cw{midend_is_solved()}
+\H{midend-status} \cw{midend_status()}
-\c int midend_is_solved(midend *me);
+\c int midend_status(midend *me);
-This function returns \cw{TRUE} if the midend is currently displaying
-a game in a solved state, according to the back end's \cw{is_solved()}
+This function returns +1 if the midend is currently displaying a game
+in a solved state, -1 if the game is in a permanently lost state, or 0
+otherwise. This function just calls the back end's \cw{status()}
function. Front ends may wish to use this as a cue to proactively
offer the option of starting a new game.
-(See \k{backend-is-solved} for more detail about the back end's
-\cw{is_solved()} function and discussion of what should count as
-\q{solved} anyway).
+(See \k{backend-status} for more detail about the back end's
+\cw{status()} function and discussion of what should count as which
+status code.)
\H{midend-can-undo} \cw{midend_can_undo()}
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
#ifdef EDITOR
FALSE, FALSE, NULL, NULL,
TRUE, /* wants_statusbar */
pegrow solution;
int next_go; /* from 0 to nguesses-1;
if next_go == nguesses then they've lost. */
- int solved;
+ int solved; /* +1 = win, -1 = lose, 0 = still playing */
};
static game_params *default_params(void)
if (!strcmp(move, "S")) {
ret = dup_game(from);
- ret->solved = 1;
+ ret->solved = -1;
return ret;
} else if (move[0] == 'G') {
p = move+1;
nc_place = mark_pegs(ret->guesses[from->next_go], ret->solution, ret->params.ncolours);
if (nc_place == ret->solution->npegs) {
- ret->solved = 1; /* win! */
+ ret->solved = +1; /* win! */
} else {
ret->next_go = from->next_go + 1;
if (ret->next_go >= ret->params.nguesses)
- ret->solved = 1; /* 'lose' so we show the pegs. */
+ ret->solved = -1; /* lose, meaning we show the pegs. */
}
return ret;
currmove_redraw(dr, ds, state->next_go, COL_HOLD);
/* draw the solution (or the big rectangle) */
- if ((state->solved != ds->solved) || !ds->started) {
+ if ((!state->solved ^ !ds->solved) || !ds->started) {
draw_rect(dr, SOLN_OX, SOLN_OY, SOLN_W, SOLN_H,
state->solved ? COL_BACKGROUND : COL_EMPTY);
draw_update(dr, SOLN_OX, SOLN_OY, SOLN_W, SOLN_H);
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
/*
- * We return true whenever the solution has been revealed, even
- * (on spoiler grounds) if it wasn't guessed correctly.
- *
- * However, in that situation, 'solved' is still true, so we don't
- * have to make any effort to arrange this.
+ * We return nonzero whenever the solution has been revealed, even
+ * (on spoiler grounds) if it wasn't guessed correctly. The
+ * correct return value from this function is already in
+ * state->solved.
*/
return state->solved;
}
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
/*
- * If the player has died, we don't list the game as solved,
- * because they're more likely to undo and carry on than to give
- * up and start a new game.
+ * We never report the game as lost, on the grounds that if the
+ * player has died they're quite likely to want to undo and carry
+ * on.
*/
- return !state->gems;
+ return state->gems == 0 ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->solved;
+ return state->solved ? +1 : 0;
}
static void game_print_size(game_params *params, float *x, float *y)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE /* wants_statusbar */,
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, TRUE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return NULL;
}
-int midend_is_solved(midend *me)
+int midend_status(midend *me)
{
/*
* We should probably never be called when the state stack has no
* practically, a user whose midend has been left in that state
* probably _does_ want the 'new game' option to be prominent.
*/
- return (me->statepos == 0 ||
- me->ourgame->is_solved(me->states[me->statepos-1].state));
+ if (me->statepos == 0)
+ return +1;
+
+ return me->ourgame->status(me->states[me->statepos-1].state);
}
char *midend_rewrite_statusbar(midend *me, char *text)
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->won;
+ /*
+ * We report the game as lost only if the player has used the
+ * Solve function to reveal all the mines. Otherwise, we assume
+ * they'll undo and continue play.
+ */
+ return state->won ? (state->used_solve ? -1 : +1) : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
TRUE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return FALSE;
+ return 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ /*
+ * Dead-end situations are assumed to be rescuable by Undo, so we
+ * don't bother to identify them and return -1.
+ */
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
int midend_can_format_as_text_now(midend *me);
char *midend_text_format(midend *me);
char *midend_solve(midend *me);
-int midend_is_solved(midend *me);
+int midend_status(midend *me);
int midend_can_undo(midend *me);
int midend_can_redo(midend *me);
void midend_supersede_game_desc(midend *me, char *desc, char *privdesc);
game_ui *ui);
float (*flash_length)(game_state *oldstate, game_state *newstate, int dir,
game_ui *ui);
- int (*is_solved)(game_state *state);
+ int (*status)(game_state *state);
int can_print, can_print_in_colour;
void (*print_size)(game_params *params, float *x, float *y);
void (*print)(drawing *dr, game_state *state, int tilesize);
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->was_solved;
+ return state->was_solved ? +1 : 0;
}
/* ----------------------------------------------------------------------
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
/*
- * If the player has run out of moves without winning, we don't
- * list the game as solved, because they're more likely to undo
- * and carry on than to give up and start a new game.
+ * Dead-end situations are assumed to be rescuable by Undo, so we
+ * don't bother to identify them and return -1.
*/
- return state->complete;
+ return state->complete ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
TRUE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return FALSE;
+ return 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return FALSE;
+ return 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
TRUE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,
return 0.0F;
}
-static int game_is_solved(game_state *state)
+static int game_status(game_state *state)
{
- return state->completed;
+ return state->completed ? +1 : 0;
}
static int game_timing_state(game_state *state, game_ui *ui)
game_redraw,
game_anim_length,
game_flash_length,
- game_is_solved,
+ game_status,
FALSE, FALSE, game_print_size, game_print,
FALSE, /* wants_statusbar */
FALSE, game_timing_state,