Module: Yahtzee::Scoring

Extended by:
LowerCard, UpperCard
Included in:
Game
Defined in:
lib/scoring.rb,
lib/scoring/lower_card.rb,
lib/scoring/upper_card.rb

Defined Under Namespace

Modules: LowerCard, UpperCard

Class Method Summary collapse

Methods included from UpperCard

score_aces, score_fives, score_fours, score_sixes, score_sums, score_threes, score_twos

Methods included from LowerCard

dup_counts_as_hash, max_dupe_count_as_hash, score_bonus_yahtzee, score_chance, score_four_of_a_kind, score_full_house, score_large_straight, score_min_of_a_kind, score_small_straight, score_three_of_a_kind, score_yahtzee

Class Method Details

.reduce_values_from_hash(hash) ⇒ Object



42
43
44
# File 'lib/scoring.rb', line 42

def reduce_values_from_hash(hash)
  hash.values.compact.reduce(:+)
end

.score(dice, placement, &updater) ⇒ Object



21
22
23
24
# File 'lib/scoring.rb', line 21

def score(dice, placement, &updater)
  value = send("score_#{placement.to_s}", dice)
  updater.call(placement, value)
end

.score_game_total(scores, &updater) ⇒ Object



37
38
39
40
# File 'lib/scoring.rb', line 37

def score_game_total(scores, &updater)
  value = reduce_values_from_hash(scores)
  updater.call(:game_total, value)
end

.score_subtotal(scores, placement, &updater) ⇒ Object



26
27
28
29
# File 'lib/scoring.rb', line 26

def score_subtotal(scores, placement, &updater)
  value = reduce_values_from_hash(scores)
  updater.call(placement, value)
end

.score_upper_total(scores, &updater) ⇒ Object



31
32
33
34
35
# File 'lib/scoring.rb', line 31

def score_upper_total(scores, &updater)
  subtotal = reduce_values_from_hash(scores)
  bonus = subtotal >= 63 ? 35 : 0
  updater.call(:upper_total, bonus+subtotal)
end