Skip to content

Commit

Permalink
cut down generator interface with rngs to minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
Emerentius committed Dec 2, 2023
1 parent 6ecccb2 commit 914147e
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions src/board/sudoku.rs
Expand Up @@ -215,26 +215,6 @@ impl Sudoku {
Sudoku::generate_with_symmetry_and_rng_from(sudoku, symmetry, &mut rand::thread_rng())
}

/// Generate a random, uniquely solvable sudoku with 180° rotational symmetry.
/// All random numbers are drawn from the given random number generator `rng`.
///
/// The puzzles are minimal in that no cell can be removed without losing uniquess of the solution
/// whilst also upholding the symmetry.
/// Most puzzles generated by this are easy.
pub fn generate_with_rng<R: Rng + ?Sized>(rng: &mut R) -> Self {
Sudoku::generate_with_symmetry_and_rng_from(Sudoku::generate_solved_with_rng(rng), Symmetry::HalfRotation, rng)
}

/// Generate a random, uniquely solvable sudoku with the desired symmetry.
/// All random numbers are drawn from the given random number generator `rng`.
///
/// The puzzles are minimal in that no cell can be removed without losing uniquess of the solution
/// whilst also upholding the symmetry.
/// Most puzzles generated by this are easy.
pub fn generate_with_symmetry_and_rng<R: Rng + ?Sized>(symmetry: Symmetry, rng: &mut R) -> Self {
Sudoku::generate_with_symmetry_and_rng_from(Sudoku::generate_solved_with_rng(rng), symmetry, rng)
}

/// Generate a random, uniqely solvable sudoku
/// that has the same solution as the given `sudoku` by removing the contents of some of its cells
/// whilst upholding the `symmetry`. If the input sudoku is partially filled without the desired
Expand All @@ -244,7 +224,11 @@ impl Sudoku {
/// Most puzzles generated by this from solved sudokus are easy.
///
/// If the source `sudoku` is invalid or has multiple solutions, it will be returned as is.
pub fn generate_with_symmetry_and_rng_from<R: Rng + ?Sized>(mut sudoku: Sudoku, symmetry: Symmetry, rng: &mut R) -> Self {
pub fn generate_with_symmetry_and_rng_from<R: Rng + ?Sized>(
mut sudoku: Sudoku,
symmetry: Symmetry,
rng: &mut R,
) -> Self {
// this function is following
// the approach outlined here: https://stackoverflow.com/a/7280517
//
Expand Down

0 comments on commit 914147e

Please sign in to comment.