diff --git a/src/main.rs b/src/main.rs index 46aa477..a2e1cc5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,10 @@ use clap::Parser; mod playfield; +mod sudoku_solver; use playfield::Playfield; +use sudoku_solver::SudokuSolver; #[derive(Parser)] #[command(version, about, long_about = None)] @@ -11,7 +13,7 @@ struct Cli { // absense field: String, - // Size of one size of the field. For standard 9x9 input 9 (default) + // Size of one side of the field. For standard 9x9 input 9 (default) #[arg(short, long)] field_size: usize, } @@ -21,5 +23,9 @@ fn main() { let playfield = Playfield::new(&cli.field, cli.field_size); - println!("Input:\n{}", playfield) + println!("Input:\n{}", playfield); + + let solved_playfield = SudokuSolver::new(&playfield).solve(); + + println!("Solved:\n{}", solved_playfield); } diff --git a/src/playfield.rs b/src/playfield.rs index e48fa08..1bd2d49 100644 --- a/src/playfield.rs +++ b/src/playfield.rs @@ -1,8 +1,8 @@ use std::fmt; -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Debug, Clone)] pub struct Playfield { size: usize, - fields: Vec>, + pub fields: Vec>, open_fields: Vec, } @@ -67,9 +67,9 @@ impl fmt::Display for Playfield { } #[derive(Clone, PartialEq, Debug)] -struct Field { - possible_values: Vec, - value: Option, +pub struct Field { + pub possible_values: Vec, + pub value: Option, } impl Field { diff --git a/src/sudoku_solver b/src/sudoku_solver new file mode 100644 index 0000000..532d99d --- /dev/null +++ b/src/sudoku_solver @@ -0,0 +1,7 @@ +struct SudokuSolver { + playfield: Playfield +} + +impl SudokuSolver { + +} diff --git a/src/sudoku_solver.rs b/src/sudoku_solver.rs new file mode 100644 index 0000000..7cc8606 --- /dev/null +++ b/src/sudoku_solver.rs @@ -0,0 +1,41 @@ +use crate::playfield::Playfield; + +pub struct SudokuSolver { + playfield: Playfield, +} + +impl SudokuSolver { + pub fn new(playfield: &Playfield) -> SudokuSolver { + Self { + playfield: playfield.clone(), + } + } + pub fn solve(&self) -> Playfield { + return self.playfield.clone(); + } + + fn populate_possible_values(&self) { + for row in &self.playfield.fields { + for field in row { + if field.value.is_some() { + continue; + } + } + } + } +} +#[cfg(test)] +mod tests { + mod solve { + use super::super::*; + #[test] + fn simple() { + let playfield = Playfield::new(&"1 2 3 2 3 1 3 1 0".to_string(), 3); + let expected = Playfield::new(&"1 2 3 2 3 1 3 1 2".to_string(), 3); + + let solved = SudokuSolver::new(&playfield).solve(); + + assert_eq!(solved, expected); + } + } +}