function to create hash map from Vec<Robot>
This commit is contained in:
parent
d0106b4d08
commit
8039d1c21f
@ -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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user