Решение на Четвърта задача от Михаела Чуренска

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

Към профила на Михаела Чуренска

Резултати

  • 1 точка от тестове
  • 0 бонус точки
  • 1 точка общо
  • 8 успешни тест(а)
  • 49 неуспешни тест(а)

Код

class Cards
def initialize (rank,suit)
@rank = rank
@suit = suit
end
def rank
@rank
end
def suit
@suit
end
def to_s
string = "#{@rank.to_s.capitalize} of #{@suit.capitalize}"
puts string + "\n"
return string
end
def ==(item)
if(item.rank == @rank and item.suit == @suit)
true
else
false
end
end
end
class Deck
include Enumerable
def general_array
all_cards = Array.new
array_of_suits = [:spades, :hearts, :diamonds, :clubs]
array_of_ranks = [:ace, :king, :queen, :jack, 10, 9, 8, 7, 6, 5, 4, 3, 2]
array_of_suits.each do |second_argument|
array_of_ranks.each do |first_argument|
all_cards << Cards.new(first_argument,second_argument)
end
end
return all_cards
end
def each
@cards.each { |item| yield item }
end
def initialize(cards = general_array)
@cards = Array.new(cards)
end
def size
@cards.length
end
def draw_random_card
@cards.delete_at(rand(size))
end
def draw_top_card
@cards.delete_at(0)
end
def draw_bottom_card
@cards.delete_at(-1)
end
def top_card
@cards.at(0)
end
def bottom_card
@cards.at(-1)
end
def shuffle
@cards.shuffle
end
def sort(size)
suits = Array.new([:spades, :hearts, :diamonds, :clubs])
case size
when 32
ranks = Array.new([:ace, 10, :king, :queen, :jack, 9, 8, 7])
when 24
ranks = Array.new([9, :jack, :queen, :king, 10, :ace])
else
ranks = Array.new([:ace, :king, :queen, :jack, 10, 9, 8, 7, 6, 5, 4, 3, 2])
end
@cards.sort_by {|item| [suits.index(item.suit), ranks.index(item.rank)]}
end
def to_s
@cards.map do |item|
item.to_s
end
end
def deal(number)
hand = []
i = 0
while (i < number) do
hand.push(@cards[0])
@cards.delete_at(0)
i += 1
end
return hand
end
end
class WarDeck < Deck
include Enumerable
def general_array
all_cards = Array.new
array_of_suits = [:spades, :hearts, :diamonds, :clubs]
array_of_ranks = [:ace, :king, :queen, :jack, 10, 9, 8, 7, 6, 5, 4, 3, 2]
array_of_suits.each do |second_argument|
array_of_ranks.each do |first_argument|
all_cards << Cards.new(first_argument,second_argument)
end
end
return all_cards
end
def initialize(cards = general_array)
super(cards)
end
def each
@cards.each { |item| yield item }
end
def deal(number = 26)
cards_in_hand = super(number)
return WarDeck.new(cards_in_hand)
end
def sort
sorted_cards = super(52)
return WarDeck.new(sorted_cards)
end
def play_card
self.draw_random_card
end
def allow_face_up?
@cards.size <= 3
end
end
class BeloteDeck < Deck
include Enumerable
def general_cards_in_belote
all_cards = Array.new
array_of_suits = [:spades, :hearts, :diamonds, :clubs]
array_of_ranks = [7, 8, 9, 10, :jack, :queen, :king, :ace]
array_of_suits.each do |second_argument|
array_of_ranks.each do |first_argument|
all_cards << Cards.new(first_argument,second_argument)
end
end
return all_cards
end
def each
@cards.each { |item| yield item }
end
def initialize(cards = general_cards_in_belote)
super(cards)
end
def deal(number = 8)
cards_in_hand = super(number)
return BeloteDeck.new(cards_in_hand)
end
def sort
sorted_war_cards = super(32)
return BeloteDeck.new(sorted_war_cards)
end
def highest_of_suit(suits)
array_of_ranks_in_order = [:ace, 10, :king, :queen, :jack, 9, 8, 7]
high_card = @cards.sort_by do |item|
[suits, array_of_ranks_in_order.index(item.rank)]
end
return high_card[0]
end
def belote?
help_array = Array.new
self.each do |item|
if (item.rank == :king or item.rank == :queen)
help_array << item
end
end
[:spades,:hearts,:clubs,:diamonds].each do |variable|
counter = help_array.select { |item| item.suit == variable }
return true if (counter.size == 2)
end
return false
end
def carre_of_jacks?
counter = 0
self.each do |item|
if (item.rank == :jack)
counter += 1
end
end
if (counter == 4)
true
else
false
end
end
def carre_of_nines?
counter = 0
self.each do |item|
if (item.rank == 9)
counter += 1
end
end
if (counter == 4)
true
else
false
end
end
def carre_of_aces?
counter = 0
self.each do |item|
if (item.rank == :ace)
counter += 1
end
end
if (counter == 4)
true
else
false
end
end
end
class SixtySixDeck < Deck
include Enumerable
def general_cards_in_sixty_six
all_cards = Array.new
array_of_suits = [:spades, :hearts, :diamonds, :clubs]
array_of_ranks = [9, 10, :jack, :queen, :king, :ace]
array_of_suits.each do |second_argument|
array_of_ranks.each do |first_argument|
all_cards << Cards.new(first_argument,second_argument)
end
end
return all_cards
end
def each
@cards.each { |item| yield item }
end
def initialize(cards = general_cards_in_sixty_six)
super(cards)
end
def deal(number = 6)
cards_in_hand = super(number)
return SixtySixDeck.new(cards_in_hand)
end
def sort
sorted_sixty_six_cards = super(24)
return SixtySixDeck.new(sorted_sixty_six_cards)
end
def twenty?(trump_suit)
help_array = Array.new
self.each do |item|
if (item.rank == :king or item.rank == :queen)
help_array << item
end
end
[:spades,:hearts,:clubs,:diamonds].each do |variable|
counter = help_array.select { |item| item.suit == variable }
return true if ((counter.size == 2) and (variable != trump_suit))
end
return false
end
def forty?(trump_suit)
help_array = Array.new
self.each do |item|
if (item.rank == :king or item.rank == :queen)
help_array << item
end
end
[:spades,:hearts,:clubs,:diamonds].each do |variable|
counter = help_array.select { |item| item.suit == variable }
return true if ((counter.size == 2) and (variable == trump_suit))
end
return false
end
end

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

FFFFFFFFFF.FF...FFFFFFF.FF.FFFFFFFFFFFFFFFFFFFFFFF.FF.FFF

Failures:

  1) Card #to_s stringifies and capitalizes the rank and suit
     Failure/Error: all_cards = suits.product(ranks).map { |suit, rank| Card.new(rank, suit) }
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:111:in `block (4 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:111:in `map'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:111: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) Card readers has readers for rank and suit
     Failure/Error: card = Card.new(:jack, :spades)
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:122: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)>'

  3) Card #== compares two cards by their rank and suit
     Failure/Error: expect(Card.new(4, :spades)).to eq Card.new(4, :spades)
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:131: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 implements Enumerable
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:140
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  5) WarDeck behaves like a deck fills the deck if no initialize parameters are given
     Failure/Error: all_available_cards = suits.product(ranks).map { |suit, rank| Card.new(rank, suit) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:140
     # /tmp/d20151112-27349-y2s9ha/spec.rb:16:in `block (3 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:16:in `map'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:16: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) WarDeck behaves like a deck #size returns the size of the deck
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:140
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  7) WarDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:140
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  8) WarDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:140
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  9) WarDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:140
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  10) WarDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:140
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  11) WarDeck behaves like a deck #to_s returns the names of the cards, each on its own line
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:140
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  12) WarDeck #sort sorts the cards in the defined order
     Failure/Error: ace_of_clubs   = Card.new(:ace, :clubs)
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:146: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 behaves like a deck implements Enumerable
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:191
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  14) BeloteDeck behaves like a deck fills the deck if no initialize parameters are given
     Failure/Error: all_available_cards = suits.product(ranks).map { |suit, rank| Card.new(rank, suit) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:191
     # /tmp/d20151112-27349-y2s9ha/spec.rb:16:in `block (3 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:16:in `map'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:16: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)>'

  15) BeloteDeck behaves like a deck #size returns the size of the deck
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:191
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  16) BeloteDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:191
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  17) BeloteDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:191
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  18) BeloteDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:191
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  19) BeloteDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:191
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  20) BeloteDeck behaves like a deck #to_s returns the names of the cards, each on its own line
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:191
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  21) BeloteDeck #sort sorts the cards in the defined order
     Failure/Error: ace_of_clubs   = Card.new(:ace, :clubs)
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:197: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)>'

  22) BeloteDeck hand #highest_of_suit returns the strongest card of the specified suit
     Failure/Error: Card.new(:ace, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:222: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 #belote? returns true if there is a king and a queen of the same suit
     Failure/Error: Card.new(:ace, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:241: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 #belote? returns false when there is no king and queen of the same suit
     Failure/Error: Card.new(:ace, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:256: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)>'

  25) BeloteDeck hand #tierce? with tierce returns true for cards with names
     Failure/Error: Card.new(:ace, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:274: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)>'

  26) BeloteDeck hand #tierce? with tierce returns true for cards with numbers
     Failure/Error: Card.new(:ace, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:289: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)>'

  27) BeloteDeck hand #tierce? without tierce does not confuse cards with different suits
     Failure/Error: Card.new(7, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:306: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)>'

  28) BeloteDeck hand #quarte? detects four cards with increasing ranks
     Failure/Error: Card.new(7, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:324: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)>'

  29) BeloteDeck hand #quarte? does not return true if there is no quarte
     Failure/Error: Card.new(7, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:339: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)>'

  30) BeloteDeck hand #quint? detects five cards with increasing ranks
     Failure/Error: Card.new(7, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:356: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)>'

  31) BeloteDeck hand #quint? does not return true if there is no quint
     Failure/Error: Card.new(7, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:371: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)>'

  32) BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns true when there is a carre
     Failure/Error: Card.new(7, :clubs),
     NameError:
       uninitialized constant Card
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-y2s9ha/spec.rb:386
     # /tmp/d20151112-27349-y2s9ha/spec.rb:76: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)>'

  33) BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns false when there is no carre
     Failure/Error: Card.new(7, :clubs),
     NameError:
       uninitialized constant Card
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-y2s9ha/spec.rb:386
     # /tmp/d20151112-27349-y2s9ha/spec.rb:91: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)>'

  34) BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns true when there is a carre
     Failure/Error: Card.new(7, :clubs),
     NameError:
       uninitialized constant Card
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-y2s9ha/spec.rb:390
     # /tmp/d20151112-27349-y2s9ha/spec.rb:76: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)>'

  35) BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns false when there is no carre
     Failure/Error: Card.new(7, :clubs),
     NameError:
       uninitialized constant Card
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-y2s9ha/spec.rb:390
     # /tmp/d20151112-27349-y2s9ha/spec.rb:91: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)>'

  36) BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns true when there is a carre
     Failure/Error: Card.new(7, :clubs),
     NameError:
       uninitialized constant Card
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-y2s9ha/spec.rb:394
     # /tmp/d20151112-27349-y2s9ha/spec.rb:76: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)>'

  37) BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns false when there is no carre
     Failure/Error: Card.new(7, :clubs),
     NameError:
       uninitialized constant Card
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-y2s9ha/spec.rb:394
     # /tmp/d20151112-27349-y2s9ha/spec.rb:91: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)>'

  38) SixtySixDeck behaves like a deck implements Enumerable
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:400
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  39) SixtySixDeck behaves like a deck fills the deck if no initialize parameters are given
     Failure/Error: all_available_cards = suits.product(ranks).map { |suit, rank| Card.new(rank, suit) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:400
     # /tmp/d20151112-27349-y2s9ha/spec.rb:16:in `block (3 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:16:in `map'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:16: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)>'

  40) SixtySixDeck behaves like a deck #size returns the size of the deck
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:400
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  41) SixtySixDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:400
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  42) SixtySixDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:400
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  43) SixtySixDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:400
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  44) SixtySixDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:400
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  45) SixtySixDeck behaves like a deck #to_s returns the names of the cards, each on its own line
     Failure/Error: let(:ace_of_spades) { Card.new(:ace, :spades) }
     NameError:
       uninitialized constant Card
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-y2s9ha/spec.rb:400
     # /tmp/d20151112-27349-y2s9ha/spec.rb:4:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-y2s9ha/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)>'

  46) SixtySixDeck #sort sorts the cards in the defined order
     Failure/Error: ace_of_clubs   = Card.new(:ace, :clubs)
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:406: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)>'

  47) SixtySixDeck hand #twenty? returns true for king and queen not of the trump suit
     Failure/Error: Card.new(:ace, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:431: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)>'

  48) SixtySixDeck hand #twenty? returns false for king and queen of the trump suit
     Failure/Error: Card.new(:ace, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:444: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)>'

  49) SixtySixDeck hand #twenty? returns false for hands without a king and queen of the same suit
     Failure/Error: Card.new(:ace, :clubs),
     NameError:
       uninitialized constant Card
     # /tmp/d20151112-27349-y2s9ha/spec.rb:457: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.09665 seconds
57 examples, 49 failures

Failed examples:

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

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

Михаела обнови решението на 10.11.2015 19:08 (преди над 8 години)

+class Cards
+ def initialize (rank,suit)
+ @rank = rank
+ @suit = suit
+ end
+
+ def rank
+ @rank
+ end
+ def suit
+ @suit
+ end
+
+ def to_s
+ string = "#{@rank.to_s.capitalize} of #{@suit.capitalize}"
+ puts string + "\n"
+ return string
+ end
+
+ def ==(item)
+ if(item.rank == @rank and item.suit == @suit)
+ true
+ else
+ false
+ end
+ end
+end
+
+class Deck
+ include Enumerable
+
+ def general_array
+ all_cards = Array.new
+ array_of_suits = [:spades, :hearts, :diamonds, :clubs]
+ array_of_ranks = [:ace, :king, :queen, :jack, 10, 9, 8, 7, 6, 5, 4, 3, 2]
+ array_of_suits.each do |second_argument|
+ array_of_ranks.each do |first_argument|
+ all_cards << Cards.new(first_argument,second_argument)
+ end
+ end
+ return all_cards
+ end
+
+ def each
+ @cards.each { |item| yield item }
+ end
+
+ def initialize(cards = general_array)
+ @cards = Array.new(cards)
+ end
+
+ def size
+ @cards.length
+ end
+
+ def draw_random_card
+ @cards.delete_at(rand(size))
+ end
+
+ def draw_top_card
+ @cards.delete_at(0)
+ end
+
+ def draw_bottom_card
+ @cards.delete_at(-1)
+ end
+
+ def top_card
+ @cards.at(0)
+ end
+
+ def bottom_card
+ @cards.at(-1)
+ end
+
+ def shuffle
+ @cards.shuffle
+ end
+
+ def sort(size)
+ suits = Array.new([:spades, :hearts, :diamonds, :clubs])
+ case size
+ when 32
+ ranks = Array.new([:ace, 10, :king, :queen, :jack, 9, 8, 7])
+ when 24
+ ranks = Array.new([9, :jack, :queen, :king, 10, :ace])
+ else
+ ranks = Array.new([:ace, :king, :queen, :jack, 10, 9, 8, 7, 6, 5, 4, 3, 2])
+ end
+ @cards.sort_by {|item| [suits.index(item.suit), ranks.index(item.rank)]}
+ end
+
+ def to_s
+ @cards.map do |item|
+ item.to_s
+ end
+ end
+
+ def deal(number)
+ hand = []
+ i = 0
+ while (i < number) do
+ hand.push(@cards[0])
+ @cards.delete_at(0)
+ i += 1
+ end
+ return hand
+ end
+end
+
+
+class WarDeck < Deck
+ include Enumerable
+ def general_array
+ all_cards = Array.new
+ array_of_suits = [:spades, :hearts, :diamonds, :clubs]
+ array_of_ranks = [:ace, :king, :queen, :jack, 10, 9, 8, 7, 6, 5, 4, 3, 2]
+ array_of_suits.each do |second_argument|
+ array_of_ranks.each do |first_argument|
+ all_cards << Cards.new(first_argument,second_argument)
+ end
+ end
+ return all_cards
+ end
+
+ def initialize(cards = general_array)
+ super(cards)
+ end
+
+ def each
+ @cards.each { |item| yield item }
+ end
+
+ def deal(number = 26)
+ cards_in_hand = super(number)
+ return WarDeck.new(cards_in_hand)
+ end
+
+ def sort
+ sorted_cards = super(52)
+ return WarDeck.new(sorted_cards)
+ end
+
+ def play_card
+ self.draw_random_card
+ end
+
+ def allow_face_up?
+ @cards.size <= 3
+ end
+end
+
+class BeloteDeck < Deck
+ include Enumerable
+
+ def general_cards_in_belote
+ all_cards = Array.new
+ array_of_suits = [:spades, :hearts, :diamonds, :clubs]
+ array_of_ranks = [7, 8, 9, 10, :jack, :queen, :king, :ace]
+ array_of_suits.each do |second_argument|
+ array_of_ranks.each do |first_argument|
+ all_cards << Cards.new(first_argument,second_argument)
+ end
+ end
+ return all_cards
+ end
+
+ def each
+ @cards.each { |item| yield item }
+ end
+
+ def initialize(cards = general_cards_in_belote)
+ super(cards)
+ end
+
+ def deal(number = 8)
+ cards_in_hand = super(number)
+ return BeloteDeck.new(cards_in_hand)
+ end
+
+ def sort
+ sorted_war_cards = super(32)
+ return BeloteDeck.new(sorted_war_cards)
+ end
+
+ def highest_of_suit(suits)
+ array_of_ranks_in_order = [:ace, 10, :king, :queen, :jack, 9, 8, 7]
+ high_card = @cards.sort_by do |item|
+ [suits, array_of_ranks_in_order.index(item.rank)]
+ end
+ return high_card[0]
+ end
+
+ def belote?
+ help_array = Array.new
+ self.each do |item|
+ if (item.rank == :king or item.rank == :queen)
+ help_array << item
+ end
+ end
+ [:spades,:hearts,:clubs,:diamonds].each do |variable|
+ counter = help_array.select { |item| item.suit == variable }
+ return true if (counter.size == 2)
+ end
+ return false
+ end
+
+ def carre_of_jacks?
+ counter = 0
+ self.each do |item|
+ if (item.rank == :jack)
+ counter += 1
+ end
+ end
+ if (counter == 4)
+ true
+ else
+ false
+ end
+ end
+
+ def carre_of_nines?
+ counter = 0
+ self.each do |item|
+ if (item.rank == 9)
+ counter += 1
+ end
+ end
+ if (counter == 4)
+ true
+ else
+ false
+ end
+ end
+
+ def carre_of_aces?
+ counter = 0
+ self.each do |item|
+ if (item.rank == :ace)
+ counter += 1
+ end
+ end
+ if (counter == 4)
+ true
+ else
+ false
+ end
+ end
+end
+
+class SixtySixDeck < Deck
+ include Enumerable
+
+ def general_cards_in_sixty_six
+ all_cards = Array.new
+ array_of_suits = [:spades, :hearts, :diamonds, :clubs]
+ array_of_ranks = [9, 10, :jack, :queen, :king, :ace]
+ array_of_suits.each do |second_argument|
+ array_of_ranks.each do |first_argument|
+ all_cards << Cards.new(first_argument,second_argument)
+ end
+ end
+ return all_cards
+ end
+
+ def each
+ @cards.each { |item| yield item }
+ end
+
+ def initialize(cards = general_cards_in_sixty_six)
+ super(cards)
+ end
+
+ def deal(number = 6)
+ cards_in_hand = super(number)
+ return SixtySixDeck.new(cards_in_hand)
+ end
+
+ def sort
+ sorted_sixty_six_cards = super(24)
+ return SixtySixDeck.new(sorted_sixty_six_cards)
+ end
+
+ def twenty?(trump_suit)
+ help_array = Array.new
+ self.each do |item|
+ if (item.rank == :king or item.rank == :queen)
+ help_array << item
+ end
+ end
+ [:spades,:hearts,:clubs,:diamonds].each do |variable|
+ counter = help_array.select { |item| item.suit == variable }
+ return true if ((counter.size == 2) and (variable != trump_suit))
+ end
+ return false
+ end
+
+ def forty?(trump_suit)
+ help_array = Array.new
+ self.each do |item|
+ if (item.rank == :king or item.rank == :queen)
+ help_array << item
+ end
+ end
+ [:spades,:hearts,:clubs,:diamonds].each do |variable|
+ counter = help_array.select { |item| item.suit == variable }
+ return true if ((counter.size == 2) and (variable == trump_suit))
+ end
+ return false
+ end
+end