Common lisp 检查列表中的元素是否相互高于或低于1

Common lisp 检查列表中的元素是否相互高于或低于1,common-lisp,Common Lisp,我正在制作一个LISP程序,模拟扑克游戏 目前,我通过以下方式订购给定的“手”: (defconstant order #(2 3 4 5 6 7 8 9 10 J Q K A)) (defun sort< (el1 el2) (< (position el1 order) (position el2 order))) 其中3是数字,H是西装(红心) 对于计算指针(如直线),我必须检查卡片是否为连续值 (poker '(8 H)(Q H)(9 H)(10 H)(J

我正在制作一个LISP程序,模拟扑克游戏

目前,我通过以下方式订购给定的“手”:

(defconstant order #(2 3 4 5 6 7 8 9 10 J Q K A))

(defun sort< (el1 el2)
  (< (position el1 order)
     (position el2 order)))
其中3是数字,H是西装(红心)

对于计算指针(如直线),我必须检查卡片是否为连续值

(poker '(8 H)(Q H)(9 H)(10 H)(J H))
例如,直插式

有没有干净的方法?
有什么方法可以使用常量顺序来实现这一点吗?

我将其分为“直”谓词和“齐平”谓词

(defun straightp (hand)
  (let ((sorted-hand (mapcar #'first (sort (copy-tree hand) #'card<))))
    (every (lambda (card0 card1)
             (= 1 (card-diff card1 card0)))
           sorted-hand
           (rest sorted-hand))))

(defun flushp (hand)
  (apply #'suite= hand))

(defun straight-flush-p (hand)
  (and (straightp hand)
       (flushp hand)))

(未测试)。

DEFPARAMETER用于全局变量。不要在DEFUN内部使用它。使用LET。
(poker '(8 H)(Q H)(9 H)(10 H)(J H))
(defun straightp (hand)
  (let ((sorted-hand (mapcar #'first (sort (copy-tree hand) #'card<))))
    (every (lambda (card0 card1)
             (= 1 (card-diff card1 card0)))
           sorted-hand
           (rest sorted-hand))))

(defun flushp (hand)
  (apply #'suite= hand))

(defun straight-flush-p (hand)
  (and (straightp hand)
       (flushp hand)))
(defconstant +card-values+
  #(2 3 4 5 6 7 8 9 10 J Q K A))

(defun card-value (card)
  (position (first card) +card-values+))

(defun card-diff (card0 card1)
  (- (card-value card0) (card-value card1)))

(defun card< (&rest cards)
  (apply #'< (mapcar #'card-value cards)))

(defun suite= (&rest cards)
  (if (endp (rest cards))
      t
      (let ((card-suites (mapcar #'second cards)))
        (every #'eql card-suites (rest card-suites)))))