sfree(params);
}
-static game_params *dup_params(game_params *params)
+static game_params *dup_params(const game_params *params)
{
game_params *ret = snew(game_params);
*ret = *params; /* structure copy */
}
}
-static char *encode_params(game_params *params, int full)
+static char *encode_params(const game_params *params, int full)
{
char data[256];
return dupstr(data);
}
-static config_item *game_configure(game_params *params)
+static config_item *game_configure(const game_params *params)
{
config_item *ret;
char buf[80];
return ret;
}
-static game_params *custom_params(config_item *cfg)
+static game_params *custom_params(const config_item *cfg)
{
game_params *ret = snew(game_params);
return ret;
}
-static char *validate_params(game_params *params, int full)
+static char *validate_params(const game_params *params, int full)
{
if (params->w < 2 || params->h < 2)
return "Width and neight must be at least two";
return state;
}
-static game_state *dup_game(game_state *state)
+static game_state *dup_game(const game_state *state)
{
game_state *ret = blank_game(state->w, state->h);
return -1;
}
-static void unpick_desc(const game_params *params, char *desc,
+static void unpick_desc(const game_params *params, const char *desc,
game_state **sout, char **mout)
{
game_state *state = blank_game(params->w, params->h);
/* --- Useful game functions (completion, etc.) --- */
-static int game_can_format_as_text_now(game_params *params)
+static int game_can_format_as_text_now(const game_params *params)
{
return TRUE;
}
-static char *game_text_format(game_state *state)
+static char *game_text_format(const game_state *state)
{
int len, x, y, i;
char *ret, *p;
for (y = 0; y < h; y++) /* check rows from (0,y) */
error += check_rowcol(state, y*w, 1, w, flags);
- /* mark (all) white regions as an error if there is more than one.
- * may want to make this less in-your-face (by only marking
- * the smallest region as an error, for example -- but what if we
- * have two regions of identical size?) */
- for (i = 0; i < state->n; i++) {
- if (!(state->flags[i] & F_BLACK) &&
- dsf_size(dsf, i) < nwhite) {
- error += 1;
- if (flags & CC_MARK_ERRORS)
- state->flags[i] |= F_ERROR;
+ /* If there's more than one white region, pick the largest one to
+ * be the canonical one (arbitrarily tie-breaking towards lower
+ * array indices), and mark all the others as erroneous. */
+ {
+ int largest = 0, canonical = -1;
+ for (i = 0; i < state->n; i++)
+ if (!(state->flags[i] & F_BLACK)) {
+ int size = dsf_size(dsf, i);
+ if (largest < size) {
+ largest = size;
+ canonical = i;
+ }
+ }
+
+ if (largest < nwhite) {
+ for (i = 0; i < state->n; i++)
+ if (!(state->flags[i] & F_BLACK) &&
+ dsf_canonify(dsf, i) != canonical) {
+ error += 1;
+ if (flags & CC_MARK_ERRORS)
+ state->flags[i] |= F_ERROR;
+ }
}
}
return (error > 0) ? 0 : 1;
}
-static char *game_state_diff(game_state *src, game_state *dst, int issolve)
+static char *game_state_diff(const game_state *src, const game_state *dst,
+ int issolve)
{
char *ret = NULL, buf[80], c;
int retlen = 0, x, y, i, k;
return state->impossible ? -1 : check_complete(state, CC_MUST_FILL);
}
-static char *solve_game(game_state *state, game_state *currstate,
- char *aux, char **error)
+static char *solve_game(const game_state *state, const game_state *currstate,
+ const char *aux, char **error)
{
game_state *solved = dup_game(currstate);
char *move = NULL;
return ret;
}
-static char *validate_desc(const game_params *params, char *desc)
+static char *validate_desc(const game_params *params, const char *desc)
{
char *ret = NULL;
return ret;
}
-static game_state *new_game(midend *me, game_params *params, char *desc)
+static game_state *new_game(midend *me, const game_params *params,
+ const char *desc)
{
game_state *state = NULL;
int show_black_nums;
};
-static game_ui *new_ui(game_state *state)
+static game_ui *new_ui(const game_state *state)
{
game_ui *ui = snew(game_ui);
sfree(ui);
}
-static char *encode_ui(game_ui *ui)
+static char *encode_ui(const game_ui *ui)
{
return NULL;
}
-static void decode_ui(game_ui *ui, char *encoding)
+static void decode_ui(game_ui *ui, const char *encoding)
{
}
-static void game_changed_state(game_ui *ui, game_state *oldstate,
- game_state *newstate)
+static void game_changed_state(game_ui *ui, const game_state *oldstate,
+ const game_state *newstate)
{
if (!oldstate->completed && newstate->completed)
ui->cshow = 0;
unsigned int *flags;
};
-static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
- int mx, int my, int button)
+static char *interpret_move(const game_state *state, game_ui *ui,
+ const game_drawstate *ds,
+ int mx, int my, int button)
{
char buf[80], c;
int i, x = FROMCOORD(mx), y = FROMCOORD(my);
return NULL;
}
-static game_state *execute_move(game_state *state, char *move)
+static game_state *execute_move(const game_state *state, const char *move)
{
game_state *ret = dup_game(state);
int x, y, i, n;
* Drawing routines.
*/
-static void game_compute_size(game_params *params, int tilesize,
- int *x, int *y)
+static void game_compute_size(const game_params *params, int tilesize,
+ int *x, int *y)
{
/* Ick: fake up `ds->tilesize' for macro expansion purposes */
struct { int tilesize; } ads, *ds = &ads;
}
static void game_set_size(drawing *dr, game_drawstate *ds,
- game_params *params, int tilesize)
+ const game_params *params, int tilesize)
{
ds->tilesize = tilesize;
}
return ret;
}
-static game_drawstate *game_new_drawstate(drawing *dr, game_state *state)
+static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state)
{
struct game_drawstate *ds = snew(struct game_drawstate);
draw_update(dr, x, y, TILE_SIZE, TILE_SIZE);
}
-static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
- game_state *state, int dir, game_ui *ui,
- float animtime, float flashtime)
+static void game_redraw(drawing *dr, game_drawstate *ds,
+ const game_state *oldstate, const game_state *state,
+ int dir, const game_ui *ui,
+ float animtime, float flashtime)
{
int x, y, i, flash;
unsigned int f;
ds->started = 1;
}
-static float game_anim_length(game_state *oldstate, game_state *newstate,
- int dir, game_ui *ui)
+static float game_anim_length(const game_state *oldstate,
+ const game_state *newstate, int dir, game_ui *ui)
{
return 0.0F;
}
-static float game_flash_length(game_state *oldstate, game_state *newstate,
- int dir, game_ui *ui)
+static float game_flash_length(const game_state *oldstate,
+ const game_state *newstate, int dir, game_ui *ui)
{
if (!oldstate->completed &&
newstate->completed && !newstate->used_solve)
return 0.0F;
}
-static int game_status(game_state *state)
+static int game_status(const game_state *state)
{
return state->completed ? +1 : 0;
}
-static int game_timing_state(game_state *state, game_ui *ui)
+static int game_timing_state(const game_state *state, game_ui *ui)
{
return TRUE;
}
-static void game_print_size(game_params *params, float *x, float *y)
+static void game_print_size(const game_params *params, float *x, float *y)
{
int pw, ph;
*y = ph / 100.0F;
}
-static void game_print(drawing *dr, game_state *state, int tilesize)
+static void game_print(drawing *dr, const game_state *state, int tilesize)
{
int ink = print_mono_colour(dr, 0);
int paper = print_mono_colour(dr, 1);