diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-02-14 23:42:13 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-02-14 23:42:13 +0000 |
commit | f00335d4576add4b84d927791107851d4bcd88b6 (patch) | |
tree | ef6c37ac824f75bbc40388c85b137836cbc45f01 /src/main.lisp | |
parent | ae68f3a8f022596db4c869f87c7110863f7be739 (diff) | |
download | cantedraw-f00335d4576add4b84d927791107851d4bcd88b6.tar.gz cantedraw-f00335d4576add4b84d927791107851d4bcd88b6.tar.bz2 cantedraw-f00335d4576add4b84d927791107851d4bcd88b6.zip |
Implement read-and-confirm for extra step before re-deal
Found that I sometimes did a misinput which lead to losing a critical
card - implemented a function which asks for confirmation (with a
print out of the cards that will be redealt) before doing the redeal.
Diffstat (limited to 'src/main.lisp')
-rw-r--r-- | src/main.lisp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/main.lisp b/src/main.lisp index f63326d..8b8aabb 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -58,6 +58,20 @@ (setq inp (remove-duplicates (read-integers)))) inp)) +(fn read-and-confirm-valid-integers (hand) (-> nil list) + (let ((confirm nil) + inp) + (while (null confirm) + (setq inp (read-until-valid-integers)) + (if (null inp) + (format t "No redeal (end of game)~%") + (->> (loop :for index :in inp + :collect (nth index hand)) + cardset->str + (format t "To redeal: ~a~%"))) + (setq confirm (y-or-n-p "Confirm: "))) + inp)) + (defun print-hand (hand) (->> hand cardset->str (format t "Hand=[~a]~%"))) @@ -70,7 +84,7 @@ (print-hand hand) (read-redeal-print hand deck))) (t - (let ((indices (read-until-valid-integers))) + (let ((indices (read-and-confirm-valid-integers hand))) (if (null indices) (cons hand deck) (destructuring-bind (hand . deck) (redeal-hand hand indices deck) |