From 2e5f1363e6efff3daefee9fe6388be2332e6fb62 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Thu, 2 Nov 2017 05:51:32 -0500 Subject: -units now move respect impassable locations, syntax more uniform --- src/list.rs | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'src/list.rs') diff --git a/src/list.rs b/src/list.rs index d622d5c..23d23df 100644 --- a/src/list.rs +++ b/src/list.rs @@ -4,8 +4,8 @@ use character::Character; use location::Location; pub struct List{ - pub men : Vec, - impassable_locations : Vec, + pub men : Vec, + impassable_locations : Vec, } impl List { @@ -17,8 +17,8 @@ impl List { men.push(c); } List { - men : men, - impassable_locations : impassable_locations, + men : men, + impassable_locations : impassable_locations, } } @@ -33,30 +33,28 @@ impl List { fn get_free_locations(&mut self, location : Location) -> Vec { let mut potential_locations = Vec::new(); potential_locations.push(location.up()); + potential_locations.push(location.upleft()); + potential_locations.push(location.upright()); potential_locations.push(location.down()); + potential_locations.push(location.downleft()); + potential_locations.push(location.downright()); potential_locations.push(location.left()); potential_locations.push(location.right()); - let mut indexes = Vec::new(); - for man in self.men.iter() { - for (index, potential_location) in potential_locations.iter().enumerate() { + potential_locations.retain(|potential_location| { + let mut keep = true; + for man in self.men.iter() { if potential_location == &man.location { - indexes.push(index); + keep = false; } } - } - - for impassable_location in self.impassable_locations.iter() { - for (index, potential_location) in potential_locations.iter().enumerate() { + for impassable_location in self.impassable_locations.iter() { if potential_location == impassable_location { - indexes.push(index); + keep = false; } } - } - - //for index in indexes.iter() { - // potential_locations.remove(index); - //} + keep + }); potential_locations } -- cgit v1.2.3