33 Commits

Author SHA1 Message Date
Aryadev Chavali
cd6ac8930d Overhaul
Loads of changes, some which I wasn't sure what I was on when doing
them
2025-07-10 00:08:23 +01:00
Aryadev Chavali
062b5f59d7 Add a reverse argument sort 2025-03-02 21:42:33 +00:00
Aryadev Chavali
e3d875d48a Implement specific function generation functions for each threading macro 2025-02-22 23:03:23 +00:00
Aryadev Chavali
a80b64b045 Make card a structure
Card is a structure instead of just a type.  Stronger type checking,
automatic constructor, destructors and existence check.
2025-02-22 23:00:17 +00:00
Aryadev Chavali
cc53e6ec42 Implement -<> operator for threading an argument through first parameter 2025-02-19 07:19:51 +00:00
Aryadev Chavali
a56355da7d Rework player package to use structures and a hash table
Instead of an association list and a type contract, let's use a hash
table and a structure.  This is: more explicit, encapsulates state
more effectively, generates much of the cruft (constructors,
destructors) for me.

A hash table is more efficient when considering large player bases.
In particular, we'll be generating unique player IDs to make it a bit
more difficult for a malicious agent to guess another player's ID and
make bad requests.
2025-02-15 20:08:32 +00:00
Aryadev Chavali
a73b0f9729 Add nicknames for all packages (cantedraw -> 5d) 2025-02-15 17:51:45 +00:00
Aryadev Chavali
24b07f9166 Introduce custom errors for player handling
Custom errors for malformed/nonexistent player IDs as well as a player
not having a high enough balance for the money requested.

This will allow me to encode more information in the errors, for
callers to use.  I'm generally of the opinion that callers should be
checking error conditions before calling these functions, but per
Murphy's law it would be nice to have more information in the error
message.
2025-02-15 15:40:56 +00:00
Aryadev Chavali
4ded442dd4 Player handler package
This package defines a player data structure, collections of players,
and different interactions you can have with them:
- Extracting attributes (destructors)
- Checking if they're bankrupt or can bet
- Modifying a collection to adjust the balance of any one
  player (including errors in case that isn't possible)
2025-02-15 15:37:16 +00:00
Aryadev Chavali
77d344a42f Implement a package for some game mechanics
Currently can deal some hands and redeal some cards.
2025-02-14 23:23:32 +00:00
Aryadev Chavali
6a3626d961 Implement a function to remove specific indices from a list 2025-02-14 23:22:18 +00:00
Aryadev Chavali
f0e7c9f3f0 WIP: Making a simple re-deal program.
Gives a hand from a shuffled deck to the user, asks them to provide
indices for cards they wish to re-deal then does so.
2025-02-14 20:53:44 +00:00
Aryadev Chavali
2c8b5e7110 Deck and joker constructor
Joker constructor takes a rank for uniqueness - rank doesn't really
change anything in terms of the "power" of a joker but helps with
ensuring jokers are unique in a deck.

Deck constructor takes an optional argument for the number of decks.
A deck includes two jokers, so n decks include 2n jokers.
2025-02-14 17:35:01 +00:00
Aryadev Chavali
e5a53957b3 Some serialisers to make pretty outputs
I can now use this package for a console application since we can
pretty print cards.
2025-02-14 17:24:35 +00:00
Aryadev Chavali
9ab585d7af Implement comparator functions for ranks, suits and cards. 2025-02-14 17:17:58 +00:00
Aryadev Chavali
76a7017246 Implement some simple converters for custom types to/from integers
Given n in 0..51, certainly there exists r, s s.t.  `n = 13s + r`
where r in 0..12 and s in 0..3.  `r` is the rank, and `s` is the suit.

ranks are ordered Ace, 2, 3, ..., Queen, King and suits are ordered
Diamond, Club, Heart, Spade.

Therefore there is a 1-1 correspondence between 0..51 and any card in
the deck.

Jokers are a bit less straightforward; for now I'll define them as an
outlier which doesn't exist in the same bounds (which is why they're
the default return for suit in int->suit).  Likely I'll go for -1
representing a Joker.
2025-02-14 17:17:43 +00:00
Aryadev Chavali
f4b43031ad 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.
2025-02-14 17:17:43 +00:00
Aryadev Chavali
f8a834c0d2 Rewrote --> to take a placeholder symbol as first argument
Instead of exporting cantedraw.lib.macro._ and making anyone who wants
to use the --> macro _require_ importing that specific symbol, let's
just make it so the user has to supply a placeholder name before they
do anything.  This means each package provides its own placeholder
symbol which lowers coupling.
2025-02-14 16:34:15 +00:00
Aryadev Chavali
02ff1a3fb3 Prefix all packages with cantedraw
This is mostly a sanity check in-case anyone else decides to load this
system for use in their own package - don't want to conflict with
their names.
2025-02-14 16:11:54 +00:00
Aryadev Chavali
4c27e7d5c1 cantedraw.lisp -> main.lisp 2025-02-14 16:00:41 +00:00
Aryadev Chavali
90ef834393 odraw -> cantedraw
Why name it something unique when this is what I'm going to be making
at the end of it all?  Just makes it more confusing for the end user.
2025-02-11 00:54:01 +00:00
Aryadev Chavali
52f7db44cf main -> odraw 2025-02-11 00:41:00 +00:00
Aryadev Chavali
82875e22d3 Import lib.functions in main 2025-02-11 00:40:19 +00:00
Aryadev Chavali
cb7dacccfa rev-map function
Given an indicator function (A->B) and a list of items of A, return
an association list associating B to the elements that map to it;
essentially the inverse map of the indicator.
2025-02-11 00:40:19 +00:00
Aryadev Chavali
3e6da6b0f4 Macro (alist-val) to access the actual value of a key in an alist 2025-02-11 00:40:19 +00:00
Aryadev Chavali
279437cb81 Implement split function.
Given a list and index into that list, return a cons where the car is
all elements up to that index (exclusive) and the cdr is the rest of
the list.
2025-02-11 00:40:19 +00:00
Aryadev Chavali
2d49ed25ac Implement a "take" function to read subsequences of a list
Basically a wrapper over subseq but for when using `->>` as the list
is the last parameter.
2025-02-11 00:40:19 +00:00
Aryadev Chavali
b29855047b Implement $ operator, second class version of the applicative operator
The `$` operator takes a sequence of FORMS and returns a unary
function which applies the input through that sequence via the `->>`
operator.

For example, consider the predicate "not null".  `null` is built into
Common Lisp but "not null" requires writing a
function (lambda (x) (not (null x))).  Now, using this operator, you
can write ($ not null) which returns the same lambda as above while
being more concise.
2025-02-11 00:40:19 +00:00
Aryadev Chavali
ef572b992b Introduce lib.functions which includes helper functions
Splitting macros and functions into different packages and source code
makes it easier to look at.   Functions currently implemented:
- range: like Python's range
- parse-integer*: parse-integer but junk-allowed is set to t.
2025-02-11 00:40:19 +00:00
Aryadev Chavali
bbde84c7d7 Add type alias for function and macro for defining functions with type specifier
`fn' is a convenience macro for defining functions with a type
specifier.  Only really matters for `sbcl` and other hard-optimising
Lisp interpreters which actually take these seriously.
2025-02-11 00:40:19 +00:00
Aryadev Chavali
4977b427d8 Implement a `while' macro. 2025-02-11 00:40:19 +00:00
Aryadev Chavali
c069917170 Implement threading macros and make package lib.macros to hold them. 2025-02-11 00:40:19 +00:00
Aryadev Chavali
19b68fa49c Initial commit.
Setup boilerplate for system/package management.  In particular, setup
an entry-point and Shinmera's "deploy" to build executables.

Also write some scripts to easily load or build the project without
Emacs - just `sbcl --load <x>.lisp`.
2025-02-11 00:40:19 +00:00