From a4ac0dfe52e1859a8e722108c1e661941a3a1f10 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 22 Jan 2023 18:42:38 +0000 Subject: [PATCH] oops, forgot to implement backwards --- rover.fnl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rover.fnl b/rover.fnl index baa8753..869da9f 100644 --- a/rover.fnl +++ b/rover.fnl @@ -39,6 +39,11 @@ :s {:y (- rover.y 1)} :w {:x (- rover.x 1)} :e {:x (+ rover.x 1)}) + :b (match rover.direction + :n {:y (- rover.y 1)} + :s {:y (+ rover.y 1)} + :w {:x (+ rover.x 1)} + :e {:x (- rover.x 1)}) :r {:direction (turn-right rover.direction)} :l {:direction (turn-left rover.direction)} _ (assert false (. "unrecognised command " string))))) @@ -86,6 +91,14 @@ (execute r [:f :f :f]) {:x 1 :y -2 :direction :s})) +(let [r (rover 3 2 :s)] + (expect "Moves north when pointing south and asked to move backward" + (execute r [:b]) {:x 3 :y 3 :direction :s})) + +(let [r (rover 3 2 :e)] + (expect "Moves west when pointing east and asked to move backward" + (execute r [:b]) {:x 2 :y 2 :direction :e})) + (let [r (rover 2 4 :e)] (expect "Rotates to south when pointing east and asked to turn right" (execute r [:r]) {:x 2 :y 4 :direction :s}))