Merge branch 'display' into 'master'

added some prints to correspond to the readme example

See merge request mhart/DancingDroids!46
This commit is contained in:
Martin HART 2020-11-02 08:30:35 +01:00
commit 4f5fe016be
2 changed files with 23 additions and 0 deletions

View File

@ -247,6 +247,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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(); let mut hash: HashMap<robot::Position, u32> = HashMap::new();
create_hash_map(&robot_pool, &mut hash); 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!("Initial state");
println!("=============="); println!("==============");
display_grid(&world, &robot_pool, &hash); display_grid(&world, &robot_pool, &hash);

View File

@ -77,6 +77,27 @@ pub fn is_piouff(r: &Robot) -> bool {
false false
} }
/// Print robots id, position and instructions.
pub fn print_robots(robot_pool: &Vec<Robot>) {
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)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;