A Subdecadence generator in Common Lisp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7KB

  1. (in-package #:subdecadence.utilities)
  2. ;;; base-deck is the unshuffled deck
  3. ;;; ♣ / C = Mj+
  4. ;;; ♠ / S = Mj-
  5. ;;; ♥ / H = Mn+
  6. ;;; ♦ / D = Mn-
  7. (defvar +base-deck+
  8. '("0♠" "0♣" "0♥" "0♦"
  9. "1♠" "1♣" "1♥" "1♦"
  10. "2♠" "2♣" "2♥" "2♦"
  11. "3♠" "3♣" "3♥" "3♦"
  12. "4♠" "4♣" "4♥" "4♦"
  13. "5♠" "5♣" "5♥" "5♦"
  14. "6♠" "6♣" "6♥" "6♦"
  15. "7♠" "7♣" "7♥" "7♦"
  16. "8♠" "8♣" "8♥" "8♦"
  17. "9♠" "9♣" "9♥" "9♦"))
  18. (defun remove-nth (seq n)
  19. "Remove the n-th element from the sequence `seq', returns a new sequence with the desired result, the function doesnt modify `seq'"
  20. (unless (typep seq 'list) (error "Type error: seq must be a sequence."))
  21. (unless (typep n 'fixnum) (error "Type error: n must be a fixnum."))
  22. (remove-if #'identity seq :start n :count 1))
  23. (defun strip-suit (card)
  24. (unless (typep card 'string) (error "Type error: card must be a string."))
  25. "Return the integer at the beginning of a card."
  26. (parse-integer (subseq card 0 1)))
  27. (defun diff (x y)
  28. (unless (typep x 'fixnum) (error "Type error: x must be a fixnum."))
  29. (unless (typep y 'fixnum) (error "Type error: y must be a fixnum."))
  30. (abs (- x y)))
  31. (defun display-cross (set)
  32. "Display 5 elements in Atlantean cross."
  33. (unless (typep set 'list) (error "Type error: set must be a list."))
  34. (format t "
  35. ~A
  36. ~A ~A
  37. ~A
  38. ~A
  39. "
  40. (elt set 3)
  41. (elt set 2)
  42. (elt set 1)
  43. (elt set 0)
  44. (elt set 4)))
  45. (defun shuffle (deck)
  46. "Shuffle a list."
  47. (unless (typep deck 'list) (error "Type error: deck must be a list."))
  48. (loop for i from (length deck) downto 2
  49. do (rotatef (elt deck (random i (make-random-state t)))
  50. (elt deck (1- i))))
  51. deck)