pub struct Deck { /* private fields */ }Implementations§
Source§impl Deck
impl Deck
Source§impl Deck
impl Deck
Sourcepub fn draw_guaranteeing_set(&mut self, hand: &[Card]) -> Option<Vec<Card>>
pub fn draw_guaranteeing_set(&mut self, hand: &[Card]) -> Option<Vec<Card>>
The smallest number of cards guaranteed to contain a Set is
21. However, the odds that there are no sets in 18 cards is so
low that it almost never happens in practice. As long as there
are at least 6 cards in the stock, we can doctor the deck to
guarantee that 18 cards will contain a Set:
15 (table) + 6 (stock) == 21
If there are only 3 more cards to deal, you could still get stuck with 18 cards, but at that point the game would be over.
In the worst case scenario, 15 cards are on the table, 6 remain
in the stock, and there’s exactly 1 Set amongst those 21
cards.* There are 3 cases we need to handle:
-
Two cards from the
Setare on the table, and one is in the stock. We need to make sure that the one card in the stock is in the next draw. -
One card from the
Setis on the table, and two are in the stock. We need to make sure that both cards in the stock are in the next draw. -
All three cards in the
Setare in the stock. We need to put those three cards into the next draw.
*NOTE: It’s possible that 21 cards always contain 2 or more sets. As far as I know, that’s an open question.