From 30290f320ee2d4212ae9a4aeca5cfad9cd769f6e Mon Sep 17 00:00:00 2001 From: Sigrid Benezra Date: Mon, 13 Aug 2018 16:35:25 -0700 Subject: [PATCH 01/15] Initial commit, list initial pool of letters. --- adagrams.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 adagrams.rb diff --git a/adagrams.rb b/adagrams.rb new file mode 100644 index 0000000..07c733b --- /dev/null +++ b/adagrams.rb @@ -0,0 +1,20 @@ + +def draw_letters + letter_pool = [] + letters_concatenated = [] + + initial_array = [["A", 9], ["B", 2], ["C", 2], ["D", 4], ["E", 12], ["F", 2], ["G", 3], ["H", 2], ["I", 9], ["J", 1], ["K", 1], ["L", 4], ["M", 2], ["N", 6], ["O", 8], ["P", 2], ["Q", 1], ["R", 6], ["S", 4], ["T", 6], ["U", 4], ["V", 2], ["W", 2], ["X", 1], ["Y", 2], ["Z", 1]] + + letter_pool = initial_array.map do |x| + [x[0]] * x[1] + end + + letter_pool.each do |x| + letters_concatenated.concat(x) + end + + return letters_concatenated + +end + +print draw_letters From d54393350290faecbac33a74e86f934d0053f29e Mon Sep 17 00:00:00 2001 From: Sigrid Benezra Date: Mon, 13 Aug 2018 16:43:12 -0700 Subject: [PATCH 02/15] Add drawing letters for hand. --- adagrams.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/adagrams.rb b/adagrams.rb index 07c733b..118db2d 100644 --- a/adagrams.rb +++ b/adagrams.rb @@ -2,6 +2,7 @@ def draw_letters letter_pool = [] letters_concatenated = [] + hand = [] initial_array = [["A", 9], ["B", 2], ["C", 2], ["D", 4], ["E", 12], ["F", 2], ["G", 3], ["H", 2], ["I", 9], ["J", 1], ["K", 1], ["L", 4], ["M", 2], ["N", 6], ["O", 8], ["P", 2], ["Q", 1], ["R", 6], ["S", 4], ["T", 6], ["U", 4], ["V", 2], ["W", 2], ["X", 1], ["Y", 2], ["Z", 1]] @@ -13,8 +14,12 @@ def draw_letters letters_concatenated.concat(x) end - return letters_concatenated - + 10.times do |x| + hand << letters_concatenated.sample + end + + return hand + end -print draw_letters +# print draw_letters From 4104ee1e5bf9034a5bc56f033f358972f09aa610 Mon Sep 17 00:00:00 2001 From: Sigrid Benezra Date: Tue, 14 Aug 2018 14:55:34 -0700 Subject: [PATCH 03/15] Refactor draw_letters and uses_available_letters --- .DS_Store | Bin 0 -> 6148 bytes adagrams.rb | 25 ------------------------- lib/adagrams.rb | 29 +++++++++++++++++++++++++++++ wave-1-game.rb | 23 +++++++++++++++++++++++ 4 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 .DS_Store delete mode 100644 adagrams.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0ca8e00053c290c594389dd67535608fb7acd0c7 GIT binary patch literal 6148 zcmeHK%Wl&^6ur}=Ws-`L1yZ~828l(e5|XwHgcL%$=mH551Pef|9lMQH$BtsB5rm*@ z_y^z*_!Pc?58(sg%%jN8gX|zebEBCvk9)@Bb3HQ|B4W*hH(Wsr+$uMr(gIA*V)K0pNEG%6ehMG zdIL%JT@Nm=U;3dNjhfLgbYnSATXk?=;DyuD-gsQA9h9wF{a{kI#z#k$vQ@7gP9_Du zd#C#Fh&K_WKF054HuLMSragCPgt=V7_a0S|E>P>Cwoik( z;E50~GwTY!Nn5Da50T_GyU=L?RA@&nU7Jx zDDck}5c`9LB(R}zs!(nn$mA6Om`AfTl*LIQIF`nS#;HQ|z?h-}6_x2L22*sjTiUOo zajHkC)&7vm{e93K#|cD+O4- z)owNMO8RV_dpU8|T1aO|!i3*cp`;+w$FVGkqj(QV8u~0z05&vE6`}=Z{s>4JOlB1L Hs|x%AkazQL literal 0 HcmV?d00001 diff --git a/adagrams.rb b/adagrams.rb deleted file mode 100644 index 118db2d..0000000 --- a/adagrams.rb +++ /dev/null @@ -1,25 +0,0 @@ - -def draw_letters - letter_pool = [] - letters_concatenated = [] - hand = [] - - initial_array = [["A", 9], ["B", 2], ["C", 2], ["D", 4], ["E", 12], ["F", 2], ["G", 3], ["H", 2], ["I", 9], ["J", 1], ["K", 1], ["L", 4], ["M", 2], ["N", 6], ["O", 8], ["P", 2], ["Q", 1], ["R", 6], ["S", 4], ["T", 6], ["U", 4], ["V", 2], ["W", 2], ["X", 1], ["Y", 2], ["Z", 1]] - - letter_pool = initial_array.map do |x| - [x[0]] * x[1] - end - - letter_pool.each do |x| - letters_concatenated.concat(x) - end - - 10.times do |x| - hand << letters_concatenated.sample - end - - return hand - -end - -# print draw_letters diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..1b9bfc1 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,29 @@ + +def draw_letters + letters_concatenated = [] + hand = [] + + initial_array = [["A", 9], ["B", 2], ["C", 2], ["D", 4], ["E", 12], ["F", 2], ["G", 3], ["H", 2], ["I", 9], ["J", 1], ["K", 1], ["L", 4], ["M", 2], ["N", 6], ["O", 8], ["P", 2], ["Q", 1], ["R", 6], ["S", 4], ["T", 6], ["U", 4], ["V", 2], ["W", 2], ["X", 1], ["Y", 2], ["Z", 1]] + + letter_pool = initial_array.map do |x| + letters_concatenated.concat([x[0]] * x[1]) + end + + hand = letters_concatenated.sample(10) + + return hand + +end + + +def uses_available_letters?(input, letters_in_hand) + word = input.chars + word.each do |letter| + if letters_in_hand.include?(letter) + letters_in_hand.delete_at(letters_in_hand.index(letter)) + else + return false + end + end + return true +end diff --git a/wave-1-game.rb b/wave-1-game.rb index 159f620..be8d1a2 100644 --- a/wave-1-game.rb +++ b/wave-1-game.rb @@ -15,4 +15,27 @@ def run_game display_drawn_letters(draw_letters) end +def draw_letters + letter_pool = [] + letters_concatenated = [] + hand = [] + + initial_array = [["A", 9], ["B", 2], ["C", 2], ["D", 4], ["E", 12], ["F", 2], ["G", 3], ["H", 2], ["I", 9], ["J", 1], ["K", 1], ["L", 4], ["M", 2], ["N", 6], ["O", 8], ["P", 2], ["Q", 1], ["R", 6], ["S", 4], ["T", 6], ["U", 4], ["V", 2], ["W", 2], ["X", 1], ["Y", 2], ["Z", 1]] + + letter_pool = initial_array.map do |x| + [x[0]] * x[1] + end + + letter_pool.each do |x| + letters_concatenated.concat(x) + end + + 10.times do |x| + hand << letters_concatenated.sample + end + + return hand + +end + run_game From 28d6e5de7b4ffa1da13d6f74cde1d62dbe53786b Mon Sep 17 00:00:00 2001 From: Sigrid Benezra Date: Tue, 14 Aug 2018 15:26:32 -0700 Subject: [PATCH 04/15] Complete score_word method --- lib/adagrams.rb | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 1b9bfc1..1d569b8 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -15,7 +15,6 @@ def draw_letters end - def uses_available_letters?(input, letters_in_hand) word = input.chars word.each do |letter| @@ -27,3 +26,31 @@ def uses_available_letters?(input, letters_in_hand) end return true end + +def score_word(word) + score = 0 + score_word = word.upcase.chars + score_word.each do |letter| + if %w[A E I O U L N R S T].include?(letter) + score += 1 + elsif %w[D G].include?(letter) + score += 2 + elsif %w[B C M P].include?(letter) + score += 3 + elsif %w[F H V W Y].include?(letter) + score += 4 + elsif %w[K].include?(letter) + score += 5 + elsif %w[J X].include?(letter) + score += 8 + elsif %w[Q Z].include?(letter) + score += 10 + end + end + + if score_word.length >= 7 && score_word.length <= 10 + score += 8 + end + + return score +end From e8585428d9fc6c70f907e123e0a8ce5e5132b1d5 Mon Sep 17 00:00:00 2001 From: Sigrid Benezra Date: Wed, 15 Aug 2018 14:29:52 -0700 Subject: [PATCH 05/15] changes to score_word method --- lib/adagrams.rb | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 1d569b8..237a991 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -51,6 +51,42 @@ def score_word(word) if score_word.length >= 7 && score_word.length <= 10 score += 8 end - return score end + +def highest_score_from(words) + array = [] + max_score = 0 + winning_word = "" + max_values = [] + min_length = 10 + + words.each do |word| + score = score_word(word) + array << {word: word, score: score} + end + + array.each do |hash| + if hash[:score] > max_score + max_values = [] + max_score = hash[:score] + winning_word = hash[:word] + max_values << {word: winning_word, score: max_score} + elsif hash[:score] = max_score + max_values << {word: winning_word, score: max_score} + end + end + + max_values.each do |array| + # if array[:word].length == 10 + # hash = {word: array[:word], score: array[:score].to_i} + # return hash + + if array[:word].length < min_length + min_length = array[:word].length + hash = {word: winning_word, score: max_score} + end + end + hash = {word: winning_word, score: max_score} + return hash +end From afa218f4478a5fc42bf7084f66e8b9ab551af06e Mon Sep 17 00:00:00 2001 From: Naheed Arang Date: Wed, 15 Aug 2018 14:36:15 -0700 Subject: [PATCH 06/15] random change test --- lib/adagrams.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 237a991..029cd7e 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,4 +1,4 @@ - +# random change def draw_letters letters_concatenated = [] hand = [] From d5d4fb95a1570ed1d1cb435e18c006553a731614 Mon Sep 17 00:00:00 2001 From: Sigrid Benezra Date: Wed, 15 Aug 2018 14:57:45 -0700 Subject: [PATCH 07/15] test changes to highest_score_from method --- lib/adagrams.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 029cd7e..e23a107 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,4 +1,5 @@ # random change +require 'pry' def draw_letters letters_concatenated = [] hand = [] @@ -67,13 +68,14 @@ def highest_score_from(words) end array.each do |hash| - if hash[:score] > max_score + if hash[:score] == max_score + winning_word = hash[:word] + max_values << {word: winning_word, score: max_score} + elsif hash[:score] > max_score max_values = [] max_score = hash[:score] winning_word = hash[:word] max_values << {word: winning_word, score: max_score} - elsif hash[:score] = max_score - max_values << {word: winning_word, score: max_score} end end @@ -81,12 +83,15 @@ def highest_score_from(words) # if array[:word].length == 10 # hash = {word: array[:word], score: array[:score].to_i} # return hash - + hash = {} if array[:word].length < min_length min_length = array[:word].length + winning_word = array[:word] + max_score = array[:score] hash = {word: winning_word, score: max_score} + binding.pry end end - hash = {word: winning_word, score: max_score} + #hash = {word: winning_word, score: max_score} return hash end From 45b4db3707b96cfd7cf73aaac3942a67a9fb8b70 Mon Sep 17 00:00:00 2001 From: Naheed Arang Date: Wed, 15 Aug 2018 14:59:46 -0700 Subject: [PATCH 08/15] changes??? --- lib/adagrams.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 029cd7e..bd6b9ae 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,4 +1,3 @@ -# random change def draw_letters letters_concatenated = [] hand = [] From d8cd51b472d08074d3f57b75c2af1cea8cfa777f Mon Sep 17 00:00:00 2001 From: Naheed Arang Date: Wed, 15 Aug 2018 15:16:45 -0700 Subject: [PATCH 09/15] correct highest_score_word method --- lib/adagrams.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e23a107..db47a61 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,12 +1,11 @@ -# random change -require 'pry' +# require 'pry' def draw_letters letters_concatenated = [] hand = [] initial_array = [["A", 9], ["B", 2], ["C", 2], ["D", 4], ["E", 12], ["F", 2], ["G", 3], ["H", 2], ["I", 9], ["J", 1], ["K", 1], ["L", 4], ["M", 2], ["N", 6], ["O", 8], ["P", 2], ["Q", 1], ["R", 6], ["S", 4], ["T", 6], ["U", 4], ["V", 2], ["W", 2], ["X", 1], ["Y", 2], ["Z", 1]] - letter_pool = initial_array.map do |x| + initial_array.each do |x| letters_concatenated.concat([x[0]] * x[1]) end @@ -61,6 +60,7 @@ def highest_score_from(words) winning_word = "" max_values = [] min_length = 10 + hash = {} words.each do |word| score = score_word(word) @@ -80,18 +80,16 @@ def highest_score_from(words) end max_values.each do |array| - # if array[:word].length == 10 - # hash = {word: array[:word], score: array[:score].to_i} - # return hash - hash = {} + if array[:word].length == 10 + hash = {word: array[:word], score: array[:score].to_i} + return hash + end if array[:word].length < min_length min_length = array[:word].length winning_word = array[:word] max_score = array[:score] hash = {word: winning_word, score: max_score} - binding.pry end end - #hash = {word: winning_word, score: max_score} return hash end From e252fdc734cf155c32c9d2f3589b7c58050cd657 Mon Sep 17 00:00:00 2001 From: Sigrid Benezra Date: Wed, 15 Aug 2018 15:17:58 -0700 Subject: [PATCH 10/15] fixed highest_score_from method --- lib/adagrams.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e23a107..ae2cf69 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -6,7 +6,7 @@ def draw_letters initial_array = [["A", 9], ["B", 2], ["C", 2], ["D", 4], ["E", 12], ["F", 2], ["G", 3], ["H", 2], ["I", 9], ["J", 1], ["K", 1], ["L", 4], ["M", 2], ["N", 6], ["O", 8], ["P", 2], ["Q", 1], ["R", 6], ["S", 4], ["T", 6], ["U", 4], ["V", 2], ["W", 2], ["X", 1], ["Y", 2], ["Z", 1]] - letter_pool = initial_array.map do |x| + initial_array.each do |x| letters_concatenated.concat([x[0]] * x[1]) end @@ -61,6 +61,7 @@ def highest_score_from(words) winning_word = "" max_values = [] min_length = 10 + hash = {} words.each do |word| score = score_word(word) @@ -80,18 +81,16 @@ def highest_score_from(words) end max_values.each do |array| - # if array[:word].length == 10 - # hash = {word: array[:word], score: array[:score].to_i} - # return hash - hash = {} + if array[:word].length == 10 + hash = {word: array[:word], score: array[:score].to_i} + return hash + end if array[:word].length < min_length min_length = array[:word].length winning_word = array[:word] max_score = array[:score] hash = {word: winning_word, score: max_score} - binding.pry end end - #hash = {word: winning_word, score: max_score} return hash end From 06af639f594f89a8ef499ddeb78926dc31498fc6 Mon Sep 17 00:00:00 2001 From: Naheed Arang Date: Wed, 15 Aug 2018 15:45:18 -0700 Subject: [PATCH 11/15] add method for checking against dictionary --- lib/adagrams.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index db47a61..3d89d58 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,4 +1,5 @@ # require 'pry' +require_relative '../assets/dictionary-english.csv' def draw_letters letters_concatenated = [] hand = [] @@ -93,3 +94,12 @@ def highest_score_from(words) end return hash end + + +def is_in_english_dict?(input) + if dictionary-english.include?(input) + return true + else + return false + end +end From 3ce6166fb8b71269be7800d4488e6648391b5c76 Mon Sep 17 00:00:00 2001 From: Naheed Arang Date: Wed, 15 Aug 2018 15:45:59 -0700 Subject: [PATCH 12/15] added test for wave 5 --- specs/adagrams_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/specs/adagrams_spec.rb b/specs/adagrams_spec.rb index ae2ccd0..6ba518d 100644 --- a/specs/adagrams_spec.rb +++ b/specs/adagrams_spec.rb @@ -168,4 +168,19 @@ expect(best_word[:score]).must_equal 18 end end + + describe 'in English dictionary' do + + it 'returns true if user input is in English dictionary' do + input = ['DOG'] + + expect(is_in_english_dict?(input)).must_equal true + end + + it 'returns false if user input is not in Enlish dictionary' do + + input = ['RRRRR'] + expect(is_in_english_dict?(input)).must_equal false + end + end end From 261fb50589ba2ad8fa89955b6e834441a9b79ea6 Mon Sep 17 00:00:00 2001 From: Naheed Arang Date: Thu, 16 Aug 2018 13:51:35 -0700 Subject: [PATCH 13/15] add dictionary method and updated spec --- lib/adagrams.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 3d89d58..c5add38 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,5 +1,6 @@ # require 'pry' -require_relative '../assets/dictionary-english.csv' +require 'csv' + def draw_letters letters_concatenated = [] hand = [] @@ -95,11 +96,14 @@ def highest_score_from(words) return hash end - def is_in_english_dict?(input) - if dictionary-english.include?(input) - return true - else - return false + verify = false + dictionary = CSV.open('assets/dictionary-english.csv') + word = input.downcase + dictionary.each do |row| + if row.include?(word) + verify = true end + end + return verify end From e81cef4a1ff192fa9197ed0585b28e58144d8861 Mon Sep 17 00:00:00 2001 From: Sigrid Benezra Date: Thu, 16 Aug 2018 13:53:32 -0700 Subject: [PATCH 14/15] dictionary method changes --- lib/adagrams.rb | 10 +++++++--- specs/adagrams_spec.rb | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 3d89d58..66dffb7 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,5 +1,6 @@ -# require 'pry' -require_relative '../assets/dictionary-english.csv' +require 'csv' +require 'pry' + def draw_letters letters_concatenated = [] hand = [] @@ -97,7 +98,10 @@ def highest_score_from(words) def is_in_english_dict?(input) - if dictionary-english.include?(input) + verify = false + dictionary = CSV.read('assets/dictionary-english.csv') + word = input.downcase + if dictionary.include?(word) return true else return false diff --git a/specs/adagrams_spec.rb b/specs/adagrams_spec.rb index 6ba518d..b8d3d1b 100644 --- a/specs/adagrams_spec.rb +++ b/specs/adagrams_spec.rb @@ -172,14 +172,14 @@ describe 'in English dictionary' do it 'returns true if user input is in English dictionary' do - input = ['DOG'] + input = 'DOG' expect(is_in_english_dict?(input)).must_equal true end it 'returns false if user input is not in Enlish dictionary' do - input = ['RRRRR'] + input = 'RRRRR' expect(is_in_english_dict?(input)).must_equal false end end From a29c25803daf16a0e43378f9f43b59771039e844 Mon Sep 17 00:00:00 2001 From: Sigrid Benezra Date: Thu, 16 Aug 2018 14:09:07 -0700 Subject: [PATCH 15/15] Add comments to file for each method --- lib/adagrams.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index ee1962d..7bbad4d 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,7 +1,7 @@ # require 'pry' require 'csv' - +# Draws 10 random letters from alphabetic array def draw_letters letters_concatenated = [] hand = [] @@ -18,6 +18,7 @@ def draw_letters end +# Determines if user word uses letters in hand def uses_available_letters?(input, letters_in_hand) word = input.chars word.each do |letter| @@ -30,6 +31,7 @@ def uses_available_letters?(input, letters_in_hand) return true end +# Calculates score for user word def score_word(word) score = 0 score_word = word.upcase.chars @@ -57,6 +59,7 @@ def score_word(word) return score end +# Determines highest scoring word and returns both word and score def highest_score_from(words) array = [] max_score = 0 @@ -97,6 +100,7 @@ def highest_score_from(words) return hash end +# Determines whether users word is a valid English word def is_in_english_dict?(input) check = false dictionary = CSV.open('assets/dictionary-english.csv')