function to create hash map from Vec<Robot>

This commit is contained in:
Volodymyr Patuta 2020-10-31 18:05:23 +01:00
parent d0106b4d08
commit 8039d1c21f
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. /// Parse the config file, generate the world and robot pool.
fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::World, String> { fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::World, String> {
let mut lines = conf.lines(); 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 mut robot_pool: Vec<robot::Robot> = Vec::new();
let world: world::World = parse_config(raw_conf, &mut robot_pool)?; 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(()) Ok(())
} }