aboutsummaryrefslogtreecommitdiff
path: root/model.lisp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-02-14 17:24:35 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-02-14 17:24:35 +0000
commite5a53957b3c91510d1f06ed54121231e3c94a86b (patch)
tree1da33aac141e0bdfe253f7cad806a20b6fec9b81 /model.lisp
parent9ab585d7affcfde2c48c6b52cb2d73953e95d428 (diff)
downloadcantedraw-e5a53957b3c91510d1f06ed54121231e3c94a86b.tar.gz
cantedraw-e5a53957b3c91510d1f06ed54121231e3c94a86b.tar.bz2
cantedraw-e5a53957b3c91510d1f06ed54121231e3c94a86b.zip
Some serialisers to make pretty outputs
I can now use this package for a console application since we can pretty print cards.
Diffstat (limited to 'model.lisp')
-rw-r--r--model.lisp29
1 files changed, 29 insertions, 0 deletions
diff --git a/model.lisp b/model.lisp
index 068844b..019e881 100644
--- a/model.lisp
+++ b/model.lisp
@@ -88,3 +88,32 @@
(if (eq r1 r2)
(suit< s1 s2)
(rank< r1 r2))))
+
+(fn suit->str (suit) (-> (suit) string)
+ (case suit
+ (:Diamonds "◆")
+ (:Clubs "♣")
+ (:Hearts "♥")
+ (:Spades "♠")
+ (t "Joker")))
+
+(fn rank->str (rank) (-> (rank) string)
+ (case rank
+ (:Ace "Ace")
+ (:Jack "Jack")
+ (:Queen "Queen")
+ (:King "King")
+ (t (format nil "~a" rank))))
+
+(fn card->str (card) (-> (card) string)
+ (destructuring-bind (rank . suit) card
+ (if (eq suit :Joker)
+ "Joker"
+ (format nil "~a[~a]"
+ (rank->str rank)
+ (suit->str suit)))))
+
+(fn cardset->str (cardset) (-> (cardset) string)
+ (->> cardset
+ (mapcar #'card->str)
+ (format nil "~{~a~^, ~}")))