Решение на Четвърта задача от Клара Кайралах

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

Към профила на Клара Кайралах

Резултати

  • 5 точки от тестове
  • 1 отнета точка
  • 4 точки общо
  • 50 успешни тест(а)
  • 7 неуспешни тест(а)

Код

class Card
def initialize(rank, suit)
@rank = rank
@suit = suit
end
attr_reader :rank, :suit
def to_s()
@rank.to_s.capitalize + " of " + @suit.to_s.capitalize
end
def ==(other_card)
if other_card == nil then return false end
if @rank == other_card.rank and @suit == other_card.suit
return true
end
false
end
end
class WarDeal
def initialize(size_of_all_cards, cards_in_hand = [])
if size_of_all_cards - 26 >= 0
@size = 26
else @size = size_of_all_cards end
@cards_in_hand = cards_in_hand
end
def size
@cards_in_hand.length
end
def draw_top_card(cards)
cards.delete(cards.first)
end
def deal(array_of_cards)
size = @size
while size > 0
@cards_in_hand.push(draw_top_card(array_of_cards))
size -= 1
end
WarDeal.new(@size, @cards_in_hand)
end
def play_card
@cards_in_hand.delete(@cards_in_hand.sample)
end
def allow_face_up?
if @size <= 3 then true else false end
end
end
class Deck
include Enumerable
def all_cards
ranks = [2, 3, 4, 5, 6, 7, 8, 9, 10, :jack, :queen, :king, :ace]
suits = [:spades, :hearts, :diamonds, :clubs]
ranks.flat_map { |rank| suits.map { |suit| Card.new(rank, suit) } }.shuffle
end
def initialize(array_of_cards = all_cards)
@ranks = [2, 3, 4, 5, 6, 7, 8, 9, 10, :jack, :queen, :king, :ace].reverse
@suits = [:spades, :hearts, :diamonds, :clubs]
@array_of_cards = array_of_cards
end
attr_reader :array_of_cards
def size
@array_of_cards.length
end
def draw_top_card
@array_of_cards.delete(@array_of_cards.first)
end
def draw_bottom_card
@array_of_cards.delete(@array_of_cards.last)
end
def top_card
@array_of_cards.first
end
def bottom_card
@array_of_cards.last
end
def shuffle
@array_of_cards.shuffle!
end
def sort
@array_of_cards.sort_by!{ |card|
[@suits.index(card.suit), @ranks.index(card.rank)] }
end
def each
@array_of_cards.each{ |x| yield x }
end
def to_s
@array_of_cards.each{ |x| x.to_s + "\n" }
end
def deal
WarDeal.new(size).deal(@array_of_cards)
end
end
class WarDeck < Deck
def initialize(array_of_cards = all_cards)
super
end
end
class BeloteDealHelper
def initialize(cards_in_hand)
@ranks = [7 ,8 ,9 ,:jack ,:queen ,:king, 10 ,:ace].reverse
@suits = [:spades, :hearts, :diamonds, :clubs]
@cards_in_hand = cards_in_hand
end
def check_if_card_has_some_suit(card, temp_array_of_cards, suit)
if card.suit == suit then temp_array_of_cards.push(card) end
end
def check_all_cards_for_some_suit(sorted_cards, suit, temp_array_of_cards)
sorted_cards.each{ |card|
check_if_card_has_some_suit(card, temp_array_of_cards, suit)
}
end
def check_for_sequence_of_cards(sequence_size)
sorted_cards = @cards_in_hand.sort_by{ |card|
@ranks.index(card.rank) }.reverse
array_of_cards_with_same_suit, index = [], 0
@suits.each{ |suit| temp_array_of_cards = []
check_all_cards_for_some_suit(sorted_cards, suit, temp_array_of_cards)
array_of_cards_with_same_suit.push(temp_array_of_cards.sort_by{ |card|
@ranks.index(card.rank) }.reverse)
}
sequence_helper(array_of_cards_with_same_suit, sequence_size)
end
def iterating_one_set_of_cards(step, array_of_cards, temp_arr)
while step + 1 <= array_of_cards.length - 1
if @ranks.index(array_of_cards.at(step).rank) -
@ranks.index(array_of_cards.at(step + 1).rank) == 1
temp_arr.push(1)
end
step += 1
end
end
def is_end_of_iteration(temp_arr, size)
if temp_arr.length == size - 1 then return true end
end
def iterating_cards(temp_arr, array_of_cards, size, step)
if array_of_cards.length >= size
iterating_one_set_of_cards(step, array_of_cards, temp_arr)
return true if is_end_of_iteration(temp_arr, size)
end
end
def sequence_helper(array, size)
array.each{ |array_of_cards|
step, temp_arr = 0, []
return true if iterating_cards(temp_arr, array_of_cards, size, step)
}
false
end
end
class BeloteDeal
def initialize(size_of_all_cards, cards_in_hand = [])
if size_of_all_cards - 8 >= 0
@size = 8
else @size = @size_of_all_cards end
@cards_in_hand = cards_in_hand
@ranks = [7 ,8 ,9 ,:jack ,:queen ,:king, 10 ,:ace].reverse
@suits = [:spades, :hearts, :diamonds, :clubs]
end
def size
@cards_in_hand.length
end
def draw_top_card(cards)
cards.delete(cards.first)
end
def deal(array_of_cards)
size = @size
while size > 0
@cards_in_hand.push(draw_top_card(array_of_cards))
size -= 1
end
BeloteDeal.new(@size, @cards_in_hand)
end
def highest_of_suit(suit)
array = @cards_in_hand.sort_by{ |card| [@ranks.index(card.rank)]}
array_of_suits = []
array.each{ | x | if x.suit == suit then array_of_suits.push(x) end }
array_of_suits.first
end
def belote?
@suits.each{ |suit| if (@cards_in_hand.include? Card.new(:king,suit) and
@cards_in_hand.include? Card.new(:queen,suit)) then return true end }
false
end
def tierce?
BeloteDealHelper.new(@cards_in_hand).check_for_sequence_of_cards(3)
end
def quarte?
BeloteDealHelper.new(@cards_in_hand).check_for_sequence_of_cards(4)
end
def quint?
BeloteDealHelper.new(@cards_in_hand).check_for_sequence_of_cards(5)
end
def has_four_cards_of_some_rank(rank)
rank_counter = 0
@cards_in_hand.each{ |card|
if card.rank == rank then rank_counter += 1 end
if rank_counter == 4 then return true end
}
false
end
def carre_of_jacks?
has_four_cards_of_some_rank(:jack)
end
def carre_of_nines?
has_four_cards_of_some_rank(9)
end
def carre_of_aces?
has_four_cards_of_some_rank(:ace)
end
end
class BeloteDeck < Deck
def all_cards
ranks = [7, 8, 9, :jack, :queen, :king, 10, :ace]
suits = [:spades, :hearts, :diamonds, :clubs]
ranks.flat_map { |rank| suits.map { |suit| Card.new(rank, suit) } }
end
def initialize(array_of_cards = all_cards)
@ranks = [7 ,8 ,9 ,:jack ,:queen ,:king, 10 ,:ace]
@suits = [:spades, :hearts, :diamonds, :clubs]
@array_of_cards = array_of_cards
end
def deal
BeloteDeal.new(size).deal(@array_of_cards)
end
end
class SixtySixDeal
def initialize(size_of_all_cards, cards_in_hand = [])
if size_of_all_cards - 6 >= 0
@size = 6
else @size = size_of_all_cards end
@cards_in_hand = cards_in_hand
@ranks = [9, :jack, :queen, :king, 10, :ace].reverse
@suits = [:spades, :hearts, :diamonds, :clubs]
end
def size
@cards_in_hand.length
end
def draw_top_card(cards)
cards.delete(cards.first)
end
def deal(array_of_cards)
size = @size
while size > 0
@cards_in_hand.push(draw_top_card(array_of_cards))
size -= 1
if array_of_cards.length == 0 then break end
end
SixtySixDeal.new(@size, @cards_in_hand)
end
def king_queen_with_same_suit(suits)
suits.each{ |suit|
if @cards_in_hand.include? Card.new(:queen,suit) and
@cards_in_hand.include? Card.new(:king,suit) then return true end
}
false
end
def twenty?(trump_suit)
suits = [:spades, :hearts, :diamonds, :clubs]
suits.delete(trump_suit)
king_queen_with_same_suit(suits)
end
def forty?(trump_suit)
suits = [:spades, :hearts, :diamonds, :clubs]
suits.delete(trump_suit)
king_queen_with_same_suit(Array(trump_suit))
end
end
class SixtySixDeck < Deck
def all_cards
ranks = [9 ,:jack ,:queen,:king, 10 ,:ace]
suits = [:spades, :hearts, :diamonds, :clubs]
ranks.flat_map { |rank| suits.map { |suit|
Card.new(rank, suit) } }.shuffle
end
def initialize(array_of_cards = all_cards)
@ranks = [9 ,:jack ,:queen,:king, 10 ,:ace]
@suits = [:spades, :hearts, :diamonds, :clubs]
@array_of_cards = array_of_cards
end
def deal
SixtySixDeal.new(size).deal(@array_of_cards)
end
end

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

...........F...F........FF....F....................FF....

Failures:

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

  2) 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-1vhp0zu/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)>'

  3) 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:0x007f3ad427c098>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1vhp0zu/spec.rb:191
     # /tmp/d20151112-27349-1vhp0zu/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)>'

  4) 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:0x007f3ad4267c60 @rank=:jack, @suit=:spades>, #<Card:0x007f3ad4267b70 @rank=10, @suit=:hearts>, #<Card:0x007f3ad4267c88 @rank=:ace, @suit=:clubs>, #<Card:0x007f3ad4267c38 @rank=7, @suit=:clubs>]
            got: [#<Card:0x007f3ad4267c60 @rank=:jack, @suit=:spades>, #<Card:0x007f3ad4267b70 @rank=10, @suit=:hearts>, #<Card:0x007f3ad4267c38 @rank=7, @suit=:clubs>, #<Card:0x007f3ad4267c88 @rank=:ace, @suit=:clubs>]
       
       (compared using ==)
       
       Diff:
       @@ -1,5 +1,5 @@
        [#<Card:0x007f3ad4267c60 @rank=:jack, @suit=:spades>,
         #<Card:0x007f3ad4267b70 @rank=10, @suit=:hearts>,
       - #<Card:0x007f3ad4267c88 @rank=:ace, @suit=:clubs>,
       - #<Card:0x007f3ad4267c38 @rank=7, @suit=:clubs>]
       + #<Card:0x007f3ad4267c38 @rank=7, @suit=:clubs>,
       + #<Card:0x007f3ad4267c88 @rank=:ace, @suit=:clubs>]
     # /tmp/d20151112-27349-1vhp0zu/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)>'

  5) BeloteDeck hand #tierce? with tierce returns true for cards with names
     Failure/Error: expect(hand.tierce?).to be true
       
       expected #<TrueClass:20> => true
            got #<FalseClass:0> => false
       
       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-1vhp0zu/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)>'

  6) 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:0x007f3ad4020da8>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1vhp0zu/spec.rb:400
     # /tmp/d20151112-27349-1vhp0zu/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)>'

  7) 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:0x007f3ad3ff1f30 @rank=:jack, @suit=:spades>, #<Card:0x007f3ad3ff1ee0 @rank=10, @suit=:hearts>, #<Card:0x007f3ad3ff1f58 @rank=:ace, @suit=:clubs>, #<Card:0x007f3ad3ff1f08 @rank=9, @suit=:clubs>]
            got: [#<Card:0x007f3ad3ff1f30 @rank=:jack, @suit=:spades>, #<Card:0x007f3ad3ff1ee0 @rank=10, @suit=:hearts>, #<Card:0x007f3ad3ff1f08 @rank=9, @suit=:clubs>, #<Card:0x007f3ad3ff1f58 @rank=:ace, @suit=:clubs>]
       
       (compared using ==)
       
       Diff:
       @@ -1,5 +1,5 @@
        [#<Card:0x007f3ad3ff1f30 @rank=:jack, @suit=:spades>,
         #<Card:0x007f3ad3ff1ee0 @rank=10, @suit=:hearts>,
       - #<Card:0x007f3ad3ff1f58 @rank=:ace, @suit=:clubs>,
       - #<Card:0x007f3ad3ff1f08 @rank=9, @suit=:clubs>]
       + #<Card:0x007f3ad3ff1f08 @rank=9, @suit=:clubs>,
       + #<Card:0x007f3ad3ff1f58 @rank=:ace, @suit=:clubs>]
     # /tmp/d20151112-27349-1vhp0zu/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)>'

Finished in 0.04666 seconds
57 examples, 7 failures

Failed examples:

rspec /tmp/d20151112-27349-1vhp0zu/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-1vhp0zu/spec.rb:175 # WarDeck hand #allow_face_up? returns true if the cards are less than or equal to 3
rspec /tmp/d20151112-27349-1vhp0zu/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-1vhp0zu/spec.rb:196 # BeloteDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-1vhp0zu/spec.rb:272 # BeloteDeck hand #tierce? with tierce returns true for cards with names
rspec /tmp/d20151112-27349-1vhp0zu/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-1vhp0zu/spec.rb:405 # SixtySixDeck #sort sorts the cards in the defined order

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

Клара обнови решението на 10.11.2015 15:35 (преди около 9 години)

+class Card
+
+ def initialize(rank, suit)
+ @rank = rank
+ @suit = suit
+ end
+
+ attr_reader :rank, :suit
+
+ def to_s()
+ @rank.to_s.capitalize + " of " + @suit.to_s.capitalize
+ end
+
+ def ==(other_card)
+ if other_card == nil then return false end
+ if @rank == other_card.rank and @suit == other_card.suit
+ return true
+ end
+ false
+ end
+end
+
+class WarDeal
+
+ def initialize(size_of_all_cards, cards_in_hand = [])
+ if size_of_all_cards - 26 >= 0
+ @size = 26
+ else @size = size_of_all_cards end
+ @cards_in_hand = cards_in_hand
+ end
+
+ def size
+ @cards_in_hand.length
+ end
+
+ def draw_top_card(cards)
+ cards.delete(cards.first)
+ end
+
+ def deal(array_of_cards)
+ size = @size
+ while size > 0
+ @cards_in_hand.push(draw_top_card(array_of_cards))
+ size -= 1
+ end
+ WarDeal.new(@size, @cards_in_hand)
+ end
+
+ def play_card
+ @cards_in_hand.delete(@cards_in_hand.sample)
+ end
+
+ def allow_face_up?
+ if @size <= 3 then true else false end
+ end
+end
+
+class Deck
+
+ include Enumerable
+
+ def all_cards
+ ranks = [2, 3, 4, 5, 6, 7, 8, 9, 10, :jack, :queen, :king, :ace]
+ suits = [:spades, :hearts, :diamonds, :clubs]
+ ranks.flat_map { |rank| suits.map { |suit| Card.new(rank, suit) } }.shuffle
+ end
+
+ def initialize(array_of_cards = all_cards)
+ @ranks = [2, 3, 4, 5, 6, 7, 8, 9, 10, :jack, :queen, :king, :ace].reverse
+ @suits = [:spades, :hearts, :diamonds, :clubs]
+ @array_of_cards = array_of_cards
+ end
+
+ attr_reader :array_of_cards
+
+ def size
+ @array_of_cards.length
+ end
+
+ def draw_top_card
+ @array_of_cards.delete(@array_of_cards.first)
+ end
+
+ def draw_bottom_card
+ @array_of_cards.delete(@array_of_cards.last)
+ end
+
+ def top_card
+ @array_of_cards.first
+ end
+
+ def bottom_card
+ @array_of_cards.last
+ end
+
+ def shuffle
+ @array_of_cards.shuffle!
+ end
+
+ def sort
+ @array_of_cards.sort_by!{ |card|
+ [@suits.index(card.suit), @ranks.index(card.rank)] }
+ end
+
+ def each
+ @array_of_cards.each{ |x| yield x }
+ end
+
+ def to_s
+ @array_of_cards.each{ |x| x.to_s + "\n" }
+ end
+
+ def deal
+ WarDeal.new(size).deal(@array_of_cards)
+ end
+end
+
+class WarDeck < Deck
+
+ def initialize(array_of_cards = all_cards)
+ super
+ end
+end
+
+class BeloteDealHelper
+
+ def initialize(cards_in_hand)
+ @ranks = [7 ,8 ,9 ,:jack ,:queen ,:king, 10 ,:ace].reverse
+ @suits = [:spades, :hearts, :diamonds, :clubs]
+ @cards_in_hand = cards_in_hand
+ end
+
+ def check_if_card_has_some_suit(card, temp_array_of_cards, suit)
+ if card.suit == suit then temp_array_of_cards.push(card) end
+ end
+
+ def check_all_cards_for_some_suit(sorted_cards, suit, temp_array_of_cards)
+ sorted_cards.each{ |card|
+ check_if_card_has_some_suit(card, temp_array_of_cards, suit)
+ }
+ end
+
+ def check_for_sequence_of_cards(sequence_size)
+ sorted_cards = @cards_in_hand.sort_by{ |card|
+ @ranks.index(card.rank) }.reverse
+ array_of_cards_with_same_suit, index = [], 0
+ @suits.each{ |suit| temp_array_of_cards = []
+ check_all_cards_for_some_suit(sorted_cards, suit, temp_array_of_cards)
+ array_of_cards_with_same_suit.push(temp_array_of_cards.sort_by{ |card|
+ @ranks.index(card.rank) }.reverse)
+ }
+ sequence_helper(array_of_cards_with_same_suit, sequence_size)
+ end
+
+ def iterating_one_set_of_cards(step, array_of_cards, temp_arr)
+ while step + 1 <= array_of_cards.length - 1
+ if @ranks.index(array_of_cards.at(step).rank) -
+ @ranks.index(array_of_cards.at(step + 1).rank) == 1
+ temp_arr.push(1)
+ end
+ step += 1
+ end
+ end
+
+ def is_end_of_iteration(temp_arr, size)
+ if temp_arr.length == size - 1 then return true end
+ end
+
+ def iterating_cards(temp_arr, array_of_cards, size, step)
+ if array_of_cards.length >= size
+ iterating_one_set_of_cards(step, array_of_cards, temp_arr)
+ return true if is_end_of_iteration(temp_arr, size)
+ end
+ end
+
+ def sequence_helper(array, size)
+ array.each{ |array_of_cards|
+ step, temp_arr = 0, []
+ return true if iterating_cards(temp_arr, array_of_cards, size, step)
+ }
+ false
+ end
+end
+
+class BeloteDeal
+
+ def initialize(size_of_all_cards, cards_in_hand = [])
+ if size_of_all_cards - 8 >= 0
+ @size = 8
+ else @size = @size_of_all_cards end
+ @cards_in_hand = cards_in_hand
+ @ranks = [7 ,8 ,9 ,:jack ,:queen ,:king, 10 ,:ace].reverse
+ @suits = [:spades, :hearts, :diamonds, :clubs]
+ end
+
+ def size
+ @cards_in_hand.length
+ end
+
+ def draw_top_card(cards)
+ cards.delete(cards.first)
+ end
+
+ def deal(array_of_cards)
+ size = @size
+ while size > 0
+ @cards_in_hand.push(draw_top_card(array_of_cards))
+ size -= 1
+ end
+ BeloteDeal.new(@size, @cards_in_hand)
+ end
+
+ def highest_of_suit(suit)
+ array = @cards_in_hand.sort_by{ |card| [@ranks.index(card.rank)]}
+ array_of_suits = []
+ array.each{ | x | if x.suit == suit then array_of_suits.push(x) end }
+ array_of_suits.first
+ end
+
+ def belote?
+ @suits.each{ |suit| if (@cards_in_hand.include? Card.new(:king,suit) and
+ @cards_in_hand.include? Card.new(:queen,suit)) then return true end }
+ false
+ end
+
+ def tierce?
+ BeloteDealHelper.new(@cards_in_hand).check_for_sequence_of_cards(3)
+ end
+
+ def quarte?
+ BeloteDealHelper.new(@cards_in_hand).check_for_sequence_of_cards(4)
+ end
+
+ def quint?
+ BeloteDealHelper.new(@cards_in_hand).check_for_sequence_of_cards(5)
+ end
+
+ def has_four_cards_of_some_rank(rank)
+ rank_counter = 0
+ @cards_in_hand.each{ |card|
+ if card.rank == rank then rank_counter += 1 end
+ if rank_counter == 4 then return true end
+ }
+ false
+ end
+
+ def carre_of_jacks?
+ has_four_cards_of_some_rank(:jack)
+ end
+
+ def carre_of_nines?
+ has_four_cards_of_some_rank(9)
+ end
+
+ def carre_of_aces?
+ has_four_cards_of_some_rank(:ace)
+ end
+end
+
+class BeloteDeck < Deck
+
+ def all_cards
+ ranks = [7, 8, 9, :jack, :queen, :king, 10, :ace]
+ suits = [:spades, :hearts, :diamonds, :clubs]
+ ranks.flat_map { |rank| suits.map { |suit| Card.new(rank, suit) } }
+ end
+
+ def initialize(array_of_cards = all_cards)
+ @ranks = [7 ,8 ,9 ,:jack ,:queen ,:king, 10 ,:ace]
+ @suits = [:spades, :hearts, :diamonds, :clubs]
+ @array_of_cards = array_of_cards
+ end
+
+ def deal
+ BeloteDeal.new(size).deal(@array_of_cards)
+ end
+end
+
+
+class SixtySixDeal
+
+ def initialize(size_of_all_cards, cards_in_hand = [])
+ if size_of_all_cards - 6 >= 0
+ @size = 6
+ else @size = size_of_all_cards end
+ @cards_in_hand = cards_in_hand
+ @ranks = [9, :jack, :queen, :king, 10, :ace].reverse
+ @suits = [:spades, :hearts, :diamonds, :clubs]
+ end
+
+ def size
+ @cards_in_hand.length
+ end
+
+ def draw_top_card(cards)
+ cards.delete(cards.first)
+ end
+
+ def deal(array_of_cards)
+ size = @size
+ while size > 0
+ @cards_in_hand.push(draw_top_card(array_of_cards))
+ size -= 1
+ if array_of_cards.length == 0 then break end
+ end
+ SixtySixDeal.new(@size, @cards_in_hand)
+ end
+
+ def king_queen_with_same_suit(suits)
+ suits.each{ |suit|
+ if @cards_in_hand.include? Card.new(:queen,suit) and
+ @cards_in_hand.include? Card.new(:king,suit) then return true end
+ }
+ false
+ end
+
+ def twenty?(trump_suit)
+ suits = [:spades, :hearts, :diamonds, :clubs]
+ suits.delete(trump_suit)
+ king_queen_with_same_suit(suits)
+ end
+
+ def forty?(trump_suit)
+ suits = [:spades, :hearts, :diamonds, :clubs]
+ suits.delete(trump_suit)
+ king_queen_with_same_suit(Array(trump_suit))
+ end
+end
+
+class SixtySixDeck < Deck
+
+ def all_cards
+ ranks = [9 ,:jack ,:queen,:king, 10 ,:ace]
+ suits = [:spades, :hearts, :diamonds, :clubs]
+ ranks.flat_map { |rank| suits.map { |suit|
+ Card.new(rank, suit) } }.shuffle
+ end
+
+ def initialize(array_of_cards = all_cards)
+ @ranks = [9 ,:jack ,:queen,:king, 10 ,:ace]
+ @suits = [:spades, :hearts, :diamonds, :clubs]
+ @array_of_cards = array_of_cards
+ end
+
+ def deal
+ SixtySixDeal.new(size).deal(@array_of_cards)
+ end
+end