working 0.3.0
This commit is contained in:
parent
72097bc702
commit
4414478771
@ -2,4 +2,4 @@ World = { HeaderWorld ~ NEWLINE+ ~ Robot+ }
|
|||||||
HeaderWorld = { ASCII_DIGIT+ ~ " " ~ ASCII_DIGIT+ }
|
HeaderWorld = { ASCII_DIGIT+ ~ " " ~ ASCII_DIGIT+ }
|
||||||
Robot = { HeaderRobot ~ NEWLINE ~ Instructions ~ NEWLINE+ }
|
Robot = { HeaderRobot ~ NEWLINE ~ Instructions ~ NEWLINE+ }
|
||||||
HeaderRobot = { ASCII_DIGIT+ ~ " " ~ ASCII_DIGIT+ ~ " " ~ ("S" | "N" | "W" | "E") }
|
HeaderRobot = { ASCII_DIGIT+ ~ " " ~ ASCII_DIGIT+ ~ " " ~ ("S" | "N" | "W" | "E") }
|
||||||
Instructions = { ("F" | "L" | "R")+ }
|
Instructions = { (("F" | "L" | "R")+) | "" }
|
||||||
|
15
src/main.rs
15
src/main.rs
@ -113,10 +113,17 @@ fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::Wor
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
Rule::Instructions => {
|
Rule::Instructions => {
|
||||||
let instructions = inner_robot.as_str();
|
if !(inner_robot.as_str() == "") {
|
||||||
vinst.push(robot::instructions_from_string(
|
let instructions = inner_robot.as_str();
|
||||||
instructions.chars().rev().collect::<String>(),
|
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(
|
let r = robot::Robot::new(
|
||||||
id,
|
id,
|
||||||
vor.pop().unwrap(),
|
vor.pop().unwrap(),
|
||||||
|
@ -116,7 +116,7 @@ pub struct Position {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Generate random instructions.
|
/// Generate random instructions.
|
||||||
fn gen_random_instructions() -> String {
|
pub fn gen_random_instructions() -> String {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let n = rng.gen_range(5, 10);
|
let n = rng.gen_range(5, 10);
|
||||||
let mut instructions = String::with_capacity(n);
|
let mut instructions = String::with_capacity(n);
|
||||||
|
Loading…
Reference in New Issue
Block a user