-
Notifications
You must be signed in to change notification settings - Fork 0
/
deck.rb
64 lines (50 loc) · 1 KB
/
deck.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require_relative 'copper'
require_relative 'estate'
class Deck
def initialize(options = {})
@cards = options[:cards] || []
7.times do
@cards.push(Copper.new)
end
3.times do
@cards.push(Estate.new)
end
end
def output
@cards.each do |card|
puts card.name
end
end
def shuffle!
@cards.shuffle!
end
def draw(n_of_cards=5)
return @cards.shift(n_of_cards)
end
def unshift(n)
@cards.unshift()
end
def shift(n)
@cards.shift(n)
end
def size
@cards.size
end
def add_to_bottom(cards)
@cards.push(cards).flatten!
end
def includes(card_type)
return !(@cards.select { |c| c.name == card_type } .empty?)
end
def count(card_type)
return @cards.select { |c| c.name == card_type } .count
end
def score
self.class.score(@cards)
end
def self.score(cards)
treasure_cards = cards.select(&:victory?)
score_count = treasure_cards.inject(0) { |sum, card| sum += card.points }
score_count
end
end