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
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user