factorio_blueprint/src/bin/beltfinding.rs

80 lines
2 KiB
Rust

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);
}
}
}
}