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.
This commit is contained in:
2025-02-14 20:53:44 +00:00
parent d328bfbbdf
commit f0e7c9f3f0
3 changed files with 26 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
(asdf:defsystem :cantedraw
:depends-on (:alexandria)
:components ((:file "packages")
(:file "lib.macros")
(:file "lib.functions")

View File

@@ -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)))

View File

@@ -48,5 +48,7 @@
:make-joker :make-deck))
(defpackage cantedraw.main
(:use :cl :cantedraw.lib.macros :cantedraw.lib.functions)
(:use :cl
:cantedraw.lib.macros :cantedraw.lib.functions
:cantedraw.model)
(:export :start))