Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun make-piece (x y dirs signatures)
- "The basic method to create a piece."
- (when (or (null dirs) (eql dirs :all)) ;; default value
- (setf dirs *all-dirs*))
- (let (final-list)
- (macrolet ((push-destination-when (direction x y)
- `(when ,direction
- (push (make-instance 'destination
- :x ,x :y ,y
- :signature (or signatures (list :move :capture))) final-list))))
- (destructuring-bind (&key n e s w ne se sw nw nne ene ese sse ssw wsw wnw nnw)
- (loop for i in dirs collect i collect t)
- ; This converts the directions list into a plist
- ; so I can refer to them individually below
- (cond ((= 0 x y) (push-destination-when t 0 0)) ;; Zero case
- ((and (or (zerop x) (zerop y))
- (not (and (zerop x) (zerop y))))
- ;; Orthogonal case
- (let ((length (max x y)))
- (push-destination-when n length 0)
- (push-destination-when e 0 length)
- (push-destination-when s 0 (- length))
- (push-destination-when w (- length) 0)))
- ((and (= x y) (not (zerop x)) (not (zerop y)))
- ;; Diagonal case
- (push-destination-when ne x x)
- (push-destination-when se x (- x))
- (push-destination-when sw (- x) (- x))
- (push-destination-when nw (- x) x))
- (t
- ;; Hippogonal case
- (let ((max (max x y)) (min (min x y))
- (-max (- (max x y))) (-min (- (min x y))))
- (push-destination-when nne min max)
- (push-destination-when ene max min)
- (push-destination-when ese max -min)
- (push-destination-when sse min -max)
- (push-destination-when ssw -min -max)
- (push-destination-when wsw -max -min)
- (push-destination-when wnw -max min)
- (push-destination-when nnw -min max))))))
- final-list))
Advertisement
Add Comment
Please, Sign In to add comment