aboutsummaryrefslogtreecommitdiff
path: root/main.lisp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-02-14 20:53:44 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-02-14 20:53:44 +0000
commitf0e7c9f3f07b57a8a02191ea0a8d86432ab0ebea (patch)
treeab5228affb674a6311495d1a43c3b8e8d55edd3a /main.lisp
parentd328bfbbdf0f9853ec600d71c4372e843dcdbf8f (diff)
downloadcantedraw-f0e7c9f3f07b57a8a02191ea0a8d86432ab0ebea.tar.gz
cantedraw-f0e7c9f3f07b57a8a02191ea0a8d86432ab0ebea.tar.bz2
cantedraw-f0e7c9f3f07b57a8a02191ea0a8d86432ab0ebea.zip
WIP: Making a simple re-deal program.
Gives a hand from a shuffled deck to the user, asks them to provide indices for cards they wish to re-deal then does so.
Diffstat (limited to 'main.lisp')
-rw-r--r--main.lisp27
1 files changed, 22 insertions, 5 deletions
diff --git a/main.lisp b/main.lisp
index 2bd3102..53d9bec 100644
--- a/main.lisp
+++ b/main.lisp
@@ -32,7 +32,8 @@
(remove-if #'null)))
(fn read-integers () (-> nil list)
- (->> (read-input "Enter numbers: ")
+ (->> "Enter numbers: "
+ read-input
parse-integers))
(fn read-until-integers () (-> nil list)
@@ -43,8 +44,24 @@
(setq inp (read-integers)))
inp))
+(fn is-valid-hand-index (n) (-> (fixnum) boolean)
+ (and (< n 5)
+ (>= n 0)))
+
+(fn read-until-valid-integers () (-> nil list)
+ (let ((inp (remove-duplicates (read-integers))))
+ (while (not (every #'is-valid-hand-index inp))
+ (format t "Need at most 5 integers between 0 and 4...~%")
+ (force-output)
+ (setq inp (remove-duplicates (read-integers))))))
+
+(defun generate-hand ()
+ (->> (make-deck)
+ alexandria:shuffle
+ (split 5)))
+
(defun start ()
- (--> var
- (read-until-integers)
- (cons '+ var)
- (format t "~a = ~a~%" var (eval var))))
+ (destructuring-bind (hand . rest) (generate-hand)
+ (declare (ignore rest))
+ (->> hand cardset->str (format t "Hand=[~a]~%"))
+ (force-output)))