Add Layout trait
This commit is contained in:
parent
00eda50872
commit
295490858b
12 changed files with 407 additions and 41 deletions
|
|
@ -14,13 +14,13 @@ pub mod brute_force;
|
|||
pub mod conflict_avoidance;
|
||||
|
||||
pub struct ConflictAvoidance {
|
||||
timeout: Option<std::time::Duration>,
|
||||
pub timeout: Option<std::time::Duration>,
|
||||
}
|
||||
|
||||
impl SinglePathfinder for ConflictAvoidance {
|
||||
fn find_paths<M: crate::Map>(
|
||||
&self,
|
||||
input: SinglePathInput<'_, M>,
|
||||
input: SinglePathInput<M>,
|
||||
) -> Option<Vec<Vec<factorio_core::pathfield::PathField>>> {
|
||||
let (pos, size) = input.map.area();
|
||||
let mut p = Problem::new(size.x as usize, size.y as usize);
|
||||
|
|
@ -34,11 +34,17 @@ impl SinglePathfinder for ConflictAvoidance {
|
|||
}
|
||||
|
||||
for i in input.connections {
|
||||
p.add_connection((i.start_pos, i.start_dir), (i.end_pos, i.end_dir));
|
||||
p.add_connection(
|
||||
(i.start_pos, i.start_dir),
|
||||
(i.end_pos.in_direction(&i.end_dir, -1), i.end_dir),
|
||||
);
|
||||
}
|
||||
|
||||
p.print_visualization();
|
||||
|
||||
if p.find_path() {
|
||||
let mut c = conflict_avoidance::ConflictAvoidance::new(&p);
|
||||
c.print_visualization();
|
||||
|
||||
if c.remove_all_conflicts(self.timeout) {
|
||||
Some(c.get_paths().to_vec())
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@ pub struct HashMapMap {
|
|||
}
|
||||
|
||||
impl HashMapMap {
|
||||
fn new(size: impl Into<Position>) -> Self {
|
||||
pub fn new(size: impl Into<Position>) -> Self {
|
||||
Self {
|
||||
map: HashSet::new(),
|
||||
size: size.into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_blocked_range(
|
||||
pub fn set_blocked_range(
|
||||
&mut self,
|
||||
min_pos: impl Into<Position>,
|
||||
max_pos: impl Into<Position>,
|
||||
|
|
@ -35,7 +35,7 @@ impl HashMapMap {
|
|||
}
|
||||
}
|
||||
|
||||
fn set_blocked(&mut self, pos: impl Into<Position>, block: bool) {
|
||||
pub fn set_blocked(&mut self, pos: impl Into<Position>, block: bool) {
|
||||
let pos = pos.into();
|
||||
if block {
|
||||
self.map.insert(pos);
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ pub mod misc;
|
|||
pub mod priority_queue;
|
||||
|
||||
pub struct PathInput<'c, M> {
|
||||
connections: &'c [Connection],
|
||||
map: M,
|
||||
pub connections: &'c [Connection],
|
||||
pub map: M,
|
||||
}
|
||||
|
||||
pub struct Connection {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue