Решение на Четвърта задача от Иван Станков

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

Към профила на Иван Станков

Резултати

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

Код

RANKS = (1..14).to_a
HIGH_CARDS = {jack: 11, queen: 12, king: 13, ace: 14}
SUITS ={spades: 0, hearts: 1, diamonds: 2, clubs: 3}
class Card
attr_accessor :rank, :suit, :rank_number
def initialize(rank = 2, suit = :spades)
@rank = rank
@rank_number = self.get_rank_number
@suit = suit
end
def get_rank_number
if HIGH_CARDS.include?(@rank) then
return HIGH_CARDS[@rank]
elsif @rank.class != "Symbol" && (@rank >= 2 || @rank <= 10) then
return @rank
end
end
def ==(other)
if self.suit != other.suit then return false end
if self.rank != other.rank then return false end
true
end
def <(other)
if self == other then return false end
if self.rank_number < other.rank_number then return true end
if SUITS[self.suit] < SUITS[other.suit] then return true end
return false
end
def to_s
rank_string = rank.to_s.capitalize
suit_string = suit.to_s.capitalize
rank_string + " of " + suit_string
end
end
class Deck
include Enumerable
attr_accessor :hand
attr_accessor :deck
def initialize(deck = self.get_deck)
@deck = deck
@hand = []
@hand_size = 26
end
def each
yield
end
def get_deck
basic_deck = Array.new()
(0..3).each do |suit|
(1..13).each do |rank|
basic_deck << Card.new(get_rank(rank), SUITS.keys[suit])
end
end
@deck = basic_deck
end
def get_rank(rank)
if rank < 10 then
return RANKS[rank]
else
return HIGH_CARDS.keys[rank - 10]
end
end
def size
@deck.count
end
def draw_top_card(deck)
end
def draw_bottom_card(deck)
end
def top_card
end
def bottom_card
end
def shuffle
@deck.shuffle
end
def sort
@deck.sort{ |first, second|
first.suit <=> second.suit
}
@deck.reverse
end
def to_s
@deck.each{|card| p card.to_s}
end
def get_hand
hand = Array.new
(0..(@hand_size - 1)).each {|card|
hand << @deck[card]
}
hand
end
def deal
Deck.new(self.get_hand)
end
def allow_face_up?
false
end
def is_hand?
self.size <= @hand_size
end
end
class WarDeck < Deck
attr_accessor :deck
def initialize(deck = self.get_deck)
super
end
def play_card
@deck.delete(@deck[Random.rand(self.size)])
end
def allow_face_up?
self.deck.size < 3
end
def deal
WarDeck.new(get_hand)
end
end
class BeloteDeck < Deck
def initialize(deck = self.get_deck)
super
@hand_size = 8
@deck = deck.delete_if{|card|
if card < Card.new(7,:spades) then
RANKS[card.rank] < 8
end
}
end
def deal
BeloteDeck.new(get_hand)
end
def highest_of_suit(suit)
found_card = false
highest_of_suit = Card.new(1,suit)
@deck.each {|card|
highest_of_suit = higher_card_check(highest_of_suit, card, suit)
}
return nil unless Card.new(1,suit) < highest_of_suit
highest_of_suit
end
def higher_card_check(current_high, new_card, suit)
if current_high < new_card && new_card.suit == suit then
current_high = new_card
end
current_high
end
def belote?
end
def tierce?
end
def quarte?
end
def quint?
end
def carre_of_jacks?
end
def carre_of_nines?
end
def carre_of_aces?
end
end
class SixtySixDeck < Deck
def initialize(deck = self.get_deck)
super
@hand_size = 6
end
def deal
SixtySixDeck.new(get_hand)
end
def twenty?
end
def forty?
end
end

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

...FF.FFFF."Ace of Spades"
"9 of Clubs"
FF..FFF.FFFF."Ace of Spades"
"9 of Clubs"
FF..FFFFFFFFFFFFFFFFF.FFFF."Ace of Spades"
"9 of Clubs"
FF.FFF

Failures:

  1) WarDeck behaves like a deck implements Enumerable
     Failure/Error: expect(small_deck.to_a).to eq [ace_of_spades, nine_of_clubs]
       
       expected: [#<Card:0x007f3d9da672c8 @rank=:ace, @rank_number=14, @suit=:spades>, #<Card:0x007f3d9da672a0 @rank=9, @rank_number=9, @suit=:clubs>]
            got: [nil]
       
       (compared using ==)
       
       Diff:
       @@ -1,3 +1,2 @@
       -[#<Card:0x007f3d9da672c8 @rank=:ace, @rank_number=14, @suit=:spades>,
       - #<Card:0x007f3d9da672a0 @rank=9, @rank_number=9, @suit=:clubs>]
       +[nil]
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:140
     # /tmp/d20151112-27349-rqsn3h/spec.rb:11: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)>'

  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
     NoMethodError:
       undefined method `suit' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:140
     # /tmp/d20151112-27349-rqsn3h/solution.rb:22:in `=='
     # /tmp/d20151112-27349-rqsn3h/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 #draw_top_card pops the top-most card
     Failure/Error: expect(small_deck.draw_top_card).to eq ace_of_spades
     ArgumentError:
       wrong number of arguments (0 for 1)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:140
     # /tmp/d20151112-27349-rqsn3h/solution.rb:77:in `draw_top_card'
     # /tmp/d20151112-27349-rqsn3h/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)>'

  4) WarDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: expect(small_deck.draw_bottom_card).to eq nine_of_clubs
     ArgumentError:
       wrong number of arguments (0 for 1)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:140
     # /tmp/d20151112-27349-rqsn3h/solution.rb:80:in `draw_bottom_card'
     # /tmp/d20151112-27349-rqsn3h/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)>'

  5) WarDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: expect(small_deck.top_card).to eq ace_of_spades
       
       expected: #<Card:0x007f3d9e8d0620 @rank=:ace, @rank_number=14, @suit=:spades>
            got: nil
       
       (compared using ==)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:140
     # /tmp/d20151112-27349-rqsn3h/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)>'

  6) WarDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: expect(small_deck.bottom_card).to eq nine_of_clubs
       
       expected: #<Card:0x007f3d9e855358 @rank=9, @rank_number=9, @suit=:clubs>
            got: nil
       
       (compared using ==)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:140
     # /tmp/d20151112-27349-rqsn3h/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)>'

  7) 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:0x007f3d9e90f280>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:140
     # /tmp/d20151112-27349-rqsn3h/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)>'

  8) WarDeck #sort sorts the cards in the defined order
     Failure/Error: expect(deck.sort.to_a).to eq [jack_of_spades, ten_of_hearts, ace_of_clubs, two_of_clubs]
       
       expected: [#<Card:0x007f3d9e90c6e8 @rank=:jack, @rank_number=11, @suit=:spades>, #<Card:0x007f3d9e90ce90 @rank=10, @rank_number=10, @suit=:hearts>, #<Card:0x007f3d9e90c5f8 @rank=:ace, @rank_number=14, @suit=:clubs>, #<Card:0x007f3d9e90cf30 @rank=2, @rank_number=2, @suit=:clubs>]
            got: [#<Card:0x007f3d9e90ce90 @rank=10, @rank_number=10, @suit=:hearts>, #<Card:0x007f3d9e90cf30 @rank=2, @rank_number=2, @suit=:clubs>, #<Card:0x007f3d9e90c6e8 @rank=:jack, @rank_number=11, @suit=:spades>, #<Card:0x007f3d9e90c5f8 @rank=:ace, @rank_number=14, @suit=:clubs>]
       
       (compared using ==)
       
       Diff:
       @@ -1,5 +1,5 @@
       -[#<Card:0x007f3d9e90c6e8 @rank=:jack, @rank_number=11, @suit=:spades>,
       - #<Card:0x007f3d9e90ce90 @rank=10, @rank_number=10, @suit=:hearts>,
       - #<Card:0x007f3d9e90c5f8 @rank=:ace, @rank_number=14, @suit=:clubs>,
       - #<Card:0x007f3d9e90cf30 @rank=2, @rank_number=2, @suit=:clubs>]
       +[#<Card:0x007f3d9e90ce90 @rank=10, @rank_number=10, @suit=:hearts>,
       + #<Card:0x007f3d9e90cf30 @rank=2, @rank_number=2, @suit=:clubs>,
       + #<Card:0x007f3d9e90c6e8 @rank=:jack, @rank_number=11, @suit=:spades>,
       + #<Card:0x007f3d9e90c5f8 @rank=:ace, @rank_number=14, @suit=:clubs>]
     # /tmp/d20151112-27349-rqsn3h/spec.rb:155: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 hand #allow_face_up? returns true if the cards are less than or equal to 3
     Failure/Error: expect(hand.allow_face_up?).to eq true
       
       expected: true
            got: false
       
       (compared using ==)
     # /tmp/d20151112-27349-rqsn3h/spec.rb:178: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)>'

  10) BeloteDeck behaves like a deck implements Enumerable
     Failure/Error: expect(small_deck.to_a).to eq [ace_of_spades, nine_of_clubs]
       
       expected: [#<Card:0x007f3d9e835198 @rank=:ace, @rank_number=14, @suit=:spades>, #<Card:0x007f3d9e835030 @rank=9, @rank_number=9, @suit=:clubs>]
            got: [nil]
       
       (compared using ==)
       
       Diff:
       @@ -1,3 +1,2 @@
       -[#<Card:0x007f3d9e835198 @rank=:ace, @rank_number=14, @suit=:spades>,
       - #<Card:0x007f3d9e835030 @rank=9, @rank_number=9, @suit=:clubs>]
       +[nil]
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:191
     # /tmp/d20151112-27349-rqsn3h/spec.rb:11: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)>'

  11) 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
     NoMethodError:
       undefined method `suit' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:191
     # /tmp/d20151112-27349-rqsn3h/solution.rb:22:in `=='
     # /tmp/d20151112-27349-rqsn3h/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)>'

  12) BeloteDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: expect(small_deck.draw_top_card).to eq ace_of_spades
     ArgumentError:
       wrong number of arguments (0 for 1)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:191
     # /tmp/d20151112-27349-rqsn3h/solution.rb:77:in `draw_top_card'
     # /tmp/d20151112-27349-rqsn3h/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)>'

  13) BeloteDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: expect(small_deck.draw_bottom_card).to eq nine_of_clubs
     ArgumentError:
       wrong number of arguments (0 for 1)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:191
     # /tmp/d20151112-27349-rqsn3h/solution.rb:80:in `draw_bottom_card'
     # /tmp/d20151112-27349-rqsn3h/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)>'

  14) BeloteDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: expect(small_deck.top_card).to eq ace_of_spades
       
       expected: #<Card:0x007f3d9e77cbe8 @rank=:ace, @rank_number=14, @suit=:spades>
            got: nil
       
       (compared using ==)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:191
     # /tmp/d20151112-27349-rqsn3h/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)>'

  15) BeloteDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: expect(small_deck.bottom_card).to eq nine_of_clubs
       
       expected: #<Card:0x007f3d9e763f30 @rank=9, @rank_number=9, @suit=:clubs>
            got: nil
       
       (compared using ==)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:191
     # /tmp/d20151112-27349-rqsn3h/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)>'

  16) BeloteDeck 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:0x007f3d9e735f90>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:191
     # /tmp/d20151112-27349-rqsn3h/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)>'

  17) BeloteDeck #sort sorts the cards in the defined order
     Failure/Error: expect(deck.sort.to_a).to eq [jack_of_spades, ten_of_hearts, ace_of_clubs, seven_of_clubs]
       
       expected: [#<Card:0x007f3d9e724a60 @rank=:jack, @rank_number=11, @suit=:spades>, #<Card:0x007f3d9e724920 @rank=10, @rank_number=10, @suit=:hearts>, #<Card:0x007f3d9e724a88 @rank=:ace, @rank_number=14, @suit=:clubs>, #<Card:0x007f3d9e724a10 @rank=7, @rank_number=7, @suit=:clubs>]
            got: [#<Card:0x007f3d9e724920 @rank=10, @rank_number=10, @suit=:hearts>, #<Card:0x007f3d9e724a10 @rank=7, @rank_number=7, @suit=:clubs>, #<Card:0x007f3d9e724a60 @rank=:jack, @rank_number=11, @suit=:spades>, #<Card:0x007f3d9e724a88 @rank=:ace, @rank_number=14, @suit=:clubs>]
       
       (compared using ==)
       
       Diff:
       @@ -1,5 +1,5 @@
       -[#<Card:0x007f3d9e724a60 @rank=:jack, @rank_number=11, @suit=:spades>,
       - #<Card:0x007f3d9e724920 @rank=10, @rank_number=10, @suit=:hearts>,
       - #<Card:0x007f3d9e724a88 @rank=:ace, @rank_number=14, @suit=:clubs>,
       - #<Card:0x007f3d9e724a10 @rank=7, @rank_number=7, @suit=:clubs>]
       +[#<Card:0x007f3d9e724920 @rank=10, @rank_number=10, @suit=:hearts>,
       + #<Card:0x007f3d9e724a10 @rank=7, @rank_number=7, @suit=:clubs>,
       + #<Card:0x007f3d9e724a60 @rank=:jack, @rank_number=11, @suit=:spades>,
       + #<Card:0x007f3d9e724a88 @rank=:ace, @rank_number=14, @suit=:clubs>]
     # /tmp/d20151112-27349-rqsn3h/spec.rb:206: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 hand #belote? returns true if there is a king and a queen of the same suit
     Failure/Error: expect(hand.belote?).to be true
       
       expected #<TrueClass:20> => true
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     # /tmp/d20151112-27349-rqsn3h/spec.rb:251: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)>'

  19) BeloteDeck hand #belote? returns false when there is no king and queen of the same suit
     Failure/Error: expect(hand.belote?).to be false
       
       expected #<FalseClass:0> => false
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     # /tmp/d20151112-27349-rqsn3h/spec.rb:266: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)>'

  20) BeloteDeck hand #tierce? with tierce returns true for cards with names
     Failure/Error: expect(hand.tierce?).to be true
       
       expected #<TrueClass:20> => true
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     # /tmp/d20151112-27349-rqsn3h/spec.rb:284: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)>'

  21) BeloteDeck hand #tierce? with tierce returns true for cards with numbers
     Failure/Error: expect(hand.tierce?).to be true
       
       expected #<TrueClass:20> => true
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     # /tmp/d20151112-27349-rqsn3h/spec.rb:299: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)>'

  22) BeloteDeck hand #tierce? without tierce does not confuse cards with different suits
     Failure/Error: expect(hand.tierce?).to be false
       
       expected #<FalseClass:0> => false
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     # /tmp/d20151112-27349-rqsn3h/spec.rb:316: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)>'

  23) BeloteDeck hand #quarte? detects four cards with increasing ranks
     Failure/Error: expect(hand.quarte?).to be true
       
       expected #<TrueClass:20> => true
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     # /tmp/d20151112-27349-rqsn3h/spec.rb:334: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 #quarte? does not return true if there is no quarte
     Failure/Error: expect(hand.quarte?).to be false
       
       expected #<FalseClass:0> => false
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     # /tmp/d20151112-27349-rqsn3h/spec.rb:349: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 #quint? detects five cards with increasing ranks
     Failure/Error: expect(hand.quint?).to be true
       
       expected #<TrueClass:20> => true
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     # /tmp/d20151112-27349-rqsn3h/spec.rb:366: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)>'

  26) BeloteDeck hand #quint? does not return true if there is no quint
     Failure/Error: expect(hand.quint?).to be false
       
       expected #<FalseClass:0> => false
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     # /tmp/d20151112-27349-rqsn3h/spec.rb:381: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)>'

  27) BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns true when there is a carre
     Failure/Error: expect(hand.public_send(method)).to be true
       
       expected #<TrueClass:20> => true
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-rqsn3h/spec.rb:386
     # /tmp/d20151112-27349-rqsn3h/spec.rb:86: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_jacks? behaves like carre-checking method returns false when there is no carre
     Failure/Error: expect(hand.public_send(method)).to be false
       
       expected #<FalseClass:0> => false
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-rqsn3h/spec.rb:386
     # /tmp/d20151112-27349-rqsn3h/spec.rb:101: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_nines? behaves like carre-checking method returns true when there is a carre
     Failure/Error: expect(hand.public_send(method)).to be true
       
       expected #<TrueClass:20> => true
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-rqsn3h/spec.rb:390
     # /tmp/d20151112-27349-rqsn3h/spec.rb:86: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) BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns false when there is no carre
     Failure/Error: expect(hand.public_send(method)).to be false
       
       expected #<FalseClass:0> => false
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-rqsn3h/spec.rb:390
     # /tmp/d20151112-27349-rqsn3h/spec.rb:101: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) BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns true when there is a carre
     Failure/Error: expect(hand.public_send(method)).to be true
       
       expected #<TrueClass:20> => true
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-rqsn3h/spec.rb:394
     # /tmp/d20151112-27349-rqsn3h/spec.rb:86: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) BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns false when there is no carre
     Failure/Error: expect(hand.public_send(method)).to be false
       
       expected #<FalseClass:0> => false
            got #<NilClass:8> => nil
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-rqsn3h/spec.rb:394
     # /tmp/d20151112-27349-rqsn3h/spec.rb:101: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) SixtySixDeck behaves like a deck implements Enumerable
     Failure/Error: expect(small_deck.to_a).to eq [ace_of_spades, nine_of_clubs]
       
       expected: [#<Card:0x007f3d9e268af8 @rank=:ace, @rank_number=14, @suit=:spades>, #<Card:0x007f3d9e268a80 @rank=9, @rank_number=9, @suit=:clubs>]
            got: [nil]
       
       (compared using ==)
       
       Diff:
       @@ -1,3 +1,2 @@
       -[#<Card:0x007f3d9e268af8 @rank=:ace, @rank_number=14, @suit=:spades>,
       - #<Card:0x007f3d9e268a80 @rank=9, @rank_number=9, @suit=:clubs>]
       +[nil]
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:400
     # /tmp/d20151112-27349-rqsn3h/spec.rb:11: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) 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
     NoMethodError:
       undefined method `suit' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:400
     # /tmp/d20151112-27349-rqsn3h/solution.rb:22:in `=='
     # /tmp/d20151112-27349-rqsn3h/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)>'

  35) SixtySixDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: expect(small_deck.draw_top_card).to eq ace_of_spades
     ArgumentError:
       wrong number of arguments (0 for 1)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:400
     # /tmp/d20151112-27349-rqsn3h/solution.rb:77:in `draw_top_card'
     # /tmp/d20151112-27349-rqsn3h/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)>'

  36) SixtySixDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: expect(small_deck.draw_bottom_card).to eq nine_of_clubs
     ArgumentError:
       wrong number of arguments (0 for 1)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:400
     # /tmp/d20151112-27349-rqsn3h/solution.rb:80:in `draw_bottom_card'
     # /tmp/d20151112-27349-rqsn3h/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)>'

  37) SixtySixDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: expect(small_deck.top_card).to eq ace_of_spades
       
       expected: #<Card:0x007f3d9da7dd48 @rank=:ace, @rank_number=14, @suit=:spades>
            got: nil
       
       (compared using ==)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:400
     # /tmp/d20151112-27349-rqsn3h/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)>'

  38) SixtySixDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: expect(small_deck.bottom_card).to eq nine_of_clubs
       
       expected: #<Card:0x007f3d9da6e820 @rank=9, @rank_number=9, @suit=:clubs>
            got: nil
       
       (compared using ==)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:400
     # /tmp/d20151112-27349-rqsn3h/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)>'

  39) SixtySixDeck 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:0x007f3d9da4cb58>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-rqsn3h/spec.rb:400
     # /tmp/d20151112-27349-rqsn3h/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)>'

  40) SixtySixDeck #sort sorts the cards in the defined order
     Failure/Error: expect(deck.sort.to_a).to eq [jack_of_spades, ten_of_hearts, ace_of_clubs, two_of_clubs]
       
       expected: [#<Card:0x007f3d9da5b950 @rank=:jack, @rank_number=11, @suit=:spades>, #<Card:0x007f3d9da5b810 @rank=10, @rank_number=10, @suit=:hearts>, #<Card:0x007f3d9da5ba40 @rank=:ace, @rank_number=14, @suit=:clubs>, #<Card:0x007f3d9da5b900 @rank=9, @rank_number=9, @suit=:clubs>]
            got: [#<Card:0x007f3d9da5b810 @rank=10, @rank_number=10, @suit=:hearts>, #<Card:0x007f3d9da5b900 @rank=9, @rank_number=9, @suit=:clubs>, #<Card:0x007f3d9da5b950 @rank=:jack, @rank_number=11, @suit=:spades>, #<Card:0x007f3d9da5ba40 @rank=:ace, @rank_number=14, @suit=:clubs>]
       
       (compared using ==)
       
       Diff:
       @@ -1,5 +1,5 @@
       -[#<Card:0x007f3d9da5b950 @rank=:jack, @rank_number=11, @suit=:spades>,
       - #<Card:0x007f3d9da5b810 @rank=10, @rank_number=10, @suit=:hearts>,
       - #<Card:0x007f3d9da5ba40 @rank=:ace, @rank_number=14, @suit=:clubs>,
       - #<Card:0x007f3d9da5b900 @rank=9, @rank_number=9, @suit=:clubs>]
       +[#<Card:0x007f3d9da5b810 @rank=10, @rank_number=10, @suit=:hearts>,
       + #<Card:0x007f3d9da5b900 @rank=9, @rank_number=9, @suit=:clubs>,
       + #<Card:0x007f3d9da5b950 @rank=:jack, @rank_number=11, @suit=:spades>,
       + #<Card:0x007f3d9da5ba40 @rank=:ace, @rank_number=14, @suit=:clubs>]
     # /tmp/d20151112-27349-rqsn3h/spec.rb:415: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 hand #twenty? returns true for king and queen not of the trump suit
     Failure/Error: expect(hand.twenty?(:hearts)).to be true
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-rqsn3h/solution.rb:194:in `twenty?'
     # /tmp/d20151112-27349-rqsn3h/spec.rb:439: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)>'

  42) SixtySixDeck hand #twenty? returns false for king and queen of the trump suit
     Failure/Error: expect(hand.twenty?(:clubs)).to be false
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-rqsn3h/solution.rb:194:in `twenty?'
     # /tmp/d20151112-27349-rqsn3h/spec.rb:452: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)>'

  43) SixtySixDeck hand #twenty? returns false for hands without a king and queen of the same suit
     Failure/Error: expect(hand.twenty?(:hearts)).to be false
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20151112-27349-rqsn3h/solution.rb:194:in `twenty?'
     # /tmp/d20151112-27349-rqsn3h/spec.rb:465: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.0556 seconds
57 examples, 43 failures

Failed examples:

rspec /tmp/d20151112-27349-rqsn3h/spec.rb:8 # WarDeck behaves like a deck implements Enumerable
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:14 # WarDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:28 # WarDeck behaves like a deck #draw_top_card pops the top-most card
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:35 # WarDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:42 # WarDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:49 # WarDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-rqsn3h/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-rqsn3h/spec.rb:145 # WarDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:175 # WarDeck hand #allow_face_up? returns true if the cards are less than or equal to 3
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:8 # BeloteDeck behaves like a deck implements Enumerable
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:14 # BeloteDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:28 # BeloteDeck behaves like a deck #draw_top_card pops the top-most card
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:35 # BeloteDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:42 # BeloteDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:49 # BeloteDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-rqsn3h/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-rqsn3h/spec.rb:196 # BeloteDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:239 # BeloteDeck hand #belote? returns true if there is a king and a queen of the same suit
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:254 # BeloteDeck hand #belote? returns false when there is no king and queen of the same suit
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:272 # BeloteDeck hand #tierce? with tierce returns true for cards with names
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:287 # BeloteDeck hand #tierce? with tierce returns true for cards with numbers
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:304 # BeloteDeck hand #tierce? without tierce does not confuse cards with different suits
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:322 # BeloteDeck hand #quarte? detects four cards with increasing ranks
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:337 # BeloteDeck hand #quarte? does not return true if there is no quarte
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:354 # BeloteDeck hand #quint? detects five cards with increasing ranks
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:369 # BeloteDeck hand #quint? does not return true if there is no quint
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:74 # BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns true when there is a carre
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:89 # BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns false when there is no carre
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:74 # BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns true when there is a carre
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:89 # BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns false when there is no carre
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:74 # BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns true when there is a carre
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:89 # BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns false when there is no carre
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:8 # SixtySixDeck behaves like a deck implements Enumerable
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:14 # SixtySixDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:28 # SixtySixDeck behaves like a deck #draw_top_card pops the top-most card
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:35 # SixtySixDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:42 # SixtySixDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:49 # SixtySixDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-rqsn3h/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-rqsn3h/spec.rb:405 # SixtySixDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:429 # SixtySixDeck hand #twenty? returns true for king and queen not of the trump suit
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:442 # SixtySixDeck hand #twenty? returns false for king and queen of the trump suit
rspec /tmp/d20151112-27349-rqsn3h/spec.rb:455 # SixtySixDeck hand #twenty? returns false for hands without a king and queen of the same suit

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

Иван обнови решението на 08.11.2015 14:58 (преди около 9 години)

+RANKS = (1..14).to_a
+HIGH_CARDS = {jack: 11, queen: 12, king: 13, ace: 14}
+SUITS ={spades: 0, hearts: 1, diamonds: 2, clubs: 3}
+
+class Card
+ attr_accessor :rank, :suit, :rank_number
+
+ def initialize(rank = 2, suit = :spades)
+ @rank = rank
+ @rank_number = self.get_rank_number
+ @suit = suit
+ end
+
+ def get_rank_number
+ if HIGH_CARDS.include?(@rank) then
+ return HIGH_CARDS[@rank]
+ elsif @rank.class != "Symbol" && (@rank >= 2 || @rank <= 10) then
+ return @rank
+ end
+ end
+ def ==(other)
+ if self.suit != other.suit then return false end
+ if self.rank != other.rank then return false end
+ true
+ end
+ def <(other)
+ if self == other then return false end
+ if self.rank_number < other.rank_number then return true end
+ if SUITS[self.suit] < SUITS[other.suit] then return true end
+ return false
+ end
+ def to_s
+ rank_string = rank.to_s.capitalize
+ suit_string = suit.to_s.capitalize
+ rank_string + " of " + suit_string
+ end
+end
+
+class Deck
+ include Enumerable
+
+ attr_accessor :hand
+ attr_accessor :deck
+
+ def initialize(deck = self.get_deck)
+ @deck = deck
+ @hand = []
+ @hand_size = 26
+ end
+
+ def each
+ yield
+ end
+
+ def get_deck
+ basic_deck = Array.new()
+ (0..3).each do |suit|
+ (1..13).each do |rank|
+ basic_deck << Card.new(get_rank(rank), SUITS.keys[suit])
+ end
+ end
+ @deck = basic_deck
+ end
+
+ def get_rank(rank)
+ if rank < 10 then
+ return RANKS[rank]
+ else
+ return HIGH_CARDS.keys[rank - 10]
+ end
+ end
+
+ def size
+ @deck.count
+ end
+
+ def draw_top_card(deck)
+ end
+
+ def draw_bottom_card(deck)
+ end
+
+ def top_card
+ end
+
+ def bottom_card
+ end
+
+ def shuffle
+ @deck.shuffle
+ end
+
+ def sort
+ @deck.sort{ |first, second|
+ first.suit <=> second.suit
+ }
+ @deck.reverse
+ end
+
+ def to_s
+ @deck.each{|card| p card.to_s}
+ end
+
+ def get_hand
+ hand = Array.new
+ (0..(@hand_size - 1)).each {|card|
+ hand << @deck[card]
+ }
+ hand
+ end
+ def deal
+ Deck.new(self.get_hand)
+ end
+ def allow_face_up?
+ false
+ end
+ def is_hand?
+ self.size <= @hand_size
+ end
+end
+
+class WarDeck < Deck
+ attr_accessor :deck
+ def initialize(deck = self.get_deck)
+ super
+ end
+
+ def play_card
+ @deck.delete(@deck[Random.rand(self.size)])
+ end
+ def allow_face_up?
+ self.deck.size < 3
+ end
+ def deal
+ WarDeck.new(get_hand)
+ end
+end
+
+class BeloteDeck < Deck
+ def initialize(deck = self.get_deck)
+ super
+ @hand_size = 8
+ @deck = deck.delete_if{|card|
+ if card < Card.new(7,:spades) then
+ RANKS[card.rank] < 8
+ end
+ }
+ end
+
+ def deal
+ BeloteDeck.new(get_hand)
+ end
+ def highest_of_suit(suit)
+ found_card = false
+ highest_of_suit = Card.new(1,suit)
+ @deck.each {|card|
+ highest_of_suit = higher_card_check(highest_of_suit, card, suit)
+ }
+ return nil unless Card.new(1,suit) < highest_of_suit
+ highest_of_suit
+ end
+
+ def higher_card_check(current_high, new_card, suit)
+ if current_high < new_card && new_card.suit == suit then
+ current_high = new_card
+ end
+ current_high
+ end
+
+ def belote?
+ end
+ def tierce?
+ end
+ def quarte?
+ end
+ def quint?
+ end
+ def carre_of_jacks?
+ end
+ def carre_of_nines?
+ end
+ def carre_of_aces?
+ end
+end
+
+class SixtySixDeck < Deck
+ def initialize(deck = self.get_deck)
+ super
+ @hand_size = 6
+ end
+ def deal
+ SixtySixDeck.new(get_hand)
+ end
+ def twenty?
+ end
+ def forty?
+ end
+end

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

Реално трябва да ти отнема и едната точка, която си изкарал, но този път те пускам метър. Постарай се повече за следващите задачи.

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