From 85baafbb18e63e4c11bfebc36c47f7317d29c4df Mon Sep 17 00:00:00 2001 From: Ana Lisa Sutherland Date: Tue, 20 Feb 2018 15:04:16 -0800 Subject: [PATCH 01/18] Al's starting self.score --- lib/scoring.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/scoring.rb b/lib/scoring.rb index fb3a3f2d..16acb513 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -1,6 +1,46 @@ module Scrabble class Scoring + letter_values = + { + :A => 1, + :E => 1, + :I => 1, + :O => 1, + :U => 1, + :L => 1, + :N => 1, + :R => 1, + :S => 1, + :T => 1, + :D => 2, + :G => 2, + :B => 3, + :C => 3, + :M => 3, + :P => 3, + :F => 4, + :H => 4, + :V => 4, + :W => 4, + :Y => 4, + :K => 5, + :J => 8, + :X => 8, + :Q => 10, + :Z => 10 + } + def self.score(word) + # Split the word into its indvidual letters and store in array + user_word = word.split(//) + # iterate over each letter + user_word.each do |letter| + letter.to_sym + if letter_values.include_key?(letter) + word_total += letter_values[:letter] + end + return word_total + end end def self.highest_score_from(array_of_words) From 890c4a994c1a5fba8e2d3a83d9bb0374883f03ab Mon Sep 17 00:00:00 2001 From: Jamila Date: Tue, 20 Feb 2018 16:09:39 -0800 Subject: [PATCH 02/18] lib/scoring.rb --- lib/scoring.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 16acb513..4e222488 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -1,6 +1,7 @@ +# require 'pry' module Scrabble class Scoring - letter_values = + @letter_values = { :A => 1, :E => 1, @@ -32,17 +33,21 @@ class Scoring def self.score(word) # Split the word into its indvidual letters and store in array - user_word = word.split(//) + user_word = word.upcase.split(//) # iterate over each letter + word_total = 0 + values = [] user_word.each do |letter| - letter.to_sym - if letter_values.include_key?(letter) - word_total += letter_values[:letter] + letter = letter.to_sym + if @letter_values.has_key?(letter) + values << @letter_values[letter] end - return word_total + # binding.pry + return values.sum end end + def self.highest_score_from(array_of_words) end end From b4a90d4a90fc2a9d8c9901322e1c476d5354716a Mon Sep 17 00:00:00 2001 From: Ana Lisa Sutherland Date: Tue, 20 Feb 2018 16:58:20 -0800 Subject: [PATCH 03/18] Invalid Chars done, greater then 7 done, add 50 for seven --- lib/scoring.rb | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 4e222488..6b548839 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -1,7 +1,6 @@ -# require 'pry' module Scrabble class Scoring - @letter_values = + @@letter_values = { :A => 1, :E => 1, @@ -32,18 +31,30 @@ class Scoring } def self.score(word) - # Split the word into its indvidual letters and store in array - user_word = word.upcase.split(//) - # iterate over each letter - word_total = 0 - values = [] - user_word.each do |letter| - letter = letter.to_sym - if @letter_values.has_key?(letter) - values << @letter_values[letter] + # Check word for invalid characters + if !/[^a-zA-Z]+/.match(word) + # Split the word into its indvidual letters and store in array + user_word = word.upcase.split(//) + # Adds 50 points for 7 letter words + word_total = 0 + # checks if word length is equal to seven and adds 50 pts + if user_word.length == 7 + word_total += 50 + elsif + # checks if word length is greater then 7, and returns nil + user_word.length > 7 + return nil end - # binding.pry - return values.sum + # iterate over each letter + user_word.each do |letter| + letter = letter.to_sym + if @@letter_values.has_key?(letter) + word_total += @@letter_values[letter] + end + end + return word_total + else + return nil end end From 6e806fdf9c94273071246a45a0230189a328f55c Mon Sep 17 00:00:00 2001 From: Jamila Date: Wed, 21 Feb 2018 14:37:19 -0800 Subject: [PATCH 04/18] passed first test of highest_score_from method --- lib/scoring.rb | 3 ++- specs/scoring_spec.rb | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 6b548839..0fcd743d 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -42,7 +42,7 @@ def self.score(word) word_total += 50 elsif # checks if word length is greater then 7, and returns nil - user_word.length > 7 + user_word.length > 7 || user_word.length == 0 return nil end # iterate over each letter @@ -60,6 +60,7 @@ def self.score(word) def self.highest_score_from(array_of_words) + end end end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index ab498929..23b5b129 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -42,21 +42,22 @@ describe 'highest_score_from' do it 'returns nil if no words were passed' do + Scrabble::Scoring.highest_score_from('').must_be_nil end - it 'returns the only word in a length-1 array' do + xit 'returns the only word in a length-1 array' do end - it 'returns the highest word if there are two words' do + xit 'returns the highest word if there are two words' do end - it 'if tied, prefer a word with 7 letters' do + xit 'if tied, prefer a word with 7 letters' do end - it 'if tied and no word has 7 letters, prefers the word with fewer letters' do + xit 'if tied and no word has 7 letters, prefers the word with fewer letters' do end - it 'returns the first word of a tie with same letter count' do + xit 'returns the first word of a tie with same letter count' do end end end From 520d5d81b8bf846abbc0dfe18b3a0081cf09e2a1 Mon Sep 17 00:00:00 2001 From: Jamila Date: Wed, 21 Feb 2018 15:06:18 -0800 Subject: [PATCH 05/18] test 1 and two passing for highest_score_from method --- lib/scoring.rb | 15 ++++++++++----- specs/scoring_spec.rb | 4 +++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 0fcd743d..a3d7452a 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -1,6 +1,6 @@ module Scrabble class Scoring - @@letter_values = + LETTER_VALUES = { :A => 1, :E => 1, @@ -41,15 +41,15 @@ def self.score(word) if user_word.length == 7 word_total += 50 elsif - # checks if word length is greater then 7, and returns nil + # checks if word length is greater then 7, and returns nil user_word.length > 7 || user_word.length == 0 return nil end # iterate over each letter user_word.each do |letter| letter = letter.to_sym - if @@letter_values.has_key?(letter) - word_total += @@letter_values[letter] + if LETTER_VALUES.has_key?(letter) + word_total += LETTER_VALUES[letter] end end return word_total @@ -60,7 +60,12 @@ def self.score(word) def self.highest_score_from(array_of_words) - + if array_of_words.length == 0 + return nil + else + return array_of_words[0] + end + end end end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 23b5b129..cf3f0e65 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -45,7 +45,9 @@ Scrabble::Scoring.highest_score_from('').must_be_nil end - xit 'returns the only word in a length-1 array' do + it 'returns the only word in a length-1 array' do + array_of_words = ['far'] + Scrabble::Scoring.highest_score_from(array_of_words).must_equal 'far' end xit 'returns the highest word if there are two words' do From cd3b54312114c5f891e0e38112d049fa450cdfa3 Mon Sep 17 00:00:00 2001 From: Ana Lisa Sutherland Date: Wed, 21 Feb 2018 17:12:33 -0800 Subject: [PATCH 06/18] We have work to do on the 7 tile score, but so far progress --- lib/scoring.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index a3d7452a..3bb1e7ce 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -1,3 +1,4 @@ +require 'pry' module Scrabble class Scoring LETTER_VALUES = @@ -60,12 +61,29 @@ def self.score(word) def self.highest_score_from(array_of_words) + # RETURNS NIL FOR EMPTY ARRAY if array_of_words.length == 0 return nil - else + # RETURNS WORD FROM ARRAY LENGTH 1 + elsif array_of_words.length == 1 return array_of_words[0] + else + scores = [] + array_of_words.each do |word| + scores << Scrabble::Scoring.score(word) + end + highest_score = scores.max + highest_words = [] + array_of_words.each do |word| + if Scrabble::Scoring.score(word) == highest_score + highest_words << word + end + highest_words.sort_by { |word| word.length } + end + # binding.pry + # array_of_words[0] < array_of_words[1] + # return array_of_words[1] end - end end end From 472c4ace589574e124fcca5f400d73388079e2ca Mon Sep 17 00:00:00 2001 From: Ana Lisa Sutherland Date: Thu, 22 Feb 2018 13:03:23 -0800 Subject: [PATCH 07/18] Spec file changes --- lib/scoring.rb | 4 ++-- specs/scoring_spec.rb | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 3bb1e7ce..fd30359c 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -80,8 +80,8 @@ def self.highest_score_from(array_of_words) end highest_words.sort_by { |word| word.length } end - # binding.pry - # array_of_words[0] < array_of_words[1] + + # array_of_words[0] < array_of_words[1] # return array_of_words[1] end end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index cf3f0e65..5acc1f43 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -50,10 +50,14 @@ Scrabble::Scoring.highest_score_from(array_of_words).must_equal 'far' end - xit 'returns the highest word if there are two words' do + it 'returns the highest word if there are two words' do + array_of_words = ['cat', 'zoo'] + Scrabble::Scoring.highest_score_from(array_of_words).must_equal 'zoo' end - xit 'if tied, prefer a word with 7 letters' do + it 'if tied, prefer a word with 7 letters' do + array_of_words = ['dog', 'course', 'lungers'] + Scrabble::Scoring.highest_score_from(array_of_words).must_equal 'lungers' end xit 'if tied and no word has 7 letters, prefers the word with fewer letters' do From 6a5244a67f79fbb5afd0cf84201f427fdd76ec93 Mon Sep 17 00:00:00 2001 From: Jamila Date: Thu, 22 Feb 2018 13:30:16 -0800 Subject: [PATCH 08/18] two test passed for method highest_score_from --- lib/scoring.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index fd30359c..e23d9753 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -74,14 +74,16 @@ def self.highest_score_from(array_of_words) end highest_score = scores.max highest_words = [] + longest_word = nil array_of_words.each do |word| if Scrabble::Scoring.score(word) == highest_score highest_words << word end - highest_words.sort_by { |word| word.length } + # binding.pry + longest_word = highest_words.sort_by { |word| word.length } end - - # array_of_words[0] < array_of_words[1] + return longest_word[0] + # array_of_words[0] < array_of_words[1] # return array_of_words[1] end end From 14a36289851eb7bc6d9631ded75b06b6defc0ca9 Mon Sep 17 00:00:00 2001 From: Jamila Date: Thu, 22 Feb 2018 14:01:06 -0800 Subject: [PATCH 09/18] fixed tie scenarios for method highest_score_from --- lib/scoring.rb | 15 +++++++++++---- specs/scoring_spec.rb | 7 ++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index e23d9753..583a390e 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -80,11 +80,18 @@ def self.highest_score_from(array_of_words) highest_words << word end # binding.pry - longest_word = highest_words.sort_by { |word| word.length } + # sorts through words depending on length + longest_word = highest_words.sort_by do |word| word.length + if word.length == 7 + longest_word = word + return longest_word + # if length is not 7 returns the shortest word + elsif word.length < 7 + longest_word = word + return longest_word + end + end end - return longest_word[0] - # array_of_words[0] < array_of_words[1] - # return array_of_words[1] end end end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 5acc1f43..550cfb76 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -60,7 +60,12 @@ Scrabble::Scoring.highest_score_from(array_of_words).must_equal 'lungers' end - xit 'if tied and no word has 7 letters, prefers the word with fewer letters' do + it 'if tied and no word has 7 letters, prefers the word with fewer letters' do + # arrange + array_of_words = ["jot","ploys","cat"] + # act/assert + Scrabble::Scoring.highest_score_from(array_of_words).must_equal 'jot' + end xit 'returns the first word of a tie with same letter count' do From 98b1f47d283ac1af752228d0452684c4f1fdeb3e Mon Sep 17 00:00:00 2001 From: Jamila Date: Thu, 22 Feb 2018 14:19:07 -0800 Subject: [PATCH 10/18] finished wave one --- lib/scoring.rb | 1 + specs/scoring_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 583a390e..060cbc45 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -88,6 +88,7 @@ def self.highest_score_from(array_of_words) # if length is not 7 returns the shortest word elsif word.length < 7 longest_word = word + binding.pry return longest_word end end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 550cfb76..a3078330 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -62,13 +62,15 @@ it 'if tied and no word has 7 letters, prefers the word with fewer letters' do # arrange - array_of_words = ["jot","ploys","cat"] + array_of_words = ['jot','ploys','cat'] # act/assert Scrabble::Scoring.highest_score_from(array_of_words).must_equal 'jot' end - xit 'returns the first word of a tie with same letter count' do + it 'returns the first word of a tie with same letter count' do + array_of_words = ['jot','jet','ploy'] + Scrabble::Scoring.highest_score_from(array_of_words).must_equal 'jot' end end end From 339816726bffb0c5f9d5023b7237ea83f4c50003 Mon Sep 17 00:00:00 2001 From: Ana Lisa Sutherland Date: Thu, 22 Feb 2018 16:33:09 -0800 Subject: [PATCH 11/18] Started Player Class, and passed tests for name and plays --- lib/player.rb | 13 ++++++++ lib/scoring.rb | 1 - specs/player_spec.rb | 76 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 lib/player.rb create mode 100644 specs/player_spec.rb diff --git a/lib/player.rb b/lib/player.rb new file mode 100644 index 00000000..3181d091 --- /dev/null +++ b/lib/player.rb @@ -0,0 +1,13 @@ +module Scrabble + class Player + @name = name + + def name (name) + return name + end + + def plays (played_words) + return played_words + end + end +end diff --git a/lib/scoring.rb b/lib/scoring.rb index 060cbc45..583a390e 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -88,7 +88,6 @@ def self.highest_score_from(array_of_words) # if length is not 7 returns the shortest word elsif word.length < 7 longest_word = word - binding.pry return longest_word end end diff --git a/specs/player_spec.rb b/specs/player_spec.rb new file mode 100644 index 00000000..06eb9282 --- /dev/null +++ b/specs/player_spec.rb @@ -0,0 +1,76 @@ +require 'minitest/autorun' +require 'minitest/reporters' +require 'minitest/skip_dsl' + +require_relative '../lib/player' + + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new + + +describe 'Player' do + describe 'name' do + it 'can return a name' do + #Arrange + name = 'Gordon' + #Act/Assert + Scrabble::Player.new.name(name).must_equal 'Gordon' + end + + xit '' do + + end + end + + describe 'play' do + it 'it can return an array' do + played_words = [] + Scrabble::Player.new.plays(played_words).must_be_instance_of Array + end + + xit '' do + + end + end + + xdescribe 'play(word)' do + # Feedback mentions testing edge cases for this method + xit '' do + + end + + xit '' do + + end + end + + xdescribe 'total_score' do + xit '' do + + end + + xit '' do + + end + end + + xdescribe 'won?' do + xit '' do + + end + + xit '' do + + end + end + + xdescribe 'highest_scoring_word' do + xit '' do + + end + + xit '' do + + end + end +end From 6d9038b15e83cbe6306add5b62f2819a91c7fb64 Mon Sep 17 00:00:00 2001 From: Jamila Date: Fri, 23 Feb 2018 14:22:00 -0800 Subject: [PATCH 12/18] tests refactor --- lib/player.rb | 9 ++++----- specs/player_spec.rb | 5 ++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 3181d091..990006be 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,12 +1,11 @@ module Scrabble class Player - @name = name - - def name (name) - return name + def initialize(name) + @name = name + @played_words = [] end - def plays (played_words) + def plays(played_words) return played_words end end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index 06eb9282..591e134d 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -14,7 +14,7 @@ #Arrange name = 'Gordon' #Act/Assert - Scrabble::Player.new.name(name).must_equal 'Gordon' + Scrabble::Player.new.name.must_equal 'Gordon' end xit '' do @@ -24,8 +24,7 @@ describe 'play' do it 'it can return an array' do - played_words = [] - Scrabble::Player.new.plays(played_words).must_be_instance_of Array + Scrabble::Player.new.plays(@played_words).must_be_instance_of Array end xit '' do From 12d5110325040d6831e236badb268aa95bddbea4 Mon Sep 17 00:00:00 2001 From: Ana Lisa Sutherland Date: Fri, 23 Feb 2018 14:51:03 -0800 Subject: [PATCH 13/18] Created Play Test --- lib/player.rb | 9 +++++---- specs/player_spec.rb | 30 ++++++++++++++++++------------ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 990006be..963b9e7c 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,12 +1,13 @@ module Scrabble class Player - def initialize(name) - @name = name + attr_reader :name + def initialize(player_name) + @name = player_name @played_words = [] end - def plays(played_words) - return played_words + def plays + return @played_words end end end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index 591e134d..79dc2b3a 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -14,31 +14,37 @@ #Arrange name = 'Gordon' #Act/Assert - Scrabble::Player.new.name.must_equal 'Gordon' + Scrabble::Player.new(name).name.must_equal 'Gordon' end - xit '' do - - end + # xit '' do + # + # end end - describe 'play' do + describe 'plays' do it 'it can return an array' do - Scrabble::Player.new.plays(@played_words).must_be_instance_of Array + Scrabble::Player.new('').plays.must_be_instance_of Array end - xit '' do - - end + # xit '' do + # + # end end - xdescribe 'play(word)' do + describe 'play(word)' do # Feedback mentions testing edge cases for this method - xit '' do + it 'takes word and adds it to the plays array' do + word = 'batshit' + @played_words = [] + Scrabble::Player.new('').play(word).must_include 'batshit' + end + + xit 'returns false if player has already won' do end - xit '' do + xit 'returns score of the word' do end end From 23d2d560394cc5702e3449247b39cf620e33b92c Mon Sep 17 00:00:00 2001 From: Jamila Date: Fri, 23 Feb 2018 15:24:17 -0800 Subject: [PATCH 14/18] created two more play tests and empty won method --- lib/player.rb | 14 ++++++++++++++ specs/player_spec.rb | 12 ++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 963b9e7c..5abd8ca6 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -9,5 +9,19 @@ def initialize(player_name) def plays return @played_words end + def play(word) + @played_words << word + if @name.won? + return false + else + return Scrabble::Scoring.score(word) + end + return word + + end + + def won? + + end end end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index 79dc2b3a..bc53c08d 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -40,11 +40,19 @@ Scrabble::Player.new('').play(word).must_include 'batshit' end - xit 'returns false if player has already won' do + it 'returns false if player has already won' do + Scrabble::Player.new('').won?.must_equal false end - xit 'returns score of the word' do + it 'returns score of the word' do + word = "guano" + Scrabble::Player.new('').play(word) + + Scrabble::Scoring.score(word).must_equal 7 + + # Scrabble::Player.new('').play(word).score(word).must_equal 7 + end end From 8773008a35f01b6d69de1116989a535a6d6280e8 Mon Sep 17 00:00:00 2001 From: Ana Lisa Sutherland Date: Fri, 23 Feb 2018 15:55:16 -0800 Subject: [PATCH 15/18] Wrote Tests For Won/No Code/Tests Currently Not Passing --- lib/player.rb | 3 +-- lib/scoring.rb | 2 ++ specs/player_spec.rb | 9 ++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 5abd8ca6..f1d072f4 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -17,10 +17,9 @@ def play(word) return Scrabble::Scoring.score(word) end return word - end - def won? + def won?(total_score) end end diff --git a/lib/scoring.rb b/lib/scoring.rb index 583a390e..6045a4bb 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -92,6 +92,8 @@ def self.highest_score_from(array_of_words) end end end + return scores + total_score = scores.inject(0, :+) end end end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index bc53c08d..d994baa2 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -52,8 +52,6 @@ Scrabble::Scoring.score(word).must_equal 7 # Scrabble::Player.new('').play(word).score(word).must_equal 7 - - end end @@ -67,9 +65,10 @@ end end - xdescribe 'won?' do - xit '' do - + describe 'won?' do + it 'if player has > 100 point score, return true' do + total_score = 101 + Scrabble::Player.new('').won?(total_score).must_equal true end xit '' do From e2a6ec73f764ab40343bd84e5434a74c19ddc578 Mon Sep 17 00:00:00 2001 From: Jamila Date: Sat, 24 Feb 2018 11:44:26 -0800 Subject: [PATCH 16/18] refactored play method and test, still needs work --- lib/player.rb | 24 ++++++++++++++++++++---- specs/player_spec.rb | 19 +++++++++++++------ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index f1d072f4..6440d0e9 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,6 +1,6 @@ module Scrabble class Player - attr_reader :name + attr_reader :name, :played_words def initialize(player_name) @name = player_name @played_words = [] @@ -9,17 +9,33 @@ def initialize(player_name) def plays return @played_words end + def play(word) @played_words << word - if @name.won? + + if won return false else return Scrabble::Scoring.score(word) + + end + end + # calculates the score of all the words + def total_score + word_scores = @played_words.map do |word| + Scrabble::Scoring.score(word) end - return word + return word_scores.inject(:+) end - def won?(total_score) + def won + if total_score > 100 + return true + else + return false + + end + end end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index d994baa2..63807bbe 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -35,13 +35,20 @@ describe 'play(word)' do # Feedback mentions testing edge cases for this method it 'takes word and adds it to the plays array' do + # arrange word = 'batshit' - @played_words = [] - Scrabble::Player.new('').play(word).must_include 'batshit' + player = Scrabble::Player.new('') + + # Act + player.play(word) + + # Assert + player.plays[0].must_equal 'batshit' end it 'returns false if player has already won' do - Scrabble::Player.new('').won?.must_equal false + word_1 = "crazy" + Scrabble::Player.new('').play(word_1).must_equal false end @@ -49,7 +56,7 @@ word = "guano" Scrabble::Player.new('').play(word) - Scrabble::Scoring.score(word).must_equal 7 + Scrabble::Scoring.score(word).must_equal 6 # Scrabble::Player.new('').play(word).score(word).must_equal 7 end @@ -67,8 +74,8 @@ describe 'won?' do it 'if player has > 100 point score, return true' do - total_score = 101 - Scrabble::Player.new('').won?(total_score).must_equal true + + Scrabble::Player.new('').won.must_equal true end xit '' do From a41ad3cab480e225a3281fb721a724ab736f2139 Mon Sep 17 00:00:00 2001 From: Jamila Date: Sat, 24 Feb 2018 14:41:48 -0800 Subject: [PATCH 17/18] play method working --- lib/player.rb | 6 ++++- specs/player_spec.rb | 62 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 6440d0e9..d1c8db55 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,3 +1,4 @@ +# require 'pry' module Scrabble class Player attr_reader :name, :played_words @@ -23,7 +24,10 @@ def play(word) # calculates the score of all the words def total_score word_scores = @played_words.map do |word| - Scrabble::Scoring.score(word) + Scrabble::Scoring.score(word) + end + if word_scores.include?(nil) + # binding.pry end return word_scores.inject(:+) end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index 63807bbe..bf1097a3 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -24,7 +24,8 @@ describe 'plays' do it 'it can return an array' do - Scrabble::Player.new('').plays.must_be_instance_of Array + player = Scrabble::Player.new('') + player.plays.must_be_instance_of Array end # xit '' do @@ -41,14 +42,28 @@ # Act player.play(word) - + # Assert - player.plays[0].must_equal 'batshit' + player.plays.must_include 'batshit' end it 'returns false if player has already won' do - word_1 = "crazy" - Scrabble::Player.new('').play(word_1).must_equal false + # Arrange + word = "crazy" + word_1 = 'janky' + word_2 = 'coding' + word_3 = 'dancing' + word_4 = 'hah' + player = Scrabble::Player.new('') + + # Act + player.play(word) + player.play(word_1) + player.play(word_2) + player.play(word_3) + + # Assert + player.play(word_4).must_equal false end @@ -63,7 +78,26 @@ end xdescribe 'total_score' do - xit '' do + xit 'Returns the sum of scores of played words' do + # Arrange + player = Scrabble::Player.new('') + word = "crazy" + word_1 = 'janky' + word_2 = 'coding' + word_3 = 'dancing' + word_4 = 'hah' + + # Act + player.play(word) + player.play(word_1) + player.play(word_2) + player.play(word_3) + player.plays + player.total_score + + # Assert + player.total_score.must_be Integer + end @@ -74,8 +108,22 @@ describe 'won?' do it 'if player has > 100 point score, return true' do + word = "crazy" + word_1 = 'janky' + word_2 = 'coding' + word_3 = 'dancing' + word_4 = 'hah' + player = Scrabble::Player.new('') - Scrabble::Player.new('').won.must_equal true + # act + player.play(word) + player.play(word_1) + player.play(word_2) + player.play(word_3) + player.total_score + + # Assert + player.won.must_equal true end xit '' do From 2771c577266bec0a457edabe12c3d0dad6587f17 Mon Sep 17 00:00:00 2001 From: Jamila Date: Sat, 24 Feb 2018 21:07:28 -0800 Subject: [PATCH 18/18] highest scoring word test not passing --- lib/player.rb | 13 ++++++++++--- specs/player_spec.rb | 19 +++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index d1c8db55..8280f287 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,4 +1,5 @@ # require 'pry' +require_relative 'scoring' module Scrabble class Player attr_reader :name, :played_words @@ -26,9 +27,10 @@ def total_score word_scores = @played_words.map do |word| Scrabble::Scoring.score(word) end - if word_scores.include?(nil) - # binding.pry - end + # this will allow me to see if something inside a loop is not what I expect + # if word_scores.include?(nil) + # binding.pry + # end return word_scores.inject(:+) end @@ -40,6 +42,11 @@ def won end + def highest_scoring_word + Scrabble::Scoring.highest_score_from(plays) + + end + end end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index bf1097a3..9b964446 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -5,6 +5,7 @@ require_relative '../lib/player' + Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new @@ -131,8 +132,22 @@ end end - xdescribe 'highest_scoring_word' do - xit '' do + describe 'highest_scoring_word' do + it 'Returns highest scoring played_word' do + word = "crazy" + word_1 = 'janky' + # word_2 = 'coding' + word_3 = 'dancing' + # word_4 = 'hah' + player = Scrabble::Player.new('') + + player.play(word) + player.play(word_1) + # player.play(word_2) + player.play(word_3) + + player.highest_scoring_word.must_equal 'dancing' + end