38 lines
931 B
Plaintext
38 lines
931 B
Plaintext
(prop &mut x 0)
|
|
(prop &mut y 0)
|
|
// 0 is east
|
|
// 1 is south
|
|
// 2 is west
|
|
// 3 is north
|
|
(prop &mut facing 0)
|
|
|
|
(function fixFacing [f]
|
|
(Math.floor (% (if (> 0 f) (+ 4 f) f) 4)))
|
|
|
|
(method N [num]
|
|
(set y (+ y num)))
|
|
(method S [num]
|
|
(set y (- y num)))
|
|
(method E [num]
|
|
(set x (+ x num)))
|
|
(method W [num]
|
|
(set x (- x num)))
|
|
(method R [angle]
|
|
(set facing (fixFacing (+ facing (/ angle 90)))))
|
|
(method L [angle]
|
|
(set facing (fixFacing (- facing (/ angle 90)))))
|
|
(method F [num]
|
|
(case facing
|
|
(0 (E num))
|
|
(1 (S num))
|
|
(2 (W num))
|
|
(3 (N num))
|
|
(otherwise (throw (+ "Bad facing" facing)))))
|
|
|
|
(defReaderMacro "" [stream &builder b]
|
|
(stream.dropWhitespace)
|
|
(if (stream.isEmpty)
|
|
null
|
|
`(,(b.symbol (stream.expect "a ship command" ->(stream.takeChars 1)))
|
|
,(b.symbol (stream.expect "a number argument" ->(stream.takeUntilAndDrop "\n"))))))
|