Merge branch 'create_hash_map' into 'master'

function to create hash map from Vec<Robot>

See merge request mhart/DancingDroids!42
This commit is contained in:
Martin HART 2020-10-31 18:09:36 +01:00
commit 8cd7fdee02
1 changed files with 8 additions and 0 deletions

View File

@ -41,6 +41,12 @@ fn check_collisions(r: &robot::Robot, h: &HashMap<robot::Position, u32>) -> Resu
}
}
fn create_hash_map(pool: &Vec<robot::Robot>, hash: &mut HashMap<robot::Position, u32>) {
for r in pool {
hash.insert(robot::Position { x: r.p.x, y: r.p.y }, r.id);
}
}
/// Parse the config file, generate the world and robot pool.
fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::World, String> {
let mut lines = conf.lines();
@ -209,6 +215,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut robot_pool: Vec<robot::Robot> = Vec::new();
let world: world::World = parse_config(raw_conf, &mut robot_pool)?;
let mut hash: HashMap<robot::Position, u32> = HashMap::new();
create_hash_map(&robot_pool, &mut hash);
Ok(())
}