separate turn-left and turn-right functions
This commit is contained in:
parent
e746bb514e
commit
94325e53a0
37
rover.fnl
37
rover.fnl
@ -13,22 +13,23 @@
|
|||||||
:actual actual#
|
:actual actual#
|
||||||
})))))
|
})))))
|
||||||
|
|
||||||
(fn rotate [direction rotation]
|
(fn turn-left [direction]
|
||||||
(let [chooser
|
(-> {
|
||||||
(match rotation
|
:n :w
|
||||||
:r {
|
:w :s
|
||||||
:n :e
|
:s :e
|
||||||
:e :s
|
:e :n
|
||||||
:s :w
|
}
|
||||||
:w :n
|
(. direction)))
|
||||||
}
|
|
||||||
:l {
|
(fn turn-right [direction]
|
||||||
:n :w
|
(-> {
|
||||||
:w :s
|
:n :e
|
||||||
:s :e
|
:e :s
|
||||||
:e :n
|
:s :w
|
||||||
})]
|
:w :n
|
||||||
(. chooser direction)))
|
}
|
||||||
|
(. direction)))
|
||||||
|
|
||||||
|
|
||||||
(fn command [rover string]
|
(fn command [rover string]
|
||||||
@ -38,8 +39,8 @@
|
|||||||
:s (merge rover {:y (- rover.y 1)})
|
:s (merge rover {:y (- rover.y 1)})
|
||||||
: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 (turn-right rover.direction)})
|
||||||
:l (merge rover {:direction (rotate rover.direction :l)})
|
:l (merge rover {:direction (turn-left rover.direction)})
|
||||||
_ (assert false (. "unrecognised command " string))))
|
_ (assert false (. "unrecognised command " string))))
|
||||||
|
|
||||||
(fn execute [rover [cmd & cmds]]
|
(fn execute [rover [cmd & cmds]]
|
||||||
|
Loading…
Reference in New Issue
Block a user