Commit Graph

14 Commits

Author SHA1 Message Date
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
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
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
334ece1ee7 Split source code into different modules for cleanliness 2025-02-14 21:46:43 +00:00