combinations method
- int count
override
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.
Implementation
@override
Iterable<Hand> combinations(int count) sync* {
if (count > _cards.length) return;
if (0 == count || _cards.isEmpty) {
yield newHand();
return;
}
List<Card> cs = _cards.toList();
ojSort(cs);
if (cs.length == count) {
Hand res = Hand(this);
res.pushN(cs.length, cs);
yield res;
return;
}
List<int> a = List<int>.generate(count, (i) => i + 1);
do {
Hand res = Hand(this);
for (int i = 0; i < count; i += 1) {
res.push(cs[a[i] - 1]);
}
yield res;
} while (ojNextCombination(a, cs.length));
}