|
|
|
@ -6,7 +6,7 @@ use std::collections::HashSet; |
|
|
|
|
#[derive(Clone)] |
|
|
|
|
pub struct World { |
|
|
|
|
pub cleared: HashSet<Point>, |
|
|
|
|
pub food: HashSet<u32>, |
|
|
|
|
pub food: HashSet<Point>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl World { |
|
|
|
@ -25,9 +25,9 @@ impl World { |
|
|
|
|
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)); |
|
|
|
|
for i in cx - radius..cx + radius { |
|
|
|
|
for j in cy - radius..cy + radius { |
|
|
|
|
self.clear(Point(i, j)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -35,8 +35,8 @@ impl World { |
|
|
|
|
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()) |
|
|
|
|
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()) |
|
|
|
@ -55,7 +55,7 @@ impl World { |
|
|
|
|
pub fn is_safe_to_dig(&self, target: &Point, b: &Screen) -> bool { |
|
|
|
|
let mut hypothetical_world = self.clone(); |
|
|
|
|
hypothetical_world.clear(*target); |
|
|
|
|
let result = astar(target, &Point(0, 0), Some(&hypothetical_world), Some(b)); |
|
|
|
|
let result = astar(target, &b.center, Some(&hypothetical_world), Some(b)); |
|
|
|
|
b.is_in_bounds(target) && result.is_ok() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -82,10 +82,12 @@ impl World { |
|
|
|
|
.collect(); |
|
|
|
|
|
|
|
|
|
if return_diggables { |
|
|
|
|
ans.extend(self.get_diggable(b, pos)); |
|
|
|
|
let digs = self.get_diggable(b, pos); |
|
|
|
|
ans.extend(digs); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ans |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -131,6 +133,7 @@ pub fn simulate(e: &mut Entities, w: &mut World, b: &mut Screen) { |
|
|
|
|
BoardCommand::SpawnFood(pos) => { |
|
|
|
|
let food = Food::new(pos.0, pos.1); |
|
|
|
|
e.add_entity(&food); |
|
|
|
|
w.food.insert(pos); |
|
|
|
|
} |
|
|
|
|
BoardCommand::Noop => {} |
|
|
|
|
} |
|
|
|
|