function to check if robot is in the map

This commit is contained in:
EliasCubz 2020-10-29 10:05:54 +01:00
parent 4fc0f07e78
commit 2eaf624137
1 changed files with 8 additions and 6 deletions

View File

@ -20,13 +20,15 @@ use std::io;
mod robot;
mod world;
fn check_map(r: &robot::Robot, w: &world::World) -> Result<(), &'static str> {}
fn check_collisions(
w: &world::World,
r: &robot::Robot,
h: &collection::HashMap<robot::Position, u32>,
) -> Result<(), &'static str> {
/// Check if the robot is in the map.
fn check_map(r: &robot::Robot, w: &world::World) -> Result<(), String> {
if (r.p.x, r.p.y) < (0, 0) && (r.p.x, r.p.y) > (w.x, w.y) {
Err(format!("The robot {} is off map", r.id))
} else {
Ok(())
}
}
/// Parse the config file, generate the world and robot pool.
fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::World, &'static str> {
let mut lines = conf.lines();