Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun determine-board-size (piece &key (min-size '((-2 -2) (2 2))) (squarep t) (extra-space 1) (rider-min-iteration 2))
- (labels ((digest-macromoves (macromove)
- ;; (:then then-args piece*)
- (flet ((finite-range-p (args)
- (and (getf args :range)
- (numberp (getf (getf args :range) :distance)))))
- (loop for (x y . args) in (nthcdr 2 macromove)
- sum (if (finite-range-p args)
- (* (getf (getf args :range) :distance) x)
- x) into total-x
- sum (if (finite-range-p args)
- (* (getf (getf args :range) :distance) y)
- y) into total-y
- finally (return (list total-x total-y)))))
- (digest-ranges (range)
- (destructuring-bind (x y &key range &allow-other-keys) range
- (let ((max-distance (getf range :distance)))
- (if (numberp max-distance) ; i.e. the range is finite
- (list (* max-distance x) (* max-distance y))
- (list (* rider-min-iteration x) (* rider-min-iteration y))))))
- ; show at least that many iterations
- (digest-dest (dest)
- (cond ((eql (first dest) :then) (digest-macromoves dest))
- ((getf (cddr dest) :range) (digest-ranges dest))
- (t dest))))
- (loop for dest in piece
- maximize (first (digest-dest dest)) into max-x
- minimize (first (digest-dest dest)) into min-x
- maximize (second (digest-dest dest)) into max-y
- minimize (second (digest-dest dest)) into min-y
- finally (return
- (destructuring-bind ((given-min-x given-min-y) (given-max-x given-max-y))
- (if min-size min-size '((0 0) (0 0)))
- (let ((max-x-pad (max given-max-x (+ max-x extra-space)))
- (min-x-pad (min given-min-x (- min-x extra-space)))
- (max-y-pad (max given-max-y (+ max-y extra-space)))
- (min-y-pad (min given-min-y (- min-y extra-space))))
- (if squarep
- (let ((square-all (max (abs (max max-x-pad max-y-pad))
- (abs (min min-x-pad min-y-pad)))))
- (list (list (- square-all) (- square-all))
- (list square-all square-all)))
- (list (list min-x-pad min-y-pad)
- (list max-x-pad max-y-pad)))))))))
Advertisement
Add Comment
Please, Sign In to add comment