Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A delightful card dealing companion for your digital table.

License

NotificationsYou must be signed in to change notification settings

svyatov/card_dealer

Repository files navigation

Gem VersionMaintainabilityTest CoverageMIT License

CardDealer is your go-to gem for creating, shuffling, and dealing decks of cardswith ease. Whether you're building a poker night app or a virtual bridge club,CardDealer has got you covered. Enjoy customizable deck options, smoothshuffling algorithms, and simple yet powerful deck manipulation tools that bringthe classic card game experience to life.

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add card_dealer

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install card_dealer

Usage

Creating a standard 52-card deck

To create a standard 52-card deck, use theCardDealer::BuildDeck.standard52 method:

deck=CardDealer::BuildDeck.standard52putsdeck.cards

Creating a standard 36-card deck

To create a standard 36-card deck, use theCardDealer::BuildDeck.standard36 method:

deck=CardDealer::BuildDeck.standard36putsdeck.cards

Creating a custom deck of cards

To create a custom deck of cards, use theCardDealer::BuildDeck.custom method.You can specify the number of decks, cards per suit, ranks, and suits:

deck=CardDealer::BuildDeck.custom(decks:2,cards_per_suit:5,ranks::highest,suits:%w[cd])putsdeck.cards

Shuffling and dealing cards

TheCardDealer::Deck class provides methods for shuffling and dealing cards:

deck=CardDealer::BuildDeck.standard52deck.shufflehand=deck.deal(5)putshand

You can also burn cards before dealing:

deck=CardDealer::BuildDeck.standard52deck.shufflehand=deck.deal(3,burn:1)putshand

To burn cards without dealing, just pass0 as the number of cards to deal:

deck=CardDealer::BuildDeck.standard52deck.shufflehand=deck.deal(0,burn:1)putshand

Burned cards are stored within the deck and can be accessed viaburned_cards method:

deck=CardDealer::BuildDeck.standard52deck.shuffledeck.deal(0,burn:10)putsdeck.burned_cards

Encoding a deck of cards as a binary string

To encode a deck of cards as a binary string, use theCardDealer::BinaryDeck.encode method.This is useful if you'd like to store a deck of cards in a database, cache, or a file:

deck=CardDealer::BuildDeck.standard52encoded_deck=CardDealer::BinaryDeck.encode(deck)# - or -encoded_deck=deck.to_binary_sputsencoded_deck

Decoding a binary string into a deck of cards

To decode a binary string into a deck of cards, use theCardDealer::BinaryDeck.decode method:

encoded_deck="\x02\xCDP"# binary stringdecoded_deck=CardDealer::BinaryDeck.decode(encoded_deck)# - or -decoded_deck=CardDealer::Deck.from_binary(encoded_deck)putsdecoded_deck.cards

Development

After checking out the repo, runbin/setup to install dependencies. Then, runrake spec to run the tests. You can also runbin/console for an interactiveprompt that will allow you to experiment.

To install this gem onto your local machine, runbundle exec rake install. Torelease a new version, update the version number inversion.rb, and then runbundle exec rake release, which will create a git tag for the version, pushgit commits and the created tag, and push the.gem file torubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub athttps://github.com/svyatov/card_dealer.

License

The gem is available as open source under the terms of theMIT License.

About

A delightful card dealing companion for your digital table.

Topics

Resources

License

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp