summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/galaxies.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2019-05-15 18:16:27 -0400
committerFranklin Wei <git@fwei.tk>2019-05-15 18:16:27 -0400
commitf940276fd9bc38ae34d4119fd1d983171a627400 (patch)
tree117a191e61c070548b4c55b35f6d1159f98f03f9 /apps/plugins/puzzles/src/galaxies.c
parent4ed57276542124a22c26ebb1d307996fc3a7556c (diff)
downloadrockbox-f940276fd9bc38ae34d4119fd1d983171a627400.tar.gz
rockbox-f940276fd9bc38ae34d4119fd1d983171a627400.zip
puzzles: resync with upstream
This brings the puzzles source to upstream commit e2135d5. (I've made my own changes on top of that.) This brings in a couple bugfixes and a new solver for Dominosa. Change-Id: I11d46b43171787832330a5e2e0d2f353f36f727d
Diffstat (limited to 'apps/plugins/puzzles/src/galaxies.c')
-rw-r--r--apps/plugins/puzzles/src/galaxies.c56
1 files changed, 39 insertions, 17 deletions
diff --git a/apps/plugins/puzzles/src/galaxies.c b/apps/plugins/puzzles/src/galaxies.c
index 0cc3198ae0..fe7cd24ecf 100644
--- a/apps/plugins/puzzles/src/galaxies.c
+++ b/apps/plugins/puzzles/src/galaxies.c
@@ -346,29 +346,44 @@ static void add_assoc(const game_state *state, space *tile, space *dot) {
346 tile->x, tile->y, dot->x, dot->y, dot->nassoc));*/ 346 tile->x, tile->y, dot->x, dot->y, dot->nassoc));*/
347} 347}
348 348
349static void add_assoc_with_opposite(game_state *state, space *tile, space *dot) { 349static bool ok_to_add_assoc_with_opposite_internal(
350 const game_state *state, space *tile, space *opposite)
351{
350 int *colors; 352 int *colors;
351 space *opposite = space_opposite_dot(state, tile, dot); 353 bool toret;
352 354
353 if (opposite == NULL) { 355 if (tile->flags & F_DOT)
354 return; 356 return false;
355 } 357 if (opposite == NULL)
356 if (opposite->flags & F_DOT) { 358 return false;
357 return; 359 if (opposite->flags & F_DOT)
358 } 360 return false;
359 361
362 toret = true;
360 colors = snewn(state->w * state->h, int); 363 colors = snewn(state->w * state->h, int);
361 check_complete(state, NULL, colors); 364 check_complete(state, NULL, colors);
362 if (colors[(tile->y - 1)/2 * state->w + (tile->x - 1)/2]) { 365
363 sfree(colors); 366 if (colors[(tile->y - 1)/2 * state->w + (tile->x - 1)/2])
364 return; 367 toret = false;
365 } 368 if (colors[(opposite->y - 1)/2 * state->w + (opposite->x - 1)/2])
366 if (colors[(opposite->y - 1)/2 * state->w + (opposite->x - 1)/2]) { 369 toret = false;
367 sfree(colors);
368 return;
369 }
370 370
371 sfree(colors); 371 sfree(colors);
372 return toret;
373}
374
375static bool ok_to_add_assoc_with_opposite(
376 const game_state *state, space *tile, space *dot)
377{
378 space *opposite = space_opposite_dot(state, tile, dot);
379 return ok_to_add_assoc_with_opposite_internal(state, tile, opposite);
380}
381
382static void add_assoc_with_opposite(game_state *state, space *tile, space *dot) {
383 space *opposite = space_opposite_dot(state, tile, dot);
384
385 assert(ok_to_add_assoc_with_opposite_internal(state, tile, opposite));
386
372 remove_assoc_with_opposite(state, tile); 387 remove_assoc_with_opposite(state, tile);
373 add_assoc(state, tile, dot); 388 add_assoc(state, tile, dot);
374 remove_assoc_with_opposite(state, opposite); 389 remove_assoc_with_opposite(state, opposite);
@@ -2596,8 +2611,15 @@ static char *interpret_move(const game_state *state, game_ui *ui,
2596 */ 2611 */
2597 if (INUI(state, px, py)) { 2612 if (INUI(state, px, py)) {
2598 sp = &SPACE(state, px, py); 2613 sp = &SPACE(state, px, py);
2614 dot = &SPACE(state, ui->dotx, ui->doty);
2599 2615
2600 if (!(sp->flags & F_DOT)) 2616 /*
2617 * Exception: if it's not actually legal to add an arrow
2618 * and its opposite at this position, we don't try,
2619 * because otherwise we'd append an empty entry to the
2620 * undo chain.
2621 */
2622 if (ok_to_add_assoc_with_opposite(state, sp, dot))
2601 sprintf(buf + strlen(buf), "%sA%d,%d,%d,%d", 2623 sprintf(buf + strlen(buf), "%sA%d,%d,%d,%d",
2602 sep, px, py, ui->dotx, ui->doty); 2624 sep, px, py, ui->dotx, ui->doty);
2603 } 2625 }