Commit Graph

76 Commits

Author SHA1 Message Date
Aryadev Chavali
62f92114ee Add unit tests for model.int->suit 2025-02-21 14:24:29 +00:00
Aryadev Chavali
4bb9173a4a Make empty unit test suite for model package 2025-02-21 14:20:34 +00:00
Aryadev Chavali
7c64d23b0a Add unit tests for lib.functions.remove-at-indices 2025-02-21 14:20:34 +00:00
Aryadev Chavali
1edd618b42 Add unit tests for lib.functions.rev-map 2025-02-21 14:11:08 +00:00
Aryadev Chavali
dc6b2f701b Add unit tests for lib.functions.split 2025-02-21 14:11:08 +00:00
Aryadev Chavali
e9dcba06bb Add unit tests for lib.functions.take 2025-02-21 14:11:08 +00:00
Aryadev Chavali
4b4421c101 Add unit tests for lib.functions.range 2025-02-21 14:11:08 +00:00
Aryadev Chavali
53174000df Add unit tests for lib.functions.parse-integer* 2025-02-21 14:11:08 +00:00
Aryadev Chavali
2538077638 Setup an empty unit test suite for lib.functions
I've added a dependency so if lib.macros isn't working, we can skip
all the tests in lib.functions.  Therefore we can use lib.macros in
the test code.
2025-02-21 14:11:08 +00:00
Aryadev Chavali
0f8b5185fd Add unit tests for lib.macros.-<> 2025-02-21 13:59:59 +00:00
Aryadev Chavali
f908ed5952 Add unit tests for lib.macros.->> 2025-02-21 13:59:55 +00:00
Aryadev Chavali
dc1f3d8970 Create a unit test system
Setup cantedraw/tests with a test-system record, as well as linking it
back to cantedraw so we can run test-system on cantedraw and run the
tests.

Using parachute, we can setup a suite of unit tests for each package.
For each package in src/ or lib/ we'll write a separate unit test
suite with tests for all the public exposing functionality.

I've setup a main suite in cantedraw/tests/main which will depend on
each of the unit test suites so we can run the tests all at once.

Currently we have one test for the --> macro.
2025-02-21 13:53:33 +00:00
Aryadev Chavali
cc53e6ec42 Implement -<> operator for threading an argument through first parameter 2025-02-19 07:19:51 +00:00
Aryadev Chavali
87554dcc3a Added :author and :license to system definition 2025-02-15 20:42:23 +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
0c04a32251 Yakshaving bob the builder 2025-02-15 17:52:04 +00:00
Aryadev Chavali
a73b0f9729 Add nicknames for all packages (cantedraw -> 5d) 2025-02-15 17:51:45 +00:00
Aryadev Chavali
143e8e03fa Disable image compression for binary. 2025-02-15 16:22:35 +00:00
Aryadev Chavali
dc94a396ec Clean up player-{pay,receive}
Clean up the implementation of player-pay and player-receive by:

- Single-clause early-error `if` for errors
- use `incf`/`decf` instead of `setf`.
2025-02-15 16:20:14 +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
2323b5e0ed Small changes 2025-02-15 15:04:59 +00:00
Aryadev Chavali
395cd9357e Rework $ operator to take a capture variable
In case operators require use of a variable, we should let the caller
provide the symbol so we don't fall into weird package issues.
2025-02-15 15:04:00 +00:00
Aryadev Chavali
be61832737 Added a tasks file to keep track of what to do next 2025-02-15 13:38:54 +00:00
Aryadev Chavali
f00335d457 Implement read-and-confirm for extra step before re-deal
Found that I sometimes did a misinput which lead to losing a critical
card - implemented a function which asks for confirmation (with a
print out of the cards that will be redealt) before doing the redeal.
2025-02-14 23:42:13 +00:00
Aryadev Chavali
ae68f3a8f0 Rework cantedraw.main:start to run a read-redeal-print-loop
We've now got one of the major stages of the game down.

I think it's worth investing in some testing functions now - we've
reached just the level of complexity.
2025-02-14 23:42:06 +00:00
Aryadev Chavali
d4e8f66c8b 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
2025-02-14 23:27:06 +00:00
Aryadev Chavali
350221cfb0 Fix problem with alexandria:shuffle not being truly random
Due to the way random works, we need to see it on each run of the
binary - thus need to make a new random state.
2025-02-14 23:26:06 +00:00
Aryadev Chavali
bf6cace5c3 Rework read-until-valid-integers to work better for redeal inputs
A player may:
- not redeal any cards
- redeal all their cards

Therefore the indices must be between 0,5 and there can be at most 5
inputs.
2025-02-14 23:24:47 +00:00
Aryadev Chavali
8f23358d3e Rework card< comparator to make Jokers the top of the hierarchy 2025-02-14 23:24: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
334ece1ee7 Split source code into different modules for cleanliness 2025-02-14 21:46:43 +00:00
Aryadev Chavali
f127e1e955 Update gitignore, add requirements to README, rework bob and build 2025-02-14 21:46:43 +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
d328bfbbdf Adjust Bob so we can use quickload the project to get all dependencies 2025-02-14 20:39:00 +00:00
Aryadev Chavali
fba391a6e8 Refactor Joker generation in make-deck to use mapcar on a range.
This new version is terser while still expressing what I want.
2025-02-14 17:44:46 +00:00
Aryadev Chavali
955e921f80 Leave FORMS as is in $ operator.
`$` takes a list of forms and makes a unary function which applies
them via `->>`.  Previous definition reversed the forms supplied
s.t. `$` was closer to the applicative operator in Haskell i.e. the
function (<$> f g) is f(g(x)).  But this version fits closer with the
lower operator (->>) being used AND allows easier lifting from
`->>` (which produces a value) to `$` (which produces a function).
2025-02-14 17:42:11 +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
c10b590420 Fixed bug in int->rank where n >= 13 leads to error
Because I assume n is modded already.
2025-02-14 17:34:31 +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
3906be4d59 Adjust rank->int and int->rank for ACE supremacy
Generally, ACE is the best card in Cantedraw in a card-by-card basis
thus it should be the higher when comparing.
2025-02-14 17:17:43 +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
b335a12b78 Added a README 2025-02-14 15:10:43 +00:00
Aryadev Chavali
8bd7900946 Use := instead of = so we're not re-interning a symbol in cl-loop 2025-02-14 15:10:43 +00:00