From 7c0cdf19188081dba006d2df0334cf75ca0a471e Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Mon, 12 Jul 2004 10:46:00 +0000 Subject: The check for solvable puzzles didn't use all squares. This fixes bug #911484. Now uses rand() instead of current_tick for randomizing. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4864 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/sliding_puzzle.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'apps/plugins') diff --git a/apps/plugins/sliding_puzzle.c b/apps/plugins/sliding_puzzle.c index 12c7a9aafa..423ab7fcf1 100644 --- a/apps/plugins/sliding_puzzle.c +++ b/apps/plugins/sliding_puzzle.c @@ -180,7 +180,7 @@ static void puzzle_init(void) /* shuffle spots */ for (i=19; i>=0; i--) { - r = (*rb->current_tick % (i+1)); + r = (rb->rand() % (i+1)); temp = spots[r]; spots[r] = spots[i]; @@ -192,11 +192,16 @@ static void puzzle_init(void) /* test if the puzzle is solvable */ for (i=0; i<20; i++) - tsp[i] = spots[i]; + tsp[i] = spots[i]; r=0; + + /* First, check if the problem has even or odd parity, + depending on where the empty square is */ if (((4-hole%5) + (3-hole/5))%2 == 1) - ++r; - for (i=0; i<15; i++) { + ++r; + + /* Now check how many swaps we need to solve it */ + for (i=0; i<19; i++) { while (tsp[i] != (i+1)) { temp = tsp[i]; tsp[i] = tsp[temp-1]; -- cgit v1.2.3