commit e746bb514ed11a8ecb75141a3ec444ad9648544c
parent 78484b11150a5113d211275532f28a6f53ada462
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 22 Jan 2023 18:06:41 +0000
now it can turn left as well as right
Diffstat:
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/rover.fnl b/rover.fnl
@@ -22,7 +22,12 @@
:s :w
:w :n
}
- )]
+ :l {
+ :n :w
+ :w :s
+ :s :e
+ :e :n
+ })]
(. chooser direction)))
@@ -34,6 +39,7 @@
:w (merge rover {:x (- rover.x 1)})
:e (merge rover {:x (+ rover.x 1)}))
:r (merge rover {:direction (rotate rover.direction :r)})
+ :l (merge rover {:direction (rotate rover.direction :l)})
_ (assert false (. "unrecognised command " string))))
(fn execute [rover [cmd & cmds]]
@@ -85,6 +91,10 @@
(expect "Rotates to south when pointing east and asked to turn right"
(r:execute [:r]) {:x 2 :y 4 :direction :s}))
+(let [r (rover 2 4 :s)]
+ (expect "Rotates to east when pointing south and asked to turn left"
+ (r:execute [:l]) {:x 2 :y 4 :direction :e}))
+
(let [r (rover 2 4 :w)]
(expect "Rotates to north when pointing west and asked to turn right"
(r:execute [:r]) {:x 2 :y 4 :direction :n}))