From 3c514f8e20ea8762025a12f9edbea27967e31d76 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Wed, 23 Aug 2017 14:20:07 -0400 Subject: puzzles: misc. changes and sync with upstream This brings puzzles up-to-date with Simon's tree, along with the rockbox-specific changes I made. Note that I also got rid of some of the ugly floating-point code in rbwrappers.c and replaced it with wrappers for our fixed-point library. Change-Id: Ibfb79acb15517116a26de1c3ea89e025146b9e2e --- apps/plugins/puzzles/src/loopy.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'apps/plugins/puzzles/src/loopy.c') diff --git a/apps/plugins/puzzles/src/loopy.c b/apps/plugins/puzzles/src/loopy.c index 652b9ecc09..7d3436aacb 100644 --- a/apps/plugins/puzzles/src/loopy.c +++ b/apps/plugins/puzzles/src/loopy.c @@ -3054,6 +3054,24 @@ static char *interpret_move(const game_state *state, game_ui *ui, state->lines[e_next - g->edges] != state->lines[i]) break; + if (e_next == e) { + /* + * Special case: we might have come all the + * way round a loop and found our way back to + * the same edge we started from. In that + * situation, we must terminate not only this + * while loop, but the 'for' outside it that + * was tracing in both directions from the + * starting edge, because if we let it trace + * in the second direction then we'll only + * find ourself traversing the same loop in + * the other order and generate an encoded + * move string that mentions the same set of + * edges twice. + */ + goto autofollow_done; + } + dot = (e_next->dot1 != dot ? e_next->dot1 : e_next->dot2); if (movelen > movesize - 40) { movesize = movesize * 5 / 4 + 128; @@ -3064,6 +3082,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, (int)(e_this - g->edges), button_char); } } + autofollow_done:; } } -- cgit v1.2.3