Resolve warnings.
This commit is contained in:
parent
2bf648f657
commit
5575cb134a
6 changed files with 103 additions and 143 deletions
|
|
@ -1,17 +1,10 @@
|
|||
use std::{
|
||||
fmt::Display,
|
||||
ops::{RangeBounds, RangeInclusive},
|
||||
};
|
||||
|
||||
use clap::builder::PathBufValueParser;
|
||||
use termcolor::ColorSpec;
|
||||
|
||||
use crate::{belt_finding::brute_force::BruteforceBuilder, misc::Map};
|
||||
|
||||
use super::{
|
||||
common::{print_map, Dimension, Direction, PathField, Position, PositionType},
|
||||
common::{print_map, Direction, PathField, Position, PositionType},
|
||||
Problem, COLORS,
|
||||
};
|
||||
use crate::{belt_finding::brute_force::BruteforceBuilder, misc::Map};
|
||||
use std::ops::RangeInclusive;
|
||||
use termcolor::ColorSpec;
|
||||
|
||||
#[derive(Default)]
|
||||
struct Field {
|
||||
|
|
@ -274,8 +267,8 @@ impl ConflictAvoidance {
|
|||
|
||||
let mut b = b.build();
|
||||
|
||||
println!("{}", b);
|
||||
println!("{}", self);
|
||||
b.print();
|
||||
self.print();
|
||||
|
||||
let mut min_cost = f64::INFINITY;
|
||||
let mut solutions = Vec::new();
|
||||
|
|
@ -315,68 +308,62 @@ impl ConflictAvoidance {
|
|||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
let mut candidate = Candidate::new(
|
||||
Position::new(
|
||||
xrange.start().saturating_sub(1) as PositionType,
|
||||
*yrange.start() as PositionType,
|
||||
),
|
||||
Position::new(*xrange.end() as PositionType, *yrange.end() as PositionType),
|
||||
);
|
||||
candidate.extend_range(&conflicts);
|
||||
if candidate != c && !candidates.iter().any(|c| c == &candidate) {
|
||||
candidates.push(candidate);
|
||||
}
|
||||
let mut candidate = Candidate::new(
|
||||
Position::new(
|
||||
*xrange.start() as PositionType,
|
||||
yrange.start().saturating_sub(1) as PositionType,
|
||||
),
|
||||
Position::new(*xrange.end() as PositionType, *yrange.end() as PositionType),
|
||||
);
|
||||
candidate.extend_range(&conflicts);
|
||||
if candidate != c && !candidates.iter().any(|c| c == &candidate) {
|
||||
candidates.push(candidate);
|
||||
}
|
||||
let mut candidate = Candidate::new(
|
||||
Position::new(
|
||||
*xrange.start() as PositionType,
|
||||
*yrange.start() as PositionType,
|
||||
),
|
||||
Position::new(
|
||||
usize::min(xrange.end() + 1, self.map.width - 1) as PositionType,
|
||||
*yrange.end() as PositionType,
|
||||
),
|
||||
);
|
||||
candidate.extend_range(&conflicts);
|
||||
if candidate != c && !candidates.iter().any(|c| c == &candidate) {
|
||||
candidates.push(candidate);
|
||||
}
|
||||
let mut candidate = Candidate::new(
|
||||
Position::new(
|
||||
*xrange.start() as PositionType,
|
||||
*yrange.start() as PositionType,
|
||||
),
|
||||
Position::new(
|
||||
*xrange.end() as PositionType,
|
||||
usize::min(yrange.end() + 1, self.map.height - 1) as PositionType,
|
||||
),
|
||||
);
|
||||
candidate.extend_range(&conflicts);
|
||||
if candidate != c && !candidates.iter().any(|c| c == &candidate) {
|
||||
candidates.push(candidate);
|
||||
}
|
||||
}
|
||||
let mut candidate = Candidate::new(
|
||||
Position::new(
|
||||
xrange.start().saturating_sub(1) as PositionType,
|
||||
*yrange.start() as PositionType,
|
||||
),
|
||||
Position::new(*xrange.end() as PositionType, *yrange.end() as PositionType),
|
||||
);
|
||||
candidate.extend_range(&conflicts);
|
||||
if candidate != c && !candidates.iter().any(|c| c == &candidate) {
|
||||
candidates.push(candidate);
|
||||
}
|
||||
let mut candidate = Candidate::new(
|
||||
Position::new(
|
||||
*xrange.start() as PositionType,
|
||||
yrange.start().saturating_sub(1) as PositionType,
|
||||
),
|
||||
Position::new(*xrange.end() as PositionType, *yrange.end() as PositionType),
|
||||
);
|
||||
candidate.extend_range(&conflicts);
|
||||
if candidate != c && !candidates.iter().any(|c| c == &candidate) {
|
||||
candidates.push(candidate);
|
||||
}
|
||||
let mut candidate = Candidate::new(
|
||||
Position::new(
|
||||
*xrange.start() as PositionType,
|
||||
*yrange.start() as PositionType,
|
||||
),
|
||||
Position::new(
|
||||
usize::min(xrange.end() + 1, self.map.width - 1) as PositionType,
|
||||
*yrange.end() as PositionType,
|
||||
),
|
||||
);
|
||||
candidate.extend_range(&conflicts);
|
||||
if candidate != c && !candidates.iter().any(|c| c == &candidate) {
|
||||
candidates.push(candidate);
|
||||
}
|
||||
let mut candidate = Candidate::new(
|
||||
Position::new(
|
||||
*xrange.start() as PositionType,
|
||||
*yrange.start() as PositionType,
|
||||
),
|
||||
Position::new(
|
||||
*xrange.end() as PositionType,
|
||||
usize::min(yrange.end() + 1, self.map.height - 1) as PositionType,
|
||||
),
|
||||
);
|
||||
candidate.extend_range(&conflicts);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_all_conflicts(&mut self) {
|
||||
while self.remove_conflict() {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ConflictAvoidance {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
pub fn print(&self) {
|
||||
let mut m: Map<Option<(usize, &str)>> = Map::new(self.map.width, self.map.height);
|
||||
|
||||
for (i, problem) in self.belts.iter().enumerate() {
|
||||
|
|
@ -474,7 +461,5 @@ impl Display for ConflictAvoidance {
|
|||
(color, " ")
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue