Add beltfinding timeout and debugging.
This commit is contained in:
parent
f20a1841c9
commit
79c8b0c710
13 changed files with 278 additions and 53 deletions
80
src/bin/beltfinding.rs
Normal file
80
src/bin/beltfinding.rs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
use clap::{Parser, Subcommand, ValueEnum};
|
||||
use factorio_blueprint::belt_finding::{conflict_avoidance::ConflictAvoidance, problems, Problem};
|
||||
use std::{io, path::PathBuf};
|
||||
|
||||
#[derive(ValueEnum, Clone)]
|
||||
enum Mode {
|
||||
Solve,
|
||||
ConflictAvoidance,
|
||||
ConflictStep,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum ProblemCase {
|
||||
Simple,
|
||||
Level1,
|
||||
Level2,
|
||||
Level3,
|
||||
Level5,
|
||||
File { filename: PathBuf },
|
||||
}
|
||||
|
||||
impl ProblemCase {
|
||||
fn get_problem(&self) -> Problem {
|
||||
match self {
|
||||
ProblemCase::Simple => problems::simple(),
|
||||
ProblemCase::Level1 => problems::belt_madness_level_1(),
|
||||
ProblemCase::Level2 => problems::belt_madness_level_2(),
|
||||
ProblemCase::Level3 => problems::belt_madness_level_3(),
|
||||
ProblemCase::Level5 => problems::belt_madness_level_5(),
|
||||
ProblemCase::File { filename } => {
|
||||
let file = std::fs::File::open(filename).unwrap();
|
||||
serde_json::from_reader(file).unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
#[arg(value_enum, default_value = "conflict-avoidance")]
|
||||
mode: Mode,
|
||||
#[command(subcommand)]
|
||||
problem: ProblemCase,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
let mut p = args.problem.get_problem();
|
||||
|
||||
match args.mode {
|
||||
Mode::Solve => {
|
||||
p.print();
|
||||
p.find_path();
|
||||
p.print();
|
||||
}
|
||||
Mode::ConflictAvoidance => {
|
||||
p.print();
|
||||
p.find_path();
|
||||
p.print();
|
||||
let mut c = ConflictAvoidance::new(&p);
|
||||
c.print();
|
||||
while c.remove_conflict(None) {
|
||||
c.print();
|
||||
}
|
||||
}
|
||||
Mode::ConflictStep => {
|
||||
p.print();
|
||||
p.find_path();
|
||||
p.print();
|
||||
let mut c = ConflictAvoidance::new(&p);
|
||||
c.print();
|
||||
while c.remove_conflict(None) {
|
||||
c.print();
|
||||
let mut s = String::new();
|
||||
let _ = io::stdin().read_line(&mut s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue