From 4514a3b1cd99cad7aa3b263cd3308c27cbb56d8f Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Tue, 30 Aug 2016 10:13:37 -0700 Subject: [PATCH 01/31] set up envirnoment with All The Folders & Stuff --- .gitignore | 18 +++++++++++++++++- Rakefile | 13 +++++++++++++ lib/scrabble_scoring.rb | 1 + scrabble.rb | 3 +++ specs/scrabble_spec.rb | 3 +++ specs/spec_helper.rb | 9 +++++++++ 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Rakefile create mode 100644 lib/scrabble_scoring.rb create mode 100644 scrabble.rb create mode 100644 specs/scrabble_spec.rb create mode 100644 specs/spec_helper.rb diff --git a/.gitignore b/.gitignore index 28f48498..fb7a88e1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,14 +5,29 @@ /InstalledFiles /pkg/ /spec/reports/ +/spec/examples.txt /test/tmp/ /test/version_tmp/ /tmp/ +# Used by dotenv library to load environment variables. +# .env + ## Specific to RubyMotion: .dat* .repl_history build/ +*.bridgesupport +build-iPhoneOS/ +build-iPhoneSimulator/ + +## Specific to RubyMotion (use of CocoaPods): +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# vendor/Pods/ ## Documentation cache and generated files: /.yardoc/ @@ -20,7 +35,7 @@ build/ /doc/ /rdoc/ -## Environment normalisation: +## Environment normalization: /.bundle/ /vendor/bundle /lib/bundler/man/ @@ -33,3 +48,4 @@ build/ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc +.DS_Store diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..b1c277bc --- /dev/null +++ b/Rakefile @@ -0,0 +1,13 @@ +require 'rake/testtask' + +Rake::TestTask.new do |t| + t.libs = ["lib", "specs"] + t.warning = false + t.verbose = false + t.test_files = FileList['specs/*_spec.rb'] + puts "Running TestTask" +end + +task default: :test do + puts "Running my Rakefile" +end diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb new file mode 100644 index 00000000..cc543d12 --- /dev/null +++ b/lib/scrabble_scoring.rb @@ -0,0 +1 @@ +require_relative '../scrabble.rb' diff --git a/scrabble.rb b/scrabble.rb new file mode 100644 index 00000000..51f50d97 --- /dev/null +++ b/scrabble.rb @@ -0,0 +1,3 @@ +module Scrabble + +end diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb new file mode 100644 index 00000000..c5ebf269 --- /dev/null +++ b/specs/scrabble_spec.rb @@ -0,0 +1,3 @@ +require_relative 'spec_helper' +require_relative '../scrabble.rb' # this is the module file +require_relative '../lib/scrabble_scoring.rb' diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb new file mode 100644 index 00000000..c0fc8196 --- /dev/null +++ b/specs/spec_helper.rb @@ -0,0 +1,9 @@ +require 'simplecov' +SimpleCov.start + +require 'minitest' +require 'minitest/spec' +require 'minitest/autorun' +require 'minitest/reporters' + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 0d25cd4bc256dea7a386b47d08ffbddd29348598 Mon Sep 17 00:00:00 2001 From: Sabrina Wilbert Date: Tue, 30 Aug 2016 11:05:43 -0700 Subject: [PATCH 02/31] added first test --- scrabble.rb | 4 +++- specs/scrabble_spec.rb | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/scrabble.rb b/scrabble.rb index 51f50d97..7d0fd34d 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,3 +1,5 @@ module Scrabble -end + SCORE_HASH = {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} + +end diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb index c5ebf269..003d3931 100644 --- a/specs/scrabble_spec.rb +++ b/specs/scrabble_spec.rb @@ -1,3 +1,17 @@ require_relative 'spec_helper' -require_relative '../scrabble.rb' # this is the module file -require_relative '../lib/scrabble_scoring.rb' +require_relative '../scrabble' # this is the module file +require_relative '../lib/scrabble_scoring' + +describe 'testing scrabble module' do + + it 'Must return correct key value' do + expect(Scrabble::SCORE_HASH[:A]).must_equal(1) + expect(Scrabble::SCORE_HASH[:D]).must_equal(2) + expect(Scrabble::SCORE_HASH[:B]).must_equal(3) + expect(Scrabble::SCORE_HASH[:F]).must_equal(4) + expect(Scrabble::SCORE_HASH[:K]).must_equal(5) + expect(Scrabble::SCORE_HASH[:X]).must_equal(8) + expect(Scrabble::SCORE_HASH[:Q]).must_equal(10) + end + +end From 19348387d036e81eb8793e1a2468815fd3337c2e Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Tue, 30 Aug 2016 11:29:28 -0700 Subject: [PATCH 03/31] added Scoring class and self.score method, plus a test for that --- lib/scrabble_scoring.rb | 22 ++++++++++++++++++++++ specs/scrabble_spec.rb | 8 ++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index cc543d12..9b1cae53 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -1 +1,23 @@ require_relative '../scrabble.rb' + +class Scoring + + def self.score(word) + letter_array = word.upcase.split('') + score = 0 + + # go through each item in the letter array + # convert it to a symbol + # get the symbol (the key)'s value from the hash constant + # add that value to the score + letter_array.each do |letter| + score += Scrabble::SCORE_HASH[letter.to_sym] + end + return score + end + + +end + + +# puts Scoring.score("hello") diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb index 003d3931..b5e4aea0 100644 --- a/specs/scrabble_spec.rb +++ b/specs/scrabble_spec.rb @@ -14,4 +14,12 @@ expect(Scrabble::SCORE_HASH[:Q]).must_equal(10) end + it 'score method must return a fixnum' do + # put this on hold rn + end + + it 'score method must return correct score for a word' do + expect(Scoring.score("hello")).must_equal(8) + end + end From 95e35b3797015828068245a696d7bc2c117d860c Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Tue, 30 Aug 2016 14:20:02 -0700 Subject: [PATCH 04/31] write tests and method bingo to add 50 pts for 7-letter word --- lib/scrabble_scoring.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index 9b1cae53..f3c58967 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -1,15 +1,14 @@ require_relative '../scrabble.rb' -class Scoring +class Scrabble::Scoring def self.score(word) letter_array = word.upcase.split('') score = 0 + # this adds 50 if word length is >= 7 by calling bingo. + score += bingo(word) - # go through each item in the letter array - # convert it to a symbol - # get the symbol (the key)'s value from the hash constant - # add that value to the score + # iterate through array and add score letter_array.each do |letter| score += Scrabble::SCORE_HASH[letter.to_sym] end @@ -17,7 +16,20 @@ def self.score(word) end + def self.bingo(word) + if word.length >= 7 + return 50 + else + return 0 + end + end + + # this is not ready to go + def self.check_input(word) + word = word.gsub + end + end -# puts Scoring.score("hello") +puts Scrabble::Scoring.score("jazzmen") From c01db0867b47658e03769370c9a8b75ffd4a785e Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Tue, 30 Aug 2016 14:56:40 -0700 Subject: [PATCH 05/31] trying to push spec updates again --- specs/scrabble_spec.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb index b5e4aea0..2ba2802d 100644 --- a/specs/scrabble_spec.rb +++ b/specs/scrabble_spec.rb @@ -19,7 +19,20 @@ end it 'score method must return correct score for a word' do - expect(Scoring.score("hello")).must_equal(8) + expect(Scrabble::Scoring.score("hello")).must_equal(8) + end + + it 'score method must add 50 points to score for a 7-letter word' do + expect(Scrabble::Scoring.score("jazzmen").must_equal(84)) + end + + it 'score method should return a fixnum' do + expect(Scrabble::Scoring.score("something").must_be_instance_of(Fixnum)) + end + + it 'score method\'s argument should only include letters' do + expect( proc {Scrabble::Scoring.score("everything!!!")} ).must_raise(ArgumentError) + expect( proc {Scrabble::Scoring.score("everything123")} ).must_raise(ArgumentError) end end From 89a92f70ebde177f3112ffba0cfd0b0e2f7ba506 Mon Sep 17 00:00:00 2001 From: Sabrina Wilbert Date: Tue, 30 Aug 2016 15:02:13 -0700 Subject: [PATCH 06/31] Added check_input method and test for check_input. --- babydragon3.rb | 8 ++++++++ lib/scrabble_scoring.rb | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 babydragon3.rb diff --git a/babydragon3.rb b/babydragon3.rb new file mode 100644 index 00000000..82aa6708 --- /dev/null +++ b/babydragon3.rb @@ -0,0 +1,8 @@ +# this is not ready to go +def self.check_input(word) + if word =~ /^[a-zA-Z]+$/ + return word + else + raise ArgumentError + end +end diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index f3c58967..ba3179f3 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -3,6 +3,7 @@ class Scrabble::Scoring def self.score(word) + check_input(word) letter_array = word.upcase.split('') score = 0 # this adds 50 if word length is >= 7 by calling bingo. @@ -26,7 +27,11 @@ def self.bingo(word) # this is not ready to go def self.check_input(word) - word = word.gsub + if word =~ /^[a-zA-Z]+$/ + return word + else + raise ArgumentError + end end end From f893441889c6b18786a64e2c00dd919a80211c20 Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Tue, 30 Aug 2016 15:31:01 -0700 Subject: [PATCH 07/31] added to check_input method to verify string argument --- babydragon3.rb | 8 -------- lib/scrabble_scoring.rb | 5 ++++- specs/scrabble_spec.rb | 10 ++++++---- 3 files changed, 10 insertions(+), 13 deletions(-) delete mode 100644 babydragon3.rb diff --git a/babydragon3.rb b/babydragon3.rb deleted file mode 100644 index 82aa6708..00000000 --- a/babydragon3.rb +++ /dev/null @@ -1,8 +0,0 @@ -# this is not ready to go -def self.check_input(word) - if word =~ /^[a-zA-Z]+$/ - return word - else - raise ArgumentError - end -end diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index ba3179f3..a93deb55 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -27,6 +27,9 @@ def self.bingo(word) # this is not ready to go def self.check_input(word) + + raise ArgumentError unless word.class == String + if word =~ /^[a-zA-Z]+$/ return word else @@ -37,4 +40,4 @@ def self.check_input(word) end -puts Scrabble::Scoring.score("jazzmen") +puts Scrabble::Scoring.score("a") diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb index 2ba2802d..97983919 100644 --- a/specs/scrabble_spec.rb +++ b/specs/scrabble_spec.rb @@ -14,10 +14,6 @@ expect(Scrabble::SCORE_HASH[:Q]).must_equal(10) end - it 'score method must return a fixnum' do - # put this on hold rn - end - it 'score method must return correct score for a word' do expect(Scrabble::Scoring.score("hello")).must_equal(8) end @@ -35,4 +31,10 @@ expect( proc {Scrabble::Scoring.score("everything123")} ).must_raise(ArgumentError) end + it 'score method should raise ArgError if the arg is not a string' do + expect( proc {Scrabble::Scoring.score(12345)} ).must_raise(ArgumentError) + expect( proc {Scrabble::Scoring.score(:symbol)} ).must_raise(ArgumentError) + expect( proc {Scrabble::Scoring.score(4000000.49)} ).must_raise(ArgumentError) + end + end From 3ec9b20808176c3e8bedbc0817cf8b8c5f37ded5 Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Tue, 30 Aug 2016 15:38:32 -0700 Subject: [PATCH 08/31] rearrange tests and add first test for highest_score_method --- specs/scrabble_spec.rb | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb index 97983919..8660e9c4 100644 --- a/specs/scrabble_spec.rb +++ b/specs/scrabble_spec.rb @@ -14,27 +14,35 @@ expect(Scrabble::SCORE_HASH[:Q]).must_equal(10) end - it 'score method must return correct score for a word' do - expect(Scrabble::Scoring.score("hello")).must_equal(8) + it 'score method\'s argument should only include letters' do + expect( proc {Scrabble::Scoring.score("everything!!!")} ).must_raise(ArgumentError) + expect( proc {Scrabble::Scoring.score("everything123")} ).must_raise(ArgumentError) end - it 'score method must add 50 points to score for a 7-letter word' do - expect(Scrabble::Scoring.score("jazzmen").must_equal(84)) + it 'score method should raise ArgError if the arg is not a string' do + expect( proc {Scrabble::Scoring.score(12345)} ).must_raise(ArgumentError) + expect( proc {Scrabble::Scoring.score(:symbol)} ).must_raise(ArgumentError) + expect( proc {Scrabble::Scoring.score(4000000.49)} ).must_raise(ArgumentError) end it 'score method should return a fixnum' do expect(Scrabble::Scoring.score("something").must_be_instance_of(Fixnum)) end - it 'score method\'s argument should only include letters' do - expect( proc {Scrabble::Scoring.score("everything!!!")} ).must_raise(ArgumentError) - expect( proc {Scrabble::Scoring.score("everything123")} ).must_raise(ArgumentError) + it 'score method must return correct score for a word' do + expect(Scrabble::Scoring.score("hello")).must_equal(8) end - it 'score method should raise ArgError if the arg is not a string' do - expect( proc {Scrabble::Scoring.score(12345)} ).must_raise(ArgumentError) + it 'score method must add 50 points to score for a 7-letter word' do + expect(Scrabble::Scoring.score("jazzmen").must_equal(84)) + end + + it 'highest_score_method raise ArgError if the arg is not an array' do + expect( proc {Scrabble::Scoring.score("string")} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.score(:symbol)} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.score(4000000.49)} ).must_raise(ArgumentError) end + + end From 9bb5870f29a27c12004e9380bc85299ccf5e1163 Mon Sep 17 00:00:00 2001 From: Sabrina Wilbert Date: Tue, 30 Aug 2016 16:14:04 -0700 Subject: [PATCH 09/31] Added highest score from method --- lib/scrabble_scoring.rb | 17 ++++++++++++++--- specs/scrabble_spec.rb | 10 ++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index a93deb55..3e28ac6d 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -25,7 +25,7 @@ def self.bingo(word) end end - # this is not ready to go + def self.check_input(word) raise ArgumentError unless word.class == String @@ -37,7 +37,18 @@ def self.check_input(word) end end -end + def self.highest_score_from(array_of_words) + raise ArgumentError unless array_of_words.class == Array + + word_hash = {} + array_of_words.each do |element| + word_hash[element] = score(element) + end + + end + +end -puts Scrabble::Scoring.score("a") +puts Scrabble::Scoring.highest_score_from(["zzzz", "abc", "xat"]) +#puts Scrabble::Scoring.score("a") diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb index 8660e9c4..3d97f1e6 100644 --- a/specs/scrabble_spec.rb +++ b/specs/scrabble_spec.rb @@ -38,11 +38,13 @@ end it 'highest_score_method raise ArgError if the arg is not an array' do - expect( proc {Scrabble::Scoring.score("string")} ).must_raise(ArgumentError) - expect( proc {Scrabble::Scoring.score(:symbol)} ).must_raise(ArgumentError) - expect( proc {Scrabble::Scoring.score(4000000.49)} ).must_raise(ArgumentError) + expect( proc {Scrabble::Scoring.highest_score_from("string")} ).must_raise(ArgumentError) + expect( proc {Scrabble::Scoring.highest_score_from(:symbol)} ).must_raise(ArgumentError) + expect( proc {Scrabble::Scoring.highest_score_from(4000000.49)} ).must_raise(ArgumentError) end - + it 'must return word with with hihgest score' do + expect(Scrabble::Scoring.highest_score_from("zzzz", "abc", "xat").must_equal("zzzz")) + end end From 3857182e662e4ef287ed14542a2104ae33163779 Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Tue, 30 Aug 2016 16:58:48 -0700 Subject: [PATCH 10/31] start work on tests & method for tiebreaker --- lib/scrabble_scoring.rb | 16 +++++++++++----- scrabble.rb | 4 +++- specs/scrabble_spec.rb | 23 +++++++++++++++++++---- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index 3e28ac6d..83e8d84c 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -27,7 +27,6 @@ def self.bingo(word) def self.check_input(word) - raise ArgumentError unless word.class == String if word =~ /^[a-zA-Z]+$/ @@ -45,10 +44,17 @@ def self.highest_score_from(array_of_words) array_of_words.each do |element| word_hash[element] = score(element) end - + + if word_hash.values.length == word_hash.values.uniq.length + tie(word_hash) + else + return word_hash.key(word_hash.values.max) + end + end -end + def self.tie(hash) + puts "it's a tie!" + end -puts Scrabble::Scoring.highest_score_from(["zzzz", "abc", "xat"]) -#puts Scrabble::Scoring.score("a") +end # end of Scoring class diff --git a/scrabble.rb b/scrabble.rb index 7d0fd34d..2169c044 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,5 +1,7 @@ module Scrabble - SCORE_HASH = {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} + SCORE_HASH = {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} end diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb index 3d97f1e6..a0248dcc 100644 --- a/specs/scrabble_spec.rb +++ b/specs/scrabble_spec.rb @@ -37,14 +37,29 @@ expect(Scrabble::Scoring.score("jazzmen").must_equal(84)) end - it 'highest_score_method raise ArgError if the arg is not an array' do + it 'highest_score_from method raise ArgError if the arg is not an array' do expect( proc {Scrabble::Scoring.highest_score_from("string")} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.highest_score_from(:symbol)} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.highest_score_from(4000000.49)} ).must_raise(ArgumentError) end - it 'must return word with with hihgest score' do - expect(Scrabble::Scoring.highest_score_from("zzzz", "abc", "xat").must_equal("zzzz")) - end + it 'must return word with with highest score' do + expect(Scrabble::Scoring.highest_score_from(["zzzz", "abc", "xat"]).must_equal("zzzz")) + end + + it 'in the case of a tie, highest_score_from method must return fewer-lettered word over higher lettered-word unless higher.length == 7' do + expect(Scrabble::Scoring.highest_score_from(["aaaa","y"]).must_equal("y")) + end + + it 'in the case of a tie, if one of the tied words is 7 letters, highest_score_method must return the 7 letter word' do + expect(Scrabble::Scoring.highest_score_from(["zzzzzz","iiiiiif"]).must_equal("iiiiiif")) + end + + it 'in the case of a tie, if the two words are the same score & same length, pick the first one to win' do + expect(Scrabble::Scoring.highest_score_from(["aaaaaa","iiiiii"]).must_equal("aaaaaa")) + end + + + end From 7959225e2b12e0662dc9bee9199b306dd7382749 Mon Sep 17 00:00:00 2001 From: Sabrina Wilbert Date: Wed, 31 Aug 2016 09:51:48 -0700 Subject: [PATCH 11/31] Added tie method --- lib/scrabble_scoring.rb | 7 +++-- lib/tie.rb | 66 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 lib/tie.rb diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index 83e8d84c..e54a34d3 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -53,8 +53,11 @@ def self.highest_score_from(array_of_words) end - def self.tie(hash) - puts "it's a tie!" + def self.tie(word_hash) + tie_words = [] + word_hash.each { |k, v| tie_words << k if v == word_hash.values.max } + puts "it's a tie!" +return tie_words end end # end of Scoring class diff --git a/lib/tie.rb b/lib/tie.rb new file mode 100644 index 00000000..6d468f8d --- /dev/null +++ b/lib/tie.rb @@ -0,0 +1,66 @@ +require_relative '../scrabble.rb' + +class Scrabble::Scoring + + def self.score(word) + check_input(word) + letter_array = word.upcase.split('') + score = 0 + # this adds 50 if word length is >= 7 by calling bingo. + score += bingo(word) + + # iterate through array and add score + letter_array.each do |letter| + score += Scrabble::SCORE_HASH[letter.to_sym] + end + return score + end + + + def self.bingo(word) + if word.length >= 7 + return 50 + else + return 0 + end + end + + + def self.check_input(word) + raise ArgumentError unless word.class == String + + if word =~ /^[a-zA-Z]+$/ + return word + else + raise ArgumentError + end + end + + def self.highest_score_from(array_of_words) + raise ArgumentError unless array_of_words.class == Array + + word_hash = {} + + array_of_words.each do |element| + word_hash[element] = score(element) + end + + if word_hash.values.length != word_hash.values.uniq.length + tie(word_hash) + else + return word_hash.key(word_hash.values.max) + end + end + + def self.tie(word_hash) + tie_words = [] + word_hash.each { |k, v| tie_words << k if v == word_hash.values.max } + puts "it's a tie!" +return tie_words + end + +end # end of Scoring class + + print Scrabble::Scoring.highest_score_from(["ZZZZ", "cat", "QQQQ"]) +# Scrabble::Scoring.score("CAT") +# Scrabble::Scoring.score("QQQQ") From 10c02ffd651a44092747b86638673e78eaf7e0e2 Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Wed, 31 Aug 2016 10:34:39 -0700 Subject: [PATCH 12/31] added self.tie and self.determine tie, added tests for both --- lib/scrabble_scoring.rb | 56 +++++++++++++++++++++++++++++------------ specs/scrabble_spec.rb | 18 +++++++++++++ 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index e54a34d3..cf276287 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -16,19 +16,21 @@ def self.score(word) return score end - + # this determines whether the word uses all 7 tiles def self.bingo(word) if word.length >= 7 - return 50 + return 50 # this adds the 50 points else - return 0 + return 0 # if not, then add 0 points end end def self.check_input(word) + # this will only allow the word to be a string raise ArgumentError unless word.class == String + # this checks to be sure the word only contains letters if word =~ /^[a-zA-Z]+$/ return word else @@ -36,28 +38,50 @@ def self.check_input(word) end end + # this method finds the highest score from an array of words def self.highest_score_from(array_of_words) + # make sure the argument is an array raise ArgumentError unless array_of_words.class == Array - word_hash = {} + word_hash = {} + + array_of_words.each do |element| + word_hash[element] = score(element) + end - array_of_words.each do |element| - word_hash[element] = score(element) - end + if !determine_tie(word_hash) + # this returns the word that has the highest score if there is no tie. + return word_hash.key(word_hash.values.max) + else + tie(word_hash) + end - if word_hash.values.length == word_hash.values.uniq.length - tie(word_hash) - else - return word_hash.key(word_hash.values.max) - end + end + def self.determine_tie(hash) + # determines if there are any ties. + if hash.values.length != hash.values.uniq.length + return true + else + return false + end end def self.tie(word_hash) - tie_words = [] - word_hash.each { |k, v| tie_words << k if v == word_hash.values.max } - puts "it's a tie!" -return tie_words + # make an empty array, will be made of the words that are tied + tie_words = [] + # iterates through hash and adds word to the array if the value is one of the max values + word_hash.each { |key, value| tie_words << key if value == word_hash.values.max } + return tie_words end + def self.tiebreaker(tie_array) + if + + end + + end + + + end # end of Scoring class diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb index a0248dcc..66eb8eee 100644 --- a/specs/scrabble_spec.rb +++ b/specs/scrabble_spec.rb @@ -5,6 +5,7 @@ describe 'testing scrabble module' do it 'Must return correct key value' do + skip expect(Scrabble::SCORE_HASH[:A]).must_equal(1) expect(Scrabble::SCORE_HASH[:D]).must_equal(2) expect(Scrabble::SCORE_HASH[:B]).must_equal(3) @@ -15,51 +16,68 @@ end it 'score method\'s argument should only include letters' do + skip expect( proc {Scrabble::Scoring.score("everything!!!")} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.score("everything123")} ).must_raise(ArgumentError) end it 'score method should raise ArgError if the arg is not a string' do + skip expect( proc {Scrabble::Scoring.score(12345)} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.score(:symbol)} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.score(4000000.49)} ).must_raise(ArgumentError) end it 'score method should return a fixnum' do + skip expect(Scrabble::Scoring.score("something").must_be_instance_of(Fixnum)) end it 'score method must return correct score for a word' do + skip expect(Scrabble::Scoring.score("hello")).must_equal(8) end it 'score method must add 50 points to score for a 7-letter word' do + skip expect(Scrabble::Scoring.score("jazzmen").must_equal(84)) end it 'highest_score_from method raise ArgError if the arg is not an array' do + skip expect( proc {Scrabble::Scoring.highest_score_from("string")} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.highest_score_from(:symbol)} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.highest_score_from(4000000.49)} ).must_raise(ArgumentError) end it 'must return word with with highest score' do + skip expect(Scrabble::Scoring.highest_score_from(["zzzz", "abc", "xat"]).must_equal("zzzz")) end it 'in the case of a tie, highest_score_from method must return fewer-lettered word over higher lettered-word unless higher.length == 7' do + skip expect(Scrabble::Scoring.highest_score_from(["aaaa","y"]).must_equal("y")) end it 'in the case of a tie, if one of the tied words is 7 letters, highest_score_method must return the 7 letter word' do + skip expect(Scrabble::Scoring.highest_score_from(["zzzzzz","iiiiiif"]).must_equal("iiiiiif")) end it 'in the case of a tie, if the two words are the same score & same length, pick the first one to win' do + skip expect(Scrabble::Scoring.highest_score_from(["aaaaaa","iiiiii"]).must_equal("aaaaaa")) end + it 'determine_tie must return true if there is a tie and false if there is no tie' do + expect(Scrabble::Scoring.determine_tie({"zzz"=>30,"qqq"=>30}).must_equal(true)) + expect(Scrabble::Scoring.determine_tie("xxkehgbnb"=>85,"a"=>1).must_equal(false)) + end + it 'tie method must return an array with highest score keys (aka words)' do + expect(Scrabble::Scoring.tie({"zzz"=>30,"qqq"=>30, "abc"=>5}).must_equal(["zzz", "qqq"])) + end end From 70428fb6b5fe1d2ad42a347cde3ba241e9cb2dae Mon Sep 17 00:00:00 2001 From: Sabrina Wilbert Date: Wed, 31 Aug 2016 11:05:56 -0700 Subject: [PATCH 13/31] Added tiebreaker method --- lib/scrabble_scoring.rb | 22 +++++++++++++++++++--- specs/scrabble_spec.rb | 6 +++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index cf276287..39e1f935 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -72,14 +72,30 @@ def self.tie(word_hash) tie_words = [] # iterates through hash and adds word to the array if the value is one of the max values word_hash.each { |key, value| tie_words << key if value == word_hash.values.max } - return tie_words + winner = tiebreaker(tie_words) + return winner end def self.tiebreaker(tie_array) - if - +#returns winning word if words are same length. + seven = 7 + + winning_word = "" + winning_length = 10000 + tie_array.each do |word| + if word.length >= seven + winning_word = word + end end + + tie_array.each do |word| + if word.length < winning_length + winning_length = word.length + winning_word = word + end + end + return winning_word end diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb index 66eb8eee..48cdc6c9 100644 --- a/specs/scrabble_spec.rb +++ b/specs/scrabble_spec.rb @@ -66,7 +66,7 @@ end it 'in the case of a tie, if the two words are the same score & same length, pick the first one to win' do - skip + expect(Scrabble::Scoring.highest_score_from(["aaaaaa","iiiiii"]).must_equal("aaaaaa")) end @@ -75,8 +75,8 @@ expect(Scrabble::Scoring.determine_tie("xxkehgbnb"=>85,"a"=>1).must_equal(false)) end - it 'tie method must return an array with highest score keys (aka words)' do - expect(Scrabble::Scoring.tie({"zzz"=>30,"qqq"=>30, "abc"=>5}).must_equal(["zzz", "qqq"])) + it 'tie method must return winning word' do + expect(Scrabble::Scoring.tie({"zzz"=>30,"qqq"=>30, "abc"=>5}).must_equal("zzz")) end From cf408f208b3b6df2c698aaae1377b28122e26fff Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Wed, 31 Aug 2016 13:09:18 -0700 Subject: [PATCH 14/31] OMG WE FINALLY FINISHED WAVE 1 --- lib/scrabble_scoring.rb | 26 ++++++++++++++++---------- specs/scrabble_spec.rb | 22 +++++++++++----------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index 39e1f935..8e24fc5d 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -77,19 +77,24 @@ def self.tie(word_hash) end def self.tiebreaker(tie_array) -#returns winning word if words are same length. - seven = 7 + #returns winning word if words are same length. + two_d_array = [] + tie_array.each do |word| + two_d_array << [word, word.length] + end + max = 7 + new_array = two_d_array.select {|word| word[1] >= max} + if new_array.length == 0 + find_winner_non7(tie_array) + else + return new_array[0][0] # returns the first word played has 7 or greater letters + end + end + def self.find_winner_non7(tie_array) winning_word = "" winning_length = 10000 tie_array.each do |word| - if word.length >= seven - winning_word = word - end - end - - - tie_array.each do |word| if word.length < winning_length winning_length = word.length winning_word = word @@ -99,5 +104,6 @@ def self.tiebreaker(tie_array) end - end # end of Scoring class + +puts Scrabble::Scoring.tiebreaker(["sabrina", "knitting"]) diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb index 48cdc6c9..13628d83 100644 --- a/specs/scrabble_spec.rb +++ b/specs/scrabble_spec.rb @@ -5,7 +5,7 @@ describe 'testing scrabble module' do it 'Must return correct key value' do - skip + # skip expect(Scrabble::SCORE_HASH[:A]).must_equal(1) expect(Scrabble::SCORE_HASH[:D]).must_equal(2) expect(Scrabble::SCORE_HASH[:B]).must_equal(3) @@ -16,52 +16,52 @@ end it 'score method\'s argument should only include letters' do - skip + # skip expect( proc {Scrabble::Scoring.score("everything!!!")} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.score("everything123")} ).must_raise(ArgumentError) end it 'score method should raise ArgError if the arg is not a string' do - skip + # skip expect( proc {Scrabble::Scoring.score(12345)} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.score(:symbol)} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.score(4000000.49)} ).must_raise(ArgumentError) end it 'score method should return a fixnum' do - skip + # skip expect(Scrabble::Scoring.score("something").must_be_instance_of(Fixnum)) end it 'score method must return correct score for a word' do - skip + # skip expect(Scrabble::Scoring.score("hello")).must_equal(8) end it 'score method must add 50 points to score for a 7-letter word' do - skip + # skip expect(Scrabble::Scoring.score("jazzmen").must_equal(84)) end it 'highest_score_from method raise ArgError if the arg is not an array' do - skip + # skip expect( proc {Scrabble::Scoring.highest_score_from("string")} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.highest_score_from(:symbol)} ).must_raise(ArgumentError) expect( proc {Scrabble::Scoring.highest_score_from(4000000.49)} ).must_raise(ArgumentError) end - it 'must return word with with highest score' do - skip + it 'highest_score_from ust return word with with highest score' do + # skip expect(Scrabble::Scoring.highest_score_from(["zzzz", "abc", "xat"]).must_equal("zzzz")) end it 'in the case of a tie, highest_score_from method must return fewer-lettered word over higher lettered-word unless higher.length == 7' do - skip + # skip expect(Scrabble::Scoring.highest_score_from(["aaaa","y"]).must_equal("y")) end it 'in the case of a tie, if one of the tied words is 7 letters, highest_score_method must return the 7 letter word' do - skip + # skip expect(Scrabble::Scoring.highest_score_from(["zzzzzz","iiiiiif"]).must_equal("iiiiiif")) end From ab848be6cfb512b65c1ce724bac72593e7014b11 Mon Sep 17 00:00:00 2001 From: Sabrina Wilbert Date: Wed, 31 Aug 2016 14:01:51 -0700 Subject: [PATCH 15/31] Added player class --- lib/Scrabble_Player.rb | 9 +++++++++ specs/Player_spec.rb | 23 +++++++++++++++++++++++ specs/scrabble_spec.rb | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 lib/Scrabble_Player.rb create mode 100644 specs/Player_spec.rb diff --git a/lib/Scrabble_Player.rb b/lib/Scrabble_Player.rb new file mode 100644 index 00000000..e3d1e22a --- /dev/null +++ b/lib/Scrabble_Player.rb @@ -0,0 +1,9 @@ +require_relative '../scrabble.rb' +require_relative 'scrabble_scoring.rb' +class Scrabble::Player + attr_reader :name + + def initialize(name) + @name = name + end +end diff --git a/specs/Player_spec.rb b/specs/Player_spec.rb new file mode 100644 index 00000000..60927d61 --- /dev/null +++ b/specs/Player_spec.rb @@ -0,0 +1,23 @@ +require_relative 'spec_helper' +require_relative '../scrabble' # this is the module file +require_relative '../lib/scrabble_scoring' +require_relative '../lib/scrabble_player' + +player = Scrabble::Player.new("sabrina") +describe 'testing player class' do + + + + it 'returns the value of the @name instance variable' do + expect(player.name.must_equal("sabrina")) + + end + + + + + # it 'returns an Array of the words played by the player' do + # expect(Scrabble::Player.play(["sabrina", "cat", "Boxer"]).must_equal(["sabrina", "cat", "Boxer"])) + # end + +end diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb index 13628d83..370cb1a1 100644 --- a/specs/scrabble_spec.rb +++ b/specs/scrabble_spec.rb @@ -2,7 +2,7 @@ require_relative '../scrabble' # this is the module file require_relative '../lib/scrabble_scoring' -describe 'testing scrabble module' do +describe 'testing scoring class' do it 'Must return correct key value' do # skip From 94a8e757718cc49fc4d3a6a006efc314ec28302b Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Wed, 31 Aug 2016 14:24:22 -0700 Subject: [PATCH 16/31] added play(word) and tests for such --- lib/Scrabble_Player.rb | 12 ++++++++++-- specs/Player_spec.rb | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/Scrabble_Player.rb b/lib/Scrabble_Player.rb index e3d1e22a..ec3745e0 100644 --- a/lib/Scrabble_Player.rb +++ b/lib/Scrabble_Player.rb @@ -1,9 +1,17 @@ require_relative '../scrabble.rb' require_relative 'scrabble_scoring.rb' class Scrabble::Player - attr_reader :name + attr_reader :name, :plays def initialize(name) @name = name + @plays = [] end -end + + def play(word) + @plays << word + score = Scrabble::Scoring.score(word) + return score + end + +end # end of class diff --git a/specs/Player_spec.rb b/specs/Player_spec.rb index 60927d61..dec37677 100644 --- a/specs/Player_spec.rb +++ b/specs/Player_spec.rb @@ -3,18 +3,27 @@ require_relative '../lib/scrabble_scoring' require_relative '../lib/scrabble_player' -player = Scrabble::Player.new("sabrina") describe 'testing player class' do + before do + end it 'returns the value of the @name instance variable' do + player = Scrabble::Player.new("sabrina") expect(player.name.must_equal("sabrina")) - end + it 'play(word) method returns the score of word' do + player = Scrabble::Player.new("sabrina2") + expect(player.play("zoo").must_equal(12)) + end - + it 'play(word) adds word to plays array' do + player = Scrabble::Player.new("sabrina3") + player.play("zoo") + expect(player.plays.must_include("zoo")) + end # it 'returns an Array of the words played by the player' do # expect(Scrabble::Player.play(["sabrina", "cat", "Boxer"]).must_equal(["sabrina", "cat", "Boxer"])) From 51dc3876a8fd44f53a824dac5fee0d5760cff5ac Mon Sep 17 00:00:00 2001 From: Sabrina Wilbert Date: Wed, 31 Aug 2016 14:54:19 -0700 Subject: [PATCH 17/31] Added highest word and score methods --- lib/Scrabble_Player.rb | 10 ++++++++++ specs/Player_spec.rb | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/Scrabble_Player.rb b/lib/Scrabble_Player.rb index ec3745e0..73896405 100644 --- a/lib/Scrabble_Player.rb +++ b/lib/Scrabble_Player.rb @@ -14,4 +14,14 @@ def play(word) return score end + def highest_score_word + highest_word = Scrabble::Scoring.highest_score_from(@plays) + return highest_word + end + + def highest_word_score + highest_score = Scrabble::Scoring.score(highest_score_word) + return highest_score + end + end # end of class diff --git a/specs/Player_spec.rb b/specs/Player_spec.rb index dec37677..f152d28f 100644 --- a/specs/Player_spec.rb +++ b/specs/Player_spec.rb @@ -25,6 +25,22 @@ expect(player.plays.must_include("zoo")) end + it 'Returns the highest scoring played word' do + player = Scrabble::Player.new("sabrina4") + player.play("zzzz") + player.play("cat") + player.play("boy") + expect(player.highest_score_word.must_equal("zzzz")) + end + it 'Returns the score of the highest scoring word ' do + player = Scrabble::Player.new("sabrina4") + player.play("zzzz") + player.play("cat") + player.play("boy") + expect(player.highest_word_score.must_equal(40)) + end + + # it 'returns an Array of the words played by the player' do # expect(Scrabble::Player.play(["sabrina", "cat", "Boxer"]).must_equal(["sabrina", "cat", "Boxer"])) # end From 114b7aa6a5680847558f23e072aedafd72dd59fd Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Wed, 31 Aug 2016 15:02:42 -0700 Subject: [PATCH 18/31] added total_score method --- lib/Scrabble_Player.rb | 8 ++++++++ lib/scrabble_scoring.rb | 4 ++-- specs/Player_spec.rb | 32 +++++++++++++++----------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/Scrabble_Player.rb b/lib/Scrabble_Player.rb index 73896405..e2c6373d 100644 --- a/lib/Scrabble_Player.rb +++ b/lib/Scrabble_Player.rb @@ -24,4 +24,12 @@ def highest_word_score return highest_score end + def total_score + score = 0 + @plays.each do |word| + score += Scrabble::Scoring.score(word) + end + return score + end + end # end of class diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index 8e24fc5d..7971f2d5 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -98,9 +98,9 @@ def self.find_winner_non7(tie_array) if word.length < winning_length winning_length = word.length winning_word = word - end end - return winning_word + end + return winning_word end diff --git a/specs/Player_spec.rb b/specs/Player_spec.rb index f152d28f..c9a7fc7f 100644 --- a/specs/Player_spec.rb +++ b/specs/Player_spec.rb @@ -5,10 +5,6 @@ describe 'testing player class' do - before do - - end - it 'returns the value of the @name instance variable' do player = Scrabble::Player.new("sabrina") expect(player.name.must_equal("sabrina")) @@ -26,23 +22,25 @@ end it 'Returns the highest scoring played word' do - player = Scrabble::Player.new("sabrina4") - player.play("zzzz") - player.play("cat") - player.play("boy") + player = Scrabble::Player.new("sabrina4") + player.play("zzzz") + player.play("cat") + player.play("boy") expect(player.highest_score_word.must_equal("zzzz")) end it 'Returns the score of the highest scoring word ' do - player = Scrabble::Player.new("sabrina4") - player.play("zzzz") - player.play("cat") - player.play("boy") + player = Scrabble::Player.new("sabrina4") + player.play("zzzz") + player.play("cat") + player.play("boy") expect(player.highest_word_score.must_equal(40)) end - - # it 'returns an Array of the words played by the player' do - # expect(Scrabble::Player.play(["sabrina", "cat", "Boxer"]).must_equal(["sabrina", "cat", "Boxer"])) - # end - + it 'total_score method returns sum of scores of played words' do + player = Scrabble::Player.new("sabrina5") + player.play("knitting") + player.play("oooooo") + player.play("kitsch") + expect(player.total_score.must_equal(84)) + end end From 3a2f59f708ef389209a3464efc2dfc14a427f544 Mon Sep 17 00:00:00 2001 From: Sabrina Wilbert Date: Wed, 31 Aug 2016 15:17:17 -0700 Subject: [PATCH 19/31] Added won method --- lib/Scrabble_Player.rb | 9 ++++++++- specs/Player_spec.rb | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Scrabble_Player.rb b/lib/Scrabble_Player.rb index e2c6373d..31d2c8cc 100644 --- a/lib/Scrabble_Player.rb +++ b/lib/Scrabble_Player.rb @@ -29,7 +29,14 @@ def total_score @plays.each do |word| score += Scrabble::Scoring.score(word) end - return score + return score + end + def won? + if total_score >= 100 + return true + else + return false + end end end # end of class diff --git a/specs/Player_spec.rb b/specs/Player_spec.rb index c9a7fc7f..8fa7138c 100644 --- a/specs/Player_spec.rb +++ b/specs/Player_spec.rb @@ -43,4 +43,21 @@ player.play("kitsch") expect(player.total_score.must_equal(84)) end + +it 'won should return true if player has over 100 points' do + player = Scrabble::Player.new("Lauren5") + player.play("knitting") + player.play("oooooo") + player.play("kitsch") + player.play("zz") + expect(player.won?.must_equal(true)) +end + +it 'won should return false if player has less than 100 points' do + player = Scrabble::Player.new("Lauren5") + player.play("knitting") + player.play("oooooo") + player.play("kitsch") + expect(player.won?.must_equal(false)) end +end#end of test From f3caba9db9d6256400ad0f9abdbd0499aa027193 Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Wed, 31 Aug 2016 15:37:06 -0700 Subject: [PATCH 20/31] added final tests and added won? to play method --- lib/Scrabble_Player.rb | 18 +++++++++++++++--- specs/Player_spec.rb | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/Scrabble_Player.rb b/lib/Scrabble_Player.rb index 31d2c8cc..533e2a02 100644 --- a/lib/Scrabble_Player.rb +++ b/lib/Scrabble_Player.rb @@ -4,26 +4,36 @@ class Scrabble::Player attr_reader :name, :plays def initialize(name) + raise ArgumentError unless name.class == String + @name = name @plays = [] end + # plays a word def play(word) - @plays << word - score = Scrabble::Scoring.score(word) - return score + if won? + return false + else + @plays << word + score = Scrabble::Scoring.score(word) + return score + end end + # method that returns the word that a player has played with the highest score def highest_score_word highest_word = Scrabble::Scoring.highest_score_from(@plays) return highest_word end + # method that returns the score of a player's highest scoring word def highest_word_score highest_score = Scrabble::Scoring.score(highest_score_word) return highest_score end + # method that checks what the total score is def total_score score = 0 @plays.each do |word| @@ -31,6 +41,8 @@ def total_score end return score end + + # method that checks if player has 100+ points def won? if total_score >= 100 return true diff --git a/specs/Player_spec.rb b/specs/Player_spec.rb index 8fa7138c..4bcb351c 100644 --- a/specs/Player_spec.rb +++ b/specs/Player_spec.rb @@ -10,17 +10,33 @@ expect(player.name.must_equal("sabrina")) end + it 'player must be initialized with a string for a name' do + # expecting if we try to init a Player with anything other than a string for a name, it should raise an error + expect( proc { player = Scrabble::Player.new(:sabrina) } ).must_raise(ArgumentError) + end + it 'play(word) method returns the score of word' do player = Scrabble::Player.new("sabrina2") expect(player.play("zoo").must_equal(12)) end + it 'play(word) must return a fixnum' do + player = Scrabble::Player.new("laurenCat") + expect(player.play("something").must_be_instance_of(Fixnum)) + end + it 'play(word) adds word to plays array' do player = Scrabble::Player.new("sabrina3") player.play("zoo") expect(player.plays.must_include("zoo")) end + it 'play(word) returns false if player has already won' do + player = Scrabble::Player.new("lauren0007") + player.play("zzzzzzz") + expect(player.play("anotherword").must_equal(false)) + end + it 'Returns the highest scoring played word' do player = Scrabble::Player.new("sabrina4") player.play("zzzz") @@ -28,6 +44,7 @@ player.play("boy") expect(player.highest_score_word.must_equal("zzzz")) end + it 'Returns the score of the highest scoring word ' do player = Scrabble::Player.new("sabrina4") player.play("zzzz") From d38e27259edd0a3b6ef8e95553a005ad4698d7d8 Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Wed, 31 Aug 2016 15:38:36 -0700 Subject: [PATCH 21/31] finished Wave 2 --- lib/Scrabble_Player.rb | 8 +++++--- specs/Player_spec.rb | 30 +++++++++++++++--------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/Scrabble_Player.rb b/lib/Scrabble_Player.rb index 533e2a02..159b0427 100644 --- a/lib/Scrabble_Player.rb +++ b/lib/Scrabble_Player.rb @@ -1,16 +1,18 @@ require_relative '../scrabble.rb' require_relative 'scrabble_scoring.rb' + class Scrabble::Player attr_reader :name, :plays def initialize(name) + # we want the player to use a string for a name raise ArgumentError unless name.class == String - + @name = name @plays = [] end - # plays a word + # allows the player to plays a word as long as they have not already won def play(word) if won? return false @@ -42,7 +44,7 @@ def total_score return score end - # method that checks if player has 100+ points + # method that checks if player has 100+ points; if so, they've won def won? if total_score >= 100 return true diff --git a/specs/Player_spec.rb b/specs/Player_spec.rb index 4bcb351c..05618435 100644 --- a/specs/Player_spec.rb +++ b/specs/Player_spec.rb @@ -61,20 +61,20 @@ expect(player.total_score.must_equal(84)) end -it 'won should return true if player has over 100 points' do - player = Scrabble::Player.new("Lauren5") - player.play("knitting") - player.play("oooooo") - player.play("kitsch") - player.play("zz") - expect(player.won?.must_equal(true)) -end + it 'won should return true if player has over 100 points' do + player = Scrabble::Player.new("Lauren5") + player.play("knitting") + player.play("oooooo") + player.play("kitsch") + player.play("zz") + expect(player.won?.must_equal(true)) + end -it 'won should return false if player has less than 100 points' do - player = Scrabble::Player.new("Lauren5") - player.play("knitting") - player.play("oooooo") - player.play("kitsch") - expect(player.won?.must_equal(false)) -end + it 'won should return false if player has less than 100 points' do + player = Scrabble::Player.new("Lauren5") + player.play("knitting") + player.play("oooooo") + player.play("kitsch") + expect(player.won?.must_equal(false)) + end end#end of test From 8116f35288319a79ce20b8ee926e1a6f0cd8b682 Mon Sep 17 00:00:00 2001 From: Sabrina Wilbert Date: Wed, 31 Aug 2016 16:57:46 -0700 Subject: [PATCH 22/31] Added Tilebag class --- lib/tilebag.rb | 6 ++++++ specs/tilebag_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 lib/tilebag.rb create mode 100644 specs/tilebag_spec.rb diff --git a/lib/tilebag.rb b/lib/tilebag.rb new file mode 100644 index 00000000..968ab216 --- /dev/null +++ b/lib/tilebag.rb @@ -0,0 +1,6 @@ +require_relative '../scrabble.rb' +require_relative 'scrabble_scoring.rb' +require_relative 'scrabble_player.rb' + +class Scrabble::Tilebag +end diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb new file mode 100644 index 00000000..dac68f40 --- /dev/null +++ b/specs/tilebag_spec.rb @@ -0,0 +1,25 @@ +require_relative 'spec_helper' +require_relative '../scrabble' # this is the module file +require_relative '../lib/scrabble_scoring' +require_relative '../lib/scrabble_player' +require_relative '../lib/tilebag' + +describe 'testing tilebag class' do + + it 'testing that tilebag exist' do + expect(Scrabble::Tilebag.must_be_instance_of(Class)) + end + + it 'Must return correct key value pair of letter and number of letters' do + expect(Scrabble::LETTER_HASH[:A]).must_equal(9) + expect(Scrabble::LETTER_HASH[:D]).must_equal(4) + expect(Scrabble::LETTER_HASH[:B]).must_equal(2) + expect(Scrabble::LETTER_HASH[:F]).must_equal(2) + expect(Scrabble::LETTER_HASH[:K]).must_equal(1) + expect(Scrabble::LETTER_HASH[:X]).must_equal(1) + expect(Scrabble::LETTER_HASH[:Q]).must_equal(1) + end + + + +end#end of spec From 6cb9ec5a2faa5c544dd6f58f18720b9a8e492f58 Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Thu, 1 Sep 2016 14:04:02 -0700 Subject: [PATCH 23/31] added LETTER_ARRAY constant --- scrabble.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/scrabble.rb b/scrabble.rb index 2169c044..124d9460 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,7 +1,35 @@ + module Scrabble SCORE_HASH = {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} + + LETTER_ARRAY = [["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"]] end From bd1ddb06effa20d0289e0af1ecf69efb739f887d Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Thu, 1 Sep 2016 14:14:33 -0700 Subject: [PATCH 24/31] added and passing tests for LETTER_ARRAY constant --- specs/tilebag_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb index dac68f40..3e3093e3 100644 --- a/specs/tilebag_spec.rb +++ b/specs/tilebag_spec.rb @@ -10,16 +10,16 @@ expect(Scrabble::Tilebag.must_be_instance_of(Class)) end - it 'Must return correct key value pair of letter and number of letters' do - expect(Scrabble::LETTER_HASH[:A]).must_equal(9) - expect(Scrabble::LETTER_HASH[:D]).must_equal(4) - expect(Scrabble::LETTER_HASH[:B]).must_equal(2) - expect(Scrabble::LETTER_HASH[:F]).must_equal(2) - expect(Scrabble::LETTER_HASH[:K]).must_equal(1) - expect(Scrabble::LETTER_HASH[:X]).must_equal(1) - expect(Scrabble::LETTER_HASH[:Q]).must_equal(1) + it 'LETTER_ARRAY constant Must return correct letter and number of letters remaining' do + expect(Scrabble::LETTER_ARRAY.rassoc("A").length.must_equal(9)) + # expect(Scrabble::LETTER_ARRAY[:D]).must_equal(4) + # expect(Scrabble::LETTER_ARRAY[:B]).must_equal(2) + # expect(Scrabble::LETTER_ARRAY[:F]).must_equal(2) + # expect(Scrabble::LETTER_ARRAY[:K]).must_equal(1) + # expect(Scrabble::LETTER_ARRAY[:X]).must_equal(1) + # expect(Scrabble::LETTER_ARRAY[:Q]).must_equal(1) end -end#end of spec +end #end of describe From bc59de77c29bcd04dc4a2e7689245c116711785c Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Thu, 1 Sep 2016 14:34:49 -0700 Subject: [PATCH 25/31] added test for Tilebag and empty initialize method --- lib/tilebag.rb | 5 +++++ specs/tilebag_spec.rb | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 968ab216..814761e7 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -3,4 +3,9 @@ require_relative 'scrabble_player.rb' class Scrabble::Tilebag + + def initialize + + end + end diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb index 3e3093e3..217e1c9b 100644 --- a/specs/tilebag_spec.rb +++ b/specs/tilebag_spec.rb @@ -6,20 +6,21 @@ describe 'testing tilebag class' do - it 'testing that tilebag exist' do + it 'testing that Tilebag exists' do expect(Scrabble::Tilebag.must_be_instance_of(Class)) end - it 'LETTER_ARRAY constant Must return correct letter and number of letters remaining' do - expect(Scrabble::LETTER_ARRAY.rassoc("A").length.must_equal(9)) - # expect(Scrabble::LETTER_ARRAY[:D]).must_equal(4) - # expect(Scrabble::LETTER_ARRAY[:B]).must_equal(2) - # expect(Scrabble::LETTER_ARRAY[:F]).must_equal(2) - # expect(Scrabble::LETTER_ARRAY[:K]).must_equal(1) - # expect(Scrabble::LETTER_ARRAY[:X]).must_equal(1) - # expect(Scrabble::LETTER_ARRAY[:Q]).must_equal(1) + it 'LETTER_ARRAY constant must return number of letters remaining for a given letter' do + expect(Scrabble::LETTER_ARRAY.assoc("A").length.must_equal(9)) + expect(Scrabble::LETTER_ARRAY.assoc("E").length.must_equal(12)) + expect(Scrabble::LETTER_ARRAY.assoc("J").length.must_equal(1)) + expect(Scrabble::LETTER_ARRAY.assoc("L").length.must_equal(4)) end + it 'new instance of Tilebag should have a @tiles instance variable that is equivalent to the LETTER_ARRAY constant' do + bag = Tilebag.new + expect(bag.must_equal(Scrabble::LETTER_ARRAY)) + end end #end of describe From 365fd790560898980a859f5d0eaa50323ceb524d Mon Sep 17 00:00:00 2001 From: Sabrina Wilbert Date: Thu, 1 Sep 2016 15:11:25 -0700 Subject: [PATCH 26/31] Added draw tile method --- lib/tilebag.rb | 13 ++++++++++++- specs/tilebag_spec.rb | 19 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 814761e7..37a47d8f 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -3,9 +3,20 @@ require_relative 'scrabble_player.rb' class Scrabble::Tilebag +attr_reader :tiles def initialize + @tiles = Scrabble::LETTER_ARRAY + + end + + def draw_tiles(num) + rack = [] + rack << @tiles.flatten.sample(num) + return rack end - end + +joe = Scrabble::Tilebag.new +print joe.draw_tiles(7) diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb index 217e1c9b..a54bf2e0 100644 --- a/specs/tilebag_spec.rb +++ b/specs/tilebag_spec.rb @@ -19,8 +19,23 @@ it 'new instance of Tilebag should have a @tiles instance variable that is equivalent to the LETTER_ARRAY constant' do - bag = Tilebag.new - expect(bag.must_equal(Scrabble::LETTER_ARRAY)) + bag = Scrabble::Tilebag.new + expect(bag.tiles.must_equal(Scrabble::LETTER_ARRAY)) end + it 'draw_tiles must return number of random tiles in parameter' do + bag = Scrabble::Tilebag.new + expect(bag.draw_tiles(4).length.must_equal(4)) + end + + it 'draw_tiles must remove the tiles chosen from @tiles' do + bag = Scrabble::Tilebag.new + bag.draw_tiles(4) + expect(@tiles).flatten.length.must_equal(94) + end + + it 'draw_tiles must return an array' do + end + + end #end of describe From 06a02ee199f1ee500bd9332ea5c1ff371c894c56 Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Thu, 1 Sep 2016 16:05:26 -0700 Subject: [PATCH 27/31] a whole bunch of stuff --- lib/scrabble_scoring.rb | 4 ++-- lib/tilebag.rb | 36 ++++++++++++++++++++++++++++++------ specs/tilebag_spec.rb | 35 +++++++++++++++++++++++------------ 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index 7971f2d5..1ffe4868 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -105,5 +105,5 @@ def self.find_winner_non7(tie_array) end # end of Scoring class - -puts Scrabble::Scoring.tiebreaker(["sabrina", "knitting"]) +# +# puts Scrabble::Scoring.tiebreaker(["sabrina", "knitting"]) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 37a47d8f..b079a513 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -1,22 +1,46 @@ require_relative '../scrabble.rb' require_relative 'scrabble_scoring.rb' require_relative 'scrabble_player.rb' +require 'awesome_print' class Scrabble::Tilebag attr_reader :tiles def initialize + @tiles = clone_constant + end - @tiles = Scrabble::LETTER_ARRAY - + def clone_constant + clone_array = [] + Scrabble::LETTER_ARRAY.each do |small_array| + clone_array << small_array.clone + end + return clone_array end def draw_tiles(num) - rack = [] - rack << @tiles.flatten.sample(num) + rack = @tiles.flatten.sample(num) + + # for each drawn letter in rack, this finds the letter's array in @tiles, + # and pops it off the end of that mini-array + rack.each do |letter| + @tiles.assoc(letter).pop + end + return rack end end - +# joe = Scrabble::Tilebag.new -print joe.draw_tiles(7) + +# rack = joe.draw_tiles(7) +# ap rack +# joe.tiles.each do |small_array| +# puts small_array.length +# end +# puts Scrabble::LETTER_ARRAY.length +# # puts "****************" +# # ap joe.tiles.flatten.length +# +# +# # puts rack.length diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb index a54bf2e0..8fd63279 100644 --- a/specs/tilebag_spec.rb +++ b/specs/tilebag_spec.rb @@ -7,10 +7,12 @@ describe 'testing tilebag class' do it 'testing that Tilebag exists' do + # skip expect(Scrabble::Tilebag.must_be_instance_of(Class)) end it 'LETTER_ARRAY constant must return number of letters remaining for a given letter' do + # skip expect(Scrabble::LETTER_ARRAY.assoc("A").length.must_equal(9)) expect(Scrabble::LETTER_ARRAY.assoc("E").length.must_equal(12)) expect(Scrabble::LETTER_ARRAY.assoc("J").length.must_equal(1)) @@ -19,23 +21,32 @@ it 'new instance of Tilebag should have a @tiles instance variable that is equivalent to the LETTER_ARRAY constant' do - bag = Scrabble::Tilebag.new - expect(bag.tiles.must_equal(Scrabble::LETTER_ARRAY)) + # skip + bag_one = Scrabble::Tilebag.new + expect(bag_one.tiles.must_equal(Scrabble::LETTER_ARRAY)) end - it 'draw_tiles must return number of random tiles in parameter' do - bag = Scrabble::Tilebag.new - expect(bag.draw_tiles(4).length.must_equal(4)) + it 'draw_tiles must return number of random tiles in parameter' do + # skip + bag_two = Scrabble::Tilebag.new + rack_two = bag_two.draw_tiles(4) + expect(rack_two.length.must_equal(4)) end - it 'draw_tiles must remove the tiles chosen from @tiles' do - bag = Scrabble::Tilebag.new - bag.draw_tiles(4) - expect(@tiles).flatten.length.must_equal(94) - end + it 'draw_tiles must return an array' do + # skip + bag_three = Scrabble::Tilebag.new + rack_three = bag_three.draw_tiles(4) + expect(rack_three.must_be_instance_of(Array)) + end + + it 'draw_tiles must remove the tiles chosen from @tiles' do + # skip + bag_four = Scrabble::Tilebag.new + bag_four.draw_tiles(4) + expect(bag_four.tiles.flatten.length.must_equal(94)) # total length of tiles initially is 98, so if you draw 4 it should equal 94 + end - it 'draw_tiles must return an array' do - end end #end of describe From ff145d594828296a7766cb086f3207900dc05732 Mon Sep 17 00:00:00 2001 From: Sabrina Wilbert Date: Fri, 2 Sep 2016 10:39:40 -0700 Subject: [PATCH 28/31] Added test for draw_tiles --- lib/tilebag.rb | 7 ++++++- specs/Player_spec.rb | 15 +++++++++++++++ specs/tilebag_spec.rb | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index b079a513..ef435f63 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -29,9 +29,14 @@ def draw_tiles(num) return rack end + + def tiles_remaining + return @tiles.flatten.length + end + end # -joe = Scrabble::Tilebag.new +#joe = Scrabble::Tilebag.new # rack = joe.draw_tiles(7) # ap rack diff --git a/specs/Player_spec.rb b/specs/Player_spec.rb index 05618435..b028d633 100644 --- a/specs/Player_spec.rb +++ b/specs/Player_spec.rb @@ -77,4 +77,19 @@ player.play("kitsch") expect(player.won?.must_equal(false)) end + + it 'player_draw_tiles()fills tiles array until player has 7 letters from the given tile bag' do + player = Scrabble::Player.new("Lauren6") + bag_six = Scrabble::Tilebag.new + player.player_draw_tiles(bag_six) + expect(player.tiles.length.must_equal(7)) + expect(bag_six.tiles_remaining.must_equal(91)) + end + it 'tiles method must return a collection of letters that the player can play (max 7)' do + player = Scrabble::Player.new("Lauren7") + bag_seven = Scrabble::Tilebag.new + player.player_draw_tiles(bag_seven) + expect(player.tiles.length.must_equal(7)) + end + end#end of test diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb index 8fd63279..ec45a4a7 100644 --- a/specs/tilebag_spec.rb +++ b/specs/tilebag_spec.rb @@ -47,6 +47,14 @@ expect(bag_four.tiles.flatten.length.must_equal(94)) # total length of tiles initially is 98, so if you draw 4 it should equal 94 end + it 'tiles_remaining must return the number of tiles remaining in the bag after a draw' do + bag_five = Scrabble::Tilebag.new + bag_five.draw_tiles(6) + expect(bag_five.tiles_remaining.must_equal(92)) + bag_five.draw_tiles(7) + expect(bag_five.tiles_remaining.must_equal(85)) + + end end #end of describe From 4355b229668be8d8a86c9949c89928e148a44f2e Mon Sep 17 00:00:00 2001 From: Lauren Brink Date: Fri, 2 Sep 2016 11:23:57 -0700 Subject: [PATCH 29/31] finished wave 3, with a slight complication --- lib/Scrabble_Player.rb | 30 ++++++++++++++++++++++++++++-- lib/scrabble_scoring.rb | 4 ++-- lib/tilebag.rb | 5 +---- scrabble.rb | 10 ++++++++++ specs/Player_spec.rb | 3 ++- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/lib/Scrabble_Player.rb b/lib/Scrabble_Player.rb index 159b0427..d0fb854c 100644 --- a/lib/Scrabble_Player.rb +++ b/lib/Scrabble_Player.rb @@ -1,5 +1,5 @@ -require_relative '../scrabble.rb' -require_relative 'scrabble_scoring.rb' +require_relative '../scrabble' + class Scrabble::Player attr_reader :name, :plays @@ -10,6 +10,7 @@ def initialize(name) @name = name @plays = [] + @player_tiles = [] # now this is empty but later when we are more advanced we will initialize it with 7 tiles. end # allows the player to plays a word as long as they have not already won @@ -53,4 +54,29 @@ def won? end end + + def tiles + return @player_tiles + end + + def player_draw_tiles(tile_bag) + puts "#{@player_tiles} <---- this is before hand" + + @player_tiles << tile_bag.draw_tiles(number_to_draw) + puts "#{@player_tiles} <---- this is after the tiles are drawn" + + return @player_tiles.flatten! + end + + def number_to_draw + number_to_draw = Scrabble::MAX_TILES - @player_tiles.length + return number_to_draw + end + end # end of class + + +player = Scrabble::Player.new("Lauren7") +bag_seven = Scrabble::Tilebag.new + +player.player_draw_tiles(bag_seven) diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index 1ffe4868..181a7fa5 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -1,4 +1,4 @@ -require_relative '../scrabble.rb' +require_relative '../scrabble' class Scrabble::Scoring @@ -105,5 +105,5 @@ def self.find_winner_non7(tie_array) end # end of Scoring class -# +# # puts Scrabble::Scoring.tiebreaker(["sabrina", "knitting"]) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index ef435f63..fe591584 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -1,7 +1,4 @@ -require_relative '../scrabble.rb' -require_relative 'scrabble_scoring.rb' -require_relative 'scrabble_player.rb' -require 'awesome_print' +require_relative '../scrabble' class Scrabble::Tilebag attr_reader :tiles diff --git a/scrabble.rb b/scrabble.rb index 124d9460..4a1409d0 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,3 +1,8 @@ +require_relative './lib/crabble_scoring' +require_relative './lib/Scrabble_Player' +require_relative './lib/tilebag' +require 'awesome_print' + module Scrabble @@ -32,4 +37,9 @@ module Scrabble ["X"], ["Y", "Y"], ["Z"]] + + + MAX_TILES = 7 + + MAX_IN_BAG = LETTER_ARRAY.flatten.length end diff --git a/specs/Player_spec.rb b/specs/Player_spec.rb index b028d633..c9a1fc58 100644 --- a/specs/Player_spec.rb +++ b/specs/Player_spec.rb @@ -85,11 +85,12 @@ expect(player.tiles.length.must_equal(7)) expect(bag_six.tiles_remaining.must_equal(91)) end + it 'tiles method must return a collection of letters that the player can play (max 7)' do player = Scrabble::Player.new("Lauren7") bag_seven = Scrabble::Tilebag.new player.player_draw_tiles(bag_seven) expect(player.tiles.length.must_equal(7)) end - + end#end of test From 1d4f31da1ef1992becdca2926d0fd57af9ba23b4 Mon Sep 17 00:00:00 2001 From: Sabrina Wilbert Date: Fri, 2 Sep 2016 13:39:31 -0700 Subject: [PATCH 30/31] Added instance variables to Player class --- lib/Scrabble_Player.rb | 5 ++-- lib/scrabble_scoring.rb | 1 + lib/tie.rb | 66 ----------------------------------------- scrabble.rb | 6 ++-- specs/Player_spec.rb | 6 ++-- specs/scrabble_spec.rb | 2 +- specs/tilebag_spec.rb | 2 -- 7 files changed, 11 insertions(+), 77 deletions(-) delete mode 100644 lib/tie.rb diff --git a/lib/Scrabble_Player.rb b/lib/Scrabble_Player.rb index d0fb854c..e180245a 100644 --- a/lib/Scrabble_Player.rb +++ b/lib/Scrabble_Player.rb @@ -1,4 +1,5 @@ require_relative '../scrabble' +require_relative '../lib/tilebag' class Scrabble::Player @@ -60,10 +61,10 @@ def tiles end def player_draw_tiles(tile_bag) - puts "#{@player_tiles} <---- this is before hand" + # puts "#{@player_tiles} <---- this is before hand" @player_tiles << tile_bag.draw_tiles(number_to_draw) - puts "#{@player_tiles} <---- this is after the tiles are drawn" + # puts "#{@player_tiles} <---- this is after the tiles are drawn" return @player_tiles.flatten! end diff --git a/lib/scrabble_scoring.rb b/lib/scrabble_scoring.rb index 181a7fa5..087eec6c 100644 --- a/lib/scrabble_scoring.rb +++ b/lib/scrabble_scoring.rb @@ -1,5 +1,6 @@ require_relative '../scrabble' + class Scrabble::Scoring def self.score(word) diff --git a/lib/tie.rb b/lib/tie.rb deleted file mode 100644 index 6d468f8d..00000000 --- a/lib/tie.rb +++ /dev/null @@ -1,66 +0,0 @@ -require_relative '../scrabble.rb' - -class Scrabble::Scoring - - def self.score(word) - check_input(word) - letter_array = word.upcase.split('') - score = 0 - # this adds 50 if word length is >= 7 by calling bingo. - score += bingo(word) - - # iterate through array and add score - letter_array.each do |letter| - score += Scrabble::SCORE_HASH[letter.to_sym] - end - return score - end - - - def self.bingo(word) - if word.length >= 7 - return 50 - else - return 0 - end - end - - - def self.check_input(word) - raise ArgumentError unless word.class == String - - if word =~ /^[a-zA-Z]+$/ - return word - else - raise ArgumentError - end - end - - def self.highest_score_from(array_of_words) - raise ArgumentError unless array_of_words.class == Array - - word_hash = {} - - array_of_words.each do |element| - word_hash[element] = score(element) - end - - if word_hash.values.length != word_hash.values.uniq.length - tie(word_hash) - else - return word_hash.key(word_hash.values.max) - end - end - - def self.tie(word_hash) - tie_words = [] - word_hash.each { |k, v| tie_words << k if v == word_hash.values.max } - puts "it's a tie!" -return tie_words - end - -end # end of Scoring class - - print Scrabble::Scoring.highest_score_from(["ZZZZ", "cat", "QQQQ"]) -# Scrabble::Scoring.score("CAT") -# Scrabble::Scoring.score("QQQQ") diff --git a/scrabble.rb b/scrabble.rb index 4a1409d0..12bbf0cf 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,6 +1,6 @@ -require_relative './lib/crabble_scoring' -require_relative './lib/Scrabble_Player' -require_relative './lib/tilebag' +#require_relative './lib/Scrabble_scoring' +#require_relative './lib/Scrabble_Player' +#require_relative './lib/tilebag' require 'awesome_print' diff --git a/specs/Player_spec.rb b/specs/Player_spec.rb index c9a1fc58..fba3072c 100644 --- a/specs/Player_spec.rb +++ b/specs/Player_spec.rb @@ -1,7 +1,7 @@ require_relative 'spec_helper' require_relative '../scrabble' # this is the module file -require_relative '../lib/scrabble_scoring' -require_relative '../lib/scrabble_player' +require_relative '../lib/Scrabble_Player' +require_relative '../lib/tilebag' describe 'testing player class' do @@ -85,7 +85,7 @@ expect(player.tiles.length.must_equal(7)) expect(bag_six.tiles_remaining.must_equal(91)) end - + it 'tiles method must return a collection of letters that the player can play (max 7)' do player = Scrabble::Player.new("Lauren7") bag_seven = Scrabble::Tilebag.new diff --git a/specs/scrabble_spec.rb b/specs/scrabble_spec.rb index 370cb1a1..ff3d6b97 100644 --- a/specs/scrabble_spec.rb +++ b/specs/scrabble_spec.rb @@ -1,6 +1,6 @@ require_relative 'spec_helper' require_relative '../scrabble' # this is the module file -require_relative '../lib/scrabble_scoring' +require_relative '../lib/Scrabble_scoring' describe 'testing scoring class' do diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb index ec45a4a7..79284fd8 100644 --- a/specs/tilebag_spec.rb +++ b/specs/tilebag_spec.rb @@ -1,7 +1,5 @@ require_relative 'spec_helper' require_relative '../scrabble' # this is the module file -require_relative '../lib/scrabble_scoring' -require_relative '../lib/scrabble_player' require_relative '../lib/tilebag' describe 'testing tilebag class' do From 5ba0f6bb0cd496e862aa121c670180a8f5ada7d2 Mon Sep 17 00:00:00 2001 From: laurenfb Date: Fri, 16 Sep 2016 10:43:56 -0700 Subject: [PATCH 31/31] added a comment --- scrabble.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scrabble.rb b/scrabble.rb index 12bbf0cf..2859fff3 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,3 +1,5 @@ +# let's add a comment to this to test if github username changing worked! + #require_relative './lib/Scrabble_scoring' #require_relative './lib/Scrabble_Player' #require_relative './lib/tilebag'