now it can turn left as well as right

main
Daniel Barlow 2023-01-22 18:06:41 +00:00
parent 78484b1115
commit e746bb514e
1 changed files with 11 additions and 1 deletions

View File

@ -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}))