Improve performance
This commit is contained in:
parent
6c2c34f9a3
commit
ce3a890237
2 changed files with 68 additions and 6 deletions
|
|
@ -28,6 +28,8 @@ fn main() {
|
|||
println!("{}\n{}\n{}", b.count(), b.solution_count(), b);
|
||||
}
|
||||
|
||||
println!("{}\n{}", b.count(), b.solution_count());
|
||||
|
||||
// println!(
|
||||
// "{}\n{}\n{}\n{}",
|
||||
// b.count(),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use std::fmt::Display;
|
||||
|
||||
use clap::builder::PathBufValueParser;
|
||||
use colored::Colorize;
|
||||
|
||||
use crate::misc::Map;
|
||||
|
|
@ -90,7 +89,6 @@ impl BruteforceBuilder {
|
|||
pointer_stack: vec![0],
|
||||
solution_count: 0,
|
||||
count: 0,
|
||||
depth: 1,
|
||||
};
|
||||
|
||||
for [start, end] in self.path {
|
||||
|
|
@ -124,7 +122,6 @@ pub struct Bruteforce {
|
|||
map: Map<BruteforceField>,
|
||||
problems: Vec<Problem>,
|
||||
pointer_stack: Vec<usize>,
|
||||
depth: usize,
|
||||
solution_count: u128,
|
||||
count: u128,
|
||||
}
|
||||
|
|
@ -223,11 +220,74 @@ impl Bruteforce {
|
|||
}
|
||||
|
||||
fn modify_path_field(&mut self, path_field: PathField) {
|
||||
self.internal_remove_path_field(self.modify_pointer());
|
||||
self.internal_apply_path_field(self.modify_pointer(), path_field);
|
||||
let i = self.modify_pointer();
|
||||
let last = self.problems[i].path.last().unwrap().clone();
|
||||
|
||||
match (last, &path_field) {
|
||||
(PathField::Belt { pos: _, dir: _ }, PathField::Belt { pos: _, dir: _ }) => {}
|
||||
(PathField::Belt { pos: _, dir: _ }, PathField::Underground { pos, dir, len }) => {
|
||||
let end_pos = self.pos_in_direction(pos, dir, *len as usize).unwrap();
|
||||
|
||||
self.map.get_mut(end_pos.x, end_pos.y).blocked = true;
|
||||
|
||||
for l in 0..=*len {
|
||||
let p = self.pos_in_direction(pos, dir, l as usize).unwrap();
|
||||
match dir.vertical() {
|
||||
true => self.map.get_mut(p.x, p.y).underground_vertical = true,
|
||||
false => self.map.get_mut(p.x, p.y).underground_horizontal = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
(
|
||||
PathField::Underground {
|
||||
pos: _,
|
||||
dir: _,
|
||||
len: _,
|
||||
},
|
||||
PathField::Belt { pos: _, dir: _ },
|
||||
) => {
|
||||
unreachable!()
|
||||
}
|
||||
(
|
||||
PathField::Underground {
|
||||
pos,
|
||||
dir,
|
||||
len: last_len,
|
||||
},
|
||||
PathField::Underground {
|
||||
pos: _,
|
||||
dir: _,
|
||||
len: new_len,
|
||||
},
|
||||
) => {
|
||||
let last_end_pos = self
|
||||
.pos_in_direction(&pos, &dir, last_len as usize)
|
||||
.unwrap();
|
||||
let new_end_pos = self
|
||||
.pos_in_direction(&pos, &dir, *new_len as usize)
|
||||
.unwrap();
|
||||
|
||||
self.map.get_mut(last_end_pos.x, last_end_pos.y).blocked = false;
|
||||
self.map.get_mut(new_end_pos.x, new_end_pos.y).blocked = true;
|
||||
|
||||
match last_len < *new_len {
|
||||
true => {
|
||||
for l in last_len + 1..=*new_len {
|
||||
let p = self.pos_in_direction(&pos, &dir, l as usize).unwrap();
|
||||
match dir.vertical() {
|
||||
true => self.map.get_mut(p.x, p.y).underground_vertical = true,
|
||||
false => self.map.get_mut(p.x, p.y).underground_horizontal = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
false => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*self.problems[i].path.last_mut().unwrap() = path_field;
|
||||
|
||||
// set finished
|
||||
let i = self.modify_pointer();
|
||||
self.problems[i].finished = self.check_finish(i);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue