diff --git a/conf.pest b/conf.pest index 5ed23cc..cdad2d5 100644 --- a/conf.pest +++ b/conf.pest @@ -2,4 +2,4 @@ World = { HeaderWorld ~ NEWLINE+ ~ Robot+ } HeaderWorld = { ASCII_DIGIT+ ~ " " ~ ASCII_DIGIT+ } Robot = { HeaderRobot ~ NEWLINE ~ Instructions ~ NEWLINE+ } HeaderRobot = { ASCII_DIGIT+ ~ " " ~ ASCII_DIGIT+ ~ " " ~ ("S" | "N" | "W" | "E") } -Instructions = { ("F" | "L" | "R")+ } +Instructions = { (("F" | "L" | "R")+) | "" } diff --git a/src/main.rs b/src/main.rs index 843f0bd..aabe45f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -113,10 +113,17 @@ fn parse_config(conf: String, pool: &mut Vec) -> Result { - let instructions = inner_robot.as_str(); - vinst.push(robot::instructions_from_string( - instructions.chars().rev().collect::(), - )?); + if !(inner_robot.as_str() == "") { + let instructions = inner_robot.as_str(); + vinst.push(robot::instructions_from_string( + instructions.chars().rev().collect::(), + )?); + } else { + let instructions = robot::gen_random_instructions(); + vinst.push(robot::instructions_from_string( + instructions.chars().rev().collect::(), + )?); + } let r = robot::Robot::new( id, vor.pop().unwrap(), diff --git a/src/robot.rs b/src/robot.rs index 33d787d..e48f571 100644 --- a/src/robot.rs +++ b/src/robot.rs @@ -116,7 +116,7 @@ pub struct Position { } /// Generate random instructions. -fn gen_random_instructions() -> String { +pub fn gen_random_instructions() -> String { let mut rng = rand::thread_rng(); let n = rng.gen_range(5, 10); let mut instructions = String::with_capacity(n);