Module: Shuffles
- Extended by:
- T::Helpers, T::Sig
- Included in:
- Packet
- Defined in:
- lib/deck_of_cards_handler/packet/shuffles.rb
Overview
typed: strict
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.faro_shuffle(top_half:, bottom_half:) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/deck_of_cards_handler/packet/shuffles.rb', line 40 def faro_shuffle(top_half:, bottom_half:) top_cards = top_half.cards bottom_cards = bottom_half.cards remaining_cards = [] remaining_cards = top_cards[bottom_cards.size..top_cards.size] if bottom_cards.size < top_cards.size zipped_cards = bottom_cards.zip(top_cards).flatten.compact [zipped_cards, remaining_cards].flatten.compact end |
.riffle_shuffle(left_half:, right_half:) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/deck_of_cards_handler/packet/shuffles.rb', line 27 def riffle_shuffle(left_half:, right_half:) shuffled_cards = [] until left_half.cards.empty? && right_half.cards.empty? if !left_half.cards.empty? && (right_half.cards.empty? || Kernel.rand < 0.5) shuffled_cards.concat(left_half.cards.shift(Kernel.rand(1..3))) else shuffled_cards.concat(right_half.cards.shift(Kernel.rand(1..3))) end end shuffled_cards end |
Instance Method Details
#overhand_shuffle ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/deck_of_cards_handler/packet/shuffles.rb', line 11 def overhand_shuffle piles = [] until size.zero? chunk_size = Kernel.rand(1..8) chunk_size = size if chunk_size > size piles << cut(number: chunk_size) end reassemble_right_to_left_on_top(piles) end |