Class: Tundengine::Hand
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Tundengine::Hand
- Defined in:
- lib/tundengine/hand.rb
Instance Method Summary collapse
- #has_all_of?(ranks = Deck::RANKS, suits = Deck::SUITS) ⇒ Boolean
- #has_knight_and_king_of?(suit) ⇒ Boolean
-
#playable_cards(trick) ⇒ Object
returns the playable cards and whether any of them would beat the current trick.
- #to_s ⇒ Object
Instance Method Details
#has_all_of?(ranks = Deck::RANKS, suits = Deck::SUITS) ⇒ Boolean
26 27 28 |
# File 'lib/tundengine/hand.rb', line 26 def has_all_of?(ranks = Deck::RANKS, suits = Deck::SUITS) Deck.cards_of(Array(ranks), Array(suits)).all? { |c| self.include? c } end |
#has_knight_and_king_of?(suit) ⇒ Boolean
22 23 24 |
# File 'lib/tundengine/hand.rb', line 22 def has_knight_and_king_of?(suit) has_all_of?([Ranks::Once, Ranks::Doce].map(&:instance), suit) end |
#playable_cards(trick) ⇒ Object
returns the playable cards and whether any of them would beat the current trick
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tundengine/hand.rb', line 5 def playable_cards(trick) suit_followers = trick.first_suit.percolate(self) trick_beaters = trick .percolate(self) suit_followers_trick_beaters = suit_followers & trick_beaters [ [suit_followers_trick_beaters, true ], [suit_followers, false], [trick_beaters, true ], [self, false] ] .find { |cards_subset, _| not cards_subset.empty? } end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/tundengine/hand.rb', line 30 def to_s "[#{map(&:to_s).join(', ')}]" end |