factorio_blueprint/factorio-pathfinding/examples/brute_force.rs

91 lines
2.1 KiB
Rust

use clap::{Parser, ValueEnum};
use factorio_core::visualize::Visualize;
use factorio_pathfinding::belt_finding::brute_force::{problems, Bruteforce};
use std::io;
#[derive(ValueEnum, Clone)]
enum Mode {
Solutions,
Step,
Statistics,
}
#[derive(ValueEnum, Clone)]
enum Problem {
Simple,
Mid,
Snake,
Weaving,
Debug,
}
impl Problem {
fn get_problem(&self) -> Bruteforce {
match self {
Problem::Simple => problems::simple(),
Problem::Mid => problems::mid(),
Problem::Snake => problems::snake(),
Problem::Weaving => problems::weaving(),
Problem::Debug => problems::debug(),
}
}
}
#[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();
b.print_visualization();
match args.mode {
Mode::Solutions => {
while b.next_finish_state(None) {
println!("{}\n{}\n{}", b.count(), b.solution_count(), b.cost());
b.print_visualization();
}
println!("Solutions: {}\nStates: {}", b.solution_count(), b.count());
}
Mode::Step => {
while b.next_state() {
b.print_visualization();
let mut s = String::new();
let _ = io::stdin().read_line(&mut s);
}
println!("Solutions: {}\nStates: {}", b.solution_count(), b.count());
}
Mode::Statistics => {
while b.next_finish_state(None) {}
println!("Solutions: {}\nStates: {}", b.solution_count(), b.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
// );
// }
}