commit a4ac0dfe52e1859a8e722108c1e661941a3a1f10
parent 67bfda490ee6315321d36a60e5463c42ca988497
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 22 Jan 2023 18:42:38 +0000
oops, forgot to implement backwards
Diffstat:
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git 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}))