-
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
Chantelle/Semret - C10 Edges - Adagrams #19
base: master
Are you sure you want to change the base?
Changes from all commits
59f4c6d
83e9275
fad4598
c017133
298c388
ecd6ac4
055277f
5b0d5dc
76e6241
6aa23ed
18c85f2
c8b1e76
e7b26a1
3bf0350
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,166 @@ | ||
# Chantelle and Semret (Pair-Programing) | ||
# Adagram project | ||
# 8/13/18 | ||
require 'csv' | ||
|
||
# WAVE 1 SYNTAX | ||
def draw_letters | ||
|
||
random_draw = [] | ||
|
||
letter_pool = ('A'..'Z').map do |char| | ||
case char | ||
when 'A', 'I' | ||
letter = char * 9 | ||
when 'B', 'C', 'F', 'H', 'M', 'P', 'V', 'W', 'Y' | ||
letter = char * 2 | ||
when 'D', 'L', 'S', 'U' | ||
letter = char * 4 | ||
when 'E' | ||
letter = char * 12 | ||
when 'G' | ||
letter = char * 3 | ||
when 'J', 'K', 'Q', 'X', 'Z' | ||
letter = char * 1 | ||
when 'N', 'R', 'T' | ||
letter = char * 6 | ||
when 'O' | ||
letter = char * 8 | ||
end | ||
end | ||
|
||
split_letter_pool = letter_pool.map do |chars| | ||
chars.split("") | ||
end | ||
|
||
#random draw of 10 from array and flatten the letter pool | ||
random_draw = split_letter_pool.flatten.sample(10) | ||
return random_draw | ||
|
||
end | ||
|
||
# puts "Random draw: #{draw_letters}" | ||
|
||
def uses_available_letters?(word, letter_in_hand) | ||
temp_hand = letter_in_hand.dup | ||
inputted_word = [] | ||
inputted_word << word.upcase.split("") | ||
inputted_word.flatten! | ||
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. Actually, calling aka, if Therefore, you can turn the above code: inputted_word = []
inputted_word << word.upcase.split("")
inputted_word.flatten! to inputted_word = word.upcase.split("") Let me know if there are any questions on this |
||
|
||
check_letter = true | ||
|
||
inputted_word.each do |letter| | ||
index = 0 | ||
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. Scope question: What is the smallest scope (the most specific/local block of code) that |
||
|
||
if !temp_hand.include?(letter) | ||
check_letter = false | ||
end | ||
|
||
if temp_hand.include?(letter) | ||
index = temp_hand.index(letter) | ||
temp_hand.delete_at(index) | ||
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 think that |
||
end | ||
end | ||
|
||
return check_letter | ||
|
||
end | ||
|
||
# WAVE 3 SYNTAX | ||
# Scoring the word based on above parameters of scoring chart | ||
def score_word (word) | ||
|
||
this_letter = [] | ||
this_letter << word.upcase.split("") | ||
this_letter.flatten! | ||
|
||
score = 0 | ||
this_letter.each do |value| | ||
|
||
case value | ||
when 'A', 'E', 'I', 'O' , 'U' , 'L' , 'N' , 'R' , 'S' , 'T' | ||
score += 1 | ||
when 'D', 'G' | ||
score += 2 | ||
when 'B', 'C', 'M', 'P' | ||
score += 3 | ||
when 'F', 'H', 'V', 'W' , 'Y' | ||
score += 4 | ||
when 'K' | ||
score += 5 | ||
when 'J', 'X' | ||
score += 8 | ||
when 'Q', 'Z' | ||
score += 10 | ||
end | ||
end | ||
|
||
|
||
if word.length > 6 && word.length < 11 | ||
score += 8 | ||
end | ||
|
||
return score | ||
end | ||
|
||
# WAVE 4 SYNTAX | ||
|
||
def highest_score_from(words) | ||
|
||
# creating a hash to store highest scoring word with its score value | ||
highest_scoring_hash = { | ||
:score => 0, | ||
:word => words.first | ||
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 declare that the initial value of |
||
} | ||
|
||
# loop thur the array and test for score and word length to identify highest scoring word | ||
words.each do |word| | ||
current_score = score_word(word) | ||
current_word = word | ||
|
||
# word that has the highest score wins | ||
if current_score > highest_scoring_hash[:score] | ||
|
||
highest_scoring_hash[:score] = current_score | ||
highest_scoring_hash[:word] = current_word | ||
|
||
# in case of a score tie | ||
elsif current_score == highest_scoring_hash[:score] | ||
|
||
#f ewer letter wins | ||
if highest_scoring_hash[:word].length > current_word.length && | ||
(highest_scoring_hash[:word].length != 10 && current_word.length !=10) | ||
|
||
highest_scoring_hash[:score] = current_score | ||
highest_scoring_hash[:word] = current_word | ||
|
||
# word length of 10 wins | ||
elsif current_word.length == 10 && highest_scoring_hash[:word].length < 10 | ||
highest_scoring_hash[:score] = current_score | ||
highest_scoring_hash[:word] = current_word | ||
# when lengths are equal picking first (the one already stored in hash) | ||
elsif current_word.length == highest_scoring_hash[:word].length || | ||
highest_scoring_hash[:word].length == 10 | ||
# do nothing | ||
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. If you need to do nothing, then you probably don't need to have this |
||
end | ||
end | ||
end | ||
return highest_scoring_hash | ||
end | ||
|
||
# WAVE 5 SYNTAX | ||
# is it a valid dictionary word? | ||
def is_in_english_dict?(input) | ||
|
||
|
||
results = false | ||
dictionary = CSV.read("assets/dictionary-english.csv",headers: true, header_converters: :symbol) | ||
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 job including headers on this! |
||
dictionary.each do |word| | ||
word.each do |k, v| | ||
if v.downcase == input.downcase | ||
results = true | ||
end | ||
end | ||
end | ||
return results | ||
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.
I think overall, your solution to this method is good-- it shows that you all know how to use iteration and specifically
map
to create an interesting array. My only concern is that I feel like maybemap
forced you all to need to make a lot of arrays and a lot of loops-- I don't recommend any changes at this moment, but if you all ever take a minute to look at this problem with fresh eyes, there may be other approaches where it doesn't feel like "fighting" withmap