Performance improvements and fix warnings
This commit is contained in:
parent
68d0f64058
commit
b5dcbccf02
6 changed files with 202 additions and 55 deletions
|
|
@ -1,35 +1,64 @@
|
|||
use factorio_blueprint::{
|
||||
belt_finding::{
|
||||
brute_force::{Bruteforce, BruteforceBuilder, PathField},
|
||||
Direction, Position,
|
||||
},
|
||||
misc::Map,
|
||||
};
|
||||
use std::io;
|
||||
|
||||
use clap::{Parser, ValueEnum};
|
||||
use factorio_blueprint::belt_finding::brute_force::{problems, Bruteforce};
|
||||
|
||||
#[derive(ValueEnum, Clone)]
|
||||
enum Mode {
|
||||
Solutions,
|
||||
Step,
|
||||
}
|
||||
|
||||
#[derive(ValueEnum, Clone)]
|
||||
enum Problem {
|
||||
Simple,
|
||||
Snake,
|
||||
Weaving,
|
||||
}
|
||||
|
||||
impl Problem {
|
||||
fn get_problem(&self) -> Bruteforce {
|
||||
match self {
|
||||
Problem::Simple => problems::simple(),
|
||||
Problem::Snake => problems::snake(),
|
||||
Problem::Weaving => problems::weaving(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
#[arg(value_enum, default_value = "simple")]
|
||||
problem: Problem,
|
||||
#[arg(value_enum, default_value = "solutions")]
|
||||
mode: Mode,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut b = BruteforceBuilder::new(6, 8);
|
||||
let args = Args::parse();
|
||||
|
||||
b.add_path(
|
||||
(Position::new(1, 0), Direction::Down),
|
||||
(Position::new(0, 0), Direction::Up),
|
||||
);
|
||||
let mut b = args.problem.get_problem();
|
||||
|
||||
b.add_path(
|
||||
(Position::new(4, 0), Direction::Down),
|
||||
(Position::new(1, 7), Direction::Up),
|
||||
);
|
||||
println!("{b}");
|
||||
|
||||
b.set_blocked_range(0, 2, 5, 5, true);
|
||||
// b.set_blocked_range(2, 0, 2, 2, true);
|
||||
match args.mode {
|
||||
Mode::Solutions => {
|
||||
while b.next_finish_state() {
|
||||
println!("{}\n{}\n{}", b.count(), b.solution_count(), b);
|
||||
}
|
||||
|
||||
let mut b = b.build();
|
||||
|
||||
while b.next_finish_state() {
|
||||
println!("{}\n{}\n{}", b.count(), b.solution_count(), b);
|
||||
println!("{}\n{}", b.count(), b.solution_count());
|
||||
}
|
||||
Mode::Step => {
|
||||
while b.next_state() {
|
||||
println!("{}", b);
|
||||
let mut s = String::new();
|
||||
let _ = io::stdin().read_line(&mut s);
|
||||
}
|
||||
println!("{}\n{}", b.count(), b.solution_count());
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}\n{}", b.count(), b.solution_count());
|
||||
|
||||
// println!(
|
||||
// "{}\n{}\n{}\n{}",
|
||||
// b.count(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue