static int solver_state(game_state *state, int maxdiff);
static int solver_obvious(game_state *state);
static int solver_obvious_dot(game_state *state, space *dot);
+static space *space_opposite_dot(const game_state *state, const space *sp,
+ const space *dot);
+static space *tile_opposite(const game_state *state, const space *sp);
/* ----------------------------------------------------------
* Game parameters and presets
}
}
+static void remove_assoc_with_opposite(game_state *state, space *tile) {
+ space *opposite;
+
+ if (!(tile->flags & F_TILE_ASSOC)) {
+ return;
+ }
+
+ opposite = tile_opposite(state, tile);
+ remove_assoc(state, tile);
+
+ if (opposite != NULL && opposite != tile) {
+ remove_assoc(state, opposite);
+ }
+}
+
static void add_assoc(const game_state *state, space *tile, space *dot) {
remove_assoc(state, tile);
tile->x, tile->y, dot->x, dot->y, dot->nassoc));*/
}
+static void add_assoc_with_opposite(game_state *state, space *tile, space *dot) {
+ int *colors;
+ space *opposite = space_opposite_dot(state, tile, dot);
+
+ if (opposite == NULL) {
+ return;
+ }
+ if (opposite->flags & F_DOT) {
+ return;
+ }
+
+ colors = snewn(state->w * state->h, int);
+ check_complete(state, NULL, colors);
+ if (colors[(tile->y - 1)/2 * state->w + (tile->x - 1)/2]) {
+ sfree(colors);
+ return;
+ }
+ if (colors[(opposite->y - 1)/2 * state->w + (opposite->x - 1)/2]) {
+ sfree(colors);
+ return;
+ }
+
+ sfree(colors);
+ remove_assoc_with_opposite(state, tile);
+ add_assoc(state, tile, dot);
+ remove_assoc_with_opposite(state, opposite);
+ add_assoc(state, opposite, dot);
+}
+
static space *sp2dot(const game_state *state, int x, int y)
{
space *sp = &SPACE(state, x, y);
}
#endif
-static space *space_opposite_dot(game_state *state, space *sp, space *dot)
+static space *space_opposite_dot(const game_state *state, const space *sp,
+ const space *dot)
{
int dx, dy, tx, ty;
space *sp2;
return sp2;
}
-static space *tile_opposite(game_state *state, space *sp)
+static space *tile_opposite(const game_state *state, const space *sp)
{
space *dot;
game_update_dots(state);
+ if (state->ndots == 1) goto generate;
+
#ifdef DEBUGGING
{
char *tmp = encode_game(state);
if (INUI(state, px, py)) {
sp = &SPACE(state, px, py);
- if (!(sp->flags & F_DOT) && !(sp->flags & F_TILE_ASSOC))
+ if (!(sp->flags & F_DOT))
sprintf(buf + strlen(buf), "%sA%d,%d,%d,%d",
sep, px, py, ui->dotx, ui->doty);
}
int x, y, ax, ay, n, dx, dy;
game_state *ret = dup_game(state);
space *sp, *dot;
+ int currently_solving = FALSE;
debug(("%s\n", move));
} else if (c == 'U') {
if (sp->type != s_tile || !(sp->flags & F_TILE_ASSOC))
goto badmove;
- remove_assoc(ret, sp);
+ /* The solver doesn't assume we'll mirror things */
+ if (currently_solving)
+ remove_assoc(ret, sp);
+ else
+ remove_assoc_with_opposite(ret, sp);
} else if (c == 'M') {
if (!(sp->flags & F_DOT)) goto badmove;
sp->flags ^= F_DOT_HOLD;
space *dot = &SPACE(ret, sp->dotx, sp->doty);
if (dot->flags & F_DOT_HOLD) continue;
}
- add_assoc(ret, sp, dot);
+ /* The solver doesn't assume we'll mirror things */
+ if (currently_solving)
+ add_assoc(ret, sp, dot);
+ else
+ add_assoc_with_opposite(ret, sp, dot);
}
}
move += n;
} else if (c == 'S') {
move++;
ret->used_solve = 1;
+ currently_solving = TRUE;
} else
goto badmove;
for (x = 0; x < w; x++) {
unsigned long flags = 0;
int ddx = 0, ddy = 0;
- space *sp;
+ space *sp, *opp;
int dx, dy;
/*
* everything goes briefly back to background colour.
*/
sp = &SPACE(state, x*2+1, y*2+1);
+ if (sp->flags & F_TILE_ASSOC) {
+ opp = tile_opposite(state, sp);
+ } else {
+ opp = NULL;
+ }
if (ds->colour_scratch[y*w+x] && !flashing) {
flags |= (ds->colour_scratch[y*w+x] == 2 ?
DRAW_BLACK : DRAW_WHITE);
*/
if ((sp->flags & F_TILE_ASSOC) && !ds->colour_scratch[y*w+x]) {
if (ui->dragging && ui->srcx == x*2+1 && ui->srcy == y*2+1) {
- /* don't do it */
+ /* tile is the source, don't do it */
+ } else if (ui->dragging && opp && ui->srcx == opp->x && ui->srcy == opp->y) {
+ /* opposite tile is the source, don't do it */
} else if (sp->doty != y*2+1 || sp->dotx != x*2+1) {
flags |= DRAW_ARROW;
ddy = sp->doty - (y*2+1);