card_shuffler_2 1.0.1
card_shuffler_2: ^1.0.1 copied to clipboard
A Dart package for shuffling, dealing, and managing playing card decks. Supports standard 52-card decks, custom decks, multiple shuffle algorithms, and dealing hands.
https://github.com/user-attachments/assets/d9493395-cc1f-44fa-afb5-b82a3bea4aab
card_shuffler #
*Submitted by: Group 6 Members: Haseeb 22k-4307 Murtaza 22k-4508 Saad 22k-4345 Shahmir 22k-4414 *
A pure Dart package for shuffling, dealing, and managing standard playing card decks.
Features #
- π Standard 52-card deck (
PlayingCard,Suit,Rank) - π Three shuffle algorithms: Fisher-Yates, Riffle, Overhand
- π΄ Deal hands to multiple players (round-robin)
- βοΈ Cut the deck
- π Reset to original order
- π² Deterministic shuffles via seeded
Random
UI Showcase #
Shuffle & Cut Tab #
Displays all 52 cards in a grid. Tap Shuffle, Cut, or Reset and watch the deck change in real time.
βββββββββββββββββββββββββββββββββββββββββββββββ
β π Card Shuffler Demo [Shuffle & Cut] β
βββββββββββββββββββββββββββββββββββββββββββββββ€
β Standard 52-card deck. Tap Shuffle or Cut! β
β β
β [Shuffle] [Cut] [Reset] β
β β
β Aβ 2β 3β 4β 5β 6β 7β β
β 8β 9β 10β Jβ Qβ Kβ Aβ₯ β
β 2β₯ 3β₯ 4β₯ 5β₯ 6β₯ 7β₯ 8β₯ β
β ... β
βββββββββββββββββββββββββββββββββββββββββββββββ
Deal Hands Tab #
Use sliders to set the number of players (2β8) and cards per hand (1β13), then tap Deal Hands.
βββββββββββββββββββββββββββββββββββββββββββββββ
β Players: 4 ββββββββββββββββ β
β Cards each: 5 βββββββββββββ β
β [Deal Hands] β
β 32 cards remaining in deck β
β βββββββββββββββββββββββββ β
β Player 1: Kβ 7β₯ Aβ¦ 3β£ Jβ β
β Player 2: 5β¦ 2β₯ 10β£ 8β Qβ₯ β
β Player 3: 9β£ 4β¦ 6β Kβ₯ 2β£ β
β Player 4: Aβ Jβ¦ 3β₯ 7β£ 10β¦ β
βββββββββββββββββββββββββββββββββββββββββββββββ
Algorithms Tab #
Pick a shuffle algorithm, run it, and see the resulting order for the first 13 cards.
βββββββββββββββββββββββββββββββββββββββββββββββ
β Choose algorithm: β
β β Fisher-Yates β uniform random β
β β Riffle β splits & interleaves halves β
β β Overhand β cuts small top packets β
β [Run Shuffle] β
β Result (first 13 cards): β
β 7β Aβ¦ Qβ₯ 3β£ 10β 5β¦ Kβ₯ ... β
βββββββββββββββββββββββββββββββββββββββββββββββ
Getting Started #
Add to your pubspec.yaml:
dependencies:
card_shuffler: ^0.0.1
Then import:
import 'package:card_shuffler/card_shuffler.dart';
Usage #
Create a standard deck #
final deck = CardDeck.standard();
print(deck.remaining); // 52
Shuffle the deck #
// Default: Fisher-Yates
deck.shuffle();
// Riffle shuffle
deck.shuffle(algorithm: ShuffleAlgorithm.riffle);
// Overhand shuffle
deck.shuffle(algorithm: ShuffleAlgorithm.overhand);
// Deterministic (for tests)
deck.shuffle(random: Random(42));
Deal cards #
// Deal 5 cards to one player
final hand = deck.deal(5);
print(hand); // [Kβ , 7β₯, Aβ¦, 3β£, Jβ ]
// Deal one card at a time
final card = deck.dealOne(); // returns null if deck is empty
Deal to multiple players #
final result = HandDealer.deal(
deck: deck,
playerCount: 4,
cardsPerHand: 5,
);
for (int i = 0; i < result.playerCount; i++) {
print('Player ${i + 1}: ${result.hands[i]}');
}
print('Remaining: ${result.remainingCards.length}');
Cut the deck #
deck.cut(); // cuts at the middle
deck.cut(10); // cuts at position 10
Peek & reset #
final top = deck.peek(); // see top card without removing it
deck.reset(); // return all cards, restore original order
Custom deck #
final custom = CardDeck.custom([
PlayingCard(rank: Rank.ace, suit: Suit.spades),
PlayingCard(rank: Rank.king, suit: Suit.hearts),
]);
PlayingCard model #
const card = PlayingCard(rank: Rank.ace, suit: Suit.spades);
print(card); // Aβ
print(card.rank.value); // 1
print(card.suit.symbol);// β
API Reference #
PlayingCard #
| Property | Type | Description |
|---|---|---|
rank |
Rank |
Card rank (AceβKing) |
suit |
Suit |
Card suit (β β₯ β¦ β£) |
toString() |
String |
e.g. "Aβ " |
CardDeck #
| Method | Returns | Description |
|---|---|---|
CardDeck.standard() |
CardDeck |
New ordered 52-card deck |
CardDeck.custom(cards) |
CardDeck |
Deck from custom card list |
shuffle({algorithm, random}) |
void |
Shuffle in place |
deal(count) |
List<PlayingCard> |
Remove & return top N cards |
dealOne() |
PlayingCard? |
Remove & return top card |
cut([position]) |
void |
Cut at position (default: middle) |
peek() |
PlayingCard? |
Top card without removing |
reset() |
void |
Restore original 52-card order |
remaining |
int |
Cards left in deck |
isEmpty |
bool |
True if deck is empty |
ShuffleAlgorithm #
| Value | Description |
|---|---|
fisherYates |
Uniform random β every permutation equally likely |
riffle |
Splits deck and interleaves packets |
overhand |
Repeatedly cuts small packets from top |
HandDealer.deal() #
| Parameter | Type | Description |
|---|---|---|
deck |
CardDeck |
The deck to deal from |
playerCount |
int |
Number of players |
cardsPerHand |
int |
Cards per player |
Returns a DealResult with hands (list of player hands) and remainingCards.
Example App #
The example/ folder contains a full Flutter app demonstrating all APIs across three tabs:
- Shuffle & Cut β visual 52-card grid with shuffle/cut/reset buttons
- Deal Hands β configurable multi-player hand dealing
- Algorithms β side-by-side comparison of all three shuffle algorithms
Run the example:
cd example
flutter run
Additional Information #
- This is a Dart-only package (no plugins, no native code).
- All operations mutate the deck in place; use
reset()to restore. - For reproducible results in tests, pass a seeded
Randomtoshuffle().
Submitted by: [Your Group Name] β Members: [Member 1], [Member 2], ...
Topic: Card Shuffler