diff --git a/examples/brute_force.rs b/examples/brute_force.rs
index b86fc35..0c7bcfa 100644
--- a/examples/brute_force.rs
+++ b/examples/brute_force.rs
@@ -1,7 +1,10 @@
use std::io;
use clap::{Parser, ValueEnum};
-use factorio_blueprint::belt_finding::brute_force::{problems, Bruteforce};
+use factorio_blueprint::{
+ belt_finding::brute_force::{problems, Bruteforce},
+ common::visualize::Visualize,
+};
#[derive(ValueEnum, Clone)]
enum Mode {
@@ -44,20 +47,20 @@ fn main() {
let mut b = args.problem.get_problem();
- b.print();
+ 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();
+ b.print_visualization();
}
println!("Solutions: {}\nStates: {}", b.solution_count(), b.count());
}
Mode::Step => {
while b.next_state() {
- b.print();
+ b.print_visualization();
let mut s = String::new();
let _ = io::stdin().read_line(&mut s);
}
diff --git a/examples/solve_belt.rs b/examples/solve_belt.rs
deleted file mode 100644
index 4ddb73a..0000000
--- a/examples/solve_belt.rs
+++ /dev/null
@@ -1,87 +0,0 @@
-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(None) {
- 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(None) {
- c.print();
- let mut s = String::new();
- let _ = io::stdin().read_line(&mut s);
- }
- }
- }
-}
diff --git a/src/belt_finding/brute_force.rs b/src/belt_finding/brute_force.rs
index e178a12..833ecf3 100644
--- a/src/belt_finding/brute_force.rs
+++ b/src/belt_finding/brute_force.rs
@@ -1,12 +1,7 @@
-use std::time::Instant;
-
-use super::{
- common::{print_map, PathField},
- Position,
-};
-use crate::misc::Map;
+use super::{common::PathField, Position};
use crate::prelude::*;
-use termcolor::ColorSpec;
+use crate::{common::visualize::Visualize, misc::Map};
+use std::time::Instant;
#[derive(Default, Debug, Clone)]
pub struct BruteforceField {
@@ -592,83 +587,67 @@ impl Bruteforce {
pub fn solution_count(&self) -> u128 {
self.solution_count
}
- pub fn print(&self) {
- let mut m: Map