Skip to content

Commit

Permalink
Bugfix in the order of operations of the algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
dark committed Feb 3, 2024
1 parent 5c20bea commit 82009b8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions create_random.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ std::optional<Board> create_random_board(const uint16_t board_size, std::mt19937
long iterations = 0;
while (!stack.empty()) {
RandomGenerationStep& state = stack.top();
// If there are no more legal options in the current board cell,
// reset it to 'empty' and go back to the previous one.
if (state.legal_values.empty()) {
b.clear(state.row, state.column);
stack.pop();
continue;
}

// Print the iteration number every now and then, for progress.
if ((++iterations % ITERATIONS_PRINT_STATE) == 0) {
Expand Down Expand Up @@ -120,6 +113,14 @@ std::optional<Board> create_random_board(const uint16_t board_size, std::mt19937
}
}

// If there are no more legal options in the current board cell,
// reset it to 'empty' and go back to the previous one.
if (state.legal_values.empty()) {
b.clear(state.row, state.column);
stack.pop();
continue;
}

// Take and use the next legal value for the current cell.
int next_value = state.legal_values.front();
state.legal_values.pop_front();
Expand Down

0 comments on commit 82009b8

Please sign in to comment.