factorio_blueprint/examples/brute_force.rs

80 lines
1.7 KiB
Rust

use std::io;
use clap::{Parser, ValueEnum};
use factorio_blueprint::belt_finding::brute_force::{problems, Bruteforce};
#[derive(ValueEnum, Clone)]
enum Mode {
Solutions,
Step,
}
#[derive(ValueEnum, Clone)]
enum Problem {
Simple,
Snake,
Weaving,
}
impl Problem {
fn get_problem(&self) -> Bruteforce {
match self {
Problem::Simple => problems::simple(),
Problem::Snake => problems::snake(),
Problem::Weaving => problems::weaving(),
}
}
}
#[derive(Parser)]
struct Args {
#[arg(value_enum, default_value = "simple")]
problem: Problem,
#[arg(value_enum, default_value = "solutions")]
mode: Mode,
}
fn main() {
let args = Args::parse();
let mut b = args.problem.get_problem();
println!("{b}");
match args.mode {
Mode::Solutions => {
while b.next_finish_state() {
println!("{}\n{}\n{}", b.count(), b.solution_count(), b);
}
println!("{}\n{}", b.count(), b.solution_count());
}
Mode::Step => {
while b.next_state() {
println!("{}", b);
let mut s = String::new();
let _ = io::stdin().read_line(&mut s);
}
println!("{}\n{}", b.count(), b.solution_count());
}
}
// println!(
// "{}\n{}\n{}\n{}",
// b.count(),
// b.solution_count(),
// b.modify_pointer(),
// b
// );
// for i in 0..20 {
// b.next_state();
// println!(
// "{}\n{}\n{}\n{}",
// b.count(),
// b.solution_count(),
// b.modify_pointer(),
// b
// );
// }
}