diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2004-07-12 10:46:00 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2004-07-12 10:46:00 +0000 |
commit | 7c0cdf19188081dba006d2df0334cf75ca0a471e (patch) | |
tree | d7609761e2d7e84be56e30a1f862e4b2d7d4837c /apps/plugins | |
parent | dcad830c92ea7e484cb972702f27770e4d469f85 (diff) | |
download | rockbox-7c0cdf19188081dba006d2df0334cf75ca0a471e.tar.gz rockbox-7c0cdf19188081dba006d2df0334cf75ca0a471e.zip |
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
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/sliding_puzzle.c | 13 |
1 files changed, 9 insertions, 4 deletions
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) | |||
180 | 180 | ||
181 | /* shuffle spots */ | 181 | /* shuffle spots */ |
182 | for (i=19; i>=0; i--) { | 182 | for (i=19; i>=0; i--) { |
183 | r = (*rb->current_tick % (i+1)); | 183 | r = (rb->rand() % (i+1)); |
184 | 184 | ||
185 | temp = spots[r]; | 185 | temp = spots[r]; |
186 | spots[r] = spots[i]; | 186 | spots[r] = spots[i]; |
@@ -192,11 +192,16 @@ static void puzzle_init(void) | |||
192 | 192 | ||
193 | /* test if the puzzle is solvable */ | 193 | /* test if the puzzle is solvable */ |
194 | for (i=0; i<20; i++) | 194 | for (i=0; i<20; i++) |
195 | tsp[i] = spots[i]; | 195 | tsp[i] = spots[i]; |
196 | r=0; | 196 | r=0; |
197 | |||
198 | /* First, check if the problem has even or odd parity, | ||
199 | depending on where the empty square is */ | ||
197 | if (((4-hole%5) + (3-hole/5))%2 == 1) | 200 | if (((4-hole%5) + (3-hole/5))%2 == 1) |
198 | ++r; | 201 | ++r; |
199 | for (i=0; i<15; i++) { | 202 | |
203 | /* Now check how many swaps we need to solve it */ | ||
204 | for (i=0; i<19; i++) { | ||
200 | while (tsp[i] != (i+1)) { | 205 | while (tsp[i] != (i+1)) { |
201 | temp = tsp[i]; | 206 | temp = tsp[i]; |
202 | tsp[i] = tsp[temp-1]; | 207 | tsp[i] = tsp[temp-1]; |