diff --git a/src/pilot.rs b/src/pilot.rs index 7925cf6..177b401 100644 --- a/src/pilot.rs +++ b/src/pilot.rs @@ -5,6 +5,7 @@ use std::io::prelude::*; pub struct Position { pub linear: i32, pub depth: i32, + aim: i32, } pub fn track_position(filename: &str) -> io::Result { @@ -13,6 +14,7 @@ pub fn track_position(filename: &str) -> io::Result { let mut pos = Position { linear: 0, depth: 0, + aim: 0, }; for line in buf.lines() { if let Ok(line) = line { @@ -23,12 +25,13 @@ pub fn track_position(filename: &str) -> io::Result { match op { "forward" => { pos.linear += value; + pos.depth += pos.aim * value; } "down" => { - pos.depth += value; + pos.aim += value; } "up" => { - pos.depth -= value; + pos.aim -= value; } _ => { eprintln!("Invalid operation: {}", op);