function to check collisions at given position

This commit is contained in:
EliasCubz 2020-10-29 10:30:11 +01:00
parent d35da41c90
commit e4b25281f7
1 changed files with 14 additions and 1 deletions

View File

@ -14,6 +14,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
use clap::{App, Arg}; use clap::{App, Arg};
use std::collections::HashMap;
use std::fs; use std::fs;
use std::io; use std::io;
@ -28,7 +29,19 @@ fn check_map(r: &robot::Robot, w: &world::World) -> Result<(), String> {
Ok(()) Ok(())
} }
} }
fn check_collisions(
r: &robot::Robot,
w: &world::World,
h: HashMap<&robot::Position, &u32>,
) -> Result<(), String> {
match h.get(&r.p) {
Some(&x) => Err(format!(
"The robot id: {} collided with robot id: {} in position: ({};{}).",
&r.id, x, &r.p.x, &r.p.y
)),
None => Ok(()),
}
}
/// 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, &'static str> { fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::World, &'static str> {
let mut lines = conf.lines(); let mut lines = conf.lines();