Some serialisers to make pretty outputs
I can now use this package for a console application since we can pretty print cards.
This commit is contained in:
29
model.lisp
29
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~^, ~}")))
|
||||
|
||||
@@ -41,7 +41,9 @@
|
||||
:int->suit :int->rank :int->card
|
||||
:suit->int :rank->int :card->int
|
||||
;; Comparators
|
||||
:suit< :rank< :card<))
|
||||
:suit< :rank< :card<
|
||||
;; Serialisers
|
||||
:suit->str :rank->str :card->str :cardset->str))
|
||||
|
||||
(defpackage cantedraw.main
|
||||
(:use :cl :cantedraw.lib.macros :cantedraw.lib.functions)
|
||||
|
||||
Reference in New Issue
Block a user