]> git.itanic.dy.fi Git - sudoku/commitdiff
generator: Fix a bug that caused identical compact lines to appear
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 20 Jun 2009 19:57:56 +0000 (22:57 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 20 Jun 2009 19:57:56 +0000 (22:57 +0300)
sudoku.cpp

index 0f9c8c6877d7b99cdedfbbe77925931f49467473..76144bfcc64561952905b51354dd73b007081a92 100644 (file)
@@ -502,11 +502,12 @@ sudoku sudoku::remove_randomly(int min_guesses, int depth)
        int count = used_numbers();
        sudoku result;
        int stop = 0;
+       sudoku work = *this;
 
-#pragma omp parallel for firstprivate(stop)
+#pragma omp parallel for firstprivate(stop, work)
        for (int i = 0; i < count; i++) {
                int x, y;
-               sudoku tmp = *this, tmp2;
+               sudoku tmp,tmp2;
                std::vector<sudoku> results;
 
                if (done || stop)
@@ -516,43 +517,43 @@ sudoku sudoku::remove_randomly(int min_guesses, int depth)
                do {
                        x = get_random() % 9;
                        y = get_random() % 9;
-               } while(tmp.get(x,y) == EMPTY);
-               tmp.table[x][y] = EMPTY;
+               } while(work.get(x,y) == EMPTY);
+               work.table[x][y] = EMPTY;
 
                //printf("Got now:\n");
-               //tmp.print();
+               //work.print();
 
-               tmp2 = tmp;
+               tmp2 = work;
                /* solve it */
-               results = tmp.solve_all();
+               results = work.solve_all();
 
                /* Does it still have only one solution */
                if (results.size() == 1 && !done) {
                        /* but not hard enough yet? */
-                       if (tmp.guesses >= min_guesses) {
+                       if (work.guesses >= min_guesses) {
                                /* It's good now */
                                printf("%d, Good!\n", depth);
-                               result = tmp;
+                               result = work;
                                done = 1;
                                #pragma omp flush(done)
                        } else {
                                printf("%2d, got only %3d guesses ", depth,
-                                      tmp.guesses);
-                               tmp.print_compact();
+                                      work.guesses);
+                               tmp2.print_compact();
                        }
 
                        if (!done) {
-                               tmp = tmp2;
-                               tmp2 = tmp.remove_randomly(min_guesses,
+                               work = tmp2;
+                               tmp = work.remove_randomly(min_guesses,
                                                   depth + 1);
 
                                /* test for emptiness */
-                               if (tmp2.guesses == 0) {
+                               if (tmp.guesses == 0) {
                                        continue;
                                }
 
-                               if (tmp2.guesses >= min_guesses) {
-                                       result = tmp2;
+                               if (tmp.guesses >= min_guesses) {
+                                       result = tmp;
                                        done = 1;
                                        #pragma omp flush(done)
                                } else {