-
-
Save calavera/766566 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def score(dice) | |
compute_singles(dice) + compute_triples(dice) | |
end | |
def compute_singles(diceRoll) | |
diceRoll.inject(0) do |result, roll| | |
result += single_value(roll) | |
end | |
end | |
SINGLE_VALUES = { 1 => 100 , 5 => 50} | |
def single_value(roll) | |
SINGLE_VALUES[roll] || 0 | |
end | |
def compute_triples(diceRoll) | |
(1..6).inject(0) do |result, points| | |
result += calculate_triple_score(points) if diceRoll.count(points) >= 3 | |
result | |
end | |
end | |
TRIPLE_FACTOR = 100 | |
SPECIAL_TRIPLE_SCORES = {1=>1000} | |
def calculate_triple_score(points) | |
tripleScore = SPECIAL_TRIPLE_SCORES[points] || ( points * TRIPLE_FACTOR ) | |
tripleScore - score_of_triple_as_singles(points) | |
end | |
def score_of_triple_as_singles(points) | |
single_value(points) * 3 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
se supone que sólo hay 5 dados, así que sólo puede haber un trío ;)