card_dealer 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/.rubocop.yml +2 -2
- data/CHANGELOG.md +47 -8
- data/CLAUDE.md +57 -0
- data/CODE_OF_CONDUCT.md +91 -0
- data/CONTRIBUTING.md +32 -0
- data/Gemfile +5 -6
- data/Gemfile.lock +83 -82
- data/README.md +70 -66
- data/SECURITY.md +14 -0
- data/card_dealer.gemspec +44 -0
- data/docs/ideation/2026-11-06-next-feature.md +131 -0
- data/lib/card_dealer/binary_deck.rb +7 -0
- data/lib/card_dealer/version.rb +1 -1
- data/lib/card_dealer.rb +0 -2
- data/sig/card_dealer/card.rbs +10 -0
- metadata +16 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 740499d4aa92d740445805a9e78e4c2ff72e0fdd79a44c1abd34d25aeed17b1d
|
|
4
|
+
data.tar.gz: 482ee0d77fcc5f171b220f601c99ce3beebfab94e60f989d2cf395ecd836178c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 67fe4b4516e2c4dd8857270330c7300a65abc6d038f9a0b8634cd63a003d6c96ccb4243ec9dbe86c5348dab9e783d9f2110d8c87443418a9bd11e5dc0aca5f29
|
|
7
|
+
data.tar.gz: 408fcce45791e37cc982665cf3432b104a21f15b937ecefed14c8dc360b9ed22ce695f4051a4e5a3a425d15eb58e2ff93e42effbb4cde84ba21e5f7abccf8f92
|
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/2.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
The public API covered by Semantic Versioning is the public methods of
|
|
9
|
+
`CardDealer::Card`, `CardDealer::Deck`, `CardDealer::BuildDeck`, and
|
|
10
|
+
`CardDealer::BinaryDeck`, the binary format `BinaryDeck` produces, and the
|
|
11
|
+
minimum Ruby version. Private methods and the RBS signatures under `sig/` are
|
|
12
|
+
outside it. While the version is below 1.0.0, an incompatible change bumps
|
|
13
|
+
MINOR and every other change bumps PATCH. A public item is deprecated with a
|
|
14
|
+
runtime warning naming its replacement for at least one release before it is
|
|
15
|
+
removed.
|
|
16
|
+
|
|
1
17
|
## [Unreleased]
|
|
2
18
|
|
|
3
|
-
## [0.
|
|
19
|
+
## [0.3.1] - 2026-11-06
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
4
22
|
|
|
5
|
-
|
|
23
|
+
- Binary decoding rejects payload lengths that do not match the declared card count with `CardDealer::BinaryDeck::InvalidEncodingError`, including truncated decks.
|
|
6
24
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
25
|
+
## [0.3.0] - 2026-09-07
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- **Breaking:** Ruby 3.3 or newer is required. Ruby 3.1 and 3.2 reached end of life and are no longer tested.
|
|
30
|
+
- Development dependencies updated to their current releases (RuboCop 1.90, RSpec 3.13, Steep 2.1, rbs 4.2)
|
|
31
|
+
- CI runs on Ruby 3.3, 3.4, and 4.0
|
|
32
|
+
|
|
33
|
+
## [0.2.0] - 2023-04-01
|
|
10
34
|
|
|
11
35
|
### Added
|
|
12
36
|
|
|
@@ -22,11 +46,20 @@
|
|
|
22
46
|
- `Deck#from_binary` helper method to convert the binary string to a deck
|
|
23
47
|
- `Deck#==` method to compare decks for equality
|
|
24
48
|
- Lots of documentation
|
|
25
|
-
- [Steep](https://github.com/soutaro/steep) gem to check
|
|
49
|
+
- [Steep](https://github.com/soutaro/steep) gem to check type correctness
|
|
26
50
|
|
|
27
51
|
### Changed
|
|
28
52
|
|
|
29
|
-
-
|
|
53
|
+
- **Breaking:** Deck building is extracted from the `Deck` class to the `BuildDeck` class.
|
|
54
|
+
`Deck#new` now takes an array of cards instead of a hash of options.
|
|
55
|
+
Call `BuildDeck.standard52`, `BuildDeck.standard36`, or `BuildDeck.custom` to build a deck.
|
|
56
|
+
- It's now possible to initialize a card with a string, e.g. `Card.new('9c')`
|
|
57
|
+
|
|
58
|
+
### Removed
|
|
59
|
+
|
|
60
|
+
- **Breaking:** `Deck#reset`. It was removed without a deprecation notice in 0.1.0,
|
|
61
|
+
so no release warned before the removal. Build a new deck with `BuildDeck` where
|
|
62
|
+
`reset` was called.
|
|
30
63
|
|
|
31
64
|
### Fixed
|
|
32
65
|
|
|
@@ -40,6 +73,12 @@ Initial release!
|
|
|
40
73
|
|
|
41
74
|
- `Card` class
|
|
42
75
|
- `Deck` class
|
|
43
|
-
- Ability to create a decks of various
|
|
76
|
+
- Ability to create a decks of various sizes, ranks, and suits
|
|
44
77
|
- Ability to shuffle a deck
|
|
45
78
|
- Ability to reset a deck
|
|
79
|
+
|
|
80
|
+
[unreleased]: https://github.com/svyatov/card_dealer/compare/v0.3.1...HEAD
|
|
81
|
+
[0.3.1]: https://github.com/svyatov/card_dealer/compare/v0.3.0...v0.3.1
|
|
82
|
+
[0.3.0]: https://github.com/svyatov/card_dealer/compare/v0.2.0...v0.3.0
|
|
83
|
+
[0.2.0]: https://github.com/svyatov/card_dealer/compare/v0.1.0...v0.2.0
|
|
84
|
+
[0.1.0]: https://github.com/svyatov/card_dealer/releases/tag/v0.1.0
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
CardDealer is a Ruby gem for creating, shuffling, and dealing decks of playing cards. It supports standard 52-card and 36-card decks, custom deck configurations, and binary serialization for storage.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Install dependencies
|
|
13
|
+
bin/setup
|
|
14
|
+
|
|
15
|
+
# Run all checks (default task: steep + rubocop + rspec)
|
|
16
|
+
bundle exec rake
|
|
17
|
+
|
|
18
|
+
# Run tests only
|
|
19
|
+
bundle exec rake spec
|
|
20
|
+
|
|
21
|
+
# Run a single test file
|
|
22
|
+
bundle exec rspec spec/card_dealer/card_spec.rb
|
|
23
|
+
|
|
24
|
+
# Run a specific test by line number
|
|
25
|
+
bundle exec rspec spec/card_dealer/deck_spec.rb:42
|
|
26
|
+
|
|
27
|
+
# Run linter
|
|
28
|
+
bundle exec rake rubocop
|
|
29
|
+
|
|
30
|
+
# Run type checker
|
|
31
|
+
bundle exec rake steep
|
|
32
|
+
|
|
33
|
+
# Interactive console
|
|
34
|
+
bin/console
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Architecture
|
|
38
|
+
|
|
39
|
+
The gem has four main classes under the `CardDealer` module:
|
|
40
|
+
|
|
41
|
+
- **Card** (`lib/card_dealer/card.rb`) - Represents a single playing card with rank (2-A, where T=10) and suit (c/d/h/s). Cards are comparable and can be used as hash keys.
|
|
42
|
+
|
|
43
|
+
- **Deck** (`lib/card_dealer/deck.rb`) - A collection of cards supporting shuffle (Fisher-Yates with optional seed), deal, and burn operations. Tracks burned cards separately.
|
|
44
|
+
|
|
45
|
+
- **BuildDeck** (`lib/card_dealer/build_deck.rb`) - Factory class with class methods for creating decks:
|
|
46
|
+
- `standard52` / `standard36` for common configurations
|
|
47
|
+
- `custom` for specifying decks count, cards per suit, ranks (`:highest`, `:lowest`, or array), and suits
|
|
48
|
+
|
|
49
|
+
- **BinaryDeck** (`lib/card_dealer/binary_deck.rb`) - Encodes/decodes decks to/from binary strings using 6-bit card representations. Supports decks up to 4 billion cards with three template sizes (8/16/32-bit headers).
|
|
50
|
+
|
|
51
|
+
## Type Definitions
|
|
52
|
+
|
|
53
|
+
RBS type signatures are in `sig/`. The project uses Steep for type checking with lenient diagnostics configured in `Steepfile`.
|
|
54
|
+
|
|
55
|
+
## Requirements
|
|
56
|
+
|
|
57
|
+
- Ruby >= 3.3.0
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
|
|
2
|
+
# Contributor Covenant 3.0 Code of Conduct
|
|
3
|
+
|
|
4
|
+
## Our Pledge
|
|
5
|
+
|
|
6
|
+
We pledge to make our community welcoming, safe, and equitable for all.
|
|
7
|
+
|
|
8
|
+
We are committed to fostering an environment that respects and promotes the dignity, rights, and contributions of all individuals, regardless of characteristics including race, ethnicity, caste, color, age, physical characteristics, neurodiversity, disability, sex or gender, gender identity or expression, sexual orientation, language, philosophy or religion, national or social origin, socio-economic position, level of education, or other status. The same privileges of participation are extended to everyone who participates in good faith and in accordance with this Covenant.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Encouraged Behaviors
|
|
12
|
+
|
|
13
|
+
While acknowledging differences in social norms, we all strive to meet our community's expectations for positive behavior. We also understand that our words and actions may be interpreted differently than we intend based on culture, background, or native language.
|
|
14
|
+
|
|
15
|
+
With these considerations in mind, we agree to behave mindfully toward each other and act in ways that center our shared values, including:
|
|
16
|
+
|
|
17
|
+
1. Respecting the **purpose of our community**, our activities, and our ways of gathering.
|
|
18
|
+
2. Engaging **kindly and honestly** with others.
|
|
19
|
+
3. Respecting **different viewpoints** and experiences.
|
|
20
|
+
4. **Taking responsibility** for our actions and contributions.
|
|
21
|
+
5. Gracefully giving and accepting **constructive feedback**.
|
|
22
|
+
6. Committing to **repairing harm** when it occurs.
|
|
23
|
+
7. Behaving in other ways that promote and sustain the **well-being of our community**.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Restricted Behaviors
|
|
27
|
+
|
|
28
|
+
We agree to restrict the following behaviors in our community. Instances, threats, and promotion of these behaviors are violations of this Code of Conduct.
|
|
29
|
+
|
|
30
|
+
1. **Harassment.** Violating explicitly expressed boundaries or engaging in unnecessary personal attention after any clear request to stop.
|
|
31
|
+
2. **Character attacks.** Making insulting, demeaning, or pejorative comments directed at a community member or group of people.
|
|
32
|
+
3. **Stereotyping or discrimination.** Characterizing anyone’s personality or behavior on the basis of immutable identities or traits.
|
|
33
|
+
4. **Sexualization.** Behaving in a way that would generally be considered inappropriately intimate in the context or purpose of the community.
|
|
34
|
+
5. **Violating confidentiality**. Sharing or acting on someone's personal or private information without their permission.
|
|
35
|
+
6. **Endangerment.** Causing, encouraging, or threatening violence or other harm toward any person or group.
|
|
36
|
+
7. Behaving in other ways that **threaten the well-being** of our community.
|
|
37
|
+
|
|
38
|
+
### Other Restrictions
|
|
39
|
+
|
|
40
|
+
1. **Misleading identity.** Impersonating someone else for any reason, or pretending to be someone else to evade enforcement actions.
|
|
41
|
+
2. **Failing to credit sources.** Not properly crediting the sources of content you contribute.
|
|
42
|
+
3. **Promotional materials**. Sharing marketing or other commercial content in a way that is outside the norms of the community.
|
|
43
|
+
4. **Irresponsible communication.** Failing to responsibly present content which includes, links or describes any other restricted behaviors.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## Reporting an Issue
|
|
47
|
+
|
|
48
|
+
Tensions can occur between community members even when they are trying their best to collaborate. Not every conflict represents a code of conduct violation, and this Code of Conduct reinforces encouraged behaviors and norms that can help avoid conflicts and minimize harm.
|
|
49
|
+
|
|
50
|
+
When an incident does occur, it is important to report it promptly. To report a possible violation, email Leonid Svyatov at leonid@svyatov.com.
|
|
51
|
+
|
|
52
|
+
Community Moderators take reports of violations seriously and will make every effort to respond in a timely manner. They will investigate all reports of code of conduct violations, reviewing messages, logs, and recordings, or interviewing witnesses and other participants. Community Moderators will keep investigation and enforcement actions as transparent as possible while prioritizing safety and confidentiality. In order to honor these values, enforcement actions are carried out in private with the involved parties, but communicating to the whole community may be part of a mutually agreed upon resolution.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Addressing and Repairing Harm
|
|
56
|
+
|
|
57
|
+
If an investigation by the Community Moderators finds that this Code of Conduct has been violated, the following enforcement ladder may be used to determine how best to repair harm, based on the incident's impact on the individuals involved and the community as a whole. Depending on the severity of a violation, lower rungs on the ladder may be skipped.
|
|
58
|
+
|
|
59
|
+
1) Warning
|
|
60
|
+
1) Event: A violation involving a single incident or series of incidents.
|
|
61
|
+
2) Consequence: A private, written warning from the Community Moderators.
|
|
62
|
+
3) Repair: Examples of repair include a private written apology, acknowledgement of responsibility, and seeking clarification on expectations.
|
|
63
|
+
2) Temporarily Limited Activities
|
|
64
|
+
1) Event: A repeated incidence of a violation that previously resulted in a warning, or the first incidence of a more serious violation.
|
|
65
|
+
2) Consequence: A private, written warning with a time-limited cooldown period designed to underscore the seriousness of the situation and give the community members involved time to process the incident. The cooldown period may be limited to particular communication channels or interactions with particular community members.
|
|
66
|
+
3) Repair: Examples of repair may include making an apology, using the cooldown period to reflect on actions and impact, and being thoughtful about re-entering community spaces after the period is over.
|
|
67
|
+
3) Temporary Suspension
|
|
68
|
+
1) Event: A pattern of repeated violation which the Community Moderators have tried to address with warnings, or a single serious violation.
|
|
69
|
+
2) Consequence: A private written warning with conditions for return from suspension. In general, temporary suspensions give the person being suspended time to reflect upon their behavior and possible corrective actions.
|
|
70
|
+
3) Repair: Examples of repair include respecting the spirit of the suspension, meeting the specified conditions for return, and being thoughtful about how to reintegrate with the community when the suspension is lifted.
|
|
71
|
+
4) Permanent Ban
|
|
72
|
+
1) Event: A pattern of repeated code of conduct violations that other steps on the ladder have failed to resolve, or a violation so serious that the Community Moderators determine there is no way to keep the community safe with this person as a member.
|
|
73
|
+
2) Consequence: Access to all community spaces, tools, and communication channels is removed. In general, permanent bans should be rarely used, should have strong reasoning behind them, and should only be resorted to if working through other remedies has failed to change the behavior.
|
|
74
|
+
3) Repair: There is no possible repair in cases of this severity.
|
|
75
|
+
|
|
76
|
+
This enforcement ladder is intended as a guideline. It does not limit the ability of Community Managers to use their discretion and judgment, in keeping with the best interests of our community.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## Scope
|
|
80
|
+
|
|
81
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public or other spaces. Examples of representing our community include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
## Attribution
|
|
85
|
+
|
|
86
|
+
This Code of Conduct is adapted from the Contributor Covenant, version 3.0, permanently available at [https://www.contributor-covenant.org/version/3/0/](https://www.contributor-covenant.org/version/3/0/).
|
|
87
|
+
|
|
88
|
+
Contributor Covenant is stewarded by the Organization for Ethical Source and licensed under CC BY-SA 4.0. To view a copy of this license, visit [https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/)
|
|
89
|
+
|
|
90
|
+
For answers to common questions about Contributor Covenant, see the FAQ at [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are provided at [https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations). Additional enforcement and community guideline resources can be found at [https://www.contributor-covenant.org/resources](https://www.contributor-covenant.org/resources). The enforcement ladder was inspired by the work of [Mozilla’s code of conduct team](https://github.com/mozilla/inclusion).
|
|
91
|
+
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Bug reports and pull requests are welcome at https://github.com/svyatov/card_dealer/issues.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
Install Ruby 3.3 or newer, then run:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
bin/setup
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Tests and checks
|
|
14
|
+
|
|
15
|
+
`bundle exec rake` runs what CI runs: Steep, RuboCop, and RSpec. `bundle exec rake spec` runs the tests alone.
|
|
16
|
+
|
|
17
|
+
## Pull requests
|
|
18
|
+
|
|
19
|
+
1. Fork the repository and create a branch from `main`.
|
|
20
|
+
2. Make the change. A change that adds or alters behavior arrives with a test in `spec/`.
|
|
21
|
+
3. Run `bundle exec rake` and fix what it reports.
|
|
22
|
+
4. Open a pull request against `main`.
|
|
23
|
+
|
|
24
|
+
CI runs `bundle exec rake` on Ruby 3.3, 3.4, and 4.0. All three must pass before merge. Pull requests are squash merged, and their titles follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
|
|
25
|
+
|
|
26
|
+
## What an acceptable change satisfies
|
|
27
|
+
|
|
28
|
+
`bundle exec rake` passes: RuboCop with the rules in [.rubocop.yml](.rubocop.yml), Steep against the signatures in [sig/](sig/), and the suite in [spec/](spec/).
|
|
29
|
+
|
|
30
|
+
## Governance
|
|
31
|
+
|
|
32
|
+
Leonid Svyatov ([@svyatov](https://github.com/svyatov)) is the only maintainer. He reviews, merges, and releases. No succession is arranged: if he stops, the project stops unless someone forks it.
|
data/Gemfile
CHANGED
|
@@ -5,14 +5,13 @@ source "https://rubygems.org"
|
|
|
5
5
|
# Specify your gem's dependencies in card_dealer.gemspec
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
-
gem "rake", "~> 13.
|
|
8
|
+
gem "rake", "~> 13.4"
|
|
9
9
|
|
|
10
|
-
gem "rspec", "~> 3.
|
|
10
|
+
gem "rspec", "~> 3.13"
|
|
11
11
|
gem "simplecov", require: false
|
|
12
|
-
gem "simplecov_json_formatter", require: false
|
|
13
12
|
|
|
14
|
-
gem "rubocop", "~> 1.
|
|
15
|
-
gem "rubocop-rake", "~> 0.
|
|
16
|
-
gem "rubocop-rspec", "~>
|
|
13
|
+
gem "rubocop", "~> 1.92"
|
|
14
|
+
gem "rubocop-rake", "~> 0.7"
|
|
15
|
+
gem "rubocop-rspec", "~> 3.10"
|
|
17
16
|
|
|
18
17
|
gem "steep", require: false
|
data/Gemfile.lock
CHANGED
|
@@ -1,119 +1,120 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
card_dealer (0.
|
|
4
|
+
card_dealer (0.3.1)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
i18n (1.12.0)
|
|
22
|
-
concurrent-ruby (~> 1.0)
|
|
23
|
-
json (2.6.3)
|
|
24
|
-
language_server-protocol (3.17.0.3)
|
|
25
|
-
listen (3.8.0)
|
|
9
|
+
ast (2.4.3)
|
|
10
|
+
concurrent-ruby (1.3.8)
|
|
11
|
+
csv (3.3.7)
|
|
12
|
+
diff-lcs (1.6.2)
|
|
13
|
+
ffi (1.17.4-arm64-darwin)
|
|
14
|
+
ffi (1.17.4-x86_64-linux-gnu)
|
|
15
|
+
fileutils (1.8.1)
|
|
16
|
+
json (3.1.0)
|
|
17
|
+
language_server-protocol (3.17.0.6)
|
|
18
|
+
lint_roller (1.1.0)
|
|
19
|
+
listen (3.10.1)
|
|
20
|
+
logger
|
|
26
21
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
27
22
|
rb-inotify (~> 0.9, >= 0.9.10)
|
|
28
|
-
logger (1.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
parser (3.2.1.1)
|
|
23
|
+
logger (1.7.0)
|
|
24
|
+
parallel (2.3.0)
|
|
25
|
+
parser (3.3.13.0)
|
|
32
26
|
ast (~> 2.4.1)
|
|
27
|
+
racc
|
|
28
|
+
prism (1.9.0)
|
|
29
|
+
racc (1.8.1)
|
|
33
30
|
rainbow (3.1.1)
|
|
34
|
-
rake (13.
|
|
31
|
+
rake (13.4.2)
|
|
35
32
|
rb-fsevent (0.11.2)
|
|
36
|
-
rb-inotify (0.
|
|
33
|
+
rb-inotify (0.11.1)
|
|
37
34
|
ffi (~> 1.0)
|
|
38
|
-
rbs (2.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
rspec-
|
|
45
|
-
|
|
46
|
-
rspec-
|
|
47
|
-
rspec-
|
|
35
|
+
rbs (4.2.0)
|
|
36
|
+
logger
|
|
37
|
+
prism (>= 1.6.0)
|
|
38
|
+
tsort
|
|
39
|
+
regexp_parser (2.13.1)
|
|
40
|
+
rspec (3.13.2)
|
|
41
|
+
rspec-core (~> 3.13.0)
|
|
42
|
+
rspec-expectations (~> 3.13.0)
|
|
43
|
+
rspec-mocks (~> 3.13.0)
|
|
44
|
+
rspec-core (3.13.6)
|
|
45
|
+
rspec-support (~> 3.13.0)
|
|
46
|
+
rspec-expectations (3.13.5)
|
|
48
47
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
49
|
-
rspec-support (~> 3.
|
|
50
|
-
rspec-mocks (3.
|
|
48
|
+
rspec-support (~> 3.13.0)
|
|
49
|
+
rspec-mocks (3.13.8)
|
|
51
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
52
|
-
rspec-support (~> 3.
|
|
53
|
-
rspec-support (3.
|
|
54
|
-
rubocop (1.
|
|
55
|
-
json (
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
rspec-support (~> 3.13.0)
|
|
52
|
+
rspec-support (3.13.7)
|
|
53
|
+
rubocop (1.92.2)
|
|
54
|
+
json (>= 2.3)
|
|
55
|
+
language_server-protocol (~> 3.17.0.2)
|
|
56
|
+
lint_roller (~> 1.1.0)
|
|
57
|
+
parallel (>= 1.10)
|
|
58
|
+
parser (>= 3.3.0.2)
|
|
58
59
|
rainbow (>= 2.2.2, < 4.0)
|
|
59
|
-
regexp_parser (>=
|
|
60
|
-
|
|
61
|
-
rubocop-ast (>= 1.26.0, < 2.0)
|
|
60
|
+
regexp_parser (>= 2.11.3, < 3.0)
|
|
61
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
62
62
|
ruby-progressbar (~> 1.7)
|
|
63
|
-
unicode-display_width (>= 2.4.0, <
|
|
64
|
-
rubocop-ast (1.
|
|
65
|
-
parser (>= 3.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
rubocop (
|
|
70
|
-
rubocop-rspec (
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
64
|
+
rubocop-ast (1.50.0)
|
|
65
|
+
parser (>= 3.3.7.2)
|
|
66
|
+
prism (~> 1.7)
|
|
67
|
+
rubocop-rake (0.7.1)
|
|
68
|
+
lint_roller (~> 1.1)
|
|
69
|
+
rubocop (>= 1.72.1)
|
|
70
|
+
rubocop-rspec (3.10.2)
|
|
71
|
+
lint_roller (~> 1.1)
|
|
72
|
+
regexp_parser (>= 2.0)
|
|
73
|
+
rubocop (~> 1.86, >= 1.86.2)
|
|
73
74
|
ruby-progressbar (1.13.0)
|
|
74
|
-
securerandom (0.
|
|
75
|
-
simplecov (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
simplecov_json_formatter (~> 0.1)
|
|
79
|
-
simplecov-html (0.12.3)
|
|
80
|
-
simplecov_json_formatter (0.1.4)
|
|
81
|
-
steep (1.3.2)
|
|
82
|
-
activesupport (>= 5.1)
|
|
75
|
+
securerandom (0.4.1)
|
|
76
|
+
simplecov (1.3.2)
|
|
77
|
+
steep (2.1.0)
|
|
78
|
+
concurrent-ruby (>= 1.1.10)
|
|
83
79
|
csv (>= 3.0.9)
|
|
84
80
|
fileutils (>= 1.1.0)
|
|
85
81
|
json (>= 2.1.0)
|
|
86
|
-
language_server-protocol (>= 3.
|
|
82
|
+
language_server-protocol (>= 3.17.0.4, < 4.0)
|
|
87
83
|
listen (~> 3.0)
|
|
88
84
|
logger (>= 1.3.0)
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
parser (>= 3.2)
|
|
86
|
+
prism (>= 0.25.0)
|
|
91
87
|
rainbow (>= 2.2.2, < 4.0)
|
|
92
|
-
rbs (~> 2
|
|
88
|
+
rbs (~> 4.2)
|
|
93
89
|
securerandom (>= 0.1)
|
|
94
90
|
strscan (>= 1.0.0)
|
|
95
|
-
terminal-table (>= 2, <
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
unicode-display_width (
|
|
91
|
+
terminal-table (>= 2, < 5)
|
|
92
|
+
uri (>= 0.12.0)
|
|
93
|
+
strscan (3.1.8)
|
|
94
|
+
terminal-table (4.0.0)
|
|
95
|
+
unicode-display_width (>= 1.1.1, < 4)
|
|
96
|
+
tsort (0.2.0)
|
|
97
|
+
unicode-display_width (3.3.0)
|
|
98
|
+
unicode-emoji (~> 4.3)
|
|
99
|
+
unicode-emoji (4.3.0)
|
|
100
|
+
uri (1.1.2)
|
|
102
101
|
|
|
103
102
|
PLATFORMS
|
|
104
103
|
arm64-darwin-22
|
|
104
|
+
arm64-darwin-23
|
|
105
|
+
arm64-darwin-24
|
|
106
|
+
arm64-darwin-25
|
|
105
107
|
x86_64-linux
|
|
106
108
|
|
|
107
109
|
DEPENDENCIES
|
|
108
110
|
card_dealer!
|
|
109
|
-
rake (~> 13.
|
|
110
|
-
rspec (~> 3.
|
|
111
|
-
rubocop (~> 1.
|
|
112
|
-
rubocop-rake (~> 0.
|
|
113
|
-
rubocop-rspec (~>
|
|
111
|
+
rake (~> 13.4)
|
|
112
|
+
rspec (~> 3.13)
|
|
113
|
+
rubocop (~> 1.92)
|
|
114
|
+
rubocop-rake (~> 0.7)
|
|
115
|
+
rubocop-rspec (~> 3.10)
|
|
114
116
|
simplecov
|
|
115
|
-
simplecov_json_formatter
|
|
116
117
|
steep
|
|
117
118
|
|
|
118
119
|
BUNDLED WITH
|
|
119
|
-
|
|
120
|
+
4.0.23
|
data/README.md
CHANGED
|
@@ -1,49 +1,58 @@
|
|
|
1
1
|
# CardDealer
|
|
2
|
-
[](https://badge.fury.io/rb/card_dealer)
|
|
3
|
-
[](https://codeclimate.com/github/svyatov/card_dealer/maintainability)
|
|
4
|
-
[](https://codeclimate.com/github/svyatov/card_dealer/test_coverage)
|
|
5
|
-
[](LICENSE.txt)
|
|
6
2
|
|
|
7
|
-
CardDealer
|
|
8
|
-
with ease. Whether you're building a poker night app or a virtual bridge club,
|
|
9
|
-
CardDealer has got you covered. Enjoy customizable deck options, smooth
|
|
10
|
-
shuffling algorithms, and simple yet powerful deck manipulation tools that bring
|
|
11
|
-
the classic card game experience to life.
|
|
3
|
+
CardDealer builds, shuffles, and deals decks of playing cards for Ruby card game applications.
|
|
12
4
|
|
|
13
|
-
|
|
5
|
+
[](https://rubygems.org/gems/card_dealer)
|
|
6
|
+
[](https://github.com/svyatov/card_dealer/actions/workflows/main.yml)
|
|
14
7
|
|
|
15
|
-
|
|
8
|
+
- **Three deck shapes.** Builds standard 52-card and 36-card decks, and custom decks from any ranks, suits, and number of decks.
|
|
9
|
+
- **Replayable shuffles.** Shuffles with Fisher-Yates from a seed you can pass in or read back from the deck.
|
|
10
|
+
- **40 bytes for 52 cards.** Encodes a deck to a binary string for a database, a cache, or a file.
|
|
11
|
+
- **No runtime dependencies.** Requires Ruby 3.3 or newer and nothing else.
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
Add it to your Gemfile:
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
```bash
|
|
16
|
+
bundle add card_dealer
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then build a deck, shuffle it, and deal a hand:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
require "card_dealer"
|
|
23
|
+
|
|
24
|
+
deck = CardDealer::BuildDeck.standard52.shuffle(42)
|
|
25
|
+
deck.deal(5).map(&:to_s) # => ["8d", "4s", "Ts", "Ac", "6s"]
|
|
26
|
+
deck.size # => 47
|
|
27
|
+
```
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
A card prints as its rank (2 to 9, T, J, Q, K, A) followed by its suit (c, d, h, s).
|
|
22
30
|
|
|
23
31
|
## Usage
|
|
24
32
|
|
|
25
|
-
###
|
|
33
|
+
### Building a standard 52-card deck
|
|
26
34
|
|
|
27
|
-
To
|
|
35
|
+
To build a 52-card deck, call `CardDealer::BuildDeck.standard52`:
|
|
28
36
|
|
|
29
37
|
```ruby
|
|
30
38
|
deck = CardDealer::BuildDeck.standard52
|
|
31
|
-
|
|
39
|
+
deck.size # => 52
|
|
40
|
+
deck.to_a.first(3) # => ["2c", "3c", "4c"]
|
|
32
41
|
```
|
|
33
42
|
|
|
34
|
-
###
|
|
43
|
+
### Building a standard 36-card deck
|
|
35
44
|
|
|
36
|
-
To
|
|
45
|
+
To build a 36-card deck, call `CardDealer::BuildDeck.standard36`:
|
|
37
46
|
|
|
38
47
|
```ruby
|
|
39
48
|
deck = CardDealer::BuildDeck.standard36
|
|
40
|
-
|
|
49
|
+
deck.size # => 36
|
|
50
|
+
deck.to_a.first(3) # => ["6c", "7c", "8c"]
|
|
41
51
|
```
|
|
42
52
|
|
|
43
|
-
###
|
|
53
|
+
### Building a custom deck
|
|
44
54
|
|
|
45
|
-
To
|
|
46
|
-
You can specify the number of decks, cards per suit, ranks, and suits:
|
|
55
|
+
To build a custom deck, call `CardDealer::BuildDeck.custom`. `ranks` takes `:highest`, `:lowest`, or an array such as `%w[2 4 6 8 T]`. `suits` takes `:all` or an array such as `%w[d h]`:
|
|
47
56
|
|
|
48
57
|
```ruby
|
|
49
58
|
deck = CardDealer::BuildDeck.custom(
|
|
@@ -52,87 +61,82 @@ deck = CardDealer::BuildDeck.custom(
|
|
|
52
61
|
ranks: :highest,
|
|
53
62
|
suits: %w[c d]
|
|
54
63
|
)
|
|
55
|
-
|
|
64
|
+
deck.size # => 20
|
|
65
|
+
deck.to_a.first(6) # => ["Tc", "Jc", "Qc", "Kc", "Ac", "Td"]
|
|
56
66
|
```
|
|
57
67
|
|
|
58
68
|
### Shuffling and dealing cards
|
|
59
69
|
|
|
60
|
-
|
|
70
|
+
`CardDealer::Deck#shuffle` takes an optional seed. Without one, it generates a seed and stores it in `seed`, so you can replay the shuffle later:
|
|
61
71
|
|
|
62
72
|
```ruby
|
|
63
73
|
deck = CardDealer::BuildDeck.standard52
|
|
64
74
|
deck.shuffle
|
|
65
|
-
|
|
66
|
-
|
|
75
|
+
seed = deck.seed # keep this to replay the shuffle
|
|
76
|
+
hand = deck.deal(5) # => five CardDealer::Card objects
|
|
77
|
+
deck.size # => 47
|
|
67
78
|
```
|
|
68
79
|
|
|
69
|
-
|
|
80
|
+
To burn cards before dealing, pass `burn:`:
|
|
70
81
|
|
|
71
82
|
```ruby
|
|
72
|
-
deck = CardDealer::BuildDeck.standard52
|
|
73
|
-
deck.shuffle
|
|
83
|
+
deck = CardDealer::BuildDeck.standard52.shuffle(42)
|
|
74
84
|
hand = deck.deal(3, burn: 1)
|
|
75
|
-
|
|
85
|
+
hand.map(&:to_s) # => ["4s", "Ts", "Ac"]
|
|
86
|
+
deck.burned_cards.map(&:to_s) # => ["8d"]
|
|
76
87
|
```
|
|
77
88
|
|
|
78
|
-
To burn cards without dealing,
|
|
89
|
+
To burn cards without dealing, deal `0` cards:
|
|
79
90
|
|
|
80
91
|
```ruby
|
|
81
|
-
deck = CardDealer::BuildDeck.standard52
|
|
82
|
-
deck.shuffle
|
|
83
|
-
hand = deck.deal(0, burn: 1)
|
|
84
|
-
puts hand
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Burned cards are stored within the deck and can be accessed via `burned_cards` method:
|
|
88
|
-
|
|
89
|
-
```ruby
|
|
90
|
-
deck = CardDealer::BuildDeck.standard52
|
|
91
|
-
deck.shuffle
|
|
92
|
+
deck = CardDealer::BuildDeck.standard52.shuffle(42)
|
|
92
93
|
deck.deal(0, burn: 10)
|
|
93
|
-
|
|
94
|
+
deck.burned_cards.size # => 10
|
|
95
|
+
deck.size # => 42
|
|
94
96
|
```
|
|
95
97
|
|
|
96
|
-
### Encoding a deck
|
|
98
|
+
### Encoding a deck as a binary string
|
|
97
99
|
|
|
98
|
-
To encode a deck
|
|
99
|
-
This is useful if you'd like to store a deck of cards in a database, cache, or a file:
|
|
100
|
+
To encode a deck, call `CardDealer::BinaryDeck.encode` or `Deck#to_binary_s`. Each card takes 6 bits, after a 1, 2, or 4 byte header carrying the card count:
|
|
100
101
|
|
|
101
102
|
```ruby
|
|
102
|
-
deck = CardDealer::
|
|
103
|
-
|
|
103
|
+
deck = CardDealer::Deck.new([CardDealer::Card.new("As"), CardDealer::Card.new("Td")])
|
|
104
|
+
encoded = CardDealer::BinaryDeck.encode(deck)
|
|
104
105
|
# - or -
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
encoded = deck.to_binary_s
|
|
107
|
+
encoded # => "\x02\xCDP"
|
|
107
108
|
```
|
|
108
109
|
|
|
109
|
-
### Decoding a binary string into a deck
|
|
110
|
+
### Decoding a binary string into a deck
|
|
110
111
|
|
|
111
|
-
To decode a binary string
|
|
112
|
+
To decode a binary string, call `CardDealer::BinaryDeck.decode` or `Deck.from_binary`:
|
|
112
113
|
|
|
113
114
|
```ruby
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
encoded = "\x02\xCDP"
|
|
116
|
+
deck = CardDealer::BinaryDeck.decode(encoded)
|
|
116
117
|
# - or -
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
deck = CardDealer::Deck.from_binary(encoded)
|
|
119
|
+
deck.to_a # => ["As", "Td"]
|
|
119
120
|
```
|
|
120
121
|
|
|
122
|
+
If the payload length does not match the declared card count, decoding raises `CardDealer::BinaryDeck::InvalidEncodingError`.
|
|
123
|
+
|
|
121
124
|
## Development
|
|
122
125
|
|
|
123
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
|
124
|
-
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
|
125
|
-
prompt that will allow you to experiment.
|
|
126
|
+
After checking out the repo, run `bin/setup` to install dependencies. Run `bundle exec rake` to run the type checker, the linter, and the tests. Run `bin/console` for an interactive prompt.
|
|
126
127
|
|
|
127
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
128
|
-
release a new version, update the version number in `version.rb`, and then run
|
|
129
|
-
`bundle exec rake release`, which will create a git tag for the version, push
|
|
130
|
-
git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
128
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `lib/card_dealer/version.rb`. Add the release to `CHANGELOG.md`. Push a tag such as `v0.3.0`, which cuts the release.
|
|
131
129
|
|
|
132
130
|
## Contributing
|
|
133
131
|
|
|
134
|
-
|
|
132
|
+
Read [CONTRIBUTING.md](CONTRIBUTING.md) for setup, tests, and how to open a pull request. To report a vulnerability, follow [SECURITY.md](SECURITY.md).
|
|
133
|
+
|
|
134
|
+
## Help and status
|
|
135
|
+
|
|
136
|
+
Ask questions and report bugs in [GitHub issues](https://github.com/svyatov/card_dealer/issues).
|
|
137
|
+
|
|
138
|
+
CardDealer is actively maintained by one person. Releases happen when there is something to release.
|
|
135
139
|
|
|
136
140
|
## License
|
|
137
141
|
|
|
138
|
-
|
|
142
|
+
CardDealer is available under the [MIT License](LICENSE.txt). Releases are listed in [CHANGELOG.md](CHANGELOG.md).
|
data/SECURITY.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Security policy
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
The latest release on [rubygems.org](https://rubygems.org/gems/card_dealer) receives security fixes. Older releases do not.
|
|
6
|
+
|
|
7
|
+
## Reporting a vulnerability
|
|
8
|
+
|
|
9
|
+
Do not open a public issue for a vulnerability. Use one of these private channels:
|
|
10
|
+
|
|
11
|
+
- [GitHub private vulnerability reporting](https://github.com/svyatov/card_dealer/security/advisories/new)
|
|
12
|
+
- Email to leonid@svyatov.com
|
|
13
|
+
|
|
14
|
+
You will get a reply within 14 days. A fix ships as a new gem release, and the advisory is published after it.
|
data/card_dealer.gemspec
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/card_dealer/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "card_dealer"
|
|
7
|
+
spec.version = CardDealer::VERSION
|
|
8
|
+
spec.authors = ["Leonid Svyatov"]
|
|
9
|
+
spec.email = ["leonid@svyatov.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Builds, shuffles, and deals decks of playing cards."
|
|
12
|
+
spec.description = <<~DESC
|
|
13
|
+
CardDealer builds standard 52-card and 36-card decks and custom decks,
|
|
14
|
+
shuffles them with a seedable Fisher-Yates shuffle, deals and burns cards,
|
|
15
|
+
and encodes a deck to a compact binary string. It has no runtime
|
|
16
|
+
dependencies and requires Ruby 3.3 or newer.
|
|
17
|
+
DESC
|
|
18
|
+
spec.homepage = "https://github.com/svyatov/card_dealer"
|
|
19
|
+
spec.license = "MIT"
|
|
20
|
+
spec.required_ruby_version = ">= 3.3.0"
|
|
21
|
+
|
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
23
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
24
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
|
25
|
+
|
|
26
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
27
|
+
|
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
30
|
+
spec.files = Dir.chdir(__dir__) do
|
|
31
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
32
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
spec.bindir = "exe"
|
|
36
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
37
|
+
spec.require_paths = ["lib"]
|
|
38
|
+
|
|
39
|
+
# Uncomment to register a new dependency of your gem
|
|
40
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
41
|
+
|
|
42
|
+
# For more information and examples about making a new gem, check out our
|
|
43
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
44
|
+
end
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Next feature for CardDealer
|
|
2
|
+
|
|
3
|
+
## Subject
|
|
4
|
+
|
|
5
|
+
Identify the next obvious missing feature in this Ruby gem. Rank one feature, as requested.
|
|
6
|
+
|
|
7
|
+
The best feature candidate is atomic round-robin dealing to multiple hands. There is no evidence that any feature is mandatory.
|
|
8
|
+
|
|
9
|
+
Repair the confirmed binary-decoder truncation defect before adding features. The validation section records its reproduction.
|
|
10
|
+
|
|
11
|
+
Follow-up: commit `4376fae` implements the length check and documents `CardDealer::BinaryDeck::InvalidEncodingError`. The findings below describe the checkout examined before that repair.
|
|
12
|
+
|
|
13
|
+
### Grounding
|
|
14
|
+
|
|
15
|
+
- README.md:3 defines the purpose: "CardDealer builds, shuffles, and deals decks of playing cards for Ruby card game applications."
|
|
16
|
+
- `lib/card_dealer/deck.rb:56-58` implements one contiguous deal with optional burns. Multi-hand distribution requires caller loops.
|
|
17
|
+
- `spec/card_dealer/deck_spec.rb:97-102` intentionally permits empty results. Exact dealing must use an explicit new contract.
|
|
18
|
+
- `lib/card_dealer/binary_deck.rb:68-98` stores remaining card order. It omits the seed and burned cards.
|
|
19
|
+
- `CHANGELOG.md:54-56` records removal of `Deck#reset` and recommends rebuilding with `BuildDeck`.
|
|
20
|
+
- Recent commits `83513ab`, `bb3d2ce`, and `afa9a3d` concern dependency maintenance. They supply no feature-demand evidence.
|
|
21
|
+
- GitHub returned no open issues for `svyatov/card_dealer` on 2026-11-06. No glossary, ADRs, or tracker guide were found.
|
|
22
|
+
|
|
23
|
+
### Method
|
|
24
|
+
|
|
25
|
+
One read-only explorer supplied grounding. Four generation tasks covered all six ideation frames. Their results merged into 18 distinct candidates and three combinations.
|
|
26
|
+
|
|
27
|
+
An independent verifier checked all 21 candidates against the source and arguments. No verifier verdict was overruled.
|
|
28
|
+
|
|
29
|
+
Utility is inferred from the API. Source evidence establishes capability gaps, not consumer demand. Sizes include implementation, signatures, documentation, and meaningful tests.
|
|
30
|
+
|
|
31
|
+
## Ranked ideas
|
|
32
|
+
|
|
33
|
+
### 1. Atomic round-robin dealing to multiple hands
|
|
34
|
+
|
|
35
|
+
Distribute one card to each hand per round, returning ordinary arrays of cards. Check the entire request before removing cards.
|
|
36
|
+
|
|
37
|
+
If capacity is insufficient, raise a documented error and leave the deck unchanged. Preserve the permissive behavior of `deal`.
|
|
38
|
+
|
|
39
|
+
**Basis, direct:** `lib/card_dealer/deck.rb:56` defines `def deal(num = 1, burn: 0)`. Line 57 executes `@burned_cards += cards.shift(burn) if burn.positive?`. Line 58 executes `cards.shift(num)`. This returns a single contiguous group and performs no capacity preflight. `spec/card_dealer/deck_spec.rb:97-102` explicitly tests empty-array results for empty decks.
|
|
40
|
+
|
|
41
|
+
**Why it matters:** Games that distribute alternating cards need a caller loop. Games that require complete hands also need a capacity check.
|
|
42
|
+
|
|
43
|
+
Combining those operations gives one bounded dealing capability. It fits the stated purpose without introducing game rules, players, or hand classes.
|
|
44
|
+
|
|
45
|
+
**Size:** M. The algorithm is small, but public error semantics, signatures, compatibility, and examples need care.
|
|
46
|
+
|
|
47
|
+
**Proposed shape, subject to design:**
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
hands = deck.deal_hands(players: 3, cards_each: 2)
|
|
51
|
+
# From an unshuffled standard deck:
|
|
52
|
+
# [[2c, 5c], [3c, 6c], [4c, 7c]] as Card objects
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The smallest scope has positive player counts, nonnegative card counts, capacity validation, and no burns. Names and zero-count behavior require design review.
|
|
56
|
+
|
|
57
|
+
Atomic means capacity validation before mutation. It does not imply thread safety or protection against external mutation through `cards`.
|
|
58
|
+
|
|
59
|
+
**Main objection:** A short Ruby loop already performs distribution. The feature earns its maintenance cost only if consumers need the shared ordering and failure contract.
|
|
60
|
+
|
|
61
|
+
**Take it further**
|
|
62
|
+
|
|
63
|
+
```text
|
|
64
|
+
$grill-with-docs Atomic round-robin dealing to multiple hands in CardDealer.
|
|
65
|
+
|
|
66
|
+
Basis, direct: lib/card_dealer/deck.rb:56 defines `def deal(num = 1, burn: 0)`. Line 57 executes `@burned_cards += cards.shift(burn) if burn.positive?`. Line 58 executes `cards.shift(num)`. This returns a single contiguous group and performs no capacity preflight. spec/card_dealer/deck_spec.rb:97-102 explicitly tests empty-array results for empty decks.
|
|
67
|
+
|
|
68
|
+
Why it matters: Games that distribute alternating cards need a caller loop. Games that require complete hands also need a capacity check. Combining those operations gives one bounded dealing capability. It fits the stated purpose without introducing game rules, players, or hand classes.
|
|
69
|
+
|
|
70
|
+
Consider a separate API such as deal_hands(players:, cards_each:), returning arrays of Card objects. Distribute one card per player per round. Validate the complete request before mutation. Insufficient capacity must leave the deck unchanged. Preserve existing deal behavior. Start without burns.
|
|
71
|
+
|
|
72
|
+
Challenge whether a documented loop is sufficient before accepting a permanent API. There is no open-issue demand evidence. Resolve names, zero counts, error types, size limits, and compatibility before implementation.
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Cut
|
|
76
|
+
|
|
77
|
+
These cuts rank one next feature. They do not declare every alternative useless. IDs refer to the merged candidate list.
|
|
78
|
+
|
|
79
|
+
| ID | Idea | Basis | Reason |
|
|
80
|
+
| --- | --- | --- | --- |
|
|
81
|
+
| I1 | Round-robin dealing alone | direct: `deck.rb:58`, `cards.shift(num)`, returns one group. | Duplicate of the stronger ranked combination, I20. |
|
|
82
|
+
| I2 | Exact dealing alone | direct: `deck.rb:57-58` burns before dealing, without preflight. | Combined into I20; a standalone strict API remains a separate design choice. |
|
|
83
|
+
| I3 | Peek | direct: `deck.rb:12`, `attr_reader :cards`, already exposes inspection. | Cost over value: `deck.cards.first(n)` already expresses the operation. |
|
|
84
|
+
| I4 | Enumerable iteration | direct: `deck.rb:93`, `cards.map(&:to_s)`, defines string-valued `to_a`. | Cost over value: collection methods exist through `cards`; iteration would need a careful `to_a` contract. |
|
|
85
|
+
| I5 | Full state snapshots | direct: `binary_deck.rb:70-71` encodes cards and size; `:98`, `Deck.new cards`, reconstructs fresh state. | Cost over value: no demonstrated consumer needs seed and burned cards restored. |
|
|
86
|
+
| I6 | Independent deck copies | direct: `deck.rb:23`, `@cards = cards`; `:35` and `:58` mutate the collection. | Cost over value for the next feature: branching demand is unproven and card mutability needs a defined policy. |
|
|
87
|
+
| I7 | Exclude known cards by multiplicity | direct: `build_deck.rb:112-115` repeats decks; `card.rb:91` compares rank and suit values. | Cost over value: useful for simulations, but the scenario is not evidenced. |
|
|
88
|
+
| I8 | Validated binary decoding | direct: `binary_deck.rb:94-95` uses `scan(/.{6}/).take(deck_size)` and map `fetch`; a truncated payload silently decoded one of two declared cards. | Classify as a confirmed repair, not a speculative feature. Prioritize the repair before the ranked feature. |
|
|
89
|
+
| I9 | Ordered import from card notation | direct: `README.md:103` constructs individual cards inside `Deck.new`. | Cost over value: mapping card strings through `Card.new` is already small. |
|
|
90
|
+
| I10 | Generic arbitrary-card decks | reasoned: dealing requires ordered removal, not ranks or suits; separating those concerns enables more games. | Cost over value: expands the domain and conflicts with assumptions in card encoding. |
|
|
91
|
+
| I11 | Caller-supplied random generator | direct: `deck.rb:35`, `Random.new(@seed.to_i)`, constructs the generator internally. | Cost over value: coordinating random streams is unproven demand and complicates replay semantics. |
|
|
92
|
+
| I12 | Replayable operation transcript | direct: `deck.rb:33-35` records a seed; `:56-58` does not log deal operations. | Cost over value: operation history adds persistent session responsibilities. |
|
|
93
|
+
| I13 | Conservation checks | reasoned: comparing initial multiplicities with remaining, burned, and supplied dealt cards detects missing or extra values. | Cost over value: the caller must supply dealt inventory; equal physical copies remain indistinguishable. |
|
|
94
|
+
| I14 | Scenario builder | reasoned: subtracting known cards from the starting multiset reconstructs a remaining population, with multiplicity preserved. | Duplicate of I7 plus existing shuffle composition. |
|
|
95
|
+
| I15 | Streaming binary encoding | direct: `binary_deck.rb:70` builds a complete mapped binary-text string with `join`. | Cost over value: no measured memory or throughput problem justifies the added interface. |
|
|
96
|
+
| I16 | Batch independent simulations | reasoned: each independent trial requires a fresh population; a helper can enforce reconstruction and seed handling. | Outside the focus: adds a simulation workflow above the deck primitives. |
|
|
97
|
+
| I17 | Jokers | reasoned: a distinct joker needs an identity outside ordinary rank/suit pairs; built-in support enables joker games. | Cost over value: no demand evidence justifies changes to Card and binary-format compatibility. |
|
|
98
|
+
| I18 | Documentation recipe only | reasoned: a recipe can teach composition without adding public compatibility obligations. | Outside the requested missing-feature result; retain as the main alternative during design. |
|
|
99
|
+
| I19 | Safe inspection, peek plus iteration | direct: `deck.rb:12` exposes mutable cards; `:93` converts them to strings. | Duplicate of I3 and I4; a combined inspection interface adds scope without stronger demand. |
|
|
100
|
+
| I21 | Reproducible simulation branches | direct: I5, I6, and I7 establish snapshot, copying, and exclusion gaps. | Cost over value: combining three speculative needs creates a larger simulation feature set. |
|
|
101
|
+
|
|
102
|
+
Paths abbreviated in this table refer to `lib/card_dealer/`, except `README.md`.
|
|
103
|
+
|
|
104
|
+
## Validation
|
|
105
|
+
|
|
106
|
+
Read-only Ruby checks confirmed contiguous repeated deals and round-robin distribution using a caller loop.
|
|
107
|
+
|
|
108
|
+
Three two-card contiguous deals produced `[["2c", "3c"], ["4c", "5c"], ["6c", "7c"]]`.
|
|
109
|
+
|
|
110
|
+
The equivalent round-robin loop produced `[["2c", "5c"], ["3c", "6c"], ["4c", "7c"]]` and left 46 cards.
|
|
111
|
+
|
|
112
|
+
A one-card deck given `deal(5, burn: 1)` returned `[]`, left zero remaining cards, and recorded the card as burned.
|
|
113
|
+
|
|
114
|
+
These checks validate the observed primitives. The proposed API has not been implemented.
|
|
115
|
+
|
|
116
|
+
### Confirmed maintenance priority
|
|
117
|
+
|
|
118
|
+
The independent verifier found that a truncated payload can decode successfully with fewer cards than its header declares. A separate local reproduction confirmed it:
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
payload = [2, 0].pack("CC")
|
|
122
|
+
CardDealer::Deck.from_binary(payload).to_a # => ["2c"]
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Location: `lib/card_dealer/binary_deck.rb:93-98`. The header declares two cards, but the returned deck contains one.
|
|
126
|
+
|
|
127
|
+
Cause: scanning produces available six-bit groups, and `take(deck_size)` accepts fewer groups without validating the declared count.
|
|
128
|
+
|
|
129
|
+
Proposed repair: reject incomplete payloads before returning a deck. Define a documented format error and preserve valid binary encodings.
|
|
130
|
+
|
|
131
|
+
The repair is implemented in `4376fae`. Broader malformed-input cases require a separate bounded investigation.
|
|
@@ -12,6 +12,7 @@ module CardDealer
|
|
|
12
12
|
#
|
|
13
13
|
class BinaryDeck
|
|
14
14
|
class DeckTooLargeError < Error; end
|
|
15
|
+
class InvalidEncodingError < Error; end
|
|
15
16
|
|
|
16
17
|
SUIT_MAP = Card::SUIT_MAP.transform_values { |value| value * 13 }
|
|
17
18
|
RANK_MAP = Card::RANK_MAP
|
|
@@ -83,6 +84,8 @@ module CardDealer
|
|
|
83
84
|
#
|
|
84
85
|
# @return [Deck] The decoded deck of cards.
|
|
85
86
|
#
|
|
87
|
+
# @raise [InvalidEncodingError] If the payload length does not match the declared card count.
|
|
88
|
+
#
|
|
86
89
|
# @example
|
|
87
90
|
# encoded_deck = "\x02\xCDP" # (binary string)
|
|
88
91
|
# decoded_deck = CardDealer::BinaryDeck.decode(encoded_deck)
|
|
@@ -91,6 +94,10 @@ module CardDealer
|
|
|
91
94
|
def decode(encoded_deck)
|
|
92
95
|
template = decoding_template_for encoded_deck.bytesize
|
|
93
96
|
deck_size, binary_numbers = encoded_deck.unpack(template)
|
|
97
|
+
if deck_size.nil? || binary_numbers.size != (((deck_size * 6) + 7) / 8) * 8
|
|
98
|
+
raise InvalidEncodingError, "Encoded deck length does not match its card count"
|
|
99
|
+
end
|
|
100
|
+
|
|
94
101
|
cards = binary_numbers.scan(/.{6}/).take(deck_size).map do |binary_number|
|
|
95
102
|
REVERSE_CARD_BINARY_NUMBER_MAP.fetch(binary_number)
|
|
96
103
|
end
|
data/lib/card_dealer/version.rb
CHANGED
data/lib/card_dealer.rb
CHANGED
data/sig/card_dealer/card.rbs
CHANGED
|
@@ -20,6 +20,16 @@ module CardDealer
|
|
|
20
20
|
|
|
21
21
|
def to_s: -> String
|
|
22
22
|
|
|
23
|
+
def eql?: (untyped other) -> bool
|
|
24
|
+
|
|
25
|
+
def hash: -> Integer
|
|
26
|
+
|
|
27
|
+
def ==: (untyped other) -> bool
|
|
28
|
+
|
|
29
|
+
def <=>: (untyped other) -> Integer?
|
|
30
|
+
|
|
31
|
+
def inspect: -> String
|
|
32
|
+
|
|
23
33
|
private
|
|
24
34
|
|
|
25
35
|
def validate_card!: -> void
|
metadata
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: card_dealer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Leonid Svyatov
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: |
|
|
14
|
-
CardDealer
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
manipulation tools that bring the classic card game experience to life.
|
|
13
|
+
CardDealer builds standard 52-card and 36-card decks and custom decks,
|
|
14
|
+
shuffles them with a seedable Fisher-Yates shuffle, deals and burns cards,
|
|
15
|
+
and encodes a deck to a compact binary string. It has no runtime
|
|
16
|
+
dependencies and requires Ruby 3.3 or newer.
|
|
19
17
|
email:
|
|
20
18
|
- leonid@svyatov.com
|
|
21
19
|
executables: []
|
|
@@ -25,12 +23,18 @@ files:
|
|
|
25
23
|
- ".rspec"
|
|
26
24
|
- ".rubocop.yml"
|
|
27
25
|
- CHANGELOG.md
|
|
26
|
+
- CLAUDE.md
|
|
27
|
+
- CODE_OF_CONDUCT.md
|
|
28
|
+
- CONTRIBUTING.md
|
|
28
29
|
- Gemfile
|
|
29
30
|
- Gemfile.lock
|
|
30
31
|
- LICENSE.txt
|
|
31
32
|
- README.md
|
|
32
33
|
- Rakefile
|
|
34
|
+
- SECURITY.md
|
|
33
35
|
- Steepfile
|
|
36
|
+
- card_dealer.gemspec
|
|
37
|
+
- docs/ideation/2026-11-06-next-feature.md
|
|
34
38
|
- lib/card_dealer.rb
|
|
35
39
|
- lib/card_dealer/binary_deck.rb
|
|
36
40
|
- lib/card_dealer/build_deck.rb
|
|
@@ -49,9 +53,8 @@ licenses:
|
|
|
49
53
|
metadata:
|
|
50
54
|
homepage_uri: https://github.com/svyatov/card_dealer
|
|
51
55
|
source_code_uri: https://github.com/svyatov/card_dealer
|
|
52
|
-
changelog_uri: https://github.com/svyatov/card_dealer/blob/
|
|
56
|
+
changelog_uri: https://github.com/svyatov/card_dealer/blob/main/CHANGELOG.md
|
|
53
57
|
rubygems_mfa_required: 'true'
|
|
54
|
-
post_install_message:
|
|
55
58
|
rdoc_options: []
|
|
56
59
|
require_paths:
|
|
57
60
|
- lib
|
|
@@ -59,15 +62,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
59
62
|
requirements:
|
|
60
63
|
- - ">="
|
|
61
64
|
- !ruby/object:Gem::Version
|
|
62
|
-
version: 3.
|
|
65
|
+
version: 3.3.0
|
|
63
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
67
|
requirements:
|
|
65
68
|
- - ">="
|
|
66
69
|
- !ruby/object:Gem::Version
|
|
67
70
|
version: '0'
|
|
68
71
|
requirements: []
|
|
69
|
-
rubygems_version: 3.
|
|
70
|
-
signing_key:
|
|
72
|
+
rubygems_version: 3.6.9
|
|
71
73
|
specification_version: 4
|
|
72
|
-
summary:
|
|
74
|
+
summary: Builds, shuffles, and deals decks of playing cards.
|
|
73
75
|
test_files: []
|