Refactoring
This commit is contained in:
parent
45c76e18c7
commit
21fa869081
|
@ -62,8 +62,7 @@ impl DijkstraMap {
|
|||
/// depth is further than the current depth.
|
||||
/// WARNING: Will give incorrect results when used with non-uniform exit costs. Much slower
|
||||
/// algorithm required to support that.
|
||||
/// Automatically branches to a parallel version if you provide more than 4 starting points
|
||||
fn build(self: &mut DijkstraMap, map: &Map) {
|
||||
fn build(&mut self, map: &Map) {
|
||||
let mapsize: usize = (self.size_x * self.size_y) as usize;
|
||||
let mut open_list: VecDeque<((usize, usize), f32)> = VecDeque::with_capacity(mapsize);
|
||||
|
||||
|
|
|
@ -53,20 +53,17 @@ impl AreaStartingPosition {
|
|||
}
|
||||
|
||||
fn build(&self, map : &Map) -> Map {
|
||||
let seed_x;
|
||||
let seed_y;
|
||||
let seed_x = match self.x {
|
||||
XStart::LEFT => 1,
|
||||
XStart::CENTER => map.width / 2,
|
||||
XStart::RIGHT => map.width - 2
|
||||
};
|
||||
|
||||
match self.x {
|
||||
XStart::LEFT => seed_x = 1,
|
||||
XStart::CENTER => seed_x = map.width / 2,
|
||||
XStart::RIGHT => seed_x = map.width - 2
|
||||
}
|
||||
|
||||
match self.y {
|
||||
YStart::TOP => seed_y = 1,
|
||||
YStart::CENTER => seed_y = map.height / 2,
|
||||
YStart::BOTTOM => seed_y = map.height - 2
|
||||
}
|
||||
let seed_y = match self.y {
|
||||
YStart::TOP => 1,
|
||||
YStart::CENTER => map.height / 2,
|
||||
YStart::BOTTOM => map.height - 2
|
||||
};
|
||||
|
||||
let mut available_floors : Vec<(usize, f32)> = Vec::new();
|
||||
for (idx, tiletype) in map.tiles.iter().enumerate() {
|
||||
|
@ -94,3 +91,33 @@ impl AreaStartingPosition {
|
|||
new_map
|
||||
}
|
||||
}
|
||||
|
||||
/// ------------------------------------------------------------------------------------------------
|
||||
/// Module unit tests
|
||||
/// ------------------------------------------------------------------------------------------------
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use rand::prelude::*;
|
||||
use super::*;
|
||||
use super::MapFilter;
|
||||
use crate::geometry::Point;
|
||||
use crate::map::Map;
|
||||
|
||||
#[test]
|
||||
fn test_exit() {
|
||||
let map_str = "
|
||||
##########
|
||||
# ## #
|
||||
# # # #
|
||||
##########
|
||||
";
|
||||
let mut map = Map::from_string(map_str);
|
||||
map.starting_point = Some(Point::new(9, 2));
|
||||
|
||||
let modifier = AreaStartingPosition::new(XStart::CENTER, YStart::TOP);
|
||||
let mut rng = StdRng::seed_from_u64(0);
|
||||
let new_map = modifier.modify_map(&mut rng, &map);
|
||||
|
||||
assert_eq!(new_map.starting_point, Some(Point::new(6, 1)));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user