factorio_blueprint/examples/solve_belt.rs
2024-03-23 23:52:46 +01:00

87 lines
2.1 KiB
Rust

use clap::{Parser, ValueEnum};
use factorio_blueprint::belt_finding::{conflict_avoidance::ConflictAvoidance, problems, Problem};
use std::io;
#[derive(ValueEnum, Clone)]
enum Mode {
Solve,
ConflictAvoidance,
ConflictStep,
}
#[derive(ValueEnum, Clone)]
enum ProblemCase {
Simple,
Level1,
Level2,
Level3,
Level5,
}
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(),
}
}
}
#[derive(Parser)]
struct Args {
#[arg(value_enum, default_value = "level1")]
problem: ProblemCase,
#[arg(value_enum, default_value = "conflict-avoidance")]
mode: Mode,
}
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();
p.find_path();
p.print();
p.find_path();
p.print();
p.find_path();
p.print();
let mut c = ConflictAvoidance::new(p);
c.print();
while c.remove_conflict() {
c.print();
}
}
Mode::ConflictStep => {
p.print();
p.find_path();
p.print();
p.find_path();
p.print();
p.find_path();
p.print();
p.find_path();
p.print();
let mut c = ConflictAvoidance::new(p);
c.print();
while c.remove_conflict() {
c.print();
let mut s = String::new();
let _ = io::stdin().read_line(&mut s);
}
}
}
}