main.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. use clap::{arg, command, value_parser, ArgAction};
  2. use std::path::PathBuf;
  3. // https://docs.rs/clap/latest/clap/_tutorial/chapter_0/index.html
  4. use sudoku::ksudoku::load_ksudoku;
  5. use sudoku::sudoku::*;
  6. fn main() {
  7. let mut s = Sudoku::new();
  8. let args = command!()
  9. .arg(
  10. arg!(-f --file <FILE> "Filename to load")
  11. .required(false)
  12. .value_parser(value_parser!(PathBuf)),
  13. )
  14. .arg(
  15. arg!(
  16. -m --make ... "Make a new sudoku puzzle"
  17. )
  18. .action(ArgAction::SetTrue),
  19. )
  20. .arg(arg!(-b --brute ... "Brute Force Solver").action(ArgAction::SetTrue))
  21. .get_matches();
  22. if args.get_flag("make") {
  23. s.make();
  24. s.display();
  25. return;
  26. }
  27. if let Some(filename) = args.get_one::<PathBuf>("file") {
  28. let puzzle = load_ksudoku(filename.to_path_buf()).unwrap();
  29. // Ksudoku is stored TLD.
  30. s.load_from_tld('b', '_', puzzle.as_str());
  31. s.display();
  32. s.display_possible();
  33. if args.get_flag("brute") {
  34. println!("Solutions: {}", s.bruteforce_solver());
  35. } else {
  36. while s.solve() {
  37. println!("Try it again...");
  38. s.display();
  39. s.display_possible();
  40. }
  41. }
  42. }
  43. }