From: Timo Kokkonen Date: Sat, 20 Jun 2009 19:57:56 +0000 (+0300) Subject: generator: Fix a bug that caused identical compact lines to appear X-Git-Url: http://git.itanic.dy.fi/?p=sudoku;a=commitdiff_plain;h=641315d9239858a16653c3cb80f7c434cea5e110 generator: Fix a bug that caused identical compact lines to appear --- diff --git a/sudoku.cpp b/sudoku.cpp index 0f9c8c6..76144bf 100644 --- a/sudoku.cpp +++ b/sudoku.cpp @@ -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 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 {