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:
commit
8cd7fdee02
@ -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(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user