Deck class cards

A "live" Deck of cards that is used for a game.

In a typical game, we expect that the deck will be created once; Hands are created from it; cards are dealt from the deck; the hand is played; and the deck is refilled and shuffled for the next hand of play. Nothing enforces this sequence of events, but it's the one optimzed for.

Inheritance
Implemented types
Available Extensions

Constructors

Deck(String dname)
Create a new Deck from a MasterDeck name

Properties

first Card
The first element.
no setterinherited
hands List<Hand>
Hands spawned from this deck
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Have all Cards been dealt?
no setteroverride
isNotEmpty bool
Are any Cards remaining?
no setteroverride
iterator Iterator<Card>
Implementation of iterator
no setteroverride
last Card
The last element.
no setterinherited
length int
How many Cards remain?
no setteroverride
master MasterDeck
Associated MasterDeck from which to fill this one
final
remaining int
Handy synonym for "length"
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single Card
Checks that this iterable has only one element, and returns that element.
no setterinherited
size int
How many cards in full deck?
no setteroverride

Methods

any(bool test(Card element)) bool
Checks whether any element of this iterable satisfies test.
inherited
cast<R>() Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
clearAll() → void
Clear all associated Hands.
override
combinations(int count) Iterable<Hand>
Iterate over all distinct count-sized Hands from the remaining deck. For this purpose, hands with the same cards in different order are considered "distinct". For example, on a fresh 52-card deck, for h in d.combinations(5) will iterate over all 2598960 5-card hands.
override
contains(Object? element) bool
Does the Deck contain the given Card?
override
dealAll(int n) bool
Deal all Hands created from this deck a number of cards. Useful at the start of a hand of play, e.g. d.dealAll(5);.
override
dealTo(Hand h) bool
Deal a single card to the given Hand
override
elementAt(int index) Card
Returns the indexth element.
inherited
every(bool test(Card element)) bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> toElements(Card element)) Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
firstWhere(bool test(Card element), {Card orElse()?}) Card
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, Card element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<Card> other) Iterable<Card>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(Card element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
join([String separator = ""]) String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(Card element), {Card orElse()?}) Card
The last element that satisfies the given predicate test.
inherited
map<T>(T toElement(Card e)) Iterable<T>
The current elements of this iterable modified by toElement.
inherited
newHand([int? size]) Hand
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pop() Card?
Pop a Card from the Deck. This is expected to be the primary way cards are taken (the dealXX functions call this).
override
popN(int n) Iterable<Card>
Pop a number of Cards from the Deck.
override
push(Card card) → void
Add a Card to the Deck. Not expected to be used often.
override
pushN(int n, Iterable<Card> cards) → void
Push a number of Cards back onto the Deck.
override
reduce(Card combine(Card value, Card element)) Card
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
refill() → void
Refill the Deck from its associated MasterDeck.
override
removeCard(Card card) bool
Remove a specific Card from the Deck by its identity. (e.g. d.removeCard(Card.JackOfClubs)).
override
shuffle() → void
Randomize the Cards remaining in the Deck.
override
singleWhere(bool test(Card element), {Card orElse()?}) Card
The single element that satisfies test.
inherited
skip(int count) Iterable<Card>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(Card value)) Iterable<Card>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
sort() → void
Sort the Deck into the same descending order by Rank and Suit as used for Hands. Note that this will make the deck appear to be in the reverse ascending order when printed (see toString(), below).
override
take(int count) Iterable<Card>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(Card value)) Iterable<Card>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toList({bool growable = true}) List<Card>
Copy the remaining Cards onto a new List.
override
toSet() Set<Card>
Creates a Set containing the same elements as this iterable.
inherited
toString() String
Print contents of Deck. Note that for performance, cards are popped from the end of the list, which makes it the notional "top" of the deck. For testing and simulation purposes, deck contents are shown backwards: i.e., from the end of the list to the front.
override
validCard(Card cin) Card
Validate that the Card passed is legal for this deck. Convert high and low aces if necessary.
override
where(bool test(Card element)) Iterable<Card>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() Iterable<T>
Creates a new lazy Iterable with all elements that have type T.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited