From b26c06fff326f61fa1d0885c5d5ff4bac77e3329 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 24 Feb 2025 23:37:01 +0000 Subject: Make suit->int and int->suit complete inverses --- src/model.lisp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/model.lisp b/src/model.lisp index 002e4f9..6a3cbaf 100644 --- a/src/model.lisp +++ b/src/model.lisp @@ -45,13 +45,13 @@ (3 :Spades) (t :Joker))) -(fn suit->int (item) (-> (suit) (integer 0 4)) +(fn suit->int (item) (-> (suit) (integer 0 52)) (case item (:Diamonds 0) - (:Clubs 1) - (:Hearts 2) - (:Spades 3) - (t 4))) + (:Clubs 13) + (:Hearts 26) + (:Spades 39) + (t 52))) (fn int->rank (n) (-> (fixnum) rank) (let ((n (mod n 13))) @@ -74,13 +74,11 @@ (make-card :rank (int->rank num) :suit (int->suit num))) -(fn card->int (card) (-> (card) int-card) +(fn card->int (card) (-> (card) fixnum) (with-slots ((rank rank) (suit suit)) card (let ((rank (rank->int rank)) (suit (suit->int suit))) - (->> suit - (* 13) - (+ rank))))) + (+ rank suit)))) (fn suit< (s1 s2) (-> (suit suit) boolean) (< (suit->int s1) (suit->int s2))) -- cgit v1.2.3-13-gbd6f