Rewrote path selection for conflict avoidance.
This commit is contained in:
parent
8f6809c17f
commit
7fdf32342a
8 changed files with 514 additions and 439 deletions
|
|
@ -1,15 +1,15 @@
|
|||
use std::fmt::Display;
|
||||
|
||||
use colored::Colorize;
|
||||
use termcolor::ColorSpec;
|
||||
|
||||
use crate::misc::Map;
|
||||
|
||||
use super::{
|
||||
common::{Dimension, Direction, PathField, PositionType},
|
||||
common::{print_map, Dimension, Direction, PathField, PositionType},
|
||||
Position, COLORS,
|
||||
};
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct BruteforceField {
|
||||
pub blocked: bool,
|
||||
underground_vertical: bool,
|
||||
|
|
@ -18,7 +18,7 @@ pub struct BruteforceField {
|
|||
|
||||
static MAX_UNDERGROUND_LENGTH: u8 = 6;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BruteforceBuilder {
|
||||
map: Map<BruteforceField>,
|
||||
path: Vec<[(Position, Direction); 2]>,
|
||||
|
|
@ -49,6 +49,7 @@ impl BruteforceBuilder {
|
|||
}
|
||||
|
||||
pub fn build(self) -> Bruteforce {
|
||||
// dbg!(&self);
|
||||
let dimension = Dimension {
|
||||
width: self.map.width,
|
||||
height: self.map.height,
|
||||
|
|
@ -583,26 +584,6 @@ impl Display for Bruteforce {
|
|||
let width_digits = self.map.width.ilog10() + 1;
|
||||
let height_digits = self.map.height.ilog10() + 1;
|
||||
|
||||
// print header
|
||||
for i in 0..width_digits {
|
||||
let d = width_digits - i - 1;
|
||||
// padding
|
||||
for _ in 0..height_digits {
|
||||
write!(f, " ")?;
|
||||
}
|
||||
|
||||
for x in 0..self.map.width {
|
||||
let digits = x / (usize::pow(10, d));
|
||||
if digits == 0 && d > 0 {
|
||||
write!(f, " ")?;
|
||||
} else {
|
||||
write!(f, "{}", char::from_u32((digits % 10) as u32 + 48).unwrap())?;
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(f)?;
|
||||
}
|
||||
|
||||
let mut m: Map<Option<(usize, &str)>> = Map::new(self.map.width, self.map.height);
|
||||
|
||||
for (i, problem) in self.problems.iter().enumerate() {
|
||||
|
|
@ -662,27 +643,23 @@ impl Display for Bruteforce {
|
|||
|
||||
// Print body
|
||||
|
||||
for y in 0..self.map.height {
|
||||
write!(f, "{:1$}", y, height_digits as usize)?;
|
||||
|
||||
for x in 0..self.map.width {
|
||||
if let Some((i, c)) = m.get(x, y) {
|
||||
write!(f, "{}", c.color(COLORS[*i]))?;
|
||||
} else if self.map.get(x, y).blocked {
|
||||
write!(f, "#")?;
|
||||
} else if self.map.get(x, y).underground_horizontal {
|
||||
write!(f, "_")?;
|
||||
} else if self.map.get(x, y).underground_vertical {
|
||||
write!(f, "|")?;
|
||||
} else if x % 8 == 0 || y % 8 == 0 {
|
||||
write!(f, "∙")?;
|
||||
} else {
|
||||
write!(f, " ")?;
|
||||
}
|
||||
print_map(self.map.width as i32, self.map.height as i32, |x, y| {
|
||||
if let Some((i, c)) = m.get(x as usize, y as usize) {
|
||||
let mut color = ColorSpec::new();
|
||||
color.set_fg(Some(COLORS[*i]));
|
||||
(color, *c)
|
||||
} else if self.map.get(x as usize, y as usize).blocked {
|
||||
(ColorSpec::new(), "#")
|
||||
} else if self.map.get(x as usize, y as usize).underground_horizontal {
|
||||
(ColorSpec::new(), "_")
|
||||
} else if self.map.get(x as usize, y as usize).underground_vertical {
|
||||
(ColorSpec::new(), "|")
|
||||
} else if x % 8 == 0 || y % 8 == 0 {
|
||||
(ColorSpec::new(), "∙")
|
||||
} else {
|
||||
(ColorSpec::new(), " ")
|
||||
}
|
||||
|
||||
writeln!(f)?;
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue