diff options
author | Dave Chapman <dave@dchapman.com> | 2006-05-01 08:23:53 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2006-05-01 08:23:53 +0000 |
commit | b4f0efc1dd2810f68e5fe7e10c49a425505e6840 (patch) | |
tree | f5afcf59247a294eb1ff9149c07470de25d2009c /apps/plugins | |
parent | ac36f7101de54531b4b7f8dac6e7d724f8216ae7 (diff) | |
download | rockbox-b4f0efc1dd2810f68e5fe7e10c49a425505e6840.tar.gz rockbox-b4f0efc1dd2810f68e5fe7e10c49a425505e6840.zip |
Call rb->yield() during the random game generation.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9847 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/sudoku/generator.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/apps/plugins/sudoku/generator.c b/apps/plugins/sudoku/generator.c index d43e970ab8..037798d761 100644 --- a/apps/plugins/sudoku/generator.c +++ b/apps/plugins/sudoku/generator.c | |||
@@ -357,6 +357,8 @@ findmoves( void ) | |||
357 | { | 357 | { |
358 | int i; | 358 | int i; |
359 | 359 | ||
360 | rb->yield(); | ||
361 | |||
360 | idx_possible = 0; | 362 | idx_possible = 0; |
361 | for( i = 0 ; i < 9 ; ++i ) | 363 | for( i = 0 ; i < 9 ; ++i ) |
362 | { | 364 | { |
@@ -392,6 +394,9 @@ void | |||
392 | pairs( int el, int (*idx_fn)( int, int ) ) | 394 | pairs( int el, int (*idx_fn)( int, int ) ) |
393 | { | 395 | { |
394 | int i, j, k, mask, idx; | 396 | int i, j, k, mask, idx; |
397 | |||
398 | rb->yield(); | ||
399 | |||
395 | for( i = 0 ; i < 8 ; ++i ) | 400 | for( i = 0 ; i < 8 ; ++i ) |
396 | if( 7 == digits[ i ] ) /* 2 digits unknown */ | 401 | if( 7 == digits[ i ] ) /* 2 digits unknown */ |
397 | for( j = i + 1 ; j < 9 ; ++j ) | 402 | for( j = i + 1 ; j < 9 ; ++j ) |
@@ -419,6 +424,8 @@ exmask( int mask, int block, int el, int (*idx_fn)( int, int ) ) | |||
419 | { | 424 | { |
420 | int i, idx; | 425 | int i, idx; |
421 | 426 | ||
427 | rb->yield(); | ||
428 | |||
422 | for( i = 0 ; i < 9 ; ++i ) | 429 | for( i = 0 ; i < 9 ; ++i ) |
423 | { | 430 | { |
424 | idx = (*idx_fn)( el, i ); | 431 | idx = (*idx_fn)( el, i ); |
@@ -434,6 +441,8 @@ exblock( int block, int el, int (*idx_fn)( int, int ) ) | |||
434 | { | 441 | { |
435 | int i, idx, mask; | 442 | int i, idx, mask; |
436 | 443 | ||
444 | rb->yield(); | ||
445 | |||
437 | /* By assumption, all unknown squares in the block appear in the | 446 | /* By assumption, all unknown squares in the block appear in the |
438 | * same row/column, so to construct a mask for these squares, it | 447 | * same row/column, so to construct a mask for these squares, it |
439 | * is sufficient to invert the mask for the known squares in the | 448 | * is sufficient to invert the mask for the known squares in the |
@@ -455,6 +464,8 @@ block( int el ) | |||
455 | { | 464 | { |
456 | int i, idx = 0, row, col; | 465 | int i, idx = 0, row, col; |
457 | 466 | ||
467 | rb->yield(); | ||
468 | |||
458 | /* Find first unknown square */ | 469 | /* Find first unknown square */ |
459 | for( i = 0 ; i < 9 && !IS_EMPTY( idx = idx_block( el, i ) ) ; ++i ) | 470 | for( i = 0 ; i < 9 && !IS_EMPTY( idx = idx_block( el, i ) ) ; ++i ) |
460 | ; | 471 | ; |
@@ -487,6 +498,8 @@ common( int el ) | |||
487 | { | 498 | { |
488 | int i, idx, row, col, digit, mask; | 499 | int i, idx, row, col, digit, mask; |
489 | 500 | ||
501 | rb->yield(); | ||
502 | |||
490 | for( digit = 1 ; digit <= 9 ; ++digit ) | 503 | for( digit = 1 ; digit <= 9 ; ++digit ) |
491 | { | 504 | { |
492 | mask = DIGIT_STATE( digit ); | 505 | mask = DIGIT_STATE( digit ); |
@@ -525,6 +538,8 @@ position2( int el ) | |||
525 | { | 538 | { |
526 | int digit, digit2, i, mask, mask2, posn, count, idx; | 539 | int digit, digit2, i, mask, mask2, posn, count, idx; |
527 | 540 | ||
541 | rb->yield(); | ||
542 | |||
528 | /* Calculate positions of each digit within block */ | 543 | /* Calculate positions of each digit within block */ |
529 | for( digit = 1 ; digit <= 9 ; ++digit ) | 544 | for( digit = 1 ; digit <= 9 ; ++digit ) |
530 | { | 545 | { |
@@ -574,6 +589,8 @@ allmoves( void ) | |||
574 | { | 589 | { |
575 | int i, n; | 590 | int i, n; |
576 | 591 | ||
592 | rb->yield(); | ||
593 | |||
577 | n = findmoves( ); | 594 | n = findmoves( ); |
578 | if( 0 < n ) | 595 | if( 0 < n ) |
579 | return n; | 596 | return n; |
@@ -619,6 +636,8 @@ findhints( void ) | |||
619 | { | 636 | { |
620 | int i, n, mutated = 0; | 637 | int i, n, mutated = 0; |
621 | 638 | ||
639 | rb->yield(); | ||
640 | |||
622 | n = findmoves( ); | 641 | n = findmoves( ); |
623 | if( n < 2 ) | 642 | if( n < 2 ) |
624 | { | 643 | { |
@@ -687,6 +706,8 @@ deterministic( void ) | |||
687 | { | 706 | { |
688 | int i, n; | 707 | int i, n; |
689 | 708 | ||
709 | rb->yield(); | ||
710 | |||
690 | n = allmoves( ); | 711 | n = allmoves( ); |
691 | while( 0 < n ) | 712 | while( 0 < n ) |
692 | { | 713 | { |
@@ -720,6 +741,9 @@ int | |||
720 | choice( void ) | 741 | choice( void ) |
721 | { | 742 | { |
722 | int i, n; | 743 | int i, n; |
744 | |||
745 | rb->yield(); | ||
746 | |||
723 | for( n = i = 0 ; i < 81 ; ++i ) | 747 | for( n = i = 0 ; i < 81 ; ++i ) |
724 | if( IS_EMPTY( i ) ) | 748 | if( IS_EMPTY( i ) ) |
725 | { | 749 | { |
@@ -746,6 +770,8 @@ static | |||
746 | int | 770 | int |
747 | choose( int idx, int digit ) | 771 | choose( int idx, int digit ) |
748 | { | 772 | { |
773 | rb->yield(); | ||
774 | |||
749 | for( ; digit <= 9 ; ++digit ) | 775 | for( ; digit <= 9 ; ++digit ) |
750 | if( !DISALLOWED( idx, digit ) ) | 776 | if( !DISALLOWED( idx, digit ) ) |
751 | { | 777 | { |
@@ -770,6 +796,8 @@ backtrack( void ) | |||
770 | { | 796 | { |
771 | int digit, idx; | 797 | int digit, idx; |
772 | 798 | ||
799 | rb->yield(); | ||
800 | |||
773 | for( ; 0 <= --idx_history ; ) | 801 | for( ; 0 <= --idx_history ; ) |
774 | if( history[ idx_history ] & CHOICE ) | 802 | if( history[ idx_history ] & CHOICE ) |
775 | { | 803 | { |
@@ -796,6 +824,8 @@ solve( void ) | |||
796 | { | 824 | { |
797 | int idx; | 825 | int idx; |
798 | 826 | ||
827 | rb->yield(); | ||
828 | |||
799 | while( 1 ) | 829 | while( 1 ) |
800 | { | 830 | { |
801 | if( 0 == deterministic( ) ) | 831 | if( 0 == deterministic( ) ) |
@@ -870,6 +900,8 @@ classify( void ) | |||
870 | { | 900 | { |
871 | int i, score; | 901 | int i, score; |
872 | 902 | ||
903 | rb->yield(); | ||
904 | |||
873 | pass = 0; | 905 | pass = 0; |
874 | clear_moves( ); | 906 | clear_moves( ); |
875 | if( -1 == solve( ) ) | 907 | if( -1 == solve( ) ) |
@@ -1049,9 +1081,13 @@ start: | |||
1049 | for( i = 0 ; i < len_tmplt ; ++i ) | 1081 | for( i = 0 ; i < len_tmplt ; ++i ) |
1050 | fill( tmplt[ i ], digits[ i % 9 ] ); | 1082 | fill( tmplt[ i ], digits[ i % 9 ] ); |
1051 | 1083 | ||
1084 | rb->yield(); | ||
1085 | |||
1052 | if( 0 != solve( ) || idx_history < 81 ) | 1086 | if( 0 != solve( ) || idx_history < 81 ) |
1053 | goto start; | 1087 | goto start; |
1054 | 1088 | ||
1089 | rb->yield(); | ||
1090 | |||
1055 | for( i = 0 ; i < len_tmplt ; ++i ) | 1091 | for( i = 0 ; i < len_tmplt ; ++i ) |
1056 | board[ tmplt[ i ] ] |= FIXED; | 1092 | board[ tmplt[ i ] ] |= FIXED; |
1057 | 1093 | ||