Skip to content

Instantly share code, notes, and snippets.

@wobh
Last active December 15, 2015 05:09
Show Gist options
  • Save wobh/5206570 to your computer and use it in GitHub Desktop.
Save wobh/5206570 to your computer and use it in GitHub Desktop.
#Scrabblesque
class ScrabblesquePlay
def inititialize(word, multipliers)
end
# TODO I haven't decided the class properties quite yet.
end
$letter_values = {
:a => 1, :e => 1, :i => 1, :o => 1, :u => 1,
:l => 1, :n => 1, :r => 1, :s => 1, :t => 1,
:d => 2, :g => 2,
:b => 3, :c => 3, :m => 3, :p => 3,
:f => 4, :h => 4, :v => 4, :w => 4, :y => 4,
:k => 5,
:j => 8, :x => 8,
:q => 10, :z => 10
}
def get_letter_score(letter)
$letter_values[letter.downcase.to_sym]
end
def get_word_score(word)
score = 0
word.each_char { |letter| score += get_letter_score(letter) }
return score
end
def get_total_score(word, multipliers)
raw_score = get_word_score(word)
bonus_score = 0
multipliers.each_pair { |pos, mult|
case mult
when :double_word
bonus_score += raw_score
when :triple_word
bonus_score += raw_score * 2
when :double_letter
bonus_score += get_letter_score(word[pos])
when :triple_letter
bonus_score += get_letter_score(word(pos)) * 2
end
}
return raw_score + bonus_score
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment