Deck and joker constructor
Joker constructor takes a rank for uniqueness - rank doesn't really change anything in terms of the "power" of a joker but helps with ensuring jokers are unique in a deck. Deck constructor takes an optional argument for the number of decks. A deck includes two jokers, so n decks include 2n jokers.
This commit is contained in:
14
model.lisp
14
model.lisp
@@ -118,3 +118,17 @@
|
|||||||
(->> cardset
|
(->> cardset
|
||||||
(mapcar #'card->str)
|
(mapcar #'card->str)
|
||||||
(format nil "~{~a~^, ~}")))
|
(format nil "~{~a~^, ~}")))
|
||||||
|
|
||||||
|
(fn make-joker (&optional (rank :ACE)) (-> (&optional rank) card)
|
||||||
|
(cons rank :Joker))
|
||||||
|
|
||||||
|
(fn make-deck (&optional (n 1)) (-> (&optional fixnum) cardset)
|
||||||
|
(append
|
||||||
|
(loop :for i :from 1 :to n
|
||||||
|
:nconc (loop :for j :from 1 :to 52
|
||||||
|
collect (int->card (1- j))))
|
||||||
|
(loop :for i :from 1 :to n
|
||||||
|
:collect (->> i
|
||||||
|
1-
|
||||||
|
int->rank
|
||||||
|
make-joker))))
|
||||||
|
|||||||
@@ -43,7 +43,9 @@
|
|||||||
;; Comparators
|
;; Comparators
|
||||||
:suit< :rank< :card<
|
:suit< :rank< :card<
|
||||||
;; Serialisers
|
;; Serialisers
|
||||||
:suit->str :rank->str :card->str :cardset->str))
|
:suit->str :rank->str :card->str :cardset->str
|
||||||
|
;; Constructors
|
||||||
|
:make-joker :make-deck))
|
||||||
|
|
||||||
(defpackage cantedraw.main
|
(defpackage cantedraw.main
|
||||||
(:use :cl :cantedraw.lib.macros :cantedraw.lib.functions)
|
(:use :cl :cantedraw.lib.macros :cantedraw.lib.functions)
|
||||||
|
|||||||
Reference in New Issue
Block a user