|
- (in-package #:subdecadence.utilities)
-
- ;;; base-deck is the unshuffled deck
- ;;; ♣ / C = Mj+
- ;;; ♠ / S = Mj-
- ;;; ♥ / H = Mn+
- ;;; ♦ / D = Mn-
-
- (defvar +base-deck+
- '("0♠" "0♣" "0♥" "0♦"
- "1♠" "1♣" "1♥" "1♦"
- "2♠" "2♣" "2♥" "2♦"
- "3♠" "3♣" "3♥" "3♦"
- "4♠" "4♣" "4♥" "4♦"
- "5♠" "5♣" "5♥" "5♦"
- "6♠" "6♣" "6♥" "6♦"
- "7♠" "7♣" "7♥" "7♦"
- "8♠" "8♣" "8♥" "8♦"
- "9♠" "9♣" "9♥" "9♦"))
-
- (defun remove-nth (seq n)
- "Remove the n-th element from the sequence `seq', returns a new sequence with the desired result, the function doesnt modify `seq'"
- (unless (typep seq 'list) (error "Type error: seq must be a sequence."))
- (unless (typep n 'fixnum) (error "Type error: n must be a fixnum."))
- (remove-if #'identity seq :start n :count 1))
-
- (defun strip-suit (card)
- (unless (typep card 'string) (error "Type error: card must be a string."))
- "Return the integer at the beginning of a card."
- (parse-integer (subseq card 0 1)))
-
- (defun diff (x y)
- (unless (typep x 'fixnum) (error "Type error: x must be a fixnum."))
- (unless (typep y 'fixnum) (error "Type error: y must be a fixnum."))
- (abs (- x y)))
-
- (defun display-cross (set)
- "Display 5 elements in Atlantean cross."
- (unless (typep set 'list) (error "Type error: set must be a list."))
- (format t "
-
- ~A
-
- ~A ~A
-
- ~A
-
- ~A
-
- "
- (elt set 3)
- (elt set 2)
- (elt set 1)
- (elt set 0)
- (elt set 4)))
-
- (defun shuffle (deck)
- "Shuffle a list."
- (unless (typep deck 'list) (error "Type error: deck must be a list."))
- (loop for i from (length deck) downto 2
- do (rotatef (elt deck (random i (make-random-state t)))
- (elt deck (1- i))))
- deck)
|