module Yahtzee::Scoring::LowerCard

Public Instance Methods

dup_counts_as_hash(dice) click to toggle source
# File lib/scoring/lower_card.rb, line 53
def dup_counts_as_hash(dice)
  dice.each_with_object(Hash.new(0)) {|o, h| h[o] += 1 }
end
max_dupe_count_as_hash(dice) click to toggle source
# File lib/scoring/lower_card.rb, line 57
def max_dupe_count_as_hash(dice)
  dup_counts_as_hash(dice).max_by {|_,v| v }
end
score_bonus_yahtzee(dice) click to toggle source
# File lib/scoring/lower_card.rb, line 41
def score_bonus_yahtzee(dice)
  dice.uniq.count == 1 ? 100 : 0
end
score_bonus_yahtzee_1(dice)
Alias for: score_bonus_yahtzee
score_bonus_yahtzee_2(dice)
Alias for: score_bonus_yahtzee
score_bonus_yahtzee_3(dice)
Alias for: score_bonus_yahtzee
score_chance(dice) click to toggle source
# File lib/scoring/lower_card.rb, line 7
def score_chance(dice)
  dice.reduce(:+)
end
score_four_of_a_kind(dice) click to toggle source
# File lib/scoring/lower_card.rb, line 33
def score_four_of_a_kind(dice)
  score_min_of_a_kind(dice, 4)
end
score_full_house(dice) click to toggle source
# File lib/scoring/lower_card.rb, line 11
def score_full_house(dice)
  sorted = dice.sort
  (sorted.count(sorted.first) + 
   sorted.count(sorted.last) == 5) ? 25 : 0
end
score_large_straight(dice) click to toggle source
# File lib/scoring/lower_card.rb, line 23
def score_large_straight(dice)
  dice.each_cons(5).any? do |a,b,c,d,e| 
    a+1==b && b+1==c && c+1==d && d+1==e
  end ? 40 : 0
end
score_min_of_a_kind(dice, min) click to toggle source
# File lib/scoring/lower_card.rb, line 48
def score_min_of_a_kind(dice, min)
  value = max_dupe_count_as_hash(dice)
  value[1] >= min ? value.reduce(:*) : 0
end
score_small_straight(dice) click to toggle source
# File lib/scoring/lower_card.rb, line 17
def score_small_straight(dice)
  dice.each_cons(4).any? do |a,b,c,d| 
    a+1==b && b+1==c && c+1==d
  end ? 30 : 0
end
score_three_of_a_kind(dice) click to toggle source
# File lib/scoring/lower_card.rb, line 29
def score_three_of_a_kind(dice)
  score_min_of_a_kind(dice, 3)
end
score_yahtzee(dice) click to toggle source
# File lib/scoring/lower_card.rb, line 37
def score_yahtzee(dice)
  dice.uniq.count == 1 ? 50 : 0
end