working 0.3.0

This commit is contained in:
Volodymyr Patuta 2020-11-08 20:54:59 +01:00
parent 72097bc702
commit 4414478771
3 changed files with 13 additions and 6 deletions

View File

@ -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")+) | "" }

View File

@ -113,10 +113,17 @@ fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::Wor
})
}
Rule::Instructions => {
if !(inner_robot.as_str() == "") {
let instructions = inner_robot.as_str();
vinst.push(robot::instructions_from_string(
instructions.chars().rev().collect::<String>(),
)?);
} else {
let instructions = robot::gen_random_instructions();
vinst.push(robot::instructions_from_string(
instructions.chars().rev().collect::<String>(),
)?);
}
let r = robot::Robot::new(
id,
vor.pop().unwrap(),

View File

@ -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);