-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Edges Layla and Dionisia's Adagrams! #16
base: master
Are you sure you want to change the base?
Changes from all commits
f51ff39
c29579f
0a52ff5
e20d2db
6cd1df6
eb9c648
781a49b
fe5c492
3a50e81
7ddef41
b2dba0b
1741514
59ed1a2
4b8645c
0c5651b
cdb0362
9ba6924
0ca9b1d
a822e4e
c2fdfe5
f5ab92e
b417534
9b44062
743f420
06eda51
456d01f
978f603
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
require 'csv' | ||
|
||
# wave 1 | ||
def stores_letters | ||
letters = [ "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "C", "C", "D", "D", "D", "D", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "F", "F", "G", "G", "G", "H", "H", "I", "I", "I", "I", "I", "I", "I", "I", "I", "J", "K", "L", "L", "L", "L", "M", "M", "N", "N", "N", "N", "N", "N", "O", "O", "O", "O", "O", "O", "O", "O", "P", "P", "Q", "R", "R", "R", "R", "R", "R", "S", "S", "S", "S", "T", "T", "T", "T", "T", "T", "U", "U", "U", "U", "V", "V", "W", "W", "X", "Y", "Y", "Z" ] | ||
end | ||
|
||
def draw_letters | ||
letter = stores_letters.shuffle.pop(10) | ||
return letter | ||
end | ||
|
||
def welcome | ||
puts "Welcome to adagrams. Here are your letters." | ||
draw_letters | ||
end | ||
|
||
|
||
def game_instructions | ||
puts "Based on these letters, give us a word." | ||
print "Word: " | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't need to implement these methods - that's what the |
||
|
||
# def get_user_input | ||
# user_input = gets.chomp | ||
# return user_input | ||
# end | ||
|
||
# wave 2 | ||
def uses_available_letters?(input, letters_in_hand) | ||
input = input.upcase.split("") | ||
input.each do |letter| | ||
if letters_in_hand.include?(letter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two problems with this implementation:
I will acknowledge that none of the tests checked for either of these behaviors, but that doesn't change the fact that they're bugs. |
||
letters_in_hand.delete(letter) | ||
else | ||
return false | ||
end | ||
end | ||
return true | ||
end | ||
|
||
|
||
# wave 3 | ||
def score_word(word) | ||
score = 0 | ||
|
||
score_hash = { | ||
"A" => 1, | ||
"E" => 1, | ||
"I" => 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this data structure. Why not store this data in a constant? |
||
"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 | ||
} | ||
|
||
word = word.upcase.split("") | ||
word.each do |letter| | ||
score += score_hash[letter] | ||
end | ||
bonus_length = [7, 8, 9, 10] | ||
if bonus_length.include?(word.length) | ||
score += 8 | ||
end | ||
return score | ||
end | ||
|
||
# wave 4 | ||
def highest_score_from(words) | ||
|
||
winning_word_and_score = { | ||
word: "", | ||
score: 0 | ||
} | ||
|
||
words.each do |word| | ||
score = score_word(word) | ||
|
||
if score > winning_word_and_score[:score] | ||
winning_word_and_score[:score] = score | ||
winning_word_and_score[:word] = word | ||
elsif score == winning_word_and_score[:score] #if it is a tie | ||
# if current word has 10 letters and current winner does not, | ||
# current word becomes new current winner. | ||
if word.length == 10 && winning_word_and_score[:word].length != 10 | ||
winning_word_and_score[:word] = word | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work getting this tricky tie-breaking logic sorted out. |
||
# is current word has less letters than current winner, | ||
# and current winner has less than 10 letters, current word | ||
# becomes new current winner. | ||
# backslash at the end of the line allows the line to continue onto the | ||
# next line. | ||
elsif (word.length < winning_word_and_score[:word].length) \ | ||
&& (winning_word_and_score[:word].length != 10) | ||
winning_word_and_score[:word] = word | ||
end | ||
end | ||
end | ||
|
||
return winning_word_and_score | ||
end | ||
|
||
# wave 5 | ||
def is_in_english_dict?(input) | ||
CSV.open("assets/dictionary-english.csv", "r").each do |word| | ||
return true if word.include?(input.downcase) | ||
end | ||
return false | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This data structure makes sense for storing the pool of letters. However, laid out like this it's not easy to see the distribution of letters. Something like this might be a bit easier to read:
Or, if you were feeling fancy: