1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- use clap::{arg, command, value_parser, ArgAction};
- use std::path::PathBuf;
- // https://docs.rs/clap/latest/clap/_tutorial/chapter_0/index.html
- use sudoku::ksudoku::load_ksudoku;
- use sudoku::sudoku::*;
- fn main() {
- let mut s = Sudoku::new();
- let args = command!()
- .arg(
- arg!(-f --file <FILE> "Filename to load")
- .required(false)
- .value_parser(value_parser!(PathBuf)),
- )
- .arg(
- arg!(
- -m --make ... "Make a new sudoku puzzle"
- )
- .action(ArgAction::SetTrue),
- )
- .arg(arg!(-b --brute ... "Brute Force Solver").action(ArgAction::SetTrue))
- .get_matches();
- if args.get_flag("make") {
- s.make();
- s.display();
- return;
- }
- if let Some(filename) = args.get_one::<PathBuf>("file") {
- let puzzle = load_ksudoku(filename.to_path_buf()).unwrap();
- // Ksudoku is stored TLD.
- s.load_from_tld('b', '_', puzzle.as_str());
- s.display();
- s.display_possible();
- if args.get_flag("brute") {
- println!("Solutions: {}", s.bruteforce_solver());
- } else {
- while s.solve() {
- println!("Try it again...");
- s.display();
- s.display_possible();
- }
- }
- }
- }
|