Commit Graph

99 Commits

Author SHA1 Message Date
Aryadev Chavali
7b5a6eb255 card: implement PlayingCard|Card::{prev,next}
Returns the next or previous card based on deck ordering.  Respects
the deck of the current card (i.e. will return a card from the same
deck) but will return None on the boundaries of the deck (3(D) and
2(S)).
2026-04-05 04:45:51 +01:00
Aryadev Chavali
3b8bdc5df9 modes:single: Implemented hashing on Singles (trivial). 2026-04-05 04:45:51 +01:00
Aryadev Chavali
abf638e869 modes:single:tests: major refactor
Better exhaustive testing, addition of messages on asserts as well.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
b796156ea5 modes:single|pair: make default struct construction private
If all fields are public, users are allowed to use the default struct
constructor.  Obviously we want users to only use the static ::new
method.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
fa4d8efb78 modes:mod:tests: test_footstool revert to basic pattern
My previous impl was based on some testing for different Pair
footstool implementations.  However, I've decided to fix it to this
set of patterns:
1) any half footstool must come from a more dominant hand.
2) full footstools are symmetric and require both hands to be
   equivalent
2026-04-05 04:45:51 +01:00
Aryadev Chavali
dce4279af2 card: make_decks -> Card::iter_all, PlayingCard::iter_deck -> iter_all 2026-04-05 04:45:51 +01:00
Aryadev Chavali
e054921462 modes:single:footstool: allow half footstools to loop
3 of Diamonds can now half-footstool 2 of Spades.  We need to fix
ordering to allow 3 of Diamonds to beat 2 of Spades specifically.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
df79488cec modes:pair:tests: refactor ordering test. 2026-04-05 04:45:51 +01:00
Aryadev Chavali
8bacbfbde3 modes:pair: adjust Pair::Ord
Instead of our more complicated interpretation before where we'd care
about whether something is proper or not, here we're just using a form
of reverse lexicographical on the Pair.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
9690fb2bf3 modes:pair:tests: refactor for name change 2026-04-05 04:45:51 +01:00
Aryadev Chavali
b7e511cbe8 modes:single:tests: rename for test_footstool 2026-04-05 04:45:51 +01:00
Aryadev Chavali
c2842c02e4 modes:mod: refactor Hand
Hand now requires Ord to be implemented, and test_footstool is a bit
more precise than test_footstool_non_reflexivity.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
fa6ce21fce modes:triple: start impl for triples
implemented Triple::new
2026-04-05 04:45:51 +01:00
Aryadev Chavali
f4cab01195 modes:*: cleanup 2026-04-05 04:45:51 +01:00
Aryadev Chavali
892c112433 helper: ordered now takes a fixed sized array of type T
I wanted to abstract ordered to any size instead of just binary
tuples - but tuples have a strange issue where you can't be generic
about them past like a limit of 12.  With this setup, ordered takes
ownership of some fixed array, sorts it, then returns it back.

modes:pair and modes:single have been refactored to utilise this new
form of ordered - it's basically the exact same in these cases.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
f8f5c12316 game: deleted
This branch is purely for creating a working classifier for hands of
cards.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
ad4057e890 modes:pair:tests: refactor for more functional style tests
Nested iteration in the form presented before was quite bad - while
it's a bit more efficient to iterate once and do all the tests in that
one go, it can be kinda hard to preserve the context in ones head.

This style makes it easier to see the flow of data and what is being
tested.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
d0de81231e modes:mod:tests: test_non_reflexivity -> test_footstool_non_reflexivity 2026-04-05 04:45:51 +01:00
Aryadev Chavali
f088915a60 modes:pair:tests: refactor for cleanliness 2026-04-05 04:45:51 +01:00
Aryadev Chavali
3cdfde07fe game: module for gameplay
Skeleton currently, not much
2026-04-05 04:45:51 +01:00
Aryadev Chavali
e4af8c1812 modes:mod: make pair and single public modules. 2026-04-05 04:45:51 +01:00
Aryadev Chavali
c39d6afd89 modes:pair:tests: footstool implemented 2026-04-05 04:45:51 +01:00
Aryadev Chavali
83ab81a569 modes:pair:tests: ordering implemented 2026-04-05 04:45:51 +01:00
Aryadev Chavali
555b82d671 modes:pair:tests: refactor exhaustive_deck 2026-04-05 04:45:51 +01:00
Aryadev Chavali
8a2cbf1bc9 modes:pair:ord: Remove useless case 2026-04-05 04:45:51 +01:00
Aryadev Chavali
2d179f0316 modes:single: make Single::new public 2026-04-05 04:45:51 +01:00
Aryadev Chavali
11d5149d35 modes:single:tests: refactor make_deck uses 2026-04-05 04:45:51 +01:00
Aryadev Chavali
47bb6c171e card: make_decks yields an iterator instead of a vector 2026-04-05 04:45:51 +01:00
Aryadev Chavali
555c8e127b card: make Rank|Suit::cards yield an iterator instead of a vector 2026-04-05 04:45:51 +01:00
Aryadev Chavali
d9cc67d3d1 modes:single:tests: refactor 2026-04-05 04:45:51 +01:00
Aryadev Chavali
0f97422722 card: iter_all_deck -> iter_deck 2026-04-05 04:45:51 +01:00
Aryadev Chavali
c61626f2d0 card: PlayingCard::iter_all_deck
Given a deck number, create an iterator over all Playing Cards in that
deck.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
8e6e11e5be card: slight clean up 2026-04-05 04:45:51 +01:00
Aryadev Chavali
e035f53234 modes:pair: refactor tests to utilise Rank::iter_all and Rank::cards 2026-04-05 04:45:51 +01:00
Aryadev Chavali
503ad53721 card: Rank|Suit::{iter_all, cards}
iter_all generates an iterator over every valid rank in order.  cards
generates an iterator over all cards for a given suit/rank.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
6119410496 card: new -> make_joker and make_playing-card
Always better to be explicit with our constructor names.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
f40596bc1d modes:pair:tests: implement test::new 2026-04-05 04:45:51 +01:00
Aryadev Chavali
cb2c220a5b modes:pair:tests:exhaustive_pairs: refactor for accuracy 2026-04-05 04:45:51 +01:00
Aryadev Chavali
e9c37d49e3 modes:pair:ord: make improper pairs worse than proper pairs
If the highcard of two pairs are equivalent, but one is improper while
the other is proper, the proper pair is always greater.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
40046fa98c modes:single:tests: Full stops on // TEST comments. 2026-04-05 04:45:51 +01:00
Aryadev Chavali
27f9f79416 modes:mod:Hand: is_proper and is_improper indicator functions
A "proper" hand is one that has no wild cards - an "improper" hand is
one that does have at least one wild card.

~is_proper~ should be implemented for any Hand - ~is_improper~ falls
out for free.

Implemented for Single and Pair.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
b76ad869ea modes:single:tests: commentary, reflexive testing on differing decks 2026-04-05 04:45:51 +01:00
Aryadev Chavali
298499207b main: permit dead code (no warnings) when building.
I want my build to tell me if there's anything wrong with it.  Dead
Code warnings distract me from checking that.

OTOH when I'm running Clippy I want it to catch everything.  Hence
this change.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
534da2ed71 modes:pair: test skeletons for pairs. 2026-04-05 04:45:51 +01:00
Aryadev Chavali
994ebea678 modes:single: rename some tests 2026-04-05 04:45:51 +01:00
Aryadev Chavali
6a86f7d62b modes:single|pair: Use square brackets instead of braces for display
Helps distinguish from the Debug print.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
30a7c466e5 modes:pair: Implement Hand for Pair
The footstool condition here is super simple since we just utilise the
Single footstool condition against Pair::1 of both pairs.
2026-04-05 04:45:51 +01:00
Aryadev Chavali
0328a828c8 modes:pair: document that Pair::1 is always a playing card in Pair::new 2026-04-05 04:45:51 +01:00
Aryadev Chavali
0267a6f567 modes:pair: adjust Ord impl for Pair
Instead of doing a deep-check where we compare their best member
before their worst member, we just compare by the best member.

This allows (Joker, 4S) to be equal to (4C, 4S).
2026-04-05 04:45:51 +01:00
Aryadev Chavali
a24d85572d modes:single|pair: make fields of Single and Pair public
So strange that this isn't default for tuple-like constructors.  I can
kinda get it for record-like constructors, but not for this.  Better
safe than sorry I guess?
2026-04-05 04:45:51 +01:00