Neither routine actually generates moves. Instead, each routine returns a list telling the caller which moves need to be generated.
Code: Select all
;;; Castling list determination
(defun calc-castling-list (my-pos)
  "Return a list of available castlings; works only for the current active color."
  (let ((result nil))
    (dolist (castling (svref mc-color-to-castling-list-vec (pos-act-color my-pos)))
      (when
        (and
          (logbit? castling (pos-castbits my-pos))
          (bb-ni2? (pos-loc-merge-bb my-pos) (svref castling-vacant-bb-vec castling))
          (bb-ni2?
            (svref (pos-atk-by-color-bb-vec my-pos) (pos-pas-color my-pos))
            (svref castling-attack-bb-vec castling)))
        (push castling result)))
    result))
Code: Select all
;;; Pawn capture target square list construction
(defun calc-pc-sqs (my-act-color my-fr-sq my-rstrct-dir my-pas-loc-bb)
  "Return a list of pawn capture target squares; works only for the current active color."
  (let ((result nil) (e-capt-sq nil) (w-capt-sq nil) (fr-file (map-sq-to-file my-fr-sq)))
    (if (= my-act-color color-white)
      (progn
        (when (and (< fr-file file-h) (or (not my-rstrct-dir) (= my-rstrct-dir dir-ne)))
          (setf e-capt-sq (+ my-fr-sq delta-ne))
          (when (sq-set? my-pas-loc-bb e-capt-sq)
            (push e-capt-sq result)))
        (when (and (> fr-file file-a) (or (not my-rstrct-dir) (= my-rstrct-dir dir-nw)))
          (setf w-capt-sq (+ my-fr-sq delta-nw))
          (when (sq-set? my-pas-loc-bb w-capt-sq)
            (push w-capt-sq result))))
      (progn
        (when (and (< fr-file file-h) (or (not my-rstrct-dir) (= my-rstrct-dir dir-se)))
          (setf e-capt-sq (+ my-fr-sq delta-se))
          (when (sq-set? my-pas-loc-bb e-capt-sq)
            (push e-capt-sq result)))
        (when (and (> fr-file file-a) (or (not my-rstrct-dir) (= my-rstrct-dir dir-sw)))
          (setf w-capt-sq (+ my-fr-sq delta-sw))
          (when (sq-set? my-pas-loc-bb w-capt-sq)
            (push w-capt-sq result)))))
    result))
