From cd6ac8930db6ad3b866b4b8398a25b49c3767a5b Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 9 Jul 2025 21:31:43 +0100 Subject: Overhaul Loads of changes, some which I wasn't sure what I was on when doing them --- src/game.lisp | 4 ++-- src/main.lisp | 5 +++-- src/model.lisp | 4 ++-- src/player.lisp | 10 +++++----- 4 files changed, 12 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/game.lisp b/src/game.lisp index e9f234f..47831f4 100644 --- a/src/game.lisp +++ b/src/game.lisp @@ -19,8 +19,8 @@ (in-package :cantedraw.game) -(fn deal-cards (n deck) (-> (fixnum cardset) (cons cardset cardset)) - (destructuring-bind (hand . rest) (split n deck) +(fn deal-cards (n deck) (-> (fixnum cardset) (cons cardset )) + (multiple-value-bind (hand rest) (split n deck) (cons (sort hand #'card<) rest))) (fn deal-hands (n deck) (-> (fixnum cardset) (cons list cardset)) diff --git a/src/main.lisp b/src/main.lisp index d8985d0..d75b08b 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -41,7 +41,7 @@ (while (null inp) (format t "Need at least one integer...~%") (force-output) - (setq inp (read-integers))) + (->> (read-integers) (setq inp))) inp)) (fn is-valid-hand-index (n) (-> (fixnum) boolean) @@ -55,7 +55,7 @@ (>= (length inp) 0))) (format t "Need at most 5 integers between 0 and 4...~%") (force-output) - (setq inp (remove-duplicates (read-integers)))) + (->> (read-integers) remove-duplicates (setq inp))) inp)) (fn read-and-confirm-valid-integers (hand) (-> (cardset) list) @@ -97,6 +97,7 @@ (->> (make-deck) alexandria:shuffle (read-redeal-print nil)) + (format t "~C[2J" #\Esc) (format t "Cards remaining: {~a} Final hand: [~a] diff --git a/src/model.lisp b/src/model.lisp index 6a3cbaf..f60ee98 100644 --- a/src/model.lisp +++ b/src/model.lisp @@ -32,9 +32,9 @@ (deftype int-card () `(integer 0 51)) -(deftype cardset () `(and list (satisfies cardsetp))) +(deftype cardset () `(and list (satisfies cardset-p))) -(fn cardsetp (lst) (-> (list) boolean) +(fn cardset-p (lst) (-> (list) boolean) (every #'card-p lst)) (fn int->suit (n) (-> (fixnum) suit) diff --git a/src/player.lisp b/src/player.lisp index 5807ac5..30eefd5 100644 --- a/src/player.lisp +++ b/src/player.lisp @@ -40,8 +40,8 @@ (id err) (balance err) (required err))))) (fn player-exists? (id table) (-> (symbol hash-table) boolean) - (and (gethash id table) - (player-p (gethash id table)))) + (let ((item (gethash id table))) + (and item (player-p item)))) (defun error-if-no-player (id table) (unless (player-exists? id table) @@ -60,12 +60,12 @@ (unless (player-can-pay? id table amount) (error 'error-player-broke :id id :balance (player-balance (gethash id table)) :required amount)) - (decf (player-balance (gethash id table)) amount)) + (-<> id (gethash table) player-balance (decf amount))) (fn player-credit (id table amount) (-> (symbol hash-table fixnum) fixnum) (error-if-no-player id table) - (incf (player-balance (gethash id table)) amount)) + (-<> id (gethash table) player-balance (incf amount))) (fn player-set-cards (id table cards) (-> (symbol hash-table cardset) t) (error-if-no-player id table) - (setf (player-hand (gethash id table)) cards)) + (-<> id (gethash table) player-hand (setf cards))) -- cgit v1.2.3-13-gbd6f