Refactor into different crates
This commit is contained in:
parent
94473c64e0
commit
dfdeae5638
82 changed files with 624 additions and 647 deletions
91
factorio-pathfinding/examples/brute_force.rs
Normal file
91
factorio-pathfinding/examples/brute_force.rs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
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
|
||||
// );
|
||||
// }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue