- 
                Notifications
    
You must be signed in to change notification settings  - Fork 29
 
Ports - Jillianne & Margaret #10
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
base: master
Are you sure you want to change the base?
Changes from all commits
f7735e1
              53efa1e
              2052eca
              a3a1ae6
              32daebe
              003b62a
              a7d1885
              e5f7059
              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,99 @@ | ||
| require "csv" | ||
| 
     | 
||
| def draw_letters | ||
| alphabet = ["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"] | ||
| letters = [] | ||
| letters = alphabet.sample(10) | ||
| 
     | 
||
| return letters | ||
| end | ||
| 
     | 
||
| def uses_available_letters?(input, letters_in_hand) | ||
| split_word = input.split(//) | ||
| 
     | 
||
| split_word.each do |l| | ||
| index = letters_in_hand.index(l) | ||
| if letters_in_hand.index(l) != nil | ||
| letters_in_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. Just a note, that this method is destructive to the   | 
||
| else | ||
| return false | ||
| end | ||
| end | ||
| return true | ||
| end | ||
| 
     | 
||
| def score_word(word) | ||
| letters_values = { | ||
| 
         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. Nice data structure.  | 
||
| "a" => 1, | ||
| "b" => 3, | ||
| "c" => 3, | ||
| "d" => 2, | ||
| "e" => 1, | ||
| "f" => 4, | ||
| "g" => 2, | ||
| "h" => 4, | ||
| "i" => 1, | ||
| "j" => 8, | ||
| "k" => 5, | ||
| "l" => 1, | ||
| "m" => 3, | ||
| "n" => 1, | ||
| "o" => 1, | ||
| "p" => 3, | ||
| "q" => 10, | ||
| "r" => 1, | ||
| "s" => 1, | ||
| "t" => 1, | ||
| "u" => 1, | ||
| "v" => 4, | ||
| "w" => 4, | ||
| "x" => 8, | ||
| "y" => 4, | ||
| "z" => 10, | ||
| } | ||
| 
     | 
||
| split_word = word.downcase.split(//) | ||
| 
     | 
||
| word_value = split_word.map do |letter| | ||
| letters_values[letter] | ||
| end | ||
| 
     | 
||
| if word.length < 7 | ||
| score = word_value.reduce(:+) | ||
| elsif word.length == 0 | ||
| score = 0 | ||
| else | ||
| score = word_value.reduce(:+) + 8 | ||
| end | ||
| 
     | 
||
| return score.to_i | ||
| end | ||
| 
     | 
||
| def highest_score_from(words) | ||
| best_word = { | ||
| word: "", | ||
| score: 0, | ||
| } | ||
| words.each do |word| | ||
| score = score_word(word) | ||
| if score > best_word[:score] | ||
| best_word[:score] = score | ||
| best_word[:word] = word | ||
| elsif score == best_word[:score] | ||
| if word.length == 10 && best_word[:word].length != 10 | ||
| best_word[:word] = word | ||
| elsif (word.length < best_word[:word].length) && (best_word[:word].length != 10) | ||
| best_word[:word] = word | ||
| end | ||
| end | ||
| end | ||
| 
     | 
||
| return best_word | ||
| end | ||
| 
     | 
||
| def is_in_english_dict?(input) | ||
| 
         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. Nice work getting started with this.  | 
||
| CSV.open("assets/dictionary-english.csv", "r").each do |word| | ||
| return true if word.include?(input) | ||
| 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.
Interesting choice in data structure for the available letters. It definitely works. Can you think of a concise way to do it?