Bug fixes
This commit is contained in:
parent
be1d26ebd0
commit
a11b39cf9f
8 changed files with 336 additions and 70 deletions
|
|
@ -196,7 +196,7 @@ impl ConflictAvoidance {
|
|||
if let Some(PathField::Underground { pos, dir, len }) = path.get(end_index + 1) {
|
||||
if xrange.contains(&(pos.x as usize)) && yrange.contains(&(pos.y as usize)) {
|
||||
let p = *pos - offset;
|
||||
println!("Blocked {:?}", p);
|
||||
// println!("Blocked {:?}", p);
|
||||
if b.get_blocked(p.x as usize, p.y as usize) {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -247,8 +247,8 @@ impl ConflictAvoidance {
|
|||
|
||||
let mut b = b.build();
|
||||
|
||||
b.print();
|
||||
self.print();
|
||||
// b.print();
|
||||
// self.print();
|
||||
|
||||
let mut min_cost = f64::INFINITY;
|
||||
let mut solutions = Vec::new();
|
||||
|
|
@ -317,6 +317,8 @@ impl ConflictAvoidance {
|
|||
// println!();
|
||||
// }
|
||||
|
||||
// self.print();
|
||||
|
||||
let mut candidates = Vec::new();
|
||||
|
||||
for y in 0..self.map.height {
|
||||
|
|
@ -337,10 +339,17 @@ impl ConflictAvoidance {
|
|||
if candidates.is_empty() {
|
||||
return false;
|
||||
}
|
||||
// dbg!(&candidates);
|
||||
|
||||
loop {
|
||||
candidates.sort_by_key(|c| -c.area());
|
||||
let c = candidates.pop().unwrap();
|
||||
// dbg!(&candidates);
|
||||
let c = match candidates.pop() {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
self.range = Some((c.min.x..=c.max.x, c.min.y..=c.max.y));
|
||||
|
||||
|
|
@ -425,12 +434,27 @@ impl ConflictAvoidance {
|
|||
if candidate != c && !candidates.iter().any(|c| c == &candidate) {
|
||||
candidates.push(candidate);
|
||||
}
|
||||
// dbg!(&candidates);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_all_conflicts(&mut self) {
|
||||
pub fn remove_all_conflicts(&mut self) -> bool {
|
||||
while self.remove_conflict() {}
|
||||
|
||||
let mut conflicts: Map<bool> = Map::new(self.map.width, self.map.height);
|
||||
|
||||
for x in 0..self.map.width {
|
||||
for y in 0..self.map.height {
|
||||
if self.map.get(x, y).blocked {
|
||||
if conflicts.get(x, y) == &true {
|
||||
return false;
|
||||
} else {
|
||||
conflicts.set(x, y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
pub fn print(&self) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue