From 7ad8268c9f9167dd28e34b703cf762308d7d6242 Mon Sep 17 00:00:00 2001 From: Martin HART Date: Tue, 20 Oct 2020 15:15:56 +0200 Subject: [PATCH 1/4] Add queues to dependencies --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 863e846..740a020 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ edition = "2018" [dependencies] clap = "2.33.3" +queues = "1.1.0" From 2dba5a97216024174e2bcda22cc8e856d9e6b813 Mon Sep 17 00:00:00 2001 From: Martin HART Date: Tue, 20 Oct 2020 15:38:03 +0200 Subject: [PATCH 2/4] add queues to Robot --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index 54baa26..7076b93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use clap::{App, Arg}; +use queues::*; use std::fs; use std::io; @@ -37,6 +38,7 @@ struct Robot { id: u32, o: Orientation, p: Position, + q: Queue, } impl Robot { From 569a6eaf94c141c0e50048ff2262664e3703b361 Mon Sep 17 00:00:00 2001 From: Martin HART Date: Tue, 20 Oct 2020 16:00:26 +0200 Subject: [PATCH 3/4] Change to_ to turn_ --- src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7076b93..3652955 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,19 +70,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 } } From 67c292b9e233be71236befd99e9f1665317cb928 Mon Sep 17 00:00:00 2001 From: Martin HART Date: Tue, 20 Oct 2020 16:57:51 +0200 Subject: [PATCH 4/4] Add empty_position() --- src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.rs b/src/main.rs index 3652955..dd5a77a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,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.