class Tundengine::Cards::Card
Attributes
rank[R]
suit[R]
Public Class Methods
new(rank, suit)
click to toggle source
Calls superclass method
Tundengine::AlgebraicDataType::new
# File lib/tundengine/cards/card.rb, line 10 def initialize(rank, suit) @rank = rank @suit = suit super() end
Public Instance Methods
beats?(other_card, trump_suit)
click to toggle source
assumes other_card is winning the current trick
# File lib/tundengine/cards/card.rb, line 33 def beats?(other_card, trump_suit) suit_powers = { other_card.suit => 1, trump_suit => 2 } suit_powers[Suits::Null.instance] = 0 own_suit_power, other_suit_power = [@suit, other_card.suit] .map { |s| suit_powers.fetch(s, 0) } if own_suit_power == other_suit_power beats_same_suit?(other_card) else own_suit_power > other_suit_power end end
beats_same_suit?(other_card)
click to toggle source
# File lib/tundengine/cards/card.rb, line 47 def beats_same_suit?(other_card) @rank > other_card.rank end
exists?()
click to toggle source
# File lib/tundengine/cards/card.rb, line 51 def exists? true end
is_of_any_rank?(ranks)
click to toggle source
# File lib/tundengine/cards/card.rb, line 20 def is_of_any_rank?(ranks) ranks.include? @rank end
is_of_any_suit?(suits)
click to toggle source
# File lib/tundengine/cards/card.rb, line 24 def is_of_any_suit?(suits) suits.include? @suit end
round_points()
click to toggle source
# File lib/tundengine/cards/card.rb, line 28 def round_points @rank.round_points end
to_s()
click to toggle source
# File lib/tundengine/cards/card.rb, line 16 def to_s "#{@rank.to_s} de #{@suit.to_s}" end
Protected Instance Methods
state()
click to toggle source
# File lib/tundengine/cards/card.rb, line 57 def state [@rank, @suit] end