From 2585f7b49bae9419b943163442699b6dae95a482 Mon Sep 17 00:00:00 2001 From: Chantal Demissie Date: Tue, 19 Feb 2019 16:42:40 -0800 Subject: [PATCH 1/6] "Added array of letters to adagrams" --- lib/adagrams.rb | 39 +++++++++++++++++++++++++++++++++++++++ specs/adagrams_spec.rb | 3 ++- wave-1-game.rb | 5 +++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..c8196df 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,39 @@ +require 'awesome_print' +require 'pry' + +def draw_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" +] + + return letters.sample(10) + +end + + +ap draw_letters diff --git a/specs/adagrams_spec.rb b/specs/adagrams_spec.rb index ae2ccd0..f171a0c 100644 --- a/specs/adagrams_spec.rb +++ b/specs/adagrams_spec.rb @@ -7,7 +7,7 @@ # Get that nice colorized output Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new -describe 'Adagrams' do +describe 'Adagrams' do |draw_letters| describe 'draw_letters method' do it 'draws ten letters from the letter pool' do drawn_letters = draw_letters @@ -56,6 +56,7 @@ end end + binding.pry describe 'score_word method' do it 'returns an accurate numerical score according to the score chart' do diff --git a/wave-1-game.rb b/wave-1-game.rb index 159f620..52b4620 100644 --- a/wave-1-game.rb +++ b/wave-1-game.rb @@ -9,10 +9,11 @@ def display_drawn_letters(letters) puts "You have drawn the letters:" puts letters.join(', ') end - +binding.pry def run_game display_welcome_message - display_drawn_letters(draw_letters) + display_drawn_letters end run_game + \ No newline at end of file From f54d378141a5a2b3d449da04120537d805efde94 Mon Sep 17 00:00:00 2001 From: Chantal Demissie Date: Wed, 20 Feb 2019 14:52:11 -0800 Subject: [PATCH 2/6] added array of letters --- specs/adagrams_spec.rb | 2 +- wave-1-game.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/adagrams_spec.rb b/specs/adagrams_spec.rb index f171a0c..6f14f9f 100644 --- a/specs/adagrams_spec.rb +++ b/specs/adagrams_spec.rb @@ -56,7 +56,7 @@ end end - binding.pry + describe 'score_word method' do it 'returns an accurate numerical score according to the score chart' do diff --git a/wave-1-game.rb b/wave-1-game.rb index 52b4620..1cf690f 100644 --- a/wave-1-game.rb +++ b/wave-1-game.rb @@ -9,7 +9,7 @@ def display_drawn_letters(letters) puts "You have drawn the letters:" puts letters.join(', ') end -binding.pry + def run_game display_welcome_message display_drawn_letters From 789a06d7746e8fa674a0b0d8237af4a2eed57ff6 Mon Sep 17 00:00:00 2001 From: Chantal Demissie Date: Fri, 22 Feb 2019 15:43:06 -0800 Subject: [PATCH 3/6] "last wave, last conditional statement needs update" --- lib/adagrams.rb | 83 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index c8196df..d7e3b6c 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -29,11 +29,88 @@ def draw_letters "X", "Y", "Y", "Z" -] + ] - return letters.sample(10) + return letters.sample(10) end -ap draw_letters +def uses_available_letters?(input, letters_in_hand) + input.each_char do |letter| + index = letters_in_hand.index(letter) + if index.nil? + return false + else + letters_in_hand.delete_at(index) + end + end + return true +end + +def score_word (word) + score = 0 + word.upcase.each_char do |letter| + + case letter + when "A", 'E', 'I', 'O', 'U', 'L', 'R', 'N', '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 + + +def highest_score_from (words) + + score_list = words.map do |element| + { word: element, score: score_word(element) } + end + +find_best_word = [] +max = 0 + +score_list.each do |element| + if element[:score] > max + find_best_word = [element] + max = element[:score] + elsif element[:score] == max + find_best_word << element + end +end + +winner = [] +longest = find_best_word[0][:word].length + +find_best_word.each do |entry| + if entry[:word].length < longest + winner = [entry] + longest = entry[:word].length + elsif entry[:word].length == longest + winner << entry + end +end +p winner +return winner.first +end + +result = ["cang", "birrr"] +highest_score_from(result) From a9e4e6b9deb4af0d0ec7a04b7c0a9967af885a3e Mon Sep 17 00:00:00 2001 From: Chantal Demissie Date: Fri, 22 Feb 2019 15:43:19 -0800 Subject: [PATCH 4/6] "json config file added" --- .vscode/launch.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..10f2f39 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Local File", + "type": "Ruby", + "request": "launch", + "cwd": "${workspaceRoot}", + "program": "${file}" + } + ] +} \ No newline at end of file From 12313a897cb8a9c081a500848bb0da47267f9b55 Mon Sep 17 00:00:00 2001 From: Chantal Demissie Date: Fri, 22 Feb 2019 18:06:37 -0800 Subject: [PATCH 5/6] last method, add check for length of 10 --- lib/adagrams.rb | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index d7e3b6c..3d015a4 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -30,12 +30,13 @@ def draw_letters "Y", "Y", "Z" ] - - return letters.sample(10) - + drawn_letters = letters.sample(10) + return drawn_letters end +draw_letters + def uses_available_letters?(input, letters_in_hand) input.each_char do |letter| index = letters_in_hand.index(letter) @@ -96,21 +97,21 @@ def highest_score_from (words) find_best_word << element end end - +p find_best_word winner = [] -longest = find_best_word[0][:word].length +shortest = find_best_word[0][:word].length find_best_word.each do |entry| - if entry[:word].length < longest - winner = [entry] - longest = entry[:word].length - elsif entry[:word].length == longest + if entry[:word].length == 10 winner << entry + break + elsif entry[:word].length < shortest + puts ">>>>>>>>>>>> #{entry}" + winner << [entry] + shortest = entry[:word].length end end -p winner -return winner.first + +return winner end -result = ["cang", "birrr"] -highest_score_from(result) From ee055d752e8c13d294046b30a05106e8741eaff6 Mon Sep 17 00:00:00 2001 From: Chantal Demissie Date: Fri, 22 Feb 2019 18:16:32 -0800 Subject: [PATCH 6/6] removed |draw_letters| from spec --- specs/adagrams_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/adagrams_spec.rb b/specs/adagrams_spec.rb index 6f14f9f..653a333 100644 --- a/specs/adagrams_spec.rb +++ b/specs/adagrams_spec.rb @@ -7,7 +7,7 @@ # Get that nice colorized output Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new -describe 'Adagrams' do |draw_letters| +describe 'Adagrams' do describe 'draw_letters method' do it 'draws ten letters from the letter pool' do drawn_letters = draw_letters