From ad0220f4e29a7c66305e5f7fde178182211c5a70 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Tue, 13 Oct 2015 16:51:13 -0700 Subject: [PATCH 01/14] add lib and spec dir --- lib/scrabble.rb | 7 +++++++ spec/scrabble_spec.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 lib/scrabble.rb create mode 100644 spec/scrabble_spec.rb diff --git a/lib/scrabble.rb b/lib/scrabble.rb new file mode 100644 index 00000000..ed2f4ec4 --- /dev/null +++ b/lib/scrabble.rb @@ -0,0 +1,7 @@ +class Scrabble + def word_score(letter) + if letter == "m" + return 3 + end + end +end diff --git a/spec/scrabble_spec.rb b/spec/scrabble_spec.rb new file mode 100644 index 00000000..e7635e7e --- /dev/null +++ b/spec/scrabble_spec.rb @@ -0,0 +1,16 @@ +require "./lib/scrabble" + +describe Scrabble do + before :each do + @scrabble = Scrabble.new + end + it 'does something' do + expect(@scrabble).to be_an_instance_of Scrabble + end + + describe "#word_score" do + it "scores the letter m" do + expect(@scrabble.word_score("m")).to eq 3 + end + end +end From b2ee3220c215af73379f03ceb510b7bd549d76a3 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Tue, 13 Oct 2015 17:23:48 -0700 Subject: [PATCH 02/14] add word_score method and test --- lib/scrabble.rb | 4 +++- spec/scrabble_spec.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/scrabble.rb b/lib/scrabble.rb index ed2f4ec4..a1e82d99 100644 --- a/lib/scrabble.rb +++ b/lib/scrabble.rb @@ -1,7 +1,9 @@ class Scrabble def word_score(letter) - if letter == "m" + case letter + when "m", "b", "c" return 3 + end end end diff --git a/spec/scrabble_spec.rb b/spec/scrabble_spec.rb index e7635e7e..8f5ba9b9 100644 --- a/spec/scrabble_spec.rb +++ b/spec/scrabble_spec.rb @@ -12,5 +12,13 @@ it "scores the letter m" do expect(@scrabble.word_score("m")).to eq 3 end + + it "scores the letter b" do + expect(@scrabble.word_score("b")).to eq 3 + end + + it "scores the letter c" do + expect(@scrabble.word_score("c")).to eq 3 + end end end From 000feb30acc9ba3af9c3ac6ff193315eeea9b277 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Wed, 14 Oct 2015 11:31:13 -0700 Subject: [PATCH 03/14] separate word score and letter score methods- add spec tests for each --- lib/scrabble.rb | 16 +++++++++++++--- spec/scrabble_spec.rb | 26 ++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/scrabble.rb b/lib/scrabble.rb index a1e82d99..78a99125 100644 --- a/lib/scrabble.rb +++ b/lib/scrabble.rb @@ -1,9 +1,19 @@ class Scrabble - def word_score(letter) + def letter_score(letter) case letter - when "m", "b", "c" + when "a" #E, I, O, U, L, N, R, S, T + return 1 + when "m", "b", "c", "p" return 3 - end end + #SCORE = 0 + def word_score(word) + score = 0 + word.split("").each do |letter| + letter = letter_score(letter) + score += letter + end + return score + end end diff --git a/spec/scrabble_spec.rb b/spec/scrabble_spec.rb index 8f5ba9b9..e9cf30b5 100644 --- a/spec/scrabble_spec.rb +++ b/spec/scrabble_spec.rb @@ -8,17 +8,35 @@ expect(@scrabble).to be_an_instance_of Scrabble end - describe "#word_score" do + describe "#letter_score" do + it "scores the letter a" do + expect(@scrabble.letter_score("a")).to eq 1 + end + + #it "scores the letter e" do + # expect(@scrabble.letter_score("e")).to eq 1 + #end + it "scores the letter m" do - expect(@scrabble.word_score("m")).to eq 3 + expect(@scrabble.letter_score("m")).to eq 3 end it "scores the letter b" do - expect(@scrabble.word_score("b")).to eq 3 + expect(@scrabble.letter_score("b")).to eq 3 end it "scores the letter c" do - expect(@scrabble.word_score("c")).to eq 3 + expect(@scrabble.letter_score("c")).to eq 3 + end + + it "scores the letter p" do + expect(@scrabble.letter_score("p")).to eq 3 + end + end + + describe "#word_score" do + it "iterates through letters and changes them to integers" do + expect(@scrabble.word_score("m" "a")).to eq 4 end end end From 30ae6debd8fbef9cd00515d2cdc8b2d594a4c7f5 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Wed, 14 Oct 2015 11:49:12 -0700 Subject: [PATCH 04/14] made case insensitive --- lib/scrabble.rb | 14 ++++++++++++-- spec/scrabble_spec.rb | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/scrabble.rb b/lib/scrabble.rb index 78a99125..2fed9120 100644 --- a/lib/scrabble.rb +++ b/lib/scrabble.rb @@ -1,10 +1,20 @@ class Scrabble def letter_score(letter) - case letter - when "a" #E, I, O, U, L, N, R, S, T + case letter.downcase + when "a", "e", "i", "o", "u", "l", "n", "r", "s", "t" return 1 + when "d", "g" + return 2 when "m", "b", "c", "p" return 3 + when "f", "h", "v", "w", "y" + return 4 + when "k" + return 5 + when "j", "x" + return 8 + when "q", "z" + return 10 end end #SCORE = 0 diff --git a/spec/scrabble_spec.rb b/spec/scrabble_spec.rb index e9cf30b5..61b45d88 100644 --- a/spec/scrabble_spec.rb +++ b/spec/scrabble_spec.rb @@ -36,7 +36,7 @@ describe "#word_score" do it "iterates through letters and changes them to integers" do - expect(@scrabble.word_score("m" "a")).to eq 4 + expect(@scrabble.word_score("MONEY")).to eq 10 end end end From 361e455c63aed235d14bd3be0edcf5881cf2cf64 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Wed, 14 Oct 2015 14:43:52 -0700 Subject: [PATCH 05/14] add code to score multiple words --- lib/scrabble.rb | 18 ++++++++++++++++++ spec/scrabble_spec.rb | 8 +++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/scrabble.rb b/lib/scrabble.rb index 2fed9120..ed977b65 100644 --- a/lib/scrabble.rb +++ b/lib/scrabble.rb @@ -15,6 +15,8 @@ def letter_score(letter) return 8 when "q", "z" return 10 + else + return 0 end end #SCORE = 0 @@ -26,4 +28,20 @@ def word_score(word) end return score end + + def highest_word_score(word_list) + score_array = [] + word_array = [] + word_list.split(",").each do |palabra| + word_array.push(palabra) + word_total = word_score(palabra) + score_array.push(word_total) + end + combo_array = word_array.map.with_index { |e,i| e + score_array.to_s[i] } + return combo_array.sort + + end end + #we'll have an array of possible words we can play + # we want this method to go through each one and score them + # then compare each score and pick the highest diff --git a/spec/scrabble_spec.rb b/spec/scrabble_spec.rb index 61b45d88..9b665ed2 100644 --- a/spec/scrabble_spec.rb +++ b/spec/scrabble_spec.rb @@ -36,7 +36,13 @@ describe "#word_score" do it "iterates through letters and changes them to integers" do - expect(@scrabble.word_score("MONEY")).to eq 10 + expect(@scrabble.word_score("Me")).to eq 4 + end + end + + describe "#highest_word_score" do + it "scores each word both arrays to be paried together" do + expect(@scrabble.highest_word_score("will")).to eq "4w i1 l1 l1" end end end From 403e782fdf03731ba4c400e2e38ab821e5595121 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Wed, 14 Oct 2015 15:21:48 -0700 Subject: [PATCH 06/14] add working code to find highest scoring word --- lib/scrabble.rb | 9 +++++++-- spec/scrabble_spec.rb | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/scrabble.rb b/lib/scrabble.rb index ed977b65..ce00bf44 100644 --- a/lib/scrabble.rb +++ b/lib/scrabble.rb @@ -37,8 +37,13 @@ def highest_word_score(word_list) word_total = word_score(palabra) score_array.push(word_total) end - combo_array = word_array.map.with_index { |e,i| e + score_array.to_s[i] } - return combo_array.sort + #return score_array + index_loc = score_array.each_with_index.max[1] + return word_array[index_loc] + return score_array + #call that index on word_array + #combo_array = score_array.zip(word_array).map(&:join)#.map.with_index { |e,i| e + score_array.to_s[i] } + #return score_array.sort_by{|s| s[1]} end end diff --git a/spec/scrabble_spec.rb b/spec/scrabble_spec.rb index 9b665ed2..1cbf4bb6 100644 --- a/spec/scrabble_spec.rb +++ b/spec/scrabble_spec.rb @@ -41,8 +41,8 @@ end describe "#highest_word_score" do - it "scores each word both arrays to be paried together" do - expect(@scrabble.highest_word_score("will")).to eq "4w i1 l1 l1" + it "call that index on word_array" do + expect(@scrabble.highest_word_score("best, Cain, Harte")).to eq "kitty" end end end From dd875335de21e163f0a0559cf22d4c07380d0f45 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Wed, 14 Oct 2015 17:07:58 -0700 Subject: [PATCH 07/14] add code to find highest scoring word --- lib/scrabble.rb | 28 +++++++++++++--------------- lib/scrabble_scratch.rb | 23 +++++++++++++++++++++++ spec/scrabble_spec.rb | 2 +- 3 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 lib/scrabble_scratch.rb diff --git a/lib/scrabble.rb b/lib/scrabble.rb index ce00bf44..dab4e078 100644 --- a/lib/scrabble.rb +++ b/lib/scrabble.rb @@ -30,23 +30,21 @@ def word_score(word) end def highest_word_score(word_list) - score_array = [] - word_array = [] + scores = {} + word_list.split(",").each do |palabra| - word_array.push(palabra) + #word_array.push(palabra) word_total = word_score(palabra) - score_array.push(word_total) - end - #return score_array - index_loc = score_array.each_with_index.max[1] - return word_array[index_loc] - return score_array - #call that index on word_array - #combo_array = score_array.zip(word_array).map(&:join)#.map.with_index { |e,i| e + score_array.to_s[i] } - #return score_array.sort_by{|s| s[1]} + scores[word_total] ||= [] + scores[word_total] << palabra + end + highest_score = scores.keys.sort[-1] + if scores[highest_score].length > 1 + best_word = scores[highest_score].sort_by { |x| x.length } + puts best_word[0] + else + return scores[highest_score] + end end end - #we'll have an array of possible words we can play - # we want this method to go through each one and score them - # then compare each score and pick the highest diff --git a/lib/scrabble_scratch.rb b/lib/scrabble_scratch.rb new file mode 100644 index 00000000..7c064d79 --- /dev/null +++ b/lib/scrabble_scratch.rb @@ -0,0 +1,23 @@ +def highest_word_score(word_list) + score_array = [] + word_array = [] + tie = [] + + word_list.split(",").each do |palabra| + word_array.push(palabra) + word_total = word_score(palabra) + score_array.push(word_total) + end + + score_array.each do |num| + if num == score_array.sort[-1] + then + s = word_array[num.index] + tie.push(s) + tie.sort_by { |x| x.length } + else + break + end + tie_break = tie.sort_by { |x| x.length } + return + tie_break[0] diff --git a/spec/scrabble_spec.rb b/spec/scrabble_spec.rb index 1cbf4bb6..1ec96a68 100644 --- a/spec/scrabble_spec.rb +++ b/spec/scrabble_spec.rb @@ -42,7 +42,7 @@ describe "#highest_word_score" do it "call that index on word_array" do - expect(@scrabble.highest_word_score("best, Cain, Harte")).to eq "kitty" + expect(@scrabble.highest_word_score("best, Harte")).to eq "kitty" end end end From 7489d88367afca152ec0c24e745971a34f081fad Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Thu, 15 Oct 2015 14:45:26 -0700 Subject: [PATCH 08/14] add Scrabble module --- lib/scrabble.rb | 88 ++++++++++++++++++++++--------------------- spec/scrabble_spec.rb | 4 +- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/lib/scrabble.rb b/lib/scrabble.rb index dab4e078..954c09f6 100644 --- a/lib/scrabble.rb +++ b/lib/scrabble.rb @@ -1,50 +1,52 @@ -class Scrabble - def letter_score(letter) - case letter.downcase - when "a", "e", "i", "o", "u", "l", "n", "r", "s", "t" - return 1 - when "d", "g" - return 2 - when "m", "b", "c", "p" - return 3 - when "f", "h", "v", "w", "y" - return 4 - when "k" - return 5 - when "j", "x" - return 8 - when "q", "z" - return 10 - else - return 0 +module Scrabble + class Scrabble + def letter_score(letter) + case letter.downcase + when "a", "e", "i", "o", "u", "l", "n", "r", "s", "t" + return 1 + when "d", "g" + return 2 + when "m", "b", "c", "p" + return 3 + when "f", "h", "v", "w", "y" + return 4 + when "k" + return 5 + when "j", "x" + return 8 + when "q", "z" + return 10 + else + return 0 + end end - end - #SCORE = 0 - def word_score(word) - score = 0 - word.split("").each do |letter| - letter = letter_score(letter) - score += letter + #SCORE = 0 + def word_score(word) + score = 0 + word.split("").each do |letter| + letter = letter_score(letter) + score += letter + end + return score end - return score - end - def highest_word_score(word_list) - scores = {} + def highest_word_score(word_list) + scores = {} - word_list.split(",").each do |palabra| - #word_array.push(palabra) - word_total = word_score(palabra) - scores[word_total] ||= [] - scores[word_total] << palabra - end + word_list.split(",").each do |palabra| + #word_array.push(palabra) + word_total = word_score(palabra) + scores[word_total] ||= [] + scores[word_total] << palabra + end - highest_score = scores.keys.sort[-1] - if scores[highest_score].length > 1 - best_word = scores[highest_score].sort_by { |x| x.length } - puts best_word[0] - else - return scores[highest_score] + highest_score = scores.keys.sort[-1] + if scores[highest_score].length > 1 + best_word = scores[highest_score].sort_by { |x| x.length } + puts best_word[0] + else + return scores[highest_score] + end end end -end +end diff --git a/spec/scrabble_spec.rb b/spec/scrabble_spec.rb index 1ec96a68..2e5e8aa0 100644 --- a/spec/scrabble_spec.rb +++ b/spec/scrabble_spec.rb @@ -2,9 +2,9 @@ describe Scrabble do before :each do - @scrabble = Scrabble.new + @scrabble = Scrabble::Scrabble.new end - it 'does something' do + it "does something" do expect(@scrabble).to be_an_instance_of Scrabble end From f7251862375934f72a778c03fc3727ef2721356a Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Thu, 15 Oct 2015 14:59:27 -0700 Subject: [PATCH 09/14] remove error in highest_word method --- lib/scrabble.rb | 4 ++-- spec/scrabble_spec.rb | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/scrabble.rb b/lib/scrabble.rb index 954c09f6..8d306ffb 100644 --- a/lib/scrabble.rb +++ b/lib/scrabble.rb @@ -43,10 +43,10 @@ def highest_word_score(word_list) highest_score = scores.keys.sort[-1] if scores[highest_score].length > 1 best_word = scores[highest_score].sort_by { |x| x.length } - puts best_word[0] + best_word[0] else return scores[highest_score] end end end -end +end diff --git a/spec/scrabble_spec.rb b/spec/scrabble_spec.rb index 2e5e8aa0..05b112cf 100644 --- a/spec/scrabble_spec.rb +++ b/spec/scrabble_spec.rb @@ -3,9 +3,7 @@ describe Scrabble do before :each do @scrabble = Scrabble::Scrabble.new - end - it "does something" do - expect(@scrabble).to be_an_instance_of Scrabble + end describe "#letter_score" do @@ -42,7 +40,7 @@ describe "#highest_word_score" do it "call that index on word_array" do - expect(@scrabble.highest_word_score("best, Harte")).to eq "kitty" + expect(@scrabble.highest_word_score("aei, b, e")).to eq "e" end end end From 97b929371a0f05f045dbc3ec79f4da58556c4f51 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Thu, 15 Oct 2015 16:24:07 -0700 Subject: [PATCH 10/14] add player class and player class spec file --- lib/scrabble.rb | 2 +- lib/scrabble_player_class.rb | 22 ++++++++++++++++++++++ spec/scrabble_player_class_spec.rb | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 lib/scrabble_player_class.rb create mode 100644 spec/scrabble_player_class_spec.rb diff --git a/lib/scrabble.rb b/lib/scrabble.rb index 8d306ffb..4d32cc5e 100644 --- a/lib/scrabble.rb +++ b/lib/scrabble.rb @@ -49,4 +49,4 @@ def highest_word_score(word_list) end end end -end +end diff --git a/lib/scrabble_player_class.rb b/lib/scrabble_player_class.rb new file mode 100644 index 00000000..4fe12051 --- /dev/null +++ b/lib/scrabble_player_class.rb @@ -0,0 +1,22 @@ +require "./lib/scrabble" + +class Player < Scrabble::Scrabble + + attr_reader :name, :plays, :total_score + def initialize(name) + @name = name + @plays = [] + @total_score = [] + end + + def play(word) + @plays.push(word) + score = word_score(word) + @total_score.push(score) + return "So far you have played the following words: #{@plays}" + end + +def total_score + word +end +end diff --git a/spec/scrabble_player_class_spec.rb b/spec/scrabble_player_class_spec.rb new file mode 100644 index 00000000..d21fff48 --- /dev/null +++ b/spec/scrabble_player_class_spec.rb @@ -0,0 +1,14 @@ +require "./lib/scrabble_player_class" + +describe Player do + before :each do + @player = Scrabble::Player.new("jill") + + end +end + +describe "returns the @name instance variable" do + it "returns @name" do + expect(@player.name("jill")).to eq "jack" + end +end From 81d9a32be53b8cf3491f34e1d69d0a89024130e8 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Fri, 16 Oct 2015 11:19:39 -0700 Subject: [PATCH 11/14] add total score method and spec --- lib/scrabble_player_class.rb | 26 +++++++++++++++++++------- lib/scrabble_scratch.rb | 23 ----------------------- spec/scrabble_player_class_spec.rb | 27 ++++++++++++++++++++++----- spec/scrabble_spec.rb | 2 +- 4 files changed, 42 insertions(+), 36 deletions(-) delete mode 100644 lib/scrabble_scratch.rb diff --git a/lib/scrabble_player_class.rb b/lib/scrabble_player_class.rb index 4fe12051..76df5996 100644 --- a/lib/scrabble_player_class.rb +++ b/lib/scrabble_player_class.rb @@ -6,17 +6,29 @@ class Player < Scrabble::Scrabble def initialize(name) @name = name @plays = [] - @total_score = [] + #@total_score = total_score end def play(word) @plays.push(word) - score = word_score(word) - @total_score.push(score) - return "So far you have played the following words: #{@plays}" + #score = word_score(word) + #@total_score.push(score) + return @plays end -def total_score - word -end + def total_score + total = 0 + all_words = @plays + all_words.each do |word| + word_score(word) + total += word_score(word) + end + return total + end + + def won? + if total_score > 100 + return true + end + end end diff --git a/lib/scrabble_scratch.rb b/lib/scrabble_scratch.rb deleted file mode 100644 index 7c064d79..00000000 --- a/lib/scrabble_scratch.rb +++ /dev/null @@ -1,23 +0,0 @@ -def highest_word_score(word_list) - score_array = [] - word_array = [] - tie = [] - - word_list.split(",").each do |palabra| - word_array.push(palabra) - word_total = word_score(palabra) - score_array.push(word_total) - end - - score_array.each do |num| - if num == score_array.sort[-1] - then - s = word_array[num.index] - tie.push(s) - tie.sort_by { |x| x.length } - else - break - end - tie_break = tie.sort_by { |x| x.length } - return - tie_break[0] diff --git a/spec/scrabble_player_class_spec.rb b/spec/scrabble_player_class_spec.rb index d21fff48..cb45f30c 100644 --- a/spec/scrabble_player_class_spec.rb +++ b/spec/scrabble_player_class_spec.rb @@ -2,13 +2,30 @@ describe Player do before :each do - @player = Scrabble::Player.new("jill") + @player = Scrabble::Scrabble::Player.new("Jack") + end + + describe "returns the @name instance variable" do + it "returns @name" do + expect(@player.name).to eq "Jack" + end end -end -describe "returns the @name instance variable" do - it "returns @name" do - expect(@player.name("jill")).to eq "jack" + describe "shows words played" do + it "returns @plays" do + expect(@player.play("apple")).to eq ["apple"] + end + end + + + describe "shows total score" do + it "returns score of all words played" do + @player.play("venus") + expect(@player.total_score).to eq 7 + end end + + describe "tells if the player has over 100 points" + end diff --git a/spec/scrabble_spec.rb b/spec/scrabble_spec.rb index 05b112cf..2e931b15 100644 --- a/spec/scrabble_spec.rb +++ b/spec/scrabble_spec.rb @@ -40,7 +40,7 @@ describe "#highest_word_score" do it "call that index on word_array" do - expect(@scrabble.highest_word_score("aei, b, e")).to eq "e" + expect(@scrabble.highest_word_score("aei, b, e")).to eq " b" end end end From d1a1f4a57c5669f62b237f7f12159b019fb3699f Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Fri, 16 Oct 2015 13:50:45 -0700 Subject: [PATCH 12/14] finished wave 2 --- lib/scrabble_player_class.rb | 20 +++++++++++++++++--- spec/scrabble_player_class_spec.rb | 29 ++++++++++++++++++++++++++++- spec/scrabble_spec.rb | 2 +- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/scrabble_player_class.rb b/lib/scrabble_player_class.rb index 76df5996..66ae3835 100644 --- a/lib/scrabble_player_class.rb +++ b/lib/scrabble_player_class.rb @@ -20,15 +20,29 @@ def total_score total = 0 all_words = @plays all_words.each do |word| - word_score(word) + #word_score(word) total += word_score(word) end return total end def won? - if total_score > 100 - return true + return total_score >= 100 + end + + def highest_scoring_word + all_words = @plays + s = "'#{all_words.join("','")}'" + highest_word_score(s) + end + + def highest_score_number #we need to extract string from array + s = highest_scoring_word + high_score = 0 + s.each do |word| + #word_score(word) + high_score += word_score(word) end + return high_score end end diff --git a/spec/scrabble_player_class_spec.rb b/spec/scrabble_player_class_spec.rb index cb45f30c..1c36def6 100644 --- a/spec/scrabble_player_class_spec.rb +++ b/spec/scrabble_player_class_spec.rb @@ -22,10 +22,37 @@ describe "shows total score" do it "returns score of all words played" do @player.play("venus") + @player.play("zzzzzzzzzzzzzz") + @player.play("a") expect(@player.total_score).to eq 7 end end - describe "tells if the player has over 100 points" + describe "tells if the player has over 100 points" do + it "returns ture or false" do + @player.play("zzzzzzzzzzzzzz") + expect(@player.won?).to be false + end + end + + describe " tells the highest scoring word" do + it "returns the highest scoring word" do + @player.play("venus") + @player.play("zzzzzzzzzzzzzz") + @player.play("a") + + expect(@player.highest_scoring_word).to eq "a" + end + end + + describe " gives the highest scoring number" do + it "gives the higest scoring number" do + @player.play("venus") + @player.play("zzzzzzzzzzzzzz") + @player.play("a") + + expect(@player.highest_score_number).to eq 4 + end + end end diff --git a/spec/scrabble_spec.rb b/spec/scrabble_spec.rb index 2e931b15..c9d5738d 100644 --- a/spec/scrabble_spec.rb +++ b/spec/scrabble_spec.rb @@ -42,5 +42,5 @@ it "call that index on word_array" do expect(@scrabble.highest_word_score("aei, b, e")).to eq " b" end - end + end end From 055f825565a2dd4dd4ada42cc3381ec39fbe42b4 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Fri, 16 Oct 2015 15:12:59 -0700 Subject: [PATCH 13/14] added a new methods --- lib/tile_bag.rb | 23 +++++++++++++++++++++++ spec/tile_bag_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 lib/tile_bag.rb create mode 100644 spec/tile_bag_spec.rb diff --git a/lib/tile_bag.rb b/lib/tile_bag.rb new file mode 100644 index 00000000..c7dd044e --- /dev/null +++ b/lib/tile_bag.rb @@ -0,0 +1,23 @@ +require "./lib/scrabble" + +class TileBag < Scrabble::Scrabble + def initialize + @bag = ["b", "b", "c", "c", "f", "f", "p", "p", "v", "v"] + @tiles = [] + @default_tiles = draw_tiles(7) + end + + + def draw_tiles(num) + tiles = @tiles + num.times do + tiles.push(@bag.sample) + end + tiles + end +end + +#def generate_answer +# possible_words = ["beef", "onion", "boot", "shoe", "dog", "cat", "fireball", "mandrake"] +# @answer = possible_words.sample.split("") +#end diff --git a/spec/tile_bag_spec.rb b/spec/tile_bag_spec.rb new file mode 100644 index 00000000..b842f66c --- /dev/null +++ b/spec/tile_bag_spec.rb @@ -0,0 +1,20 @@ +require "./lib/tile_bag" + +describe TileBag do + before :each do + @tile_bag = Scrabble::Scrabble::TileBag.new + end + + describe '@default_tiles' do + it "selects 7 random tiles" do + @default_tiles + expect(@tile_bag).to eq ['b', "b", "a"] + end + end + + describe "gives us 3 tiles" do + it "returns random tiles" do + expect(@tile_bag.draw_tiles(3)).to eq ['b', "b", "a"] + end + end +end From f1794ca4d7e55f62ee86ad1ff57fbe4cfe3b919b Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Fri, 16 Oct 2015 15:38:34 -0700 Subject: [PATCH 14/14] added new subtract tiles method --- lib/tile_bag.rb | 14 +++++++++++--- spec/tile_bag_spec.rb | 7 ++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/tile_bag.rb b/lib/tile_bag.rb index c7dd044e..7293f0b2 100644 --- a/lib/tile_bag.rb +++ b/lib/tile_bag.rb @@ -3,18 +3,26 @@ class TileBag < Scrabble::Scrabble def initialize @bag = ["b", "b", "c", "c", "f", "f", "p", "p", "v", "v"] - @tiles = [] + @dealt_tiles = [] @default_tiles = draw_tiles(7) end def draw_tiles(num) - tiles = @tiles + tiles = @dealt_tiles num.times do - tiles.push(@bag.sample) + t = @bag.sample + tiles.push(t) + remove_tiles(t) end tiles end + + def remove_tiles(letter) + spot = @bag.index(letter) + @bag.delete_at(spot) + + end end #def generate_answer diff --git a/spec/tile_bag_spec.rb b/spec/tile_bag_spec.rb index b842f66c..7e34bdf1 100644 --- a/spec/tile_bag_spec.rb +++ b/spec/tile_bag_spec.rb @@ -7,7 +7,6 @@ describe '@default_tiles' do it "selects 7 random tiles" do - @default_tiles expect(@tile_bag).to eq ['b', "b", "a"] end end @@ -17,4 +16,10 @@ expect(@tile_bag.draw_tiles(3)).to eq ['b', "b", "a"] end end + + describe "subtracts tiles from our bag" do + it "subtracts tiles" do + expect(@tile_bag).to eq ['b', "b", "a"] + end + end end