aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-07-09 21:31:43 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-07-10 00:08:23 +0100
commitcd6ac8930db6ad3b866b4b8398a25b49c3767a5b (patch)
treeb7d85e0845f1d0aa1b17ee3a0105823190bba4be /src
parent062b5f59d74bda9710c3b532648658a4a7910290 (diff)
downloadcantedraw-cd6ac8930db6ad3b866b4b8398a25b49c3767a5b.tar.gz
cantedraw-cd6ac8930db6ad3b866b4b8398a25b49c3767a5b.tar.bz2
cantedraw-cd6ac8930db6ad3b866b4b8398a25b49c3767a5b.zip
Overhaulmaster
Loads of changes, some which I wasn't sure what I was on when doing them
Diffstat (limited to 'src')
-rw-r--r--src/game.lisp4
-rw-r--r--src/main.lisp5
-rw-r--r--src/model.lisp4
-rw-r--r--src/player.lisp10
4 files changed, 12 insertions, 11 deletions
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)))