From 2eaf624137247baff9b08bc5a47bd455bafd4bef Mon Sep 17 00:00:00 2001 From: EliasCubz Date: Thu, 29 Oct 2020 10:05:54 +0100 Subject: [PATCH] function to check if robot is in the map --- src/main.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3ee6291..62906d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, -) -> 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) -> Result { let mut lines = conf.lines();