Shifting Positions
;;; Given a list of positions, apply the DIRECTION which
;;; is either LEFT (shift each to -1), RIGHT (shift each to +1)
;;; NEXT (shift to both +1 and -1), TO (do not shift). In
;;; each case make sure the shift doesn't produce an invalid
(defun apply-direction (direction positions)
(T (let* ((next-position (first positions))
(if (valid-position-p (- next-position 1))
(list (- next-position 1))
(if (valid-position-p (+ next-position 1))
(list (+ next-position 1) )
((and (valid-position-p (- next-position 1))
(valid-position-p (+ next-position 1)))
(list (- next-position 1) (+ next-position 1)))
((valid-position-p (- next-position 1))
(list (- next-position 1)))
((valid-position-p (+ next-position 1))
(list (+ next-position 1)))
(append new-positions (apply-direction direction (cdr positions)))))))