diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-02-14 16:59:46 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-02-14 17:17:43 +0000 |
commit | f4b43031adf1094d007ce9e44b191255909d178c (patch) | |
tree | 838f8f2b2bd536f7bd44ddb13eaffce04102b26e | |
parent | f8a834c0d24b1c57f14e9f86ec827aad73e4473e (diff) | |
download | cantedraw-f4b43031adf1094d007ce9e44b191255909d178c.tar.gz cantedraw-f4b43031adf1094d007ce9e44b191255909d178c.tar.bz2 cantedraw-f4b43031adf1094d007ce9e44b191255909d178c.zip |
Add a package for modelling cards
Time to do the fun non-yakshaving part. I'll start out by writing
some custom types for the objects of concern: ranks, suits, cards and
sets of cards.
-rw-r--r-- | cantedraw.asd | 1 | ||||
-rw-r--r-- | model.lisp | 37 | ||||
-rw-r--r-- | packages.lisp | 4 |
3 files changed, 42 insertions, 0 deletions
diff --git a/cantedraw.asd b/cantedraw.asd index ede4524..653afb4 100644 --- a/cantedraw.asd +++ b/cantedraw.asd @@ -2,6 +2,7 @@ :components ((:file "packages") (:file "lib.macros") (:file "lib.functions") + (:file "model") (:file "main")) :build-operation "program-op" :build-pathname "bin/cantedraw" diff --git a/model.lisp b/model.lisp new file mode 100644 index 0000000..7ce8b99 --- /dev/null +++ b/model.lisp @@ -0,0 +1,37 @@ +;;; model.lisp - 2025-02-14 + +;; Copyright (C) 2025 Aryadev Chavali + +;; This program is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +;; FOR A PARTICULAR PURPOSE. See the GNU General Public License Version 2 for +;; details. + +;; You may distribute and modify this code under the terms of the GNU General +;; Public License Version 2, which you should have received a copy of along with +;; this program. If not, please go to <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Model of cards and sets of cards in Lisp. + +;;; Code: + +(in-package :cantedraw.model) + +(deftype rank () + `(or (member :Jack :Queen :King :Ace) + (integer 2 10))) + +(deftype suit () + `(member :Diamonds :Clubs :Hearts :Spades :Joker)) + +(deftype card () `(cons rank suit)) + +(deftype int-card () `(integer 0 51)) + +(fn cardsetp (lst) (-> (list) boolean) + (every #'(lambda (x) (typep x 'card)) lst)) + +(deftype cardset () `(and list (satisfies cardsetp))) + diff --git a/packages.lisp b/packages.lisp index 56d3727..cd99262 100644 --- a/packages.lisp +++ b/packages.lisp @@ -32,6 +32,10 @@ :range :take :split :rev-map)) +(defpackage cantedraw.model + (:use :cl :cantedraw.lib.macros :cantedraw.lib.functions) + (:export :int-card :rank :suit :card :cardset)) + (defpackage cantedraw.main (:use :cl :cantedraw.lib.macros :cantedraw.lib.functions) (:export :start)) |