Code: Select all
(defun calc-sq-sq-dir (my-sq0-index my-sq1-index)
"Calculate the direction from the first square to the second square."
(let
(
(result nil)
(f-delta (- (map-sq-to-file my-sq1-index) (map-sq-to-file my-sq0-index)))
(r-delta (- (map-sq-to-rank my-sq1-index) (map-sq-to-rank my-sq0-index)))
)
(cond
((and (zerop f-delta) (zerop r-delta))
(setf result nil))
((and (plusp f-delta) (zerop r-delta))
(setf result dir-e))
((and (zerop f-delta) (plusp r-delta))
(setf result dir-n))
((and (minusp f-delta) (zerop r-delta))
(setf result dir-w))
((and (zerop f-delta) (minusp r-delta))
(setf result dir-s))
((and (= f-delta r-delta) (plusp f-delta))
(setf result dir-ne))
((and (= f-delta (- r-delta)) (minusp f-delta))
(setf result dir-nw))
((and (= f-delta r-delta) (minusp f-delta))
(setf result dir-sw))
((and (= f-delta (- r-delta)) (plusp f-delta))
(setf result dir-se))
((and (= f-delta file-delta-ene) (= r-delta rank-delta-ene))
(setf result dir-ene))
((and (= f-delta file-delta-nne) (= r-delta rank-delta-nne))
(setf result dir-nne))
((and (= f-delta file-delta-nnw) (= r-delta rank-delta-nnw))
(setf result dir-nnw))
((and (= f-delta file-delta-wnw) (= r-delta rank-delta-wnw))
(setf result dir-wnw))
((and (= f-delta file-delta-wsw) (= r-delta rank-delta-wsw))
(setf result dir-wsw))
((and (= f-delta file-delta-ssw) (= r-delta rank-delta-ssw))
(setf result dir-ssw))
((and (= f-delta file-delta-sse) (= r-delta rank-delta-sse))
(setf result dir-sse))
((and (= f-delta file-delta-ese) (= r-delta rank-delta-ese))
(setf result dir-ese))
(t
(setf result nil)))
result))
(defun initialize-sq-sq-dir-vec ()
"Calculate the initial value of the intersquare direction array."
(let ((result (make-array (list sq-limit sq-limit))))
(dotimes (sq0-index sq-limit)
(dotimes (sq1-index sq-limit)
(setf (aref result sq0-index sq1-index)
(calc-sq-sq-dir sq0-index sq1-index))))
result))
(defconstant sq-sq-dir-vec (initialize-sq-sq-dir-vec))