Merge branch 'queues' into 'master'

Queues

See merge request mhart/DancingDroids!23
This commit is contained in:
Martin HART 2020-10-20 17:01:09 +02:00
commit 08557961a1
2 changed files with 11 additions and 4 deletions

View File

@ -8,3 +8,4 @@ edition = "2018"
[dependencies]
clap = "2.33.3"
queues = "1.1.0"

View File

@ -1,4 +1,5 @@
use clap::{App, Arg};
use queues::*;
use std::fs;
use std::io;
@ -23,6 +24,10 @@ impl World {
Orientation::W => '←',
}
}
/// Check if a position is free.
fn empty_position(&mut self, p: Position) -> bool {
self.map[(p.x * p.y) as usize] == '.'
}
}
/// Struct to store robot position.
@ -37,6 +42,7 @@ struct Robot {
id: u32,
o: Orientation,
p: Position,
q: Queue<char>,
}
impl Robot {
@ -68,19 +74,19 @@ impl Robot {
}
}
/// Apply North orientation to the robot.
fn to_north(&mut self) {
fn turn_north(&mut self) {
self.o = Orientation::N
}
/// Apply South orientation to the robot.
fn to_south(&mut self) {
fn turn_south(&mut self) {
self.o = Orientation::S
}
/// Apply East orientation to the robot.
fn to_east(&mut self) {
fn turn_east(&mut self) {
self.o = Orientation::E
}
/// Apply West orientation to the robot.
fn to_west(&mut self) {
fn turn_west(&mut self) {
self.o = Orientation::W
}
}