Решение на Четвърта задача от Веселин Стоянов

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

Към профила на Веселин Стоянов

Резултати

  • 2 точки от тестове
  • 0 бонус точки
  • 2 точки общо
  • 22 успешни тест(а)
  • 35 неуспешни тест(а)

Код

class Card
RANKS = {
2 => ["2", 1],
3 => ["3", 2],
4 => ["4", 3],
5 => ["5", 4],
6 => ["6", 5],
7 => ["7", 6],
8 => ["8", 7],
9 => ["9", 8],
10 => ["10", 9],
:jack => ["Jack", 10],
:queen => ["Queen", 11],
:king => ["King", 12],
:ace => ["Ace", 13]
}
SUITS = {
:spades => ["Spades", 1],
:hearts => ["Hearts", 2],
:diamonds => ["Diamonds", 3],
:clubs => ["Clubs", 4]
}
attr_reader :rank, :suit, :rank_order, :suit_order
def initialize(rank, suit)
@rank, @suit = rank, suit
@rank_order, @suit_order = RANKS[rank][1], SUITS[suit][1]
end
def to_s
"#{RANKS[@rank][0]} of #{SUITS[@suit][0]}"
end
def ==(compare)
self.to_s == compare.to_s
end
end
class Hand
SUITS = [:spades, :hearts, :diamonds, :clubs]
attr_accessor :cards
def initialize(cards)
@cards = cards
end
def size
@cards.length
end
end
class Deck
include Enumerable
attr_accessor :deck_size, :hand_size, :cards
SUITS = [:spades, :hearts, :diamonds, :clubs]
def initialize(cards = [])
@cards = []
@ranks.each do |rank|
SUITS.each { |suit| @cards.push(Card.new(rank[0], suit)) }
end
@cards = cards.empty? ? @cards : cards
end
def size
@cards.length
end
def draw_top_card
@cards.pop
end
def draw_bottom_card
@cards.shift
end
def top_card
@cards.last
end
def bottom_card
@cards.first
end
def shuffle
@cards.shuffle!
end
def sort
@cards.sort! do |a, b|
first = a.suit_order <=> b.suit_order
second = b.rank_order <=> a.rank_order
if not first == 0 then first * second else second end
end
end
def to_s
cards.each { |card| puts card.to_s }
end
def deal
deal_cards = []
(1..@hand_size).each do |i|
card = self.draw_top_card
deal_cards.push(Card.new(card.rank, card.suit))
end
self.class::Hand.new(deal_cards)
end
end
class WarDeck < Deck
RANKS = {
2 => ["2", 1],
3 => ["3", 2],
4 => ["4", 3],
5 => ["5", 4],
6 => ["6", 5],
7 => ["7", 6],
8 => ["8", 7],
9 => ["9", 8],
10 => ["10", 9],
:jack => ["Jack", 10],
:queen => ["Queen", 11],
:king => ["King", 12],
:ace => ["Ace", 13]
}
def initialize(cards = [])
@deck_size = 52
@hand_size = 26
@ranks = RANKS
super
end
class Hand < Hand
def play_card
@cards.sample
end
def allow_face_up?
@cards.length <= 3
end
end
end
class BeloteDeck < Deck
RANKS = {
7 => ["7", 1],
8 => ["8", 2],
9 => ["9", 3],
:jack => ["Jack", 4],
:queen => ["Queen", 5],
:king => ["King", 6],
10 => ["10", 7],
:ace => ["Ace", 8]
}
def initialize(cards = [])
@deck_size = 32
@hand_size = 8
@ranks = RANKS
super
end
class Hand < Hand
RANK_ORDER = [7, 8, 9, :jack, :queen, :king, 10, :ace]
def sort
@cards.sort! do |a, b|
first = a.suit_order <=> b.suit_order
second = b.rank_order <=> a.rank_order
if not first == 0 then first * second else second end
end
end
def highest_of_suit(suit)
suit_cards = []
self.sort
@cards.each { |card| if card.suit == suit then suit_cards.push(card) end}
suit_cards.first
end
def suit_cards(suit)
suit_cards = []
self.sort
@cards.each do |card|
if card.suit == suit then suit_cards.push(card.rank) end
end
suit_cards
end
def belote?
SUITS.each do |suit|
suit_cards = suit_cards(suit)
return true if suit_cards.include? :king and suit_cards.include? :queen
end
false
end
def first_check(suit_cards, n)
i, yes = 0, false
while i + n < RANKS.length
yes = true if second_check(suit_cards, i, n)
i += 1
end
return yes
end
def second_check(suit_cards, i, n)
suit_cards.all? {|i| (i..i + n).include?(RANK_ORDER[i])}
end
def tierce?
SUITS.each do |suit|
suit_cards = suit_cards(suit)
result = first_check(suit_cards, 3)
return true if result
end
return false
end
def quarte?
SUITS.each do |suit|
suit_cards = suit_cards(suit)
result = first_check(suit_cards, 4)
return true if result
end
return false
end
def quint?
SUITS.each do |suit|
suit_cards = suit_cards(suit)
result = first_check(suit_cards, 5)
return true if result
end
return false
end
def carre_of_jacks?
count = 0
@cards.each { |card| count += 1 if card.rank == :jack }
count == 4
end
def carre_of_nines?
count = 0
@cards.each { |card| count += 1 if card.rank == 9 }
count == 4
end
def carre_of_aces?
count = 0
@cards.each { |card| count += 1 if card.rank == :ace }
count == 4
end
end
end
class SixtySixDeck < Deck
RANKS = {
9 => ["9", 1],
:jack => ["Jack", 2],
:queen => ["Queen", 3],
:king => ["King", 4],
10 => ["10", 5],
:ace => ["Ace", 6]
}
def initialize(cards = [])
@deck_size = 24
@hand_size = 6
@ranks = RANKS
super
end
class Hand < Hand
def suit_cards(suit)
suit_cards = []
self.sort
@cards.each do |card|
if card.suit == suit then suit_cards.push(card.rank) end
end
suit_cards
end
def first_check(suit, trump_suit)
unless suit == trump_suit
color = suit_cards(suit)
return true if color.include? :king and color.include? :queen
end
end
def twenty?(trump_suit)
SUITS.each do |suit|
return true if first_check(suit, trump_suit)
end
false
end
def second_check(suit, trump_suit)
if suit == trump_suit
color = suit_cards(suit)
return true if color.include? :king and color.include? :queen
end
end
def forty?(trump_suit)
SUITS.each do |suit|
return true if second_check(suit, trump_suit)
end
false
end
end
end

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

...FF.FFFF.Ace of Spades
9 of Clubs
FF..FFF.FFFF.Ace of Spades
9 of Clubs
FF.F...FFFFFF......FF.FFFF.Ace of Spades
9 of Clubs
FF.FFF

Failures:

  1) WarDeck behaves like a deck implements Enumerable
     Failure/Error: expect(small_deck).to respond_to(:each)
       expected #<WarDeck:0x007fbc0f875de8 @deck_size=52, @hand_size=26, @ranks={2=>["2", 1], 3=>["3", 2], 4=>["4", 3], 5=>["5", 4], 6=>["6", 5], 7=>["7", 6], 8=>["8", 7], 9=>["9", 8], 10=>["10", 9], :jack=>["Jack", 10], :queen=>["Queen", 11], :king=>["King", 12], :ace=>["Ace", 13]}, @cards=[#<Card:0x007fbc0f875fc8 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>, #<Card:0x007fbc0f875eb0 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>]> to respond to :each
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:140
     # /tmp/d20151112-27349-503p6k/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)>'

  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 `each' for #<WarDeck:0x007fbc106e5838>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:140
     # /tmp/d20151112-27349-503p6k/spec.rb:18:in `to_a'
     # /tmp/d20151112-27349-503p6k/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
       
       expected: #<Card:0x007fbc107035b8 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>
            got: #<Card:0x007fbc10703568 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,2 @@
       -#<Card:0x007fbc107035b8
       - @rank=:ace,
       - @rank_order=13,
       - @suit=:spades,
       - @suit_order=1>
       +#<Card:0x007fbc10703568 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:140
     # /tmp/d20151112-27349-503p6k/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
       
       expected: #<Card:0x007fbc1073ea50 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>
            got: #<Card:0x007fbc1073eac8 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,6 @@
       -#<Card:0x007fbc1073ea50 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>
       +#<Card:0x007fbc1073eac8
       + @rank=:ace,
       + @rank_order=13,
       + @suit=:spades,
       + @suit_order=1>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:140
     # /tmp/d20151112-27349-503p6k/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:0x007fbc10716e10 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>
            got: #<Card:0x007fbc10716dc0 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,2 @@
       -#<Card:0x007fbc10716e10
       - @rank=:ace,
       - @rank_order=13,
       - @suit=:spades,
       - @suit_order=1>
       +#<Card:0x007fbc10716dc0 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:140
     # /tmp/d20151112-27349-503p6k/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:0x007fbc106cbc58 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>
            got: #<Card:0x007fbc106cbca8 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,6 @@
       -#<Card:0x007fbc106cbc58 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>
       +#<Card:0x007fbc106cbca8
       + @rank=:ace,
       + @rank_order=13,
       + @suit=:spades,
       + @suit_order=1>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:140
     # /tmp/d20151112-27349-503p6k/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:0x007fbc106967d8>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:140
     # /tmp/d20151112-27349-503p6k/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:0x007fbc10684718 @suit=:spades, @rank=:jack, @rank_order=10, @suit_order=1>, #<Card:0x007fbc106845d8 @suit=:hearts, @rank=10, @rank_order=9, @suit_order=2>, #<Card:0x007fbc10684768 @suit=:clubs, @rank=:ace, @rank_order=13, @suit_order=4>, #<Card:0x007fbc10684678 @suit=:clubs, @rank=2, @rank_order=1, @suit_order=4>]
            got: [#<Card:0x007fbc10684768 @suit=:clubs, @rank=:ace, @rank_order=13, @suit_order=4>, #<Card:0x007fbc106845d8 @suit=:hearts, @rank=10, @rank_order=9, @suit_order=2>, #<Card:0x007fbc10684678 @suit=:clubs, @rank=2, @rank_order=1, @suit_order=4>, #<Card:0x007fbc10684718 @suit=:spades, @rank=:jack, @rank_order=10, @suit_order=1>]
       
       (compared using ==)
       
       Diff:
       
       @@ -1,17 +1,17 @@
       -[#<Card:0x007fbc10684718
       -  @rank=:jack,
       -  @rank_order=10,
       -  @suit=:spades,
       -  @suit_order=1>,
       +[#<Card:0x007fbc10684768
       +  @rank=:ace,
       +  @rank_order=13,
       +  @suit=:clubs,
       +  @suit_order=4>,
         #<Card:0x007fbc106845d8
          @rank=10,
          @rank_order=9,
          @suit=:hearts,
          @suit_order=2>,
       - #<Card:0x007fbc10684768
       -  @rank=:ace,
       -  @rank_order=13,
       -  @suit=:clubs,
       -  @suit_order=4>,
       - #<Card:0x007fbc10684678 @rank=2, @rank_order=1, @suit=:clubs, @suit_order=4>]
       + #<Card:0x007fbc10684678 @rank=2, @rank_order=1, @suit=:clubs, @suit_order=4>,
       + #<Card:0x007fbc10684718
       +  @rank=:jack,
       +  @rank_order=10,
       +  @suit=:spades,
       +  @suit_order=1>]
     # /tmp/d20151112-27349-503p6k/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-503p6k/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 respond_to(:each)
       expected #<BeloteDeck:0x007fbc10538cd8 @deck_size=32, @hand_size=8, @ranks={7=>["7", 1], 8=>["8", 2], 9=>["9", 3], :jack=>["Jack", 4], :queen=>["Queen", 5], :king=>["King", 6], 10=>["10", 7], :ace=>["Ace", 8]}, @cards=[#<Card:0x007fbc10538e90 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>, #<Card:0x007fbc10538da0 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>]> to respond to :each
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:191
     # /tmp/d20151112-27349-503p6k/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)>'

  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 `each' for #<BeloteDeck:0x007fbc10528f40>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:191
     # /tmp/d20151112-27349-503p6k/spec.rb:18:in `to_a'
     # /tmp/d20151112-27349-503p6k/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
       
       expected: #<Card:0x007fbc104fe088 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>
            got: #<Card:0x007fbc104fe038 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,2 @@
       -#<Card:0x007fbc104fe088
       - @rank=:ace,
       - @rank_order=13,
       - @suit=:spades,
       - @suit_order=1>
       +#<Card:0x007fbc104fe038 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:191
     # /tmp/d20151112-27349-503p6k/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
       
       expected: #<Card:0x007fbc104cd9d8 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>
            got: #<Card:0x007fbc104cdaf0 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,6 @@
       -#<Card:0x007fbc104cd9d8 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>
       +#<Card:0x007fbc104cdaf0
       + @rank=:ace,
       + @rank_order=13,
       + @suit=:spades,
       + @suit_order=1>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:191
     # /tmp/d20151112-27349-503p6k/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:0x007fbc104632b8 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>
            got: #<Card:0x007fbc10463240 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,2 @@
       -#<Card:0x007fbc104632b8
       - @rank=:ace,
       - @rank_order=13,
       - @suit=:spades,
       - @suit_order=1>
       +#<Card:0x007fbc10463240 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:191
     # /tmp/d20151112-27349-503p6k/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:0x007fbc104171b0 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>
            got: #<Card:0x007fbc10417228 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,6 @@
       -#<Card:0x007fbc104171b0 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>
       +#<Card:0x007fbc10417228
       + @rank=:ace,
       + @rank_order=13,
       + @suit=:spades,
       + @suit_order=1>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:191
     # /tmp/d20151112-27349-503p6k/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:0x007fbc10200228>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:191
     # /tmp/d20151112-27349-503p6k/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:0x007fbc101e3088 @suit=:spades, @rank=:jack, @rank_order=10, @suit_order=1>, #<Card:0x007fbc101c7e28 @suit=:hearts, @rank=10, @rank_order=9, @suit_order=2>, #<Card:0x007fbc101e0658 @suit=:clubs, @rank=:ace, @rank_order=13, @suit_order=4>, #<Card:0x007fbc101c7f90 @suit=:clubs, @rank=7, @rank_order=6, @suit_order=4>]
            got: [#<Card:0x007fbc101e0658 @suit=:clubs, @rank=:ace, @rank_order=13, @suit_order=4>, #<Card:0x007fbc101c7e28 @suit=:hearts, @rank=10, @rank_order=9, @suit_order=2>, #<Card:0x007fbc101c7f90 @suit=:clubs, @rank=7, @rank_order=6, @suit_order=4>, #<Card:0x007fbc101e3088 @suit=:spades, @rank=:jack, @rank_order=10, @suit_order=1>]
       
       (compared using ==)
       
       Diff:
       
       @@ -1,17 +1,17 @@
       -[#<Card:0x007fbc101e3088
       -  @rank=:jack,
       -  @rank_order=10,
       -  @suit=:spades,
       -  @suit_order=1>,
       +[#<Card:0x007fbc101e0658
       +  @rank=:ace,
       +  @rank_order=13,
       +  @suit=:clubs,
       +  @suit_order=4>,
         #<Card:0x007fbc101c7e28
          @rank=10,
          @rank_order=9,
          @suit=:hearts,
          @suit_order=2>,
       - #<Card:0x007fbc101e0658
       -  @rank=:ace,
       -  @rank_order=13,
       -  @suit=:clubs,
       -  @suit_order=4>,
       - #<Card:0x007fbc101c7f90 @rank=7, @rank_order=6, @suit=:clubs, @suit_order=4>]
       + #<Card:0x007fbc101c7f90 @rank=7, @rank_order=6, @suit=:clubs, @suit_order=4>,
       + #<Card:0x007fbc101e3088
       +  @rank=:jack,
       +  @rank_order=10,
       +  @suit=:spades,
       +  @suit_order=1>]
     # /tmp/d20151112-27349-503p6k/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 #highest_of_suit returns the strongest card of the specified suit
     Failure/Error: expect(hand.highest_of_suit(:clubs)).to eq Card.new(:ace, :clubs)
       
       expected: #<Card:0x007fbc0fc44500 @suit=:clubs, @rank=:ace, @rank_order=13, @suit_order=4>
            got: #<Card:0x007fbc0fc54180 @suit=:clubs, @rank=:queen, @rank_order=11, @suit_order=4>
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,6 @@
       -#<Card:0x007fbc0fc44500
       - @rank=:ace,
       - @rank_order=13,
       +#<Card:0x007fbc0fc54180
       + @rank=:queen,
       + @rank_order=11,
         @suit=:clubs,
         @suit_order=4>
     # /tmp/d20151112-27349-503p6k/spec.rb:232: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 #tierce? with tierce returns true for cards with numbers
     Failure/Error: expect(hand.tierce?).to be true
     NoMethodError:
       undefined method `+' for :jack:Symbol
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `block in second_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `all?'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `second_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:216:in `first_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:229:in `block in tierce?'
     # /tmp/d20151112-27349-503p6k/solution.rb:227:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:227:in `tierce?'
     # /tmp/d20151112-27349-503p6k/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)>'

  20) BeloteDeck hand #tierce? without tierce does not confuse cards with different suits
     Failure/Error: expect(hand.tierce?).to be false
     NoMethodError:
       undefined method `+' for :king:Symbol
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `block in second_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `all?'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `second_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:216:in `first_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:229:in `block in tierce?'
     # /tmp/d20151112-27349-503p6k/solution.rb:227:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:227:in `tierce?'
     # /tmp/d20151112-27349-503p6k/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)>'

  21) BeloteDeck hand #quarte? detects four cards with increasing ranks
     Failure/Error: expect(hand.quarte?).to be true
     NoMethodError:
       undefined method `+' for :ace:Symbol
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `block in second_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `all?'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `second_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:216:in `first_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:238:in `block in quarte?'
     # /tmp/d20151112-27349-503p6k/solution.rb:236:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:236:in `quarte?'
     # /tmp/d20151112-27349-503p6k/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)>'

  22) BeloteDeck hand #quarte? does not return true if there is no quarte
     Failure/Error: expect(hand.quarte?).to be false
     NoMethodError:
       undefined method `+' for :king:Symbol
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `block in second_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `all?'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `second_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:216:in `first_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:238:in `block in quarte?'
     # /tmp/d20151112-27349-503p6k/solution.rb:236:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:236:in `quarte?'
     # /tmp/d20151112-27349-503p6k/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)>'

  23) BeloteDeck hand #quint? detects five cards with increasing ranks
     Failure/Error: expect(hand.quint?).to be true
     NoMethodError:
       undefined method `+' for :king:Symbol
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `block in second_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `all?'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `second_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:216:in `first_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:247:in `block in quint?'
     # /tmp/d20151112-27349-503p6k/solution.rb:245:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:245:in `quint?'
     # /tmp/d20151112-27349-503p6k/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)>'

  24) BeloteDeck hand #quint? does not return true if there is no quint
     Failure/Error: expect(hand.quint?).to be false
     NoMethodError:
       undefined method `+' for :king:Symbol
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `block in second_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `all?'
     # /tmp/d20151112-27349-503p6k/solution.rb:223:in `second_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:216:in `first_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:247:in `block in quint?'
     # /tmp/d20151112-27349-503p6k/solution.rb:245:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:245:in `quint?'
     # /tmp/d20151112-27349-503p6k/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)>'

  25) SixtySixDeck behaves like a deck implements Enumerable
     Failure/Error: expect(small_deck).to respond_to(:each)
       expected #<SixtySixDeck:0x007fbc10192a48 @deck_size=24, @hand_size=6, @ranks={9=>["9", 1], :jack=>["Jack", 2], :queen=>["Queen", 3], :king=>["King", 4], 10=>["10", 5], :ace=>["Ace", 6]}, @cards=[#<Card:0x007fbc10192bd8 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>, #<Card:0x007fbc10192b88 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>]> to respond to :each
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:400
     # /tmp/d20151112-27349-503p6k/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)>'

  26) 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 `each' for #<SixtySixDeck:0x007fbc10187120>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:400
     # /tmp/d20151112-27349-503p6k/spec.rb:18:in `to_a'
     # /tmp/d20151112-27349-503p6k/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)>'

  27) 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
       
       expected: #<Card:0x007fbc101b5cf0 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>
            got: #<Card:0x007fbc101b5c78 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,2 @@
       -#<Card:0x007fbc101b5cf0
       - @rank=:ace,
       - @rank_order=13,
       - @suit=:spades,
       - @suit_order=1>
       +#<Card:0x007fbc101b5c78 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:400
     # /tmp/d20151112-27349-503p6k/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)>'

  28) 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
       
       expected: #<Card:0x007fbc10248cf8 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>
            got: #<Card:0x007fbc10248d48 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,6 @@
       -#<Card:0x007fbc10248cf8 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>
       +#<Card:0x007fbc10248d48
       + @rank=:ace,
       + @rank_order=13,
       + @suit=:spades,
       + @suit_order=1>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:400
     # /tmp/d20151112-27349-503p6k/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)>'

  29) 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:0x007fbc10483108 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>
            got: #<Card:0x007fbc10483018 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,2 @@
       -#<Card:0x007fbc10483108
       - @rank=:ace,
       - @rank_order=13,
       - @suit=:spades,
       - @suit_order=1>
       +#<Card:0x007fbc10483018 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:400
     # /tmp/d20151112-27349-503p6k/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)>'

  30) 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:0x007fbc1048f660 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>
            got: #<Card:0x007fbc1048f728 @suit=:spades, @rank=:ace, @rank_order=13, @suit_order=1>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,6 @@
       -#<Card:0x007fbc1048f660 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>
       +#<Card:0x007fbc1048f728
       + @rank=:ace,
       + @rank_order=13,
       + @suit=:spades,
       + @suit_order=1>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:400
     # /tmp/d20151112-27349-503p6k/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)>'

  31) 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:0x007fbc104f60b8>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-503p6k/spec.rb:400
     # /tmp/d20151112-27349-503p6k/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)>'

  32) 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:0x007fbc10532680 @suit=:spades, @rank=:jack, @rank_order=10, @suit_order=1>, #<Card:0x007fbc105324c8 @suit=:hearts, @rank=10, @rank_order=9, @suit_order=2>, #<Card:0x007fbc105326f8 @suit=:clubs, @rank=:ace, @rank_order=13, @suit_order=4>, #<Card:0x007fbc105325b8 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>]
            got: [#<Card:0x007fbc105326f8 @suit=:clubs, @rank=:ace, @rank_order=13, @suit_order=4>, #<Card:0x007fbc105324c8 @suit=:hearts, @rank=10, @rank_order=9, @suit_order=2>, #<Card:0x007fbc105325b8 @suit=:clubs, @rank=9, @rank_order=8, @suit_order=4>, #<Card:0x007fbc10532680 @suit=:spades, @rank=:jack, @rank_order=10, @suit_order=1>]
       
       (compared using ==)
       
       Diff:
       
       @@ -1,17 +1,17 @@
       -[#<Card:0x007fbc10532680
       -  @rank=:jack,
       -  @rank_order=10,
       -  @suit=:spades,
       -  @suit_order=1>,
       +[#<Card:0x007fbc105326f8
       +  @rank=:ace,
       +  @rank_order=13,
       +  @suit=:clubs,
       +  @suit_order=4>,
         #<Card:0x007fbc105324c8
          @rank=10,
          @rank_order=9,
          @suit=:hearts,
          @suit_order=2>,
       - #<Card:0x007fbc105326f8
       -  @rank=:ace,
       -  @rank_order=13,
       -  @suit=:clubs,
       -  @suit_order=4>,
       - #<Card:0x007fbc105325b8 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>]
       + #<Card:0x007fbc105325b8 @rank=9, @rank_order=8, @suit=:clubs, @suit_order=4>,
       + #<Card:0x007fbc10532680
       +  @rank=:jack,
       +  @rank_order=10,
       +  @suit=:spades,
       +  @suit_order=1>]
     # /tmp/d20151112-27349-503p6k/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)>'

  33) SixtySixDeck hand #twenty? returns true for king and queen not of the trump suit
     Failure/Error: expect(hand.twenty?(:hearts)).to be true
     NoMethodError:
       undefined method `sort' for #<SixtySixDeck::Hand:0x007fbc105d9908>
     # /tmp/d20151112-27349-503p6k/solution.rb:297:in `suit_cards'
     # /tmp/d20151112-27349-503p6k/solution.rb:308:in `first_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:315:in `block in twenty?'
     # /tmp/d20151112-27349-503p6k/solution.rb:314:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:314:in `twenty?'
     # /tmp/d20151112-27349-503p6k/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)>'

  34) SixtySixDeck hand #twenty? returns false for king and queen of the trump suit
     Failure/Error: expect(hand.twenty?(:clubs)).to be false
     NoMethodError:
       undefined method `sort' for #<SixtySixDeck::Hand:0x007fbc105c4c10>
     # /tmp/d20151112-27349-503p6k/solution.rb:297:in `suit_cards'
     # /tmp/d20151112-27349-503p6k/solution.rb:308:in `first_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:315:in `block in twenty?'
     # /tmp/d20151112-27349-503p6k/solution.rb:314:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:314:in `twenty?'
     # /tmp/d20151112-27349-503p6k/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)>'

  35) 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
     NoMethodError:
       undefined method `sort' for #<SixtySixDeck::Hand:0x007fbc10614440>
     # /tmp/d20151112-27349-503p6k/solution.rb:297:in `suit_cards'
     # /tmp/d20151112-27349-503p6k/solution.rb:308:in `first_check'
     # /tmp/d20151112-27349-503p6k/solution.rb:315:in `block in twenty?'
     # /tmp/d20151112-27349-503p6k/solution.rb:314:in `each'
     # /tmp/d20151112-27349-503p6k/solution.rb:314:in `twenty?'
     # /tmp/d20151112-27349-503p6k/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.07568 seconds
57 examples, 35 failures

Failed examples:

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

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

Веселин обнови решението на 11.11.2015 02:15 (преди над 8 години)

+class Card
+ RANKS = {
+ 2 => ["2", 1],
+ 3 => ["3", 2],
+ 4 => ["4", 3],
+ 5 => ["5", 4],
+ 6 => ["6", 5],
+ 7 => ["7", 6],
+ 8 => ["8", 7],
+ 9 => ["9", 8],
+ 10 => ["10", 9],
+ :jack => ["Jack", 10],
+ :queen => ["Queen", 11],
+ :king => ["King", 12],
+ :ace => ["Ace", 13]
+ }
+
+ SUITS = {
+ :spades => ["Spades", 1],
+ :hearts => ["Hearts", 2],
+ :diamonds => ["Diamonds", 3],
+ :clubs => ["Clubs", 4]
+ }
+
+ attr_reader :rank, :suit, :rank_order, :suit_order
+
+ def initialize(rank, suit)
+ @rank, @suit = rank, suit
+ @rank_order, @suit_order = RANKS[rank][1], SUITS[suit][1]
+ end
+
+ def to_s
+ "#{RANKS[@rank][0]} of #{SUITS[@suit][0]}"
+ end
+
+ def ==(compare)
+ self.to_s == compare.to_s
+ end
+end
+
+class Hand
+ SUITS = [:spades, :hearts, :diamonds, :clubs]
+
+ attr_accessor :cards
+
+ def initialize(cards)
+ @cards = cards
+ end
+
+ def size
+ @cards.length
+ end
+end
+
+class Deck
+ include Enumerable
+
+ attr_accessor :deck_size, :hand_size, :cards
+
+ SUITS = [:spades, :hearts, :diamonds, :clubs]
+
+ def initialize(cards = [])
+ @cards = []
+ @ranks.each do |rank|
+ SUITS.each { |suit| @cards.push(Card.new(rank[0], suit)) }
+ end
+ @cards = cards.empty? ? @cards : cards
+ end
+
+ def size
+ @cards.length
+ end
+
+ def draw_top_card
+ @cards.pop
+ end
+
+ def draw_bottom_card
+ @cards.shift
+ end
+
+ def top_card
+ @cards.last
+ end
+
+ def bottom_card
+ @cards.first
+ end
+
+ def shuffle
+ @cards.shuffle!
+ end
+
+ def sort
+ @cards.sort! do |a, b|
+ first = a.suit_order <=> b.suit_order
+ second = b.rank_order <=> a.rank_order
+
+ if not first == 0 then first * second else second end
+ end
+ end
+
+ def to_s
+ cards.each { |card| puts card.to_s }
+ end
+
+ def deal
+ deal_cards = []
+ (1..@hand_size).each do |i|
+ card = self.draw_top_card
+ deal_cards.push(Card.new(card.rank, card.suit))
+ end
+ self.class::Hand.new(deal_cards)
+ end
+end
+
+class WarDeck < Deck
+ RANKS = {
+ 2 => ["2", 1],
+ 3 => ["3", 2],
+ 4 => ["4", 3],
+ 5 => ["5", 4],
+ 6 => ["6", 5],
+ 7 => ["7", 6],
+ 8 => ["8", 7],
+ 9 => ["9", 8],
+ 10 => ["10", 9],
+ :jack => ["Jack", 10],
+ :queen => ["Queen", 11],
+ :king => ["King", 12],
+ :ace => ["Ace", 13]
+ }
+
+ def initialize(cards = [])
+ @deck_size = 52
+ @hand_size = 26
+ @ranks = RANKS
+
+ super
+ end
+
+ class Hand < Hand
+ def play_card
+ @cards.sample
+ end
+
+ def allow_face_up?
+ @cards.length <= 3
+ end
+ end
+end
+
+class BeloteDeck < Deck
+ RANKS = {
+ 7 => ["7", 1],
+ 8 => ["8", 2],
+ 9 => ["9", 3],
+ :jack => ["Jack", 4],
+ :queen => ["Queen", 5],
+ :king => ["King", 6],
+ 10 => ["10", 7],
+ :ace => ["Ace", 8]
+ }
+
+ def initialize(cards = [])
+ @deck_size = 32
+ @hand_size = 8
+ @ranks = RANKS
+
+ super
+ end
+
+ class Hand < Hand
+ RANK_ORDER = [7, 8, 9, :jack, :queen, :king, 10, :ace]
+
+ def sort
+ @cards.sort! do |a, b|
+ first = a.suit_order <=> b.suit_order
+ second = b.rank_order <=> a.rank_order
+
+ if not first == 0 then first * second else second end
+ end
+ end
+
+ def highest_of_suit(suit)
+ suit_cards = []
+
+ self.sort
+ @cards.each { |card| if card.suit == suit then suit_cards.push(card) end}
+
+ suit_cards.first
+ end
+
+ def suit_cards(suit)
+ suit_cards = []
+ self.sort
+
+ @cards.each do |card|
+ if card.suit == suit then suit_cards.push(card.rank) end
+ end
+
+ suit_cards
+ end
+
+ def belote?
+ SUITS.each do |suit|
+ suit_cards = suit_cards(suit)
+ return true if suit_cards.include? :king and suit_cards.include? :queen
+ end
+ false
+ end
+
+ def first_check(suit_cards, n)
+ i, yes = 0, false
+ while i + n < RANKS.length
+ yes = true if second_check(suit_cards, i, n)
+ i += 1
+ end
+ return yes
+ end
+
+ def second_check(suit_cards, i, n)
+ suit_cards.all? {|i| (i..i + n).include?(RANK_ORDER[i])}
+ end
+
+ def tierce?
+ SUITS.each do |suit|
+ suit_cards = suit_cards(suit)
+ result = first_check(suit_cards, 3)
+ return true if result
+ end
+ return false
+ end
+
+ def quarte?
+ SUITS.each do |suit|
+ suit_cards = suit_cards(suit)
+ result = first_check(suit_cards, 4)
+ return true if result
+ end
+ return false
+ end
+
+ def quint?
+ SUITS.each do |suit|
+ suit_cards = suit_cards(suit)
+ result = first_check(suit_cards, 5)
+ return true if result
+ end
+ return false
+ end
+
+ def carre_of_jacks?
+ count = 0
+ @cards.each { |card| count += 1 if card.rank == :jack }
+
+ count == 4
+ end
+
+ def carre_of_nines?
+ count = 0
+ @cards.each { |card| count += 1 if card.rank == 9 }
+
+ count == 4
+ end
+
+ def carre_of_aces?
+ count = 0
+ @cards.each { |card| count += 1 if card.rank == :ace }
+
+ count == 4
+ end
+ end
+end
+
+class SixtySixDeck < Deck
+ RANKS = {
+ 9 => ["9", 1],
+ :jack => ["Jack", 2],
+ :queen => ["Queen", 3],
+ :king => ["King", 4],
+ 10 => ["10", 5],
+ :ace => ["Ace", 6]
+ }
+
+ def initialize(cards = [])
+ @deck_size = 24
+ @hand_size = 6
+ @ranks = RANKS
+
+ super
+ end
+
+ class Hand < Hand
+ def suit_cards(suit)
+ suit_cards = []
+ self.sort
+
+ @cards.each do |card|
+ if card.suit == suit then suit_cards.push(card.rank) end
+ end
+
+ suit_cards
+ end
+
+ def first_check(suit, trump_suit)
+ unless suit == trump_suit
+ color = suit_cards(suit)
+ return true if color.include? :king and color.include? :queen
+ end
+ end
+
+ def twenty?(trump_suit)
+ SUITS.each do |suit|
+ return true if first_check(suit, trump_suit)
+ end
+ false
+ end
+
+ def second_check(suit, trump_suit)
+ if suit == trump_suit
+ color = suit_cards(suit)
+ return true if color.include? :king and color.include? :queen
+ end
+ end
+
+ def forty?(trump_suit)
+ SUITS.each do |suit|
+ return true if second_check(suit, trump_suit)
+ end
+ false
+ end
+ end
+end