|
|
|
@ -21,44 +21,28 @@ impl World { |
|
|
|
|
self.cleared.insert(pos); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// make sure that this is as simple & robust as possible
|
|
|
|
|
// then, use this set of rules when digging
|
|
|
|
|
// call astar from the suggested dig site to origin (or whatever "home" coordinate")
|
|
|
|
|
// if route does not exist, do not dig
|
|
|
|
|
pub fn is_valid_movement(&self, target: &Point, b: &Screen) -> bool { |
|
|
|
|
let safe =
|
|
|
|
|
pub fn create_chamber(&mut self, center: Point, radius: i32) { |
|
|
|
|
let cx = center.0; |
|
|
|
|
let cy = center.1; |
|
|
|
|
|
|
|
|
|
for i in cx-radius..cx+radius { |
|
|
|
|
for j in cy-radius..cy+radius { |
|
|
|
|
self.clear(Point(i,j)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn is_valid_movement(&self, current: &Point, target: &Point, b: &Screen) -> bool { |
|
|
|
|
// should allow down movements always
|
|
|
|
|
|
|
|
|
|
let safe = target.is_below(*current) || ( |
|
|
|
|
!self.cleared.contains(&target.down()) |
|
|
|
|
|| !self.cleared.contains(&target.left()) |
|
|
|
|
|| !self.cleared.contains(&target.right()) |
|
|
|
|
|| !self.cleared.contains(&target.bldiag()) |
|
|
|
|
|| !self.cleared.contains(&target.uldiag()) |
|
|
|
|
|| !self.cleared.contains(&target.brdiag()) |
|
|
|
|
|| !self.cleared.contains(&target.urdiag()); |
|
|
|
|
|
|
|
|
|
// can only go to target if
|
|
|
|
|
// its above or left or right of a not cleared space
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
if target.is_above(current_pos) { |
|
|
|
|
safe = |
|
|
|
|
(!self.cleared.contains(&target.left()) || !self.cleared.contains(&target.right())) |
|
|
|
|
|| (!self.cleared.contains(¤t_pos.right()) && self.cleared.contains(&target.right())) |
|
|
|
|
|| (!self.cleared.contains(¤t_pos.left()) && self.cleared.contains(&target.left())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if target.is_adjacent(current_pos) { |
|
|
|
|
let target_down = target.down(); |
|
|
|
|
if self.cleared.contains(&target_down) { |
|
|
|
|
safe = !self.cleared.contains(&target_down.left()) |
|
|
|
|
|| !self.cleared.contains(&target_down.right()); |
|
|
|
|
} else { |
|
|
|
|
safe = !self.cleared.contains(&target.down()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if target.is_below(current_pos) { |
|
|
|
|
safe = true; |
|
|
|
|
}*/ |
|
|
|
|
|| !self.cleared.contains(&target.urdiag())); |
|
|
|
|
|
|
|
|
|
// of course, its only a valid move if you can walk there!
|
|
|
|
|
b.is_in_bounds(target) && self.cleared.contains(target) && safe |
|
|
|
@ -68,25 +52,10 @@ impl World { |
|
|
|
|
self.cleared.contains(pos) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn is_safe_to_dig(&self, current_pos: &Point, target: &Point, b: &Screen) -> bool { |
|
|
|
|
// create a scenario in which this has been dug out
|
|
|
|
|
pub fn is_safe_to_dig(&self, target: &Point, b: &Screen) -> bool { |
|
|
|
|
let mut hypothetical_world = self.clone(); |
|
|
|
|
hypothetical_world.clear(*target); |
|
|
|
|
// test if we can return from the target to the beginning
|
|
|
|
|
// if yes, dig
|
|
|
|
|
let result = astar(target, &Point(0, 0), Some(&hypothetical_world), Some(b)); |
|
|
|
|
//let to_current_pos = astar(target, current_pos, Some(&hypothetical_world), Some(b));
|
|
|
|
|
/*if target.is_above(current_pos) {
|
|
|
|
|
safe = !self.cleared.contains(&target.up()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if target.is_adjacent(current_pos) { |
|
|
|
|
safe = !self.cleared.contains(&target.up()) && !self.cleared.contains(&target.down()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if target.is_below(current_pos) { |
|
|
|
|
safe = !self.cleared.contains(&target.down()) && !self.cleared.contains(&target.left()) && !self.cleared.contains(&target.right()); |
|
|
|
|
}*/ |
|
|
|
|
b.is_in_bounds(target) && result.is_ok() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -108,7 +77,7 @@ impl World { |
|
|
|
|
let moves = b.get_valid_movements(pos); |
|
|
|
|
let mut ans: Vec<Point> = moves |
|
|
|
|
.iter() |
|
|
|
|
.filter(|p| self.is_valid_movement(p, b)) |
|
|
|
|
.filter(|p| self.is_valid_movement(pos, p, b)) |
|
|
|
|
.map(|p| p.clone()) |
|
|
|
|
.collect(); |
|
|
|
|
|
|
|
|
|