HomeAboutCodePastes

Paste on 2021-04-24T15:49:25

(defpackage :cards (:use :cl)
            (:export card
                     card-value
                     card-suit
                     card<
                     card>
                     card=
                     make-hand
                     ))

(in-package :cards)

(defclass card ()
  ((value
    :initarg :value
    :reader %card-value)
   (suit
    :initarg :suit
    :reader card-suit)))

(defun card (lst)
  (destructuring-bind (value suit) lst
      (make-instance 'card
                     :value (case value
                              ((J) 11)
                              ((Q) 12)
                              ((K) 13)
                              ((A) 14)
                              (t value))
                     :suit suit)))

(defmethod card-value ((c card))
  (let ((v (%card-value c)))
    (case v
      ((11) 'J)
      ((12) 'Q)
      ((13) 'K)
      ((14) 'A)
      (t v))))

plain