forked from len0rd/rockbox
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
This commit is contained in:
parent
dcad830c92
commit
7c0cdf1918
1 changed files with 9 additions and 4 deletions
|
@ -180,7 +180,7 @@ static void puzzle_init(void)
|
||||||
|
|
||||||
/* shuffle spots */
|
/* shuffle spots */
|
||||||
for (i=19; i>=0; i--) {
|
for (i=19; i>=0; i--) {
|
||||||
r = (*rb->current_tick % (i+1));
|
r = (rb->rand() % (i+1));
|
||||||
|
|
||||||
temp = spots[r];
|
temp = spots[r];
|
||||||
spots[r] = spots[i];
|
spots[r] = spots[i];
|
||||||
|
@ -194,9 +194,14 @@ static void puzzle_init(void)
|
||||||
for (i=0; i<20; i++)
|
for (i=0; i<20; i++)
|
||||||
tsp[i] = spots[i];
|
tsp[i] = spots[i];
|
||||||
r=0;
|
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)
|
if (((4-hole%5) + (3-hole/5))%2 == 1)
|
||||||
++r;
|
++r;
|
||||||
for (i=0; i<15; i++) {
|
|
||||||
|
/* Now check how many swaps we need to solve it */
|
||||||
|
for (i=0; i<19; i++) {
|
||||||
while (tsp[i] != (i+1)) {
|
while (tsp[i] != (i+1)) {
|
||||||
temp = tsp[i];
|
temp = tsp[i];
|
||||||
tsp[i] = tsp[temp-1];
|
tsp[i] = tsp[temp-1];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue