From 73232d2657c4fbf346f5c016fd7621ca5f521916 Mon Sep 17 00:00:00 2001 From: Volodymyr Patuta <6977238-fiplox@users.noreply.gitlab.com> Date: Sun, 1 Nov 2020 21:19:36 +0100 Subject: [PATCH] added some prints to correspond to the readme example --- src/main.rs | 2 ++ src/robot.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main.rs b/src/main.rs index 143631b..22feaca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -247,6 +247,8 @@ fn main() -> Result<(), Box> { let world: world::World = parse_config(raw_conf, &mut robot_pool)?; let mut hash: HashMap = HashMap::new(); create_hash_map(&robot_pool, &mut hash); + println!("World {{ x_max = {}; y_max = {} }}", world.x, world.y); + robot::print_robots(&robot_pool); println!("Initial state"); println!("=============="); display_grid(&world, &robot_pool, &hash); diff --git a/src/robot.rs b/src/robot.rs index 25edfc3..ad6552f 100644 --- a/src/robot.rs +++ b/src/robot.rs @@ -77,6 +77,27 @@ pub fn is_piouff(r: &Robot) -> bool { false } +/// Print robots id, position and instructions. +pub fn print_robots(robot_pool: &Vec) { + println!("Robots ["); + for r in robot_pool { + println!( + "{{ id = {}, x = {}; y = {}; orientation: {}, instructions: {:?}, }},", + r.id, + r.p.x, + r.p.y, + match r.o { + Orientation::N => "Norts", + Orientation::S => "South", + Orientation::E => "East", + Orientation::W => "West", + }, + r.i + ); + } + println!("]"); +} + #[cfg(test)] mod tests { use super::*;