now it can turn left as well as right
This commit is contained in:
parent
78484b1115
commit
e746bb514e
12
rover.fnl
12
rover.fnl
@ -22,7 +22,12 @@
|
|||||||
:s :w
|
:s :w
|
||||||
:w :n
|
:w :n
|
||||||
}
|
}
|
||||||
)]
|
:l {
|
||||||
|
:n :w
|
||||||
|
:w :s
|
||||||
|
:s :e
|
||||||
|
:e :n
|
||||||
|
})]
|
||||||
(. chooser direction)))
|
(. chooser direction)))
|
||||||
|
|
||||||
|
|
||||||
@ -34,6 +39,7 @@
|
|||||||
:w (merge rover {:x (- rover.x 1)})
|
:w (merge rover {:x (- rover.x 1)})
|
||||||
:e (merge rover {:x (+ rover.x 1)}))
|
:e (merge rover {:x (+ rover.x 1)}))
|
||||||
:r (merge rover {:direction (rotate rover.direction :r)})
|
:r (merge rover {:direction (rotate rover.direction :r)})
|
||||||
|
:l (merge rover {:direction (rotate rover.direction :l)})
|
||||||
_ (assert false (. "unrecognised command " string))))
|
_ (assert false (. "unrecognised command " string))))
|
||||||
|
|
||||||
(fn execute [rover [cmd & cmds]]
|
(fn execute [rover [cmd & cmds]]
|
||||||
@ -85,6 +91,10 @@
|
|||||||
(expect "Rotates to south when pointing east and asked to turn right"
|
(expect "Rotates to south when pointing east and asked to turn right"
|
||||||
(r:execute [:r]) {:x 2 :y 4 :direction :s}))
|
(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)]
|
(let [r (rover 2 4 :w)]
|
||||||
(expect "Rotates to north when pointing west and asked to turn right"
|
(expect "Rotates to north when pointing west and asked to turn right"
|
||||||
(r:execute [:r]) {:x 2 :y 4 :direction :n}))
|
(r:execute [:r]) {:x 2 :y 4 :direction :n}))
|
||||||
|
Loading…
Reference in New Issue
Block a user