]> git.itanic.dy.fi Git - sudoku/blobdiff - sudoku.cpp
random.cpp: Return better random numbers
[sudoku] / sudoku.cpp
index 167a44cfce739fbfa936a0589142f5a569f4566f..76144bfcc64561952905b51354dd73b007081a92 100644 (file)
@@ -151,16 +151,6 @@ void sudoku::print_compact(void)
        printf("%s\n", str);
 }
 
-void sudoku::clone_to(sudoku &to)
-{
-       sudoku clone;
-       int x, y;
-
-       for (x = 0; x < 9; x++)
-               for (y = 0; y < 9; y++)
-                       to.table[x][y] = table[x][y];
-}
-
 std::string sudoku::get_row_contents(int row)
 {
        std::string s;
@@ -512,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)
@@ -526,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 {