From bbe00d6b5fb2efec0fbfd41fe19f60e1361736f6 Mon Sep 17 00:00:00 2001 From: dnguye2 Date: Mon, 10 Feb 2020 20:09:22 -0800 Subject: [PATCH 01/11] initial commit --- lib/adagrams.rb | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..ab1050b 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,67 @@ +# (1) +# Draw 10 random letters + +# Base - draw_letters method +# need to have a letter pool +# generate the whole alphabet +('a'..'z').to_a + +# letter_pool = [] +# 9.times do +# letter_pool << 'a' +# end + +# 2.times do +# letter_pool << 'b' +# end + + + +# letter.with_index do |letter, i| +# quantity = [9, 2] +# i.times do +# letter_pool << letter +# end +# end + + +# print letter_pool +letter = [] +letter = ('a'..'z').to_a +###### !!!! edit the quantity array +quantity = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 1, 2, 1, 1 ] +quantity = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1] +puts letter +puts quantity.length + +# letter_pool = [] +# letter_pool.fill(letter[0], letter_pool.size, quantity[0]) +# puts letter_pool + +# letter.each_with_index do |letter, i| +# quantity = [9, 2] +# letter_pool.fill(letter[i], letter_pool.size, quantity[0]) +# end +# print letter_pool + +# def create_specialties_hash(array_1, array_2) +# i = 1 +# result = [] +# while i <= array_1.size && array_2.size +# result << {name: array_1[i -1], specialty: array_2[i-1], id: i} +# i += 1 +# end +# end + +# create_specialties_hash(NAMES, SPECIALTIES) + +def create_letter_pool(letter, quantity) + index = 0 + letter_pool = [] + letter.each_with_index do |letter, index| + letter_pool.fill(letter, letter_pool.size, quantity[index]) + end + return letter_pool +end + +print create_letter_pool(letter, quantity) \ No newline at end of file From 0cbe47a00df583fc85c55cc290b8791c6c3a2e3b Mon Sep 17 00:00:00 2001 From: dnguye2 Date: Mon, 10 Feb 2020 20:21:42 -0800 Subject: [PATCH 02/11] cleaned code, fixed quantity numbers --- lib/adagrams.rb | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index ab1050b..6e73f7b 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -4,56 +4,14 @@ # Base - draw_letters method # need to have a letter pool # generate the whole alphabet -('a'..'z').to_a - -# letter_pool = [] -# 9.times do -# letter_pool << 'a' -# end - -# 2.times do -# letter_pool << 'b' -# end - - - -# letter.with_index do |letter, i| -# quantity = [9, 2] -# i.times do -# letter_pool << letter -# end -# end - # print letter_pool letter = [] letter = ('a'..'z').to_a -###### !!!! edit the quantity array -quantity = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 1, 2, 1, 1 ] -quantity = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1] +quantity = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1] puts letter puts quantity.length -# letter_pool = [] -# letter_pool.fill(letter[0], letter_pool.size, quantity[0]) -# puts letter_pool - -# letter.each_with_index do |letter, i| -# quantity = [9, 2] -# letter_pool.fill(letter[i], letter_pool.size, quantity[0]) -# end -# print letter_pool - -# def create_specialties_hash(array_1, array_2) -# i = 1 -# result = [] -# while i <= array_1.size && array_2.size -# result << {name: array_1[i -1], specialty: array_2[i-1], id: i} -# i += 1 -# end -# end - -# create_specialties_hash(NAMES, SPECIALTIES) def create_letter_pool(letter, quantity) index = 0 From f859c5c8f828887d3735675059a641316dbb47b8 Mon Sep 17 00:00:00 2001 From: dnguye2 Date: Tue, 11 Feb 2020 15:17:13 -0800 Subject: [PATCH 03/11] wave 1 code completed --- lib/adagrams.rb | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 6e73f7b..8dd0a68 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,17 +1,6 @@ -# (1) -# Draw 10 random letters - -# Base - draw_letters method -# need to have a letter pool -# generate the whole alphabet - -# print letter_pool -letter = [] -letter = ('a'..'z').to_a -quantity = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1] -puts letter -puts quantity.length - +# Creating letter pool +letter = ('A'..'Z').to_a +quantity = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1 ] def create_letter_pool(letter, quantity) index = 0 @@ -21,5 +10,28 @@ def create_letter_pool(letter, quantity) end return letter_pool end +letter_pool_array = create_letter_pool(letter, quantity) -print create_letter_pool(letter, quantity) \ No newline at end of file +# Wave (1) +# Method to draw 10 random letters +def draw_letters + # Welcome message + puts "Welcome to Adagrams!" + puts "Let's draw 10 letters from the letter pool..." + puts "You have drawn the letters:" + + letter = ('A'..'Z').to_a + quantity = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1 ] + + # Use the create_letter_pool method + create_letter_pool(letter, quantity) + letter_pool_array = create_letter_pool(letter, quantity) + + # Shuffle the letter pool + letter_pool_array = letter_pool_array.shuffle() + letters = letter_pool_array.sample(10) # Not sure if it will have more than 2 Cs + letter.join(', ') + return drawn_letters = letters +end +draw_letters +print draw_letters.join(', ') \ No newline at end of file From bf8a8c832e73a3416ac68de58bbe8e797dc6213e Mon Sep 17 00:00:00 2001 From: dnguye2 Date: Tue, 11 Feb 2020 16:19:55 -0800 Subject: [PATCH 04/11] wave 2 codes completed --- lib/adagrams.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 8dd0a68..285c17d 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -33,5 +33,22 @@ def draw_letters letter.join(', ') return drawn_letters = letters end -draw_letters -print draw_letters.join(', ') \ No newline at end of file +drawn_letters = draw_letters +puts drawn_letters.join(', ') + + +# Wave (2) +puts "Please provide a word that only uses the letters from the letter bank: " +test_word = gets.chomp + +def uses_available_letters? (input, letters_in_hand) + input = input.upcase.chars + is_valid = + input.all? do |input| + letters_in_hand.include?(input) + end + return is_valid +end + + +puts uses_available_letters?(test_word, drawn_letters) \ No newline at end of file From bde407071c4174bcd7936ea864bb7d7ced74e1e9 Mon Sep 17 00:00:00 2001 From: dnguye2 Date: Wed, 12 Feb 2020 09:15:17 -0800 Subject: [PATCH 05/11] wave 2 with all tests passed --- lib/adagrams.rb | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 285c17d..2404302 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -41,14 +41,35 @@ def draw_letters puts "Please provide a word that only uses the letters from the letter bank: " test_word = gets.chomp +# method to check whether word by user is in drawn letters def uses_available_letters? (input, letters_in_hand) input = input.upcase.chars - is_valid = - input.all? do |input| - letters_in_hand.include?(input) + # make copy of drawn letters + dl_copy = letters_in_hand.dup + + # if letter of input = letter in drawn letters, remove letter in drawn letters + # continue to compare rest of letters to drawn letters + # times_true array used to determine if word is valid + times_true = [] + input.each do |letter| + if dl_copy.include?(letter) == true + dl_copy.delete_at(dl_copy.index(letter)) + times_true << "true" + else + times_true << "false" + end + end + + if times_true.count("true") == input.length + is_valid = true + else + is_valid = false end + return is_valid + end +puts uses_available_letters?(test_word, drawn_letters) -puts uses_available_letters?(test_word, drawn_letters) \ No newline at end of file +# Wave (3) From 748011fc15ac329b636ce983a9615f36972f65b7 Mon Sep 17 00:00:00 2001 From: dnguye2 Date: Wed, 12 Feb 2020 09:59:46 -0800 Subject: [PATCH 06/11] wave 3 completed --- lib/adagrams.rb | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 2404302..53f025d 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -65,11 +65,51 @@ def uses_available_letters? (input, letters_in_hand) else is_valid = false end - return is_valid - end puts uses_available_letters?(test_word, drawn_letters) # Wave (3) +# method to calculate score +def score_word(word) + word = word.upcase.chars + + if word.empty? == true # nil case or empty string + score_word = 0 + else + # scoring + score_word = word.map do |letter| + case letter + when "A", "E", "I", "O", "U", "L", "N", "R", "S", "T" + 1 + when "D", "G" + 2 + when "B", "C", "M", "P" + 3 + when "F", "H", "V", "W", "Y" + 4 + when "K" + 5 + when "J", "X" + 8 + when "Q", "Z" + 10 + else + 0 + end + end + + # calculate total score + score_word = score_word.inject(:+) + + if word.length >= 7 + score_word = score_word + 8 + else + score_word = score_word + end + end + return score_word +end + +puts score_word(test_word) \ No newline at end of file From 02525d84641d695895bdf54f2ff1f810522b67c2 Mon Sep 17 00:00:00 2001 From: dnguye2 Date: Wed, 12 Feb 2020 16:49:40 -0800 Subject: [PATCH 07/11] wave 4 with 3/6 tests passed --- lib/adagrams.rb | 107 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 53f025d..1b7a9c6 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -12,6 +12,9 @@ def create_letter_pool(letter, quantity) end letter_pool_array = create_letter_pool(letter, quantity) + + + # Wave (1) # Method to draw 10 random letters def draw_letters @@ -112,4 +115,106 @@ def score_word(word) return score_word end -puts score_word(test_word) \ No newline at end of file +# hash to hold words and scores +# master array for Wave 4 -> words +words = [] +scores = [] + +words << test_word + +score = score_word(test_word) +scores << score + +# Do ya want to play again prompt +# put as method +# repeat through game wave 1 - 3 + +# use until loop/while +# use keyword arguments? example, how many times would you like to play again? +# def play_again (how_many_times: ) +puts "Would you like to play again? Enter y to play again." +answer = gets.chomp + +while answer == "y" + # Wave 1 + drawn_letters = draw_letters + puts drawn_letters.join(', ') + + puts "Please provide a word that only uses the letters from the letter bank: " + test_word = gets.chomp + + # Wave 2 + puts uses_available_letters?(test_word, drawn_letters) + + # Wave 3 + + words << test_word + + score = score_word(test_word) + scores << score + + # Prompt again + puts "Would you like to play again? Enter y to play again." + answer = gets.chomp + +end + +print words +# Wave (4) +# play multiple times +# array of words + +# score_tracker = {game1:{word, score}, game2:{word,score}} + + +def highest_score_from (words) + # hash with all words and scores + all_words_score = words.map do |word| + score = score_word(word) + { + :word => word, + :score => score + } + end + + # highest score calculation + highest_score = 0 + highest_word = "" + best_word = {} + all_words_score.each do |word| + if word[:score] > highest_score + highest_score = word[:score] + highest_word = word[:word] + else word[:score] == highest_score + # tie rules + # `conditionals` galore: + # prefer word with fewest letters + # if word has 10 letters, top word is the one with more tiles wins + # multiple words of same length, pick first one + if (word[:word]).length == 10 + highest_score = word[:score] + highest_word = word[:word] + elsif ((word[:word]).length < (highest_word.length)) && ((word[:word]).length != 10) + highest_score = word[:score] + highest_word = word[:word] + # else (word[:word]).length < highest_word.length + # highest_word = word[:word] + elsif (word[:word]).length == (highest_word.length) + highest_score = highest_score + highest_word = highest_word + else + highest_score = highest_score + highest_word = highest_word + end + end + + end + + best_word[:word] = "#{highest_word}" + best_word[:score] = highest_score + + return best_word + +end + +puts highest_score_from(words) \ No newline at end of file From 41ca17a17ab4dab2fa0166e70a7fb615abd1ca6f Mon Sep 17 00:00:00 2001 From: dnguye2 Date: Thu, 13 Feb 2020 15:22:42 -0800 Subject: [PATCH 08/11] wave 4 completed, 6/6 tests passed --- lib/adagrams.rb | 58 +++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 1b7a9c6..d6330b2 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -160,12 +160,9 @@ def score_word(word) end print words -# Wave (4) -# play multiple times -# array of words - -# score_tracker = {game1:{word, score}, game2:{word,score}} +# Wave (4) +# method to calculate winning word def highest_score_from (words) # hash with all words and scores @@ -182,32 +179,31 @@ def highest_score_from (words) highest_word = "" best_word = {} all_words_score.each do |word| - if word[:score] > highest_score - highest_score = word[:score] - highest_word = word[:word] - else word[:score] == highest_score - # tie rules - # `conditionals` galore: - # prefer word with fewest letters - # if word has 10 letters, top word is the one with more tiles wins - # multiple words of same length, pick first one - if (word[:word]).length == 10 - highest_score = word[:score] - highest_word = word[:word] - elsif ((word[:word]).length < (highest_word.length)) && ((word[:word]).length != 10) - highest_score = word[:score] - highest_word = word[:word] - # else (word[:word]).length < highest_word.length - # highest_word = word[:word] - elsif (word[:word]).length == (highest_word.length) - highest_score = highest_score - highest_word = highest_word - else - highest_score = highest_score - highest_word = highest_word - end - end + #tie rules + case + when word[:score] > highest_score + highest_score = word[:score] + highest_word = word[:word] + # test 7 - tied score and same length words, prefers the first word + when (word[:score] == highest_score) && ((word[:word]).length == highest_word.length) + highest_score = highest_score + highest_word = highest_word + # test 5 & 6 - tied score, prefers most the word with 10 letters regardless of order + when (word[:score] == highest_score) && ((word[:word]).length == 10) + highest_score = word[:score] + highest_word = word[:word] + when (word[:score] == highest_score) && (highest_word.length == 10) + highest_score = highest_score + highest_word = highest_word + # test 3 & 4 - tied score, prefers the word with fewer letters regardless of order + when (word[:score] == highest_score) && ((word[:word]).length < highest_word.length) + highest_score = word[:score] + highest_word = word[:word] + when (word[:score] == highest_score) && ((word[:word]).length > highest_word.length) + highest_score = highest_score + highest_word = highest_word + end end best_word[:word] = "#{highest_word}" @@ -217,4 +213,4 @@ def highest_score_from (words) end -puts highest_score_from(words) \ No newline at end of file +puts highest_score_from(words) From d3bad176c105b6fb4ac1f9123cffafdf14753a4d Mon Sep 17 00:00:00 2001 From: dnguye2 Date: Thu, 13 Feb 2020 16:19:53 -0800 Subject: [PATCH 09/11] cleaned up comments --- lib/adagrams.rb | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index d6330b2..c305e81 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,3 +1,10 @@ +# Adagrams +# Lak & Diana + +# Dependencies +require 'awesome_print' +require 'csv' + # Creating letter pool letter = ('A'..'Z').to_a quantity = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1 ] @@ -44,6 +51,13 @@ def draw_letters puts "Please provide a word that only uses the letters from the letter bank: " test_word = gets.chomp +def is_in_english_dict? (input) + dictionary = CSV.read('../assets/dictionary-english.csv') + dictionary = dictionary.flatten + is_valid_word = dictionary.include?(input) + return is_valid_word +end + # method to check whether word by user is in drawn letters def uses_available_letters? (input, letters_in_hand) input = input.upcase.chars @@ -71,7 +85,11 @@ def uses_available_letters? (input, letters_in_hand) return is_valid end + + puts uses_available_letters?(test_word, drawn_letters) + + # Wave (3) # method to calculate score @@ -125,13 +143,7 @@ def score_word(word) score = score_word(test_word) scores << score -# Do ya want to play again prompt -# put as method -# repeat through game wave 1 - 3 - -# use until loop/while -# use keyword arguments? example, how many times would you like to play again? -# def play_again (how_many_times: ) +# Do you want to play again prompt puts "Would you like to play again? Enter y to play again." answer = gets.chomp @@ -214,3 +226,4 @@ def highest_score_from (words) end puts highest_score_from(words) + From 5ea245baa8a37f96336b74d08396eafe34a80afc Mon Sep 17 00:00:00 2001 From: dnguye2 Date: Thu, 13 Feb 2020 16:43:43 -0800 Subject: [PATCH 10/11] wave 5 code completed --- lib/adagrams.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index c305e81..990ee76 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -19,9 +19,6 @@ def create_letter_pool(letter, quantity) end letter_pool_array = create_letter_pool(letter, quantity) - - - # Wave (1) # Method to draw 10 random letters def draw_letters @@ -51,13 +48,16 @@ def draw_letters puts "Please provide a word that only uses the letters from the letter bank: " test_word = gets.chomp +# Wave (5) Is the word in the English dictionary? def is_in_english_dict? (input) - dictionary = CSV.read('../assets/dictionary-english.csv') + dictionary = CSV.read('assets/dictionary-english.csv') dictionary = dictionary.flatten is_valid_word = dictionary.include?(input) return is_valid_word end +puts is_in_english_dict?(test_word) + # method to check whether word by user is in drawn letters def uses_available_letters? (input, letters_in_hand) input = input.upcase.chars @@ -90,7 +90,6 @@ def uses_available_letters? (input, letters_in_hand) puts uses_available_letters?(test_word, drawn_letters) - # Wave (3) # method to calculate score def score_word(word) @@ -227,3 +226,4 @@ def highest_score_from (words) puts highest_score_from(words) + From 9c77557ddb5fea1d270fe72b533b5fea361bef5d Mon Sep 17 00:00:00 2001 From: dnguye2 Date: Fri, 14 Feb 2020 13:23:45 -0800 Subject: [PATCH 11/11] removed call of methods --- lib/adagrams.rb | 92 +++++++------------------------------------------ 1 file changed, 12 insertions(+), 80 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 990ee76..7a31596 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -5,30 +5,21 @@ require 'awesome_print' require 'csv' -# Creating letter pool -letter = ('A'..'Z').to_a -quantity = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1 ] - +# Method to create letter pool def create_letter_pool(letter, quantity) index = 0 letter_pool = [] + letter.each_with_index do |letter, index| letter_pool.fill(letter, letter_pool.size, quantity[index]) end return letter_pool end -letter_pool_array = create_letter_pool(letter, quantity) -# Wave (1) -# Method to draw 10 random letters +# Wave (1) - method to draw 10 random letters def draw_letters - # Welcome message - puts "Welcome to Adagrams!" - puts "Let's draw 10 letters from the letter pool..." - puts "You have drawn the letters:" - letter = ('A'..'Z').to_a - quantity = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1 ] + quantity = [9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1] # Use the create_letter_pool method create_letter_pool(letter, quantity) @@ -40,15 +31,8 @@ def draw_letters letter.join(', ') return drawn_letters = letters end -drawn_letters = draw_letters -puts drawn_letters.join(', ') - -# Wave (2) -puts "Please provide a word that only uses the letters from the letter bank: " -test_word = gets.chomp - -# Wave (5) Is the word in the English dictionary? +# Wave (5) - method to verify if word is a valid word in the English dictionary def is_in_english_dict? (input) dictionary = CSV.read('assets/dictionary-english.csv') dictionary = dictionary.flatten @@ -56,9 +40,7 @@ def is_in_english_dict? (input) return is_valid_word end -puts is_in_english_dict?(test_word) - -# method to check whether word by user is in drawn letters +# Wave (2)- method to check whether word by user is in drawn letters def uses_available_letters? (input, letters_in_hand) input = input.upcase.chars # make copy of drawn letters @@ -85,20 +67,14 @@ def uses_available_letters? (input, letters_in_hand) return is_valid end - - -puts uses_available_letters?(test_word, drawn_letters) - - -# Wave (3) -# method to calculate score +# Wave (3) - method to calculate score def score_word(word) word = word.upcase.chars + # scoring if word.empty? == true # nil case or empty string score_word = 0 else - # scoring score_word = word.map do |letter| case letter when "A", "E", "I", "O", "U", "L", "N", "R", "S", "T" @@ -123,6 +99,7 @@ def score_word(word) # calculate total score score_word = score_word.inject(:+) + # > 7 letter bonus if word.length >= 7 score_word = score_word + 8 else @@ -132,49 +109,7 @@ def score_word(word) return score_word end -# hash to hold words and scores -# master array for Wave 4 -> words -words = [] -scores = [] - -words << test_word - -score = score_word(test_word) -scores << score - -# Do you want to play again prompt -puts "Would you like to play again? Enter y to play again." -answer = gets.chomp - -while answer == "y" - # Wave 1 - drawn_letters = draw_letters - puts drawn_letters.join(', ') - - puts "Please provide a word that only uses the letters from the letter bank: " - test_word = gets.chomp - - # Wave 2 - puts uses_available_letters?(test_word, drawn_letters) - - # Wave 3 - - words << test_word - - score = score_word(test_word) - scores << score - - # Prompt again - puts "Would you like to play again? Enter y to play again." - answer = gets.chomp - -end - -print words - -# Wave (4) -# method to calculate winning word - +# Wave (4)- method to calculate winning word def highest_score_from (words) # hash with all words and scores all_words_score = words.map do |word| @@ -189,6 +124,7 @@ def highest_score_from (words) highest_score = 0 highest_word = "" best_word = {} + all_words_score.each do |word| #tie rules case @@ -206,14 +142,13 @@ def highest_score_from (words) when (word[:score] == highest_score) && (highest_word.length == 10) highest_score = highest_score highest_word = highest_word - # test 3 & 4 - tied score, prefers the word with fewer letters regardless of order + # test 3 & 4 - tied score, prefers the word with fewer letters regardless of order when (word[:score] == highest_score) && ((word[:word]).length < highest_word.length) highest_score = word[:score] highest_word = word[:word] when (word[:score] == highest_score) && ((word[:word]).length > highest_word.length) highest_score = highest_score highest_word = highest_word - end end @@ -224,6 +159,3 @@ def highest_score_from (words) end -puts highest_score_from(words) - -