aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-02-14 23:27:06 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-02-14 23:27:06 +0000
commitd4e8f66c8bed16245328a010e55541d6265af5e0 (patch)
treef1717ec5397a24c0cc09f13d5a34b28155f7b718 /src
parent350221cfb0019d03b3ad4d78c9c443f890080c03 (diff)
downloadcantedraw-d4e8f66c8bed16245328a010e55541d6265af5e0.tar.gz
cantedraw-d4e8f66c8bed16245328a010e55541d6265af5e0.tar.bz2
cantedraw-d4e8f66c8bed16245328a010e55541d6265af5e0.zip
Implement a read -> redeal -> print loop
Like REPL stands for Read -> Evaluate -> Print -> Loop, here we implement a similar loop which reads a set of indices for cards to remove from the user, redeals those cards then loops back. This keeps happening until either: - the user does not want to redeal (empty input) - there aren't enough cards for a redeal
Diffstat (limited to 'src')
-rw-r--r--src/main.lisp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main.lisp b/src/main.lisp
index 422beab..8a0631d 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -62,6 +62,24 @@
(->> (make-deck)
alexandria:shuffle
(split 5)))
+(defun print-hand (hand)
+ (->> hand cardset->str (format t "Hand=[~a]~%")))
+
+(defun read-redeal-print (hand deck)
+ (cond
+ ((<= (length deck) 5)
+ (cons hand deck))
+ ((null hand)
+ (destructuring-bind ((hand) . deck) (deal-hands 1 deck)
+ (print-hand hand)
+ (read-redeal-print hand deck)))
+ (t
+ (let ((indices (read-until-valid-integers)))
+ (if (null indices)
+ (cons hand deck)
+ (destructuring-bind (hand . deck) (redeal-hand hand indices deck)
+ (print-hand hand)
+ (read-redeal-print hand deck)))))))
(defun start ()
(setf *random-state* (make-random-state t))