Решение на Четвърта задача от Пламен Никифоров

Обратно към всички решения

Към профила на Пламен Никифоров

Резултати

  • 2 точки от тестове
  • 1 отнета точка
  • 1 точка общо
  • 16 успешни тест(а)
  • 41 неуспешни тест(а)

Код

class Card
attr_accessor :suit, :rank
SUITS = {spades: :Spades, hearts: :Hearts, diamonds: :Diamonds, clubs: :Clubs}
RANKS = {king: :King, queen: :Queen, ace: :Ace, jack: :Jack}
def initialize(rank, suit)
@rank = rank
SUITS.has_key?(suit) ? @suit = SUITS[suit] : @suit = suit
end
def to_s
if RANKS.has_key?(@rank)
"#{RANKS[@rank]} of #{@suit}"
else
"#{@rank} of #{@suit}"
end
end
def ==(other)
@rank == other.rank and @suit == other.suit
end
end
class Hand
def initialize(cards)
@cards = cards
end
def size
@cards.size
end
end
class WarHand < Hand
def play_card
@cards.pop
end
def allow_face_up?
@cards.size <= 3 ? true : false
end
end
class BeloteHand < Hand
RANKS = {
7 => 1,
8 => 2,
9 => 3,
:jack => 4,
:queen => 5,
:king => 6,
10 => 7,
:ace => 8,
}
def highest_of_suit(suit)
cards_of_suit = @cards.select {|card| card.suit == SUITS[suit]}
cards_of_suit.sort_by{|card| card.rank}[-1]
end
def belote?
cards = cards.select{|card| card.rank == :queen or card.rank == :king}
cards = cards.group_by{|card| card.suit}.detect{|suit| suit[1].size == 2}
cards ? true : false
end
def tierce?
end
def quarte?
end
def quint?
end
def carre_of_jacks?
cards = @cards.group_by{|card| card.rank}
if cards[:jack]
cards[:jack] == 4 ? true : false
else
false
end
end
def carre_of_nines?
cards = @cards.group_by{|card| card.rank}
if cards[9]
cards[9] == 4 ? true : false
else
false
end
end
def carre_of_aces?
cards = @cards.group_by{|card| card.rank}
if cards[:ace]
cards[:ace] == 4 ? true : false
else
false
end
end
end
class SixtySixHand < Hand
SUITS = {spades: :Spades, hearts: :Hearts, diamonds: :Diamonds, clubs: :Clubs}
def twenty?(trump_suit)
cards = @cards.select{|card| card.rank == :queen or card.rank == :king}
cards = cards.group_by{|card| card.suit}.detect{|suit| suit[1].size == 2}
if cards
cards.tap { |suit| suit.delete(SUITS[trump_suit]) }
end
cards ? true : false
end
def forty?(trump_suit)
cards = @cards.select{|card| card.rank == :queen or card.rank == :king}
cards = @cards.group_by{|card| card.suit}
if cards[SUITS[trump_suit]] != nil
cards[SUITS[trump_suit]].size == 2 ? true : false
else
false
end
end
end
class Deck
include Enumerable
SUITS = {Spades: 1, Hearts: 2, Dimonds: 3, Clubs: 4}
RANKS = {
2 => 1,
3 => 2,
4 => 3,
5 => 4,
6 => 5,
7 => 6,
8 => 7,
9 => 8,
10 => 9,
jack: 10,
queen: 11,
king: 12,
ace: 13,
}
def initialize(cards = nil)
@cards = []
cards ? @cards = cards : RANKS.keys.product(SUITS.keys).each do |card|
@cards << Card.new(card[0],card[1])
end
end
def size
@cards.size
end
def draw_top_card
@cards.shift
end
def draw_bottom_card
@cards.pop
end
def top_card
@cards[0]
end
def bottom_card
@cards[@cardsx.size - 1]
end
def shuffle
@cards.sort_by!{ rand }
end
def sort
@cards = @cards.sort_by {|card| [card.suit,RANKS[card.rank]] }.reverse
end
def to_s
@cards.each{|card| puts card}
end
def each
@cards.each{|card| yield card}
end
end
class WarDeck < Deck
def deal
WarHand.new(@cards.first(26))
end
end
class BeloteDeck < Deck
RANKS = {
7 => 1,
8 => 2,
9 => 3,
:jack => 4,
:queen => 5,
:king => 6,
10 => 7,
:ace => 8,
}
def initialize
super
@cards = @cards.reverse.first(32)
end
def deal
BeloteHand.new(@cards.first(8))
end
def sort
@cards = @cards.sort_by {|card| [card.suit,RANKS[card.rank]] }.reverse
end
end
class SixtySixDeck < Deck
RANKS = {9 => 3, :jack => 4, :queen => 5, :king => 6, 10 => 7, :ace => 8}
def initialize
super
@cards = @cards.reverse.first(28)
end
def deal
SixtySixHand.new(@cards.first(6))
end
def sort
@cards = @cards.sort_by {|card| [card.suit,RANKS[card.rank]] }.reverse
end
end

Лог от изпълнението

.F..F....F.Ace of Spades
9 of Clubs
F....FFFFFFF.FF.FFFFFFFFFFFFFFFFFFFFFFF.FF.FFF

Failures:

  1) Card readers has readers for rank and suit
     Failure/Error: expect(card.suit).to eq :spades
       
       expected: :spades
            got: :Spades
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -:spades
       +:Spades
     # /tmp/d20151112-27349-1npwzl8/spec.rb:125:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) WarDeck behaves like a deck fills the deck if no initialize parameters are given
     Failure/Error: expect(deck.to_a).to match_array all_available_cards
       expected collection contained:  [#<Card:0x007f73bb663c68 @rank=2, @suit=:Clubs>, #<Card:0x007f73bb663c40 @rank=3, @suit=:Clubs>, #<Card:0x007f73bb663c18 @rank=4, @suit=:Clubs>, #<Card:0x007f73bb663bf0 @rank=5, @suit=:Clubs>, #<Card:0x007f73bb663bc8 @rank=6, @suit=:Clubs>, #<Card:0x007f73bb663ba0 @rank=7, @suit=:Clubs>, #<Card:0x007f73bb663b78 @rank=8, @suit=:Clubs>, #<Card:0x007f73bb663b50 @rank=9, @suit=:Clubs>, #<Card:0x007f73bb663b28 @rank=10, @suit=:Clubs>, #<Card:0x007f73bb663b00 @rank=:jack, @suit=:Clubs>, #<Card:0x007f73bb663ad8 @rank=:queen, @suit=:Clubs>, #<Card:0x007f73bb663ab0 @rank=:king, @suit=:Clubs>, #<Card:0x007f73bb663a88 @rank=:ace, @suit=:Clubs>, #<Card:0x007f73bb663a60 @rank=2, @suit=:Diamonds>, #<Card:0x007f73bb663a38 @rank=3, @suit=:Diamonds>, #<Card:0x007f73bb663a10 @rank=4, @suit=:Diamonds>, #<Card:0x007f73bb6639e8 @rank=5, @suit=:Diamonds>, #<Card:0x007f73bb6639c0 @rank=6, @suit=:Diamonds>, #<Card:0x007f73bb663998 @rank=7, @suit=:Diamonds>, #<Card:0x007f73bb663970 @rank=8, @suit=:Diamonds>, #<Card:0x007f73bb663948 @rank=9, @suit=:Diamonds>, #<Card:0x007f73bb663920 @rank=10, @suit=:Diamonds>, #<Card:0x007f73bb6638f8 @rank=:jack, @suit=:Diamonds>, #<Card:0x007f73bb6638d0 @rank=:queen, @suit=:Diamonds>, #<Card:0x007f73bb6638a8 @rank=:king, @suit=:Diamonds>, #<Card:0x007f73bb663880 @rank=:ace, @suit=:Diamonds>, #<Card:0x007f73bb6637e0 @rank=2, @suit=:Hearts>, #<Card:0x007f73bb6637b8 @rank=3, @suit=:Hearts>, #<Card:0x007f73bb663790 @rank=4, @suit=:Hearts>, #<Card:0x007f73bb663768 @rank=5, @suit=:Hearts>, #<Card:0x007f73bb663740 @rank=6, @suit=:Hearts>, #<Card:0x007f73bb663718 @rank=7, @suit=:Hearts>, #<Card:0x007f73bb6636f0 @rank=8, @suit=:Hearts>, #<Card:0x007f73bb6636a0 @rank=9, @suit=:Hearts>, #<Card:0x007f73bb663678 @rank=10, @suit=:Hearts>, #<Card:0x007f73bb663650 @rank=:jack, @suit=:Hearts>, #<Card:0x007f73bb663628 @rank=:queen, @suit=:Hearts>, #<Card:0x007f73bb663600 @rank=:king, @suit=:Hearts>, #<Card:0x007f73bb6635d8 @rank=:ace, @suit=:Hearts>, #<Card:0x007f73bb6635b0 @rank=2, @suit=:Spades>, #<Card:0x007f73bb663588 @rank=3, @suit=:Spades>, #<Card:0x007f73bb663560 @rank=4, @suit=:Spades>, #<Card:0x007f73bb663538 @rank=5, @suit=:Spades>, #<Card:0x007f73bb663510 @rank=6, @suit=:Spades>, #<Card:0x007f73bb6634e8 @rank=7, @suit=:Spades>, #<Card:0x007f73bb6634c0 @rank=8, @suit=:Spades>, #<Card:0x007f73bb663498 @rank=9, @suit=:Spades>, #<Card:0x007f73bb663420 @rank=10, @suit=:Spades>, #<Card:0x007f73bb6633f8 @rank=:jack, @suit=:Spades>, #<Card:0x007f73bb6633d0 @rank=:queen, @suit=:Spades>, #<Card:0x007f73bb6633a8 @rank=:king, @suit=:Spades>, #<Card:0x007f73bb663380 @rank=:ace, @suit=:Spades>]
       actual collection contained:    [#<Card:0x007f73bb5e9008 @rank=2, @suit=:Spades>, #<Card:0x007f73bb5e8fe0 @rank=2, @suit=:Hearts>, #<Card:0x007f73bb5e8f90 @rank=2, @suit=:Dimonds>, #<Card:0x007f73bb5e8f68 @rank=2, @suit=:Clubs>, #<Card:0x007f73bb5e8f40 @rank=3, @suit=:Spades>, #<Card:0x007f73bb5e8f18 @rank=3, @suit=:Hearts>, #<Card:0x007f73bb5e8ef0 @rank=3, @suit=:Dimonds>, #<Card:0x007f73bb5e8ec8 @rank=3, @suit=:Clubs>, #<Card:0x007f73bb5e8e78 @rank=4, @suit=:Spades>, #<Card:0x007f73bb5e8e50 @rank=4, @suit=:Hearts>, #<Card:0x007f73bb5e8e28 @rank=4, @suit=:Dimonds>, #<Card:0x007f73bb5e8e00 @rank=4, @suit=:Clubs>, #<Card:0x007f73bb5e8dd8 @rank=5, @suit=:Spades>, #<Card:0x007f73bb5e8d88 @rank=5, @suit=:Hearts>, #<Card:0x007f73bb5e8d38 @rank=5, @suit=:Dimonds>, #<Card:0x007f73bb5e8d10 @rank=5, @suit=:Clubs>, #<Card:0x007f73bb5e8cc0 @rank=6, @suit=:Spades>, #<Card:0x007f73bb5e8c98 @rank=6, @suit=:Hearts>, #<Card:0x007f73bb5e8c70 @rank=6, @suit=:Dimonds>, #<Card:0x007f73bb5e8c20 @rank=6, @suit=:Clubs>, #<Card:0x007f73bb5e8bf8 @rank=7, @suit=:Spades>, #<Card:0x007f73bb5e8bd0 @rank=7, @suit=:Hearts>, #<Card:0x007f73bb5e8ba8 @rank=7, @suit=:Dimonds>, #<Card:0x007f73bb5e8b80 @rank=7, @suit=:Clubs>, #<Card:0x007f73bb5e8b58 @rank=8, @suit=:Spades>, #<Card:0x007f73bb5e8b08 @rank=8, @suit=:Hearts>, #<Card:0x007f73bb5e8ae0 @rank=8, @suit=:Dimonds>, #<Card:0x007f73bb5e8ab8 @rank=8, @suit=:Clubs>, #<Card:0x007f73bb5e8a90 @rank=9, @suit=:Spades>, #<Card:0x007f73bb5e8a40 @rank=9, @suit=:Hearts>, #<Card:0x007f73bb5e8a18 @rank=9, @suit=:Dimonds>, #<Card:0x007f73bb5e89f0 @rank=9, @suit=:Clubs>, #<Card:0x007f73bb5e89a0 @rank=10, @suit=:Spades>, #<Card:0x007f73bb5e8978 @rank=10, @suit=:Hearts>, #<Card:0x007f73bb5e8950 @rank=10, @suit=:Dimonds>, #<Card:0x007f73bb5e8928 @rank=10, @suit=:Clubs>, #<Card:0x007f73bb5e8900 @rank=:jack, @suit=:Spades>, #<Card:0x007f73bb5e88d8 @rank=:jack, @suit=:Hearts>, #<Card:0x007f73bb5e8888 @rank=:jack, @suit=:Dimonds>, #<Card:0x007f73bb5e8860 @rank=:jack, @suit=:Clubs>, #<Card:0x007f73bb5e8838 @rank=:queen, @suit=:Spades>, #<Card:0x007f73bb5e8810 @rank=:queen, @suit=:Hearts>, #<Card:0x007f73bb5e87e8 @rank=:queen, @suit=:Dimonds>, #<Card:0x007f73bb5e87c0 @rank=:queen, @suit=:Clubs>, #<Card:0x007f73bb5e8770 @rank=:king, @suit=:Spades>, #<Card:0x007f73bb5e8748 @rank=:king, @suit=:Hearts>, #<Card:0x007f73bb5e8720 @rank=:king, @suit=:Dimonds>, #<Card:0x007f73bb5e86f8 @rank=:king, @suit=:Clubs>, #<Card:0x007f73bb5e86d0 @rank=:ace, @suit=:Spades>, #<Card:0x007f73bb5e86a8 @rank=:ace, @suit=:Hearts>, #<Card:0x007f73bb5e8658 @rank=:ace, @suit=:Dimonds>, #<Card:0x007f73bb5e8630 @rank=:ace, @suit=:Clubs>]
       the missing elements were:      [#<Card:0x007f73bb663a60 @rank=2, @suit=:Diamonds>, #<Card:0x007f73bb663a38 @rank=3, @suit=:Diamonds>, #<Card:0x007f73bb663a10 @rank=4, @suit=:Diamonds>, #<Card:0x007f73bb6639e8 @rank=5, @suit=:Diamonds>, #<Card:0x007f73bb6639c0 @rank=6, @suit=:Diamonds>, #<Card:0x007f73bb663998 @rank=7, @suit=:Diamonds>, #<Card:0x007f73bb663970 @rank=8, @suit=:Diamonds>, #<Card:0x007f73bb663948 @rank=9, @suit=:Diamonds>, #<Card:0x007f73bb663920 @rank=10, @suit=:Diamonds>, #<Card:0x007f73bb6638f8 @rank=:jack, @suit=:Diamonds>, #<Card:0x007f73bb6638d0 @rank=:queen, @suit=:Diamonds>, #<Card:0x007f73bb6638a8 @rank=:king, @suit=:Diamonds>, #<Card:0x007f73bb663880 @rank=:ace, @suit=:Diamonds>]
       the extra elements were:        [#<Card:0x007f73bb5e8f90 @rank=2, @suit=:Dimonds>, #<Card:0x007f73bb5e8ef0 @rank=3, @suit=:Dimonds>, #<Card:0x007f73bb5e8e28 @rank=4, @suit=:Dimonds>, #<Card:0x007f73bb5e8d38 @rank=5, @suit=:Dimonds>, #<Card:0x007f73bb5e8c70 @rank=6, @suit=:Dimonds>, #<Card:0x007f73bb5e8ba8 @rank=7, @suit=:Dimonds>, #<Card:0x007f73bb5e8ae0 @rank=8, @suit=:Dimonds>, #<Card:0x007f73bb5e8a18 @rank=9, @suit=:Dimonds>, #<Card:0x007f73bb5e8950 @rank=10, @suit=:Dimonds>, #<Card:0x007f73bb5e8888 @rank=:jack, @suit=:Dimonds>, #<Card:0x007f73bb5e87e8 @rank=:queen, @suit=:Dimonds>, #<Card:0x007f73bb5e8720 @rank=:king, @suit=:Dimonds>, #<Card:0x007f73bb5e8658 @rank=:ace, @suit=:Dimonds>]
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:140
     # /tmp/d20151112-27349-1npwzl8/spec.rb:18:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) WarDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: expect(small_deck.bottom_card).to eq nine_of_clubs
     NoMethodError:
       undefined method `size' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:140
     # /tmp/d20151112-27349-1npwzl8/solution.rb:184:in `bottom_card'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) WarDeck behaves like a deck #to_s returns the names of the cards, each on its own line
     Failure/Error: expect(small_deck.to_s.strip).to eq "Ace of Spades\n9 of Clubs"
     NoMethodError:
       undefined method `strip' for #<Array:0x007f73bb6ac3a0>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:140
     # /tmp/d20151112-27349-1npwzl8/spec.rb:68:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) BeloteDeck behaves like a deck implements Enumerable
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:191
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:10:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) BeloteDeck behaves like a deck fills the deck if no initialize parameters are given
     Failure/Error: expect(deck.to_a).to match_array all_available_cards
       expected collection contained:  [#<Card:0x007f73bb638180 @rank=7, @suit=:Clubs>, #<Card:0x007f73bb638158 @rank=8, @suit=:Clubs>, #<Card:0x007f73bb638130 @rank=9, @suit=:Clubs>, #<Card:0x007f73bb638108 @rank=:jack, @suit=:Clubs>, #<Card:0x007f73bb6380e0 @rank=:queen, @suit=:Clubs>, #<Card:0x007f73bb6380b8 @rank=:king, @suit=:Clubs>, #<Card:0x007f73bb638090 @rank=10, @suit=:Clubs>, #<Card:0x007f73bb638068 @rank=:ace, @suit=:Clubs>, #<Card:0x007f73bb639e68 @rank=7, @suit=:Diamonds>, #<Card:0x007f73bb633f90 @rank=8, @suit=:Diamonds>, #<Card:0x007f73bb633f68 @rank=9, @suit=:Diamonds>, #<Card:0x007f73bb633f40 @rank=:jack, @suit=:Diamonds>, #<Card:0x007f73bb633f18 @rank=:queen, @suit=:Diamonds>, #<Card:0x007f73bb633ef0 @rank=:king, @suit=:Diamonds>, #<Card:0x007f73bb633e50 @rank=10, @suit=:Diamonds>, #<Card:0x007f73bb633e28 @rank=:ace, @suit=:Diamonds>, #<Card:0x007f73bb633e00 @rank=7, @suit=:Hearts>, #<Card:0x007f73bb633dd8 @rank=8, @suit=:Hearts>, #<Card:0x007f73bb633d88 @rank=9, @suit=:Hearts>, #<Card:0x007f73bb633d60 @rank=:jack, @suit=:Hearts>, #<Card:0x007f73bb633d38 @rank=:queen, @suit=:Hearts>, #<Card:0x007f73bb633d10 @rank=:king, @suit=:Hearts>, #<Card:0x007f73bb633ce8 @rank=10, @suit=:Hearts>, #<Card:0x007f73bb633cc0 @rank=:ace, @suit=:Hearts>, #<Card:0x007f73bb633c98 @rank=7, @suit=:Spades>, #<Card:0x007f73bb633c48 @rank=8, @suit=:Spades>, #<Card:0x007f73bb633c20 @rank=9, @suit=:Spades>, #<Card:0x007f73bb633bd0 @rank=:jack, @suit=:Spades>, #<Card:0x007f73bb633ba8 @rank=:queen, @suit=:Spades>, #<Card:0x007f73bb633b80 @rank=:king, @suit=:Spades>, #<Card:0x007f73bb633b30 @rank=10, @suit=:Spades>, #<Card:0x007f73bb633b08 @rank=:ace, @suit=:Spades>]
       actual collection contained:    [#<Card:0x007f73bb638a68 @rank=:ace, @suit=:Clubs>, #<Card:0x007f73bb638a90 @rank=:ace, @suit=:Dimonds>, #<Card:0x007f73bb638ab8 @rank=:ace, @suit=:Hearts>, #<Card:0x007f73bb638ae0 @rank=:ace, @suit=:Spades>, #<Card:0x007f73bb638b08 @rank=:king, @suit=:Clubs>, #<Card:0x007f73bb638b30 @rank=:king, @suit=:Dimonds>, #<Card:0x007f73bb638b58 @rank=:king, @suit=:Hearts>, #<Card:0x007f73bb638b80 @rank=:king, @suit=:Spades>, #<Card:0x007f73bb638ba8 @rank=:queen, @suit=:Clubs>, #<Card:0x007f73bb638bd0 @rank=:queen, @suit=:Dimonds>, #<Card:0x007f73bb638bf8 @rank=:queen, @suit=:Hearts>, #<Card:0x007f73bb638c20 @rank=:queen, @suit=:Spades>, #<Card:0x007f73bb638c48 @rank=:jack, @suit=:Clubs>, #<Card:0x007f73bb638c70 @rank=:jack, @suit=:Dimonds>, #<Card:0x007f73bb638c98 @rank=:jack, @suit=:Hearts>, #<Card:0x007f73bb638cc0 @rank=:jack, @suit=:Spades>, #<Card:0x007f73bb638ce8 @rank=10, @suit=:Clubs>, #<Card:0x007f73bb638d10 @rank=10, @suit=:Dimonds>, #<Card:0x007f73bb638d38 @rank=10, @suit=:Hearts>, #<Card:0x007f73bb638d60 @rank=10, @suit=:Spades>, #<Card:0x007f73bb638d88 @rank=9, @suit=:Clubs>, #<Card:0x007f73bb638db0 @rank=9, @suit=:Dimonds>, #<Card:0x007f73bb638dd8 @rank=9, @suit=:Hearts>, #<Card:0x007f73bb638e00 @rank=9, @suit=:Spades>, #<Card:0x007f73bb638e28 @rank=8, @suit=:Clubs>, #<Card:0x007f73bb638e50 @rank=8, @suit=:Dimonds>, #<Card:0x007f73bb638e78 @rank=8, @suit=:Hearts>, #<Card:0x007f73bb638ea0 @rank=8, @suit=:Spades>, #<Card:0x007f73bb638ec8 @rank=7, @suit=:Clubs>, #<Card:0x007f73bb638ef0 @rank=7, @suit=:Dimonds>, #<Card:0x007f73bb638f18 @rank=7, @suit=:Hearts>, #<Card:0x007f73bb638f40 @rank=7, @suit=:Spades>]
       the missing elements were:      [#<Card:0x007f73bb639e68 @rank=7, @suit=:Diamonds>, #<Card:0x007f73bb633f90 @rank=8, @suit=:Diamonds>, #<Card:0x007f73bb633f68 @rank=9, @suit=:Diamonds>, #<Card:0x007f73bb633f40 @rank=:jack, @suit=:Diamonds>, #<Card:0x007f73bb633f18 @rank=:queen, @suit=:Diamonds>, #<Card:0x007f73bb633ef0 @rank=:king, @suit=:Diamonds>, #<Card:0x007f73bb633e50 @rank=10, @suit=:Diamonds>, #<Card:0x007f73bb633e28 @rank=:ace, @suit=:Diamonds>]
       the extra elements were:        [#<Card:0x007f73bb638a90 @rank=:ace, @suit=:Dimonds>, #<Card:0x007f73bb638b30 @rank=:king, @suit=:Dimonds>, #<Card:0x007f73bb638bd0 @rank=:queen, @suit=:Dimonds>, #<Card:0x007f73bb638c70 @rank=:jack, @suit=:Dimonds>, #<Card:0x007f73bb638d10 @rank=10, @suit=:Dimonds>, #<Card:0x007f73bb638db0 @rank=9, @suit=:Dimonds>, #<Card:0x007f73bb638e50 @rank=8, @suit=:Dimonds>, #<Card:0x007f73bb638ef0 @rank=7, @suit=:Dimonds>]
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:191
     # /tmp/d20151112-27349-1npwzl8/spec.rb:18:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) BeloteDeck behaves like a deck #size returns the size of the deck
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:191
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:23:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) BeloteDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:191
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:29:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) BeloteDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:191
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:36:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) BeloteDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:191
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:43:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) BeloteDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:191
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) BeloteDeck behaves like a deck #to_s returns the names of the cards, each on its own line
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:191
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:68:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  13) BeloteDeck #sort sorts the cards in the defined order
     Failure/Error: deck = BeloteDeck.new(cards)
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:204:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:204:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  14) BeloteDeck hand #highest_of_suit returns the strongest card of the specified suit
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:221:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:221:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  15) BeloteDeck hand #belote? returns true if there is a king and a queen of the same suit
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:240:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:240:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  16) BeloteDeck hand #belote? returns false when there is no king and queen of the same suit
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:255:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:255:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  17) BeloteDeck hand #tierce? with tierce returns true for cards with names
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:273:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:273:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  18) BeloteDeck hand #tierce? with tierce returns true for cards with numbers
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:288:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:288:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  19) BeloteDeck hand #tierce? without tierce does not confuse cards with different suits
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:305:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:305:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  20) BeloteDeck hand #quarte? detects four cards with increasing ranks
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:323:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:323:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  21) BeloteDeck hand #quarte? does not return true if there is no quarte
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:338:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:338:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  22) BeloteDeck hand #quint? detects five cards with increasing ranks
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:355:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:355:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  23) BeloteDeck hand #quint? does not return true if there is no quint
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:370:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:370:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  24) BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns true when there is a carre
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-1npwzl8/spec.rb:386
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:75:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:75:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  25) BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns false when there is no carre
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-1npwzl8/spec.rb:386
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:90:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:90:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  26) BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns true when there is a carre
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-1npwzl8/spec.rb:390
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:75:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:75:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  27) BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns false when there is no carre
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-1npwzl8/spec.rb:390
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:90:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:90:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  28) BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns true when there is a carre
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-1npwzl8/spec.rb:394
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:75:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:75:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  29) BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns false when there is no carre
     Failure/Error: hand = BeloteDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-1npwzl8/spec.rb:394
     # /tmp/d20151112-27349-1npwzl8/solution.rb:226:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:90:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:90:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  30) SixtySixDeck behaves like a deck implements Enumerable
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:400
     # /tmp/d20151112-27349-1npwzl8/solution.rb:245:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:10:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  31) SixtySixDeck behaves like a deck fills the deck if no initialize parameters are given
     Failure/Error: expect(deck.to_a).to match_array all_available_cards
       expected collection contained:  [#<Card:0x007f73bb3dea60 @rank=9, @suit=:Clubs>, #<Card:0x007f73bb3dea38 @rank=:jack, @suit=:Clubs>, #<Card:0x007f73bb3de9c0 @rank=:queen, @suit=:Clubs>, #<Card:0x007f73bb3de998 @rank=:king, @suit=:Clubs>, #<Card:0x007f73bb3de970 @rank=10, @suit=:Clubs>, #<Card:0x007f73bb3de880 @rank=:ace, @suit=:Clubs>, #<Card:0x007f73bb3de830 @rank=9, @suit=:Diamonds>, #<Card:0x007f73bb3de790 @rank=:jack, @suit=:Diamonds>, #<Card:0x007f73bb3de740 @rank=:queen, @suit=:Diamonds>, #<Card:0x007f73bb3de678 @rank=:king, @suit=:Diamonds>, #<Card:0x007f73bb3de628 @rank=10, @suit=:Diamonds>, #<Card:0x007f73bb3de5b0 @rank=:ace, @suit=:Diamonds>, #<Card:0x007f73bb3de588 @rank=9, @suit=:Hearts>, #<Card:0x007f73bb3de560 @rank=:jack, @suit=:Hearts>, #<Card:0x007f73bb3de510 @rank=:queen, @suit=:Hearts>, #<Card:0x007f73bb3de470 @rank=:king, @suit=:Hearts>, #<Card:0x007f73bb3de3f8 @rank=10, @suit=:Hearts>, #<Card:0x007f73bb3de3d0 @rank=:ace, @suit=:Hearts>, #<Card:0x007f73bb3de358 @rank=9, @suit=:Spades>, #<Card:0x007f73bb3de330 @rank=:jack, @suit=:Spades>, #<Card:0x007f73bb3de290 @rank=:queen, @suit=:Spades>, #<Card:0x007f73bb3de268 @rank=:king, @suit=:Spades>, #<Card:0x007f73bb3de240 @rank=10, @suit=:Spades>, #<Card:0x007f73bb3de218 @rank=:ace, @suit=:Spades>]
       actual collection contained:    [#<Card:0x007f73bb3df460 @rank=:ace, @suit=:Clubs>, #<Card:0x007f73bb3df4b0 @rank=:ace, @suit=:Dimonds>, #<Card:0x007f73bb3df500 @rank=:ace, @suit=:Hearts>, #<Card:0x007f73bb3df528 @rank=:ace, @suit=:Spades>, #<Card:0x007f73bb3df550 @rank=:king, @suit=:Clubs>, #<Card:0x007f73bb3df578 @rank=:king, @suit=:Dimonds>, #<Card:0x007f73bb3df618 @rank=:king, @suit=:Hearts>, #<Card:0x007f73bb3df640 @rank=:king, @suit=:Spades>, #<Card:0x007f73bb3df6b8 @rank=:queen, @suit=:Clubs>, #<Card:0x007f73bb3df708 @rank=:queen, @suit=:Dimonds>, #<Card:0x007f73bb3df758 @rank=:queen, @suit=:Hearts>, #<Card:0x007f73bb3df780 @rank=:queen, @suit=:Spades>, #<Card:0x007f73bb3df898 @rank=:jack, @suit=:Clubs>, #<Card:0x007f73bb3df910 @rank=:jack, @suit=:Dimonds>, #<Card:0x007f73bb3dfaa0 @rank=:jack, @suit=:Hearts>, #<Card:0x007f73bb3dfb18 @rank=:jack, @suit=:Spades>, #<Card:0x007f73bb3dfbe0 @rank=10, @suit=:Clubs>, #<Card:0x007f73bb3dfc80 @rank=10, @suit=:Dimonds>, #<Card:0x007f73bb3dfdc0 @rank=10, @suit=:Hearts>, #<Card:0x007f73bb3dfe88 @rank=10, @suit=:Spades>, #<Card:0x007f73bb3dff78 @rank=9, @suit=:Clubs>, #<Card:0x007f73bb407bb8 @rank=9, @suit=:Dimonds>, #<Card:0x007f73bb407528 @rank=9, @suit=:Hearts>, #<Card:0x007f73bb4069e8 @rank=9, @suit=:Spades>, #<Card:0x007f73bb406290 @rank=8, @suit=:Clubs>, #<Card:0x007f73bb405f48 @rank=8, @suit=:Dimonds>, #<Card:0x007f73bb404008 @rank=8, @suit=:Hearts>, #<Card:0x007f73bb404080 @rank=8, @suit=:Spades>]
       the missing elements were:      [#<Card:0x007f73bb3de830 @rank=9, @suit=:Diamonds>, #<Card:0x007f73bb3de790 @rank=:jack, @suit=:Diamonds>, #<Card:0x007f73bb3de740 @rank=:queen, @suit=:Diamonds>, #<Card:0x007f73bb3de678 @rank=:king, @suit=:Diamonds>, #<Card:0x007f73bb3de628 @rank=10, @suit=:Diamonds>, #<Card:0x007f73bb3de5b0 @rank=:ace, @suit=:Diamonds>]
       the extra elements were:        [#<Card:0x007f73bb3df4b0 @rank=:ace, @suit=:Dimonds>, #<Card:0x007f73bb3df578 @rank=:king, @suit=:Dimonds>, #<Card:0x007f73bb3df708 @rank=:queen, @suit=:Dimonds>, #<Card:0x007f73bb3df910 @rank=:jack, @suit=:Dimonds>, #<Card:0x007f73bb3dfc80 @rank=10, @suit=:Dimonds>, #<Card:0x007f73bb407bb8 @rank=9, @suit=:Dimonds>, #<Card:0x007f73bb406290 @rank=8, @suit=:Clubs>, #<Card:0x007f73bb405f48 @rank=8, @suit=:Dimonds>, #<Card:0x007f73bb404008 @rank=8, @suit=:Hearts>, #<Card:0x007f73bb404080 @rank=8, @suit=:Spades>]
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:400
     # /tmp/d20151112-27349-1npwzl8/spec.rb:18:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  32) SixtySixDeck behaves like a deck #size returns the size of the deck
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:400
     # /tmp/d20151112-27349-1npwzl8/solution.rb:245:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:23:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  33) SixtySixDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:400
     # /tmp/d20151112-27349-1npwzl8/solution.rb:245:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:29:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  34) SixtySixDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:400
     # /tmp/d20151112-27349-1npwzl8/solution.rb:245:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:36:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  35) SixtySixDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:400
     # /tmp/d20151112-27349-1npwzl8/solution.rb:245:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:43:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  36) SixtySixDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:400
     # /tmp/d20151112-27349-1npwzl8/solution.rb:245:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  37) SixtySixDeck behaves like a deck #to_s returns the names of the cards, each on its own line
     Failure/Error: let(:small_deck) { deck_class.new([ace_of_spades, nine_of_clubs]) }
     ArgumentError:
       wrong number of arguments (1 for 0)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1npwzl8/spec.rb:400
     # /tmp/d20151112-27349-1npwzl8/solution.rb:245:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:68:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  38) SixtySixDeck #sort sorts the cards in the defined order
     Failure/Error: deck = SixtySixDeck.new(cards)
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:245:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:413:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:413:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  39) SixtySixDeck hand #twenty? returns true for king and queen not of the trump suit
     Failure/Error: hand = SixtySixDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:245:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:430:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:430:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  40) SixtySixDeck hand #twenty? returns false for king and queen of the trump suit
     Failure/Error: hand = SixtySixDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:245:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:443:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:443:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  41) SixtySixDeck hand #twenty? returns false for hands without a king and queen of the same suit
     Failure/Error: hand = SixtySixDeck.new([
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-1npwzl8/solution.rb:245:in `initialize'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:456:in `new'
     # /tmp/d20151112-27349-1npwzl8/spec.rb:456:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.04404 seconds
57 examples, 41 failures

Failed examples:

rspec /tmp/d20151112-27349-1npwzl8/spec.rb:121 # Card readers has readers for rank and suit
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:14 # WarDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:49 # WarDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:67 # WarDeck behaves like a deck #to_s returns the names of the cards, each on its own line
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:8 # BeloteDeck behaves like a deck implements Enumerable
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:14 # BeloteDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:22 # BeloteDeck behaves like a deck #size returns the size of the deck
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:28 # BeloteDeck behaves like a deck #draw_top_card pops the top-most card
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:35 # BeloteDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:42 # BeloteDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:49 # BeloteDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:67 # BeloteDeck behaves like a deck #to_s returns the names of the cards, each on its own line
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:196 # BeloteDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:220 # BeloteDeck hand #highest_of_suit returns the strongest card of the specified suit
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:239 # BeloteDeck hand #belote? returns true if there is a king and a queen of the same suit
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:254 # BeloteDeck hand #belote? returns false when there is no king and queen of the same suit
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:272 # BeloteDeck hand #tierce? with tierce returns true for cards with names
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:287 # BeloteDeck hand #tierce? with tierce returns true for cards with numbers
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:304 # BeloteDeck hand #tierce? without tierce does not confuse cards with different suits
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:322 # BeloteDeck hand #quarte? detects four cards with increasing ranks
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:337 # BeloteDeck hand #quarte? does not return true if there is no quarte
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:354 # BeloteDeck hand #quint? detects five cards with increasing ranks
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:369 # BeloteDeck hand #quint? does not return true if there is no quint
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:74 # BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns true when there is a carre
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:89 # BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns false when there is no carre
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:74 # BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns true when there is a carre
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:89 # BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns false when there is no carre
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:74 # BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns true when there is a carre
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:89 # BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns false when there is no carre
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:8 # SixtySixDeck behaves like a deck implements Enumerable
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:14 # SixtySixDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:22 # SixtySixDeck behaves like a deck #size returns the size of the deck
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:28 # SixtySixDeck behaves like a deck #draw_top_card pops the top-most card
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:35 # SixtySixDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:42 # SixtySixDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:49 # SixtySixDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:67 # SixtySixDeck behaves like a deck #to_s returns the names of the cards, each on its own line
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:405 # SixtySixDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:429 # SixtySixDeck hand #twenty? returns true for king and queen not of the trump suit
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:442 # SixtySixDeck hand #twenty? returns false for king and queen of the trump suit
rspec /tmp/d20151112-27349-1npwzl8/spec.rb:455 # SixtySixDeck hand #twenty? returns false for hands without a king and queen of the same suit

История (2 версии и 1 коментар)

Пламен обнови решението на 11.11.2015 16:57 (преди около 9 години)

+class Card
+ attr_accessor :suit, :rank
+
+ SUITS = {spades: :Spades, hearts: :Hearts, diamonds: :Diamonds, clubs: :Clubs}
+ RANKS = {king: :King, queen: :Queen, ace: :Ace, jack: :Jack}
+ def initialize(rank, suit)
+ @rank = rank
+ SUITS.has_key?(suit) ? @suit = SUITS[suit] : @suit = suit
+ end
+
+ def to_s
+ if RANKS.has_key?(@rank)
+ "#{RANKS[@rank]} of #{@suit}"
+ else
+ "#{@rank} of #{@suit}"
+ end
+ end
+
+ def ==(other)
+ @rank == other.rank and @suit == other.suit
+ end
+end
+
+class Hand
+
+ def initialize(cards)
+ @cards = cards
+ end
+
+ def size
+ @cards.size
+ end
+
+end
+
+class WarHand < Hand
+
+ def play_card
+ @cards.pop
+ end
+
+ def allow_face_up?
+ @cards.size <= 3 ? true : false
+ end
+
+end
+
+class BeloteHand < Hand
+
+ RANKS = {
+ 7 => 1,
+ 8 => 2,
+ 9 => 3,
+ :jack => 4,
+ :queen => 5,
+ :king => 6,
+ 10 => 7,
+ :ace => 8,
+ }
+
+ def highest_of_suit(suit)
+ cards_of_suit = @cards.select {|card| card.suit == SUITS[suit]}
+ cards_of_suit.sort_by{|card| card.rank}[-1]
+ end
+
+ def belote?
+ cards = cards.select{|card| card.rank == :queen or card.rank == :king}
+ cards = cards.group_by{|card| card.suit}.detect{|suit| suit[1].size == 2}
+ cards ? true : false
+ end
+
+ def tierce?
+
+ end
+
+ def quarte?
+
+ end
+
+ def quint?
+
+ end
+
+ def carre_of_jacks?
+ cards = @cards.group_by{|card| card.rank}
+ if cards[:jack]
+ cards[:jack] == 4 ? true : false
+ else
+ false
+ end
+ end
+
+ def carre_of_nines?
+ cards = @cards.group_by{|card| card.rank}
+ if cards[9]
+ cards[9] == 4 ? true : false
+ else
+ false
+ end
+ end
+
+ def carre_of_aces?
+ cards = @cards.group_by{|card| card.rank}
+ if cards[:ace]
+ cards[:ace] == 4 ? true : false
+ else
+ false
+ end
+ end
+
+end
+
+class SixtySixHand < Hand
+
+ SUITS = {spades: :Spades, hearts: :Hearts, diamonds: :Diamonds, clubs: :Clubs}
+
+ def twenty?(trump_suit)
+ cards = @cards.select{|card| card.rank == :queen or card.rank == :king}
+ cards = cards.group_by{|card| card.suit}.detect{|suit| suit[1].size == 2}
+ if cards
+ cards.tap { |suit| suit.delete(SUITS[trump_suit]) }
+ end
+ cards ? true : false
+ end
+
+ def forty?(trump_suit)
+ cards = @cards.select{|card| card.rank == :queen or card.rank == :king}
+ cards = @cards.group_by{|card| card.suit}
+
+ if cards[SUITS[trump_suit]] != nil
+ cards[SUITS[trump_suit]].size == 2 ? true : false
+ else
+ false
+ end
+ end
+
+end
+
+class Deck
+
+ include Enumerable
+
+ SUITS = {Spades: 1, Hearts: 2, Dimonds: 3, Clubs: 4}
+ RANKS = {
+ 2 => 1,
+ 3 => 2,
+ 4 => 3,
+ 5 => 4,
+ 6 => 5,
+ 7 => 6,
+ 8 => 7,
+ 9 => 8,
+ 10 => 9,
+ jack: 10,
+ queen: 11,
+ king: 12,
+ ace: 13,
+ }
+
+ def initialize(cards = nil)
+ @cards = []
+ cards ? @cards = cards : RANKS.keys.product(SUITS.keys).each do |card|
+ @cards << Card.new(card[0],card[1])
+ end
+ end
+
+ def size
+ @cards.size
+ end
+
+ def draw_top_card
+ @cards.shift
+ end
+
+ def draw_bottom_card
+ @cards.pop
+ end
+
+ def top_card
+ @cards[0]
+ end
+
+ def bottom_card
+ @cards[@cardsx.size - 1]
+ end
+
+ def shuffle
+ @cards.sort_by!{ rand }
+ end
+
+ def sort
+ @cards = @cards.sort_by {|card| [card.suit,RANKS[card.rank]] }.reverse
+ end
+
+ def to_s
+ @cards.each{|card| puts card}
+ end
+
+ def each
+ @cards.each{|card| yield card}
+ end
+
+end
+
+class WarDeck < Deck
+
+ def deal
+ WarHand.new(@cards.first(26))
+ end
+
+end
+
+class BeloteDeck < Deck
+
+ RANKS = {
+ 7 => 1,
+ 8 => 2,
+ 9 => 3,
+ :jack => 4,
+ :queen => 5,
+ :king => 6,
+ 10 => 7,
+ :ace => 8,
+ }
+
+ def initialize
+ super
+ @cards = @cards.reverse.first(32)
+ end
+
+ def deal
+ BeloteHand.new(@cards.first(8))
+ end
+
+ def sort
+ @cards = @cards.sort_by {|card| [card.suit,RANKS[card.rank]] }.reverse
+ end
+
+end
+
+class SixtySixDeck < Deck
+
+ RANKS = {9 => 3, :jack => 4, :queen => 5, :king => 6, 10 => 7, :ace => 8}
+
+ def initialize
+ super
+ @cards = @cards.reverse.first(28)
+ end
+
+ def deal
+ SixtySixHand.new(@cards.first(6))
+ end
+
+ def sort
+ @cards = @cards.sort_by {|card| [card.suit,RANKS[card.rank]] }.reverse
+ end
+
+end
+

Пламен обнови решението на 11.11.2015 17:08 (преди около 9 години)

class Card
attr_accessor :suit, :rank
SUITS = {spades: :Spades, hearts: :Hearts, diamonds: :Diamonds, clubs: :Clubs}
RANKS = {king: :King, queen: :Queen, ace: :Ace, jack: :Jack}
def initialize(rank, suit)
@rank = rank
SUITS.has_key?(suit) ? @suit = SUITS[suit] : @suit = suit
end
def to_s
- if RANKS.has_key?(@rank)
- "#{RANKS[@rank]} of #{@suit}"
- else
+ if RANKS.has_key?(@rank)
+ "#{RANKS[@rank]} of #{@suit}"
+ else
"#{@rank} of #{@suit}"
end
end
def ==(other)
@rank == other.rank and @suit == other.suit
end
end
class Hand
def initialize(cards)
@cards = cards
end
def size
@cards.size
end
end
class WarHand < Hand
def play_card
@cards.pop
end
def allow_face_up?
@cards.size <= 3 ? true : false
end
end
class BeloteHand < Hand
RANKS = {
7 => 1,
8 => 2,
9 => 3,
:jack => 4,
:queen => 5,
:king => 6,
10 => 7,
:ace => 8,
}
def highest_of_suit(suit)
cards_of_suit = @cards.select {|card| card.suit == SUITS[suit]}
cards_of_suit.sort_by{|card| card.rank}[-1]
end
def belote?
cards = cards.select{|card| card.rank == :queen or card.rank == :king}
cards = cards.group_by{|card| card.suit}.detect{|suit| suit[1].size == 2}
cards ? true : false
end
def tierce?
end
def quarte?
end
def quint?
end
def carre_of_jacks?
cards = @cards.group_by{|card| card.rank}
if cards[:jack]
cards[:jack] == 4 ? true : false
else
false
end
end
def carre_of_nines?
cards = @cards.group_by{|card| card.rank}
if cards[9]
cards[9] == 4 ? true : false
else
false
end
end
def carre_of_aces?
- cards = @cards.group_by{|card| card.rank}
+ cards = @cards.group_by{|card| card.rank}
if cards[:ace]
cards[:ace] == 4 ? true : false
else
false
end
end
end
class SixtySixHand < Hand
SUITS = {spades: :Spades, hearts: :Hearts, diamonds: :Diamonds, clubs: :Clubs}
def twenty?(trump_suit)
cards = @cards.select{|card| card.rank == :queen or card.rank == :king}
cards = cards.group_by{|card| card.suit}.detect{|suit| suit[1].size == 2}
if cards
cards.tap { |suit| suit.delete(SUITS[trump_suit]) }
end
cards ? true : false
end
def forty?(trump_suit)
cards = @cards.select{|card| card.rank == :queen or card.rank == :king}
cards = @cards.group_by{|card| card.suit}
if cards[SUITS[trump_suit]] != nil
cards[SUITS[trump_suit]].size == 2 ? true : false
else
false
end
end
end
class Deck
include Enumerable
SUITS = {Spades: 1, Hearts: 2, Dimonds: 3, Clubs: 4}
RANKS = {
- 2 => 1,
- 3 => 2,
- 4 => 3,
- 5 => 4,
- 6 => 5,
- 7 => 6,
- 8 => 7,
- 9 => 8,
- 10 => 9,
- jack: 10,
- queen: 11,
- king: 12,
- ace: 13,
+ 2 => 1,
+ 3 => 2,
+ 4 => 3,
+ 5 => 4,
+ 6 => 5,
+ 7 => 6,
+ 8 => 7,
+ 9 => 8,
+ 10 => 9,
+ jack: 10,
+ queen: 11,
+ king: 12,
+ ace: 13,
}
def initialize(cards = nil)
@cards = []
cards ? @cards = cards : RANKS.keys.product(SUITS.keys).each do |card|
@cards << Card.new(card[0],card[1])
end
end
def size
@cards.size
end
def draw_top_card
@cards.shift
end
def draw_bottom_card
- @cards.pop
+ @cards.pop
end
def top_card
@cards[0]
end
def bottom_card
- @cards[@cardsx.size - 1]
+ @cards[@cardsx.size - 1]
end
def shuffle
- @cards.sort_by!{ rand }
+ @cards.sort_by!{ rand }
end
def sort
- @cards = @cards.sort_by {|card| [card.suit,RANKS[card.rank]] }.reverse
+ @cards = @cards.sort_by {|card| [card.suit,RANKS[card.rank]] }.reverse
end
def to_s
@cards.each{|card| puts card}
end
def each
@cards.each{|card| yield card}
end
end
class WarDeck < Deck
def deal
WarHand.new(@cards.first(26))
end
end
class BeloteDeck < Deck
RANKS = {
- 7 => 1,
- 8 => 2,
- 9 => 3,
- :jack => 4,
- :queen => 5,
- :king => 6,
- 10 => 7,
- :ace => 8,
+ 7 => 1,
+ 8 => 2,
+ 9 => 3,
+ :jack => 4,
+ :queen => 5,
+ :king => 6,
+ 10 => 7,
+ :ace => 8,
}
def initialize
- super
- @cards = @cards.reverse.first(32)
+ super
+ @cards = @cards.reverse.first(32)
end
def deal
BeloteHand.new(@cards.first(8))
end
def sort
@cards = @cards.sort_by {|card| [card.suit,RANKS[card.rank]] }.reverse
end
end
class SixtySixDeck < Deck
RANKS = {9 => 3, :jack => 4, :queen => 5, :king => 6, 10 => 7, :ace => 8}
def initialize
- super
- @cards = @cards.reverse.first(28)
+ super
+ @cards = @cards.reverse.first(28)
end
def deal
SixtySixHand.new(@cards.first(6))
end
def sort
- @cards = @cards.sort_by {|card| [card.suit,RANKS[card.rank]] }.reverse
+ @cards = @cards.sort_by {|card| [card.suit,RANKS[card.rank]] }.reverse
end
-end
-
+end

Имаш значителни проблеми със спазването на конвенциите на места, направи справка с ръководството за стил.

Освен това, вадиш текст на екрана, вместо да го връщаш като стойност.

Прегледай решенията на колеги и нашето примерно решение за алтернативни идеи.