From dac1b989964aef3ae456947969395832d31f15cc Mon Sep 17 00:00:00 2001 From: Ania Gonzalez Date: Mon, 7 Mar 2016 16:50:37 -0800 Subject: [PATCH 01/19] Created the empty files and directories Also the set-up --- .ruby-gemset | 1 + .ruby-version | 1 + Rakefile | 9 +++++++++ lib/player.rb | 0 lib/scoring.rb | 0 scrabble.rb | 0 specs/player_spec.rb | 0 specs/scoring_spec.rb | 0 specs/spec_helper.rb | 8 ++++++++ 9 files changed, 19 insertions(+) create mode 100644 .ruby-gemset create mode 100644 .ruby-version create mode 100644 Rakefile create mode 100644 lib/player.rb create mode 100644 lib/scoring.rb create mode 100644 scrabble.rb create mode 100644 specs/player_spec.rb create mode 100644 specs/scoring_spec.rb create mode 100644 specs/spec_helper.rb diff --git a/.ruby-gemset b/.ruby-gemset new file mode 100644 index 00000000..b0582e1f --- /dev/null +++ b/.ruby-gemset @@ -0,0 +1 @@ +Scrabble diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 00000000..276cbf9e --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.3.0 diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..deb52f2c --- /dev/null +++ b/Rakefile @@ -0,0 +1,9 @@ +require 'rake/testtask' + +Rake::TestTask.new do |t| + t.libs = ["lib"] + t.warning = true + t.test_files = FileList['specs/*_spec.rb'] +end + +task default: :test diff --git a/lib/player.rb b/lib/player.rb new file mode 100644 index 00000000..e69de29b diff --git a/lib/scoring.rb b/lib/scoring.rb new file mode 100644 index 00000000..e69de29b diff --git a/scrabble.rb b/scrabble.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/player_spec.rb b/specs/player_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb new file mode 100644 index 00000000..e69de29b diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb new file mode 100644 index 00000000..1500c32e --- /dev/null +++ b/specs/spec_helper.rb @@ -0,0 +1,8 @@ +require 'minitest' +require 'minitest/spec' +require 'minitest/autorun' +require 'minitest/reporters' + +#give us some really pretty output :) + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 586d6147b55ad65a17391e82dce4209c3b1c669b Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Tue, 8 Mar 2016 10:09:33 -0800 Subject: [PATCH 02/19] Added a hash of letter alues --- scrabble.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scrabble.rb b/scrabble.rb index e69de29b..40e8c502 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -0,0 +1,16 @@ +module Scrabble + + class Scoring + letter_value = { 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 + } + + end + + +end From 31f78b8384a60af97a54e076021bfbe6aea369d4 Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Tue, 8 Mar 2016 10:34:50 -0800 Subject: [PATCH 03/19] we have a passing test --- scrabble.rb | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/scrabble.rb b/scrabble.rb index 40e8c502..5c2fbaac 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,16 +1,6 @@ module Scrabble - class Scoring - letter_value = { 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 - } - - end - + #require the class Scoring from scoring.rb + require_relative './lib/scoring.rb' end From 78f37937f7c14f1379a0960bdecf5905957a8ee0 Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Tue, 8 Mar 2016 13:43:01 -0800 Subject: [PATCH 04/19] added some tests for case sensitivity, fixed hash --- lib/scoring.rb | 19 +++++++++++++++++++ specs/scoring_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/lib/scoring.rb b/lib/scoring.rb index e69de29b..da7514e0 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -0,0 +1,19 @@ +class Scoring + LETTER_VALUE = { "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) + total = 0 + word.upcase.each_char do |key| + total = total + LETTER_VALUE[key] + end + return total + end + +end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index e69de29b..95c8344a 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -0,0 +1,24 @@ +require_relative './spec_helper' +require_relative '../scrabble.rb' + +#describe -> works with minitest, its for specs** +describe Scoring do + it "will not be nil" do + Scoring.wont_be_nil + end +end + +describe "Scoring#score" do + TEST_CASES = { + "CAT" => 5, + "cat" => 5, + "kittens" => 61 + } + + + TEST_CASES.each do |word, score| + it "should return the total score #{score} for the word #{word}" do + Scoring.score(word).must_equal(score) + end + end +end From c7242ec5293b921ad6916ad354d061a6b524fb13 Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Tue, 8 Mar 2016 13:48:43 -0800 Subject: [PATCH 05/19] made a new rule to our test for words that are 7 letters long --- lib/scoring.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index da7514e0..0dee9293 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -13,7 +13,11 @@ def self.score(word) word.upcase.each_char do |key| total = total + LETTER_VALUE[key] end - return total + if word.length == 7 + return total + 50 + else + return total + end end end From 3669531cf0f9fdd3e4b792370c1169e4af550da1 Mon Sep 17 00:00:00 2001 From: Ania Gonzalez Date: Tue, 8 Mar 2016 14:08:33 -0800 Subject: [PATCH 06/19] Refactored our if conditional into a single-line conditional. --- lib/scoring.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 0dee9293..695dd6c9 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -13,11 +13,7 @@ def self.score(word) word.upcase.each_char do |key| total = total + LETTER_VALUE[key] end - if word.length == 7 - return total + 50 - else - return total - end + word.length == 7 ? total + 50 : total # Return is implicit end end From 2e424aef6015347eb501e36569a396164fd509ac Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Tue, 8 Mar 2016 15:34:28 -0800 Subject: [PATCH 07/19] made highest score test and method --- lib/scoring.rb | 19 +++++++++++++++++++ specs/scoring_spec.rb | 37 +++++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 695dd6c9..7dbdc22b 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -16,4 +16,23 @@ def self.score(word) word.length == 7 ? total + 50 : total # Return is implicit end + + + + def self.highest_score_from(array) + hash ={} #this hash will contain words and their values/scores + + array.each do |word| + hash[word] = score(word) + end + + array_values = hash.values #this is taking the values of the hash and storing them in an array + + max_value = array_values.max #this is finding the max value of the values and storing as a variable + + winner = hash.key(max_value) #this is finding the corresponding key/word to that max value + + return winner + + end end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 95c8344a..9adf91fa 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -6,19 +6,36 @@ it "will not be nil" do Scoring.wont_be_nil end -end -describe "Scoring#score" do - TEST_CASES = { - "CAT" => 5, - "cat" => 5, - "kittens" => 61 - } + describe "Scoring#score" do #this is testing the method that will return the numeric value of the word + TEST_CASES = { + "CAT" => 5, + "cat" => 5, + "kittens" => 61 + } + + + TEST_CASES.each do |word, score| + it "should return the total score #{score} for the word #{word}" do + Scoring.score(word).must_equal(score) + end + end + end + + + describe "Scoring#highest_score_from" do #this is testing the method that will return the word with the greatest value + TEST_CASES = { + [ "cat", "kittens", "dog"] => "kittens" + + } - TEST_CASES.each do |word, score| - it "should return the total score #{score} for the word #{word}" do - Scoring.score(word).must_equal(score) + TEST_CASES.each do |array, highest_word| + it "should return the word with the highest score #{highest_word} for the array of words #{array}" do + Scoring.highest_score_from(array).must_equal(highest_word) + end end + + end end From 181d5ae24d4a2785648a689dc5fe625e03e92fe6 Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Tue, 8 Mar 2016 16:37:31 -0800 Subject: [PATCH 08/19] we added a test and method to decide the winner of a tie based on fewest tiles used --- lib/scoring.rb | 34 +++++++++++++++++++++++++--------- specs/scoring_spec.rb | 3 ++- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 7dbdc22b..3576a963 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -8,19 +8,19 @@ class Scoring "Q"=> 10, "Z"=> 10 } - def self.score(word) - total = 0 - word.upcase.each_char do |key| - total = total + LETTER_VALUE[key] + def self.score(word) #this is going to find the total value of the word/ self. bc its a method of the class, not an instance + total = 0 #defining total (variable) as zero for now + word.upcase.each_char do |key| #turning the word into upcase and iterating through each character(letter) of the word + total = total + LETTER_VALUE[key] #tally the total sum of the value of those letters, when we call [key] on LETTER_VALUE it will give us the value of that key and add it to our total end - word.length == 7 ? total + 50 : total # Return is implicit + word.length == 7 ? total + 50 : total #Return is implicit #if the word's length is 7 then we add 50 to our total/ this is an ternary!!! end def self.highest_score_from(array) - hash ={} #this hash will contain words and their values/scores + hash ={} #this hash will contain words and their values/scores array.each do |word| hash[word] = score(word) @@ -28,11 +28,27 @@ def self.highest_score_from(array) array_values = hash.values #this is taking the values of the hash and storing them in an array - max_value = array_values.max #this is finding the max value of the values and storing as a variable + max_value = array_values.max #this is finding the max value of the values and storing as a variable - winner = hash.key(max_value) #this is finding the corresponding key/word to that max value + array_tie = [] + + hash.each do |key, value| #iterating through the hash and if the value of the word is equal to the max_value + if value ==max_value #it pushes that corresponding word into an array for the ties + array_tie << key + end + end + + min = array_tie[0].length #we are setting the minimum by default to the length of the first word in the array + winner = array_tie[0] #we are setting the winner by default to the first word + + array_tie.each do |word| #iterating through the tie array and checking if the current word's length is less than the minimum + if word.length < min + min = word.length #if it is, set it's length as the new min value + winner = word #set the corresponding word as the current winner (which might change the next iteration though) + end + end return winner - + end end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 9adf91fa..703831a2 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -26,7 +26,8 @@ describe "Scoring#highest_score_from" do #this is testing the method that will return the word with the greatest value TEST_CASES = { - [ "cat", "kittens", "dog"] => "kittens" + [ "cat", "kittens", "dog"] => "kittens", + [ "fare", "mom"] => "mom" } From 6f625e234c5b74483af70c635a275e31bf07910c Mon Sep 17 00:00:00 2001 From: Ania Gonzalez Date: Wed, 9 Mar 2016 09:54:38 -0800 Subject: [PATCH 09/19] Added the last conditional where a 7 tile word wins over other words with same score --- lib/scoring.rb | 3 +++ specs/scoring_spec.rb | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 3576a963..a2a01323 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -42,6 +42,9 @@ def self.highest_score_from(array) winner = array_tie[0] #we are setting the winner by default to the first word array_tie.each do |word| #iterating through the tie array and checking if the current word's length is less than the minimum + if word.length == 7 #add conditional so that if the word is 7 letters long, it is automatically the winner + return word + end #return the word and exit if word.length < min min = word.length #if it is, set it's length as the new min value winner = word #set the corresponding word as the current winner (which might change the next iteration though) diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 703831a2..18762625 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -27,8 +27,9 @@ describe "Scoring#highest_score_from" do #this is testing the method that will return the word with the greatest value TEST_CASES = { [ "cat", "kittens", "dog"] => "kittens", - [ "fare", "mom"] => "mom" - + [ "fare", "mom"] => "mom", + ["qzqzqz", "aeiounf"] => "aeiounf", #testing that between 2 words with the same score (60), the one with 7 tiles wins, even if it's not the first word in array + ["wadeiou", "kittens", "dog"] => "wadeiou" #testing that between 2 words with same score (61) with same numer of tiles (7), the first one wins } TEST_CASES.each do |array, highest_word| From 2279f7942b39ba743152e8f7e423ac227c946914 Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Thu, 10 Mar 2016 12:41:51 -0800 Subject: [PATCH 10/19] we have started wave 2 and make the skeleton of the methods and a few tests --- lib/player.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/scoring.rb | 11 +++++------ scrabble.rb | 1 + specs/player_spec.rb | 31 +++++++++++++++++++++++++++++++ specs/scoring_spec.rb | 19 ++++++++++--------- 5 files changed, 89 insertions(+), 15 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index e69de29b..c3b117ba 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -0,0 +1,42 @@ +class Player + + def initialize (name) + @name = name + end + + + def plays(name) #do we need to pass in words one by one and iterate through to then shovel them into an array?? + words_played = [] #how are we getting the words? are these TEST_CASES?? + + + end + + + def play(word) + + end + + + def total_score + + end + + + def won? + + end + + + def highest_scoring_word + + end + + + def highest_word_score + + end + + + + +end diff --git a/lib/scoring.rb b/lib/scoring.rb index a2a01323..00521a22 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -8,7 +8,7 @@ class Scoring "Q"=> 10, "Z"=> 10 } - def self.score(word) #this is going to find the total value of the word/ self. bc its a method of the class, not an instance + def self.score(word) #this is going to find the total value of the word.... self. bc its a method of the class, not an instance (the numbers are always the same for the letters) total = 0 #defining total (variable) as zero for now word.upcase.each_char do |key| #turning the word into upcase and iterating through each character(letter) of the word total = total + LETTER_VALUE[key] #tally the total sum of the value of those letters, when we call [key] on LETTER_VALUE it will give us the value of that key and add it to our total @@ -18,11 +18,10 @@ def self.score(word) #this is going to find the total value o - def self.highest_score_from(array) hash ={} #this hash will contain words and their values/scores - array.each do |word| + array.each do |word| #iterating through words given and assigning the score (through the score method) to the word hash[word] = score(word) end @@ -42,9 +41,9 @@ def self.highest_score_from(array) winner = array_tie[0] #we are setting the winner by default to the first word array_tie.each do |word| #iterating through the tie array and checking if the current word's length is less than the minimum - if word.length == 7 #add conditional so that if the word is 7 letters long, it is automatically the winner - return word - end #return the word and exit + if word.length == 7 #add conditional so that if the word is 7 letters long, it is automatically the winner + return word #return the word and exit + end if word.length < min min = word.length #if it is, set it's length as the new min value winner = word #set the corresponding word as the current winner (which might change the next iteration though) diff --git a/scrabble.rb b/scrabble.rb index 5c2fbaac..5dc2edec 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -2,5 +2,6 @@ module Scrabble #require the class Scoring from scoring.rb require_relative './lib/scoring.rb' + require_relative './lib/player.rb' end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index e69de29b..83a6f213 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -0,0 +1,31 @@ +require_relative './spec_helper' +require_relative '../scrabble.rb' + +describe Player do #this is testing to make sure Player exists + it "will not be nil" do + Player.wont_be_nil + end +end + + + describe "Player#new(name)" do + it "does the class initialize a name" do + Player.new(name).wont_be_nil + + end +end + + + +describe "Player#plays" do + TEST_CASES = { + + } + + + TEST_CASES.each do |name, words_played| + it "should return the name of the player #{name} for the word #{word}" do + Scoring.score(word).must_equal(score) + end + end +end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 18762625..01d92acb 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -2,13 +2,13 @@ require_relative '../scrabble.rb' #describe -> works with minitest, its for specs** -describe Scoring do +describe Scoring do #this is testing to make sure Scoring exists it "will not be nil" do Scoring.wont_be_nil end - describe "Scoring#score" do #this is testing the method that will return the numeric value of the word + describe "Scoring#score" do #this is testing the method that will return the numeric value of the word TEST_CASES = { "CAT" => 5, "cat" => 5, @@ -16,7 +16,7 @@ } - TEST_CASES.each do |word, score| + TEST_CASES.each do |word, score| #iterating through the test cases above to return the score of each word it "should return the total score #{score} for the word #{word}" do Scoring.score(word).must_equal(score) end @@ -24,15 +24,16 @@ end - describe "Scoring#highest_score_from" do #this is testing the method that will return the word with the greatest value - TEST_CASES = { + describe "Scoring#highest_score_from" do #this is testing the method that will return the word with the greatest value + TEST_CASES_2 = { [ "cat", "kittens", "dog"] => "kittens", - [ "fare", "mom"] => "mom", - ["qzqzqz", "aeiounf"] => "aeiounf", #testing that between 2 words with the same score (60), the one with 7 tiles wins, even if it's not the first word in array - ["wadeiou", "kittens", "dog"] => "wadeiou" #testing that between 2 words with same score (61) with same numer of tiles (7), the first one wins + [ "fare", "mom"] => "mom", #testing that between two words with the same score (7), the one with fewer tiles wins + ["qzqzqz", "aeiounf"] => "aeiounf", #testing that between 2 words with the same score (60), the one with 7 tiles wins, even if it's not the first word in array + ["wadeiou", "kittens", "dog"] => "wadeiou", #testing that between 2 words with same score (61) with same number of tiles (7), the first one wins + ["cat", "hi"] => "hi" #testing that between two words with the same score, the one with the fewer tiles wins } - TEST_CASES.each do |array, highest_word| + TEST_CASES_2.each do |array, highest_word| #iterating through the test cases above with the method to return the highest_word it "should return the word with the highest score #{highest_word} for the array of words #{array}" do Scoring.highest_score_from(array).must_equal(highest_word) end From 9763f179115c207beebe47c070a1d9a7a6256a95 Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Thu, 10 Mar 2016 13:41:57 -0800 Subject: [PATCH 11/19] we got the first two tests working --- lib/player.rb | 16 ++++++++++------ specs/player_spec.rb | 19 +++++++++---------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index c3b117ba..f736af02 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,19 +1,23 @@ class Player - +attr_accessor :name, :words_played def initialize (name) @name = name + @words_played = [] + #@total_score = end - def plays(name) #do we need to pass in words one by one and iterate through to then shovel them into an array?? - words_played = [] #how are we getting the words? are these TEST_CASES?? - - + def plays(name) + return @words_played end def play(word) - + @words_played << word + #if won == true + #return false + #end + return Scoring.score(word) end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index 83a6f213..95c9ff45 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -7,7 +7,7 @@ end end - +#this tests to make sure the initialize method exists describe "Player#new(name)" do it "does the class initialize a name" do Player.new(name).wont_be_nil @@ -16,16 +16,15 @@ end +describe "Player#play(word)" do + mindy = Player.new("mindy") -describe "Player#plays" do - TEST_CASES = { - - } - + it "should return the score of the word played" do + mindy.play("cat").must_equal(5) + end - TEST_CASES.each do |name, words_played| - it "should return the name of the player #{name} for the word #{word}" do - Scoring.score(word).must_equal(score) + it "should return the array of words played with the new word added" do + mindy.words_played.must_equal(["cat"]) end - end + end From 553078551bda6520126fd9b1e27846f98dbe7aa2 Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Thu, 10 Mar 2016 15:18:25 -0800 Subject: [PATCH 12/19] we got the tests passing. they were erroring bc they were dependant on order --- lib/player.rb | 10 +++++++--- specs/player_spec.rb | 32 +++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index f736af02..5bd063d2 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -7,8 +7,8 @@ def initialize (name) end - def plays(name) - return @words_played + def plays + return @words_played end @@ -22,7 +22,11 @@ def play(word) def total_score - + sum_of_scores = 0 + @words_played.each do |word| + sum_of_scores =+ Scoring.score(word) + end + return sum_of_scores end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index 95c9ff45..619595df 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -22,9 +22,39 @@ it "should return the score of the word played" do mindy.play("cat").must_equal(5) end +end + + describe "Player#play(word)" do + mindy = Player.new("mindy") + mindy.play("cat") it "should return the array of words played with the new word added" do mindy.words_played.must_equal(["cat"]) end -end + end + + describe "Player#play(word)" do + mindy = Player.new("mindy") + mindy.play("cat") + + it "should return the sum of scores" do + mindy.total_score.must_equal(5) + end + + end + + + + + # it "should return the score of the word played" do + # mindy.play("kittens").must_equal(61) + # end + # + # it "should return the array of words played with the new word added" do + # mindy.words_played.must_equal(["cat", "kittens"]) + # end + # + # it "should return the sum of scores" do + # mindy.total_score.must_equal(66) + # end From 9634745bb68b22dca9c6be2b7daf126764a7c80b Mon Sep 17 00:00:00 2001 From: Ania Gonzalez Date: Thu, 10 Mar 2016 15:27:44 -0800 Subject: [PATCH 13/19] Added more tests for the total_score and play methods. --- lib/player.rb | 2 +- specs/player_spec.rb | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 5bd063d2..169c27e7 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -24,7 +24,7 @@ def play(word) def total_score sum_of_scores = 0 @words_played.each do |word| - sum_of_scores =+ Scoring.score(word) + sum_of_scores = sum_of_scores + Scoring.score(word) end return sum_of_scores end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index 619595df..2e08cc11 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -44,17 +44,30 @@ end + describe "Player#play(word)" do + mindy = Player.new("mindy") + it "should return the score of the word played" do + mindy.play("kittens").must_equal(61) + end + end + describe "Player#play(word)" do + mindy = Player.new("mindy") + mindy.play("cat") + mindy.play("kittens") + + it "should return the array of words played with the new word added" do + mindy.words_played.must_equal(["cat", "kittens"]) + end + end - # it "should return the score of the word played" do - # mindy.play("kittens").must_equal(61) - # end - # - # it "should return the array of words played with the new word added" do - # mindy.words_played.must_equal(["cat", "kittens"]) - # end - # - # it "should return the sum of scores" do - # mindy.total_score.must_equal(66) - # end + describe "Player#play(word)" do + mindy = Player.new("mindy") + mindy.play("cat") + mindy.play("kittens") + + it "should return the sum of scores" do + mindy.total_score.must_equal(66) + end + end From 3cccb60f9773d01fbf44df5f8053506f9b6b63fc Mon Sep 17 00:00:00 2001 From: Ania Gonzalez Date: Thu, 10 Mar 2016 15:42:41 -0800 Subject: [PATCH 14/19] Created the won? method and corresponding tests. --- lib/player.rb | 12 ++++++++---- specs/player_spec.rb | 33 +++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 169c27e7..7f06acfc 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -13,10 +13,10 @@ def plays def play(word) + if won? == true + return false + end @words_played << word - #if won == true - #return false - #end return Scoring.score(word) end @@ -31,7 +31,11 @@ def total_score def won? - + if total_score > 100 + return true + else + return false + end end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index 2e08cc11..e3d5754c 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -24,17 +24,17 @@ end end - describe "Player#play(word)" do + describe "Player#plays" do mindy = Player.new("mindy") mindy.play("cat") it "should return the array of words played with the new word added" do - mindy.words_played.must_equal(["cat"]) + mindy.plays.must_equal(["cat"]) end end - describe "Player#play(word)" do + describe "Player#total_score" do mindy = Player.new("mindy") mindy.play("cat") @@ -51,18 +51,18 @@ end end - describe "Player#play(word)" do + describe "Player#plays" do mindy = Player.new("mindy") mindy.play("cat") mindy.play("kittens") it "should return the array of words played with the new word added" do - mindy.words_played.must_equal(["cat", "kittens"]) + mindy.plays.must_equal(["cat", "kittens"]) end end - describe "Player#play(word)" do + describe "Player#total_score" do mindy = Player.new("mindy") mindy.play("cat") mindy.play("kittens") @@ -71,3 +71,24 @@ mindy.total_score.must_equal(66) end end + + describe "Player#won?" do + mindy = Player.new("mindy") + mindy.play("cat") + mindy.play("kittens") + + it "should return false when total_score is less than 100" do + mindy.won?.must_equal(false) + end + end + + describe "Player#won?" do + mindy = Player.new("mindy") + mindy.play("cat") + mindy.play("kittens") + mindy.play("singing") + + it "should return true when total_score is more than 100" do + mindy.won?.must_equal(true) + end + end From 2ebce5d85fa0337f0ea6f732563d48b3a95dca9e Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Thu, 10 Mar 2016 16:58:01 -0800 Subject: [PATCH 15/19] have everything working through wave 2 --- lib/player.rb | 8 ++++---- specs/player_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 7f06acfc..cd85b2a4 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -40,15 +40,15 @@ def won? def highest_scoring_word - + winner_word = Scoring.highest_score_from(@words_played) + return winner_word end def highest_word_score - + winner_score = Scoring.score(Scoring.highest_score_from(@words_played)) + return winner_score end - - end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index e3d5754c..d74a719c 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -92,3 +92,24 @@ mindy.won?.must_equal(true) end end + + describe "Player#won?" do + mindy = Player.new("mindy") + mindy.play("cat") + mindy.play("kittens") + + it "should give the highest_scoring_word" do + mindy.highest_scoring_word.must_equal("kittens") + end + end + + + describe "Player#won?" do + mindy = Player.new("mindy") + mindy.play("cat") + mindy.play("kittens") + + it "should give the highest_scoring_word's score" do + mindy.highest_word_score.must_equal(61) + end + end From 40f6c0871e199414dbfbc121dd8f3d270c4022fa Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Fri, 11 Mar 2016 10:40:19 -0800 Subject: [PATCH 16/19] added initialize and test for it for wave 3 --- lib/tilebag.rb | 34 ++++++++++++++++++++++++++++++++++ scrabble.rb | 1 + specs/tilebag_spec.rb | 17 +++++++++++++++++ 3 files changed, 52 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..60cdfdf3 --- /dev/null +++ b/lib/tilebag.rb @@ -0,0 +1,34 @@ +class Tilebag + attr_accessor :tiles_in_bag + def initialize + @tiles_in_bag = {"A" => 9, "N" => 6, + "B" => 2, "O" => 8, + "C" => 2, "P" => 2, + "D" => 4, "Q" => 1, + "E" => 12, "R" => 6, + "F" => 2, "S" => 4, + "G" => 3, "T" => 6, + "H" => 2, "U" => 4, + "I" => 9, "V" => 2, + "J" => 1, "W" => 2, + "K" => 1, "X" => 1, + "L" => 4, "Y" => 2, + "M" => 2, "Z" => 1} + end + + + def draw_tiles(num) + + tiles_to_draw = tiles_in_bag.keys.sample(num) + + tiles_to_draw.each do |letter| + tiles_in_bag[letter] = tiles_in_bag[letter] - 1 + end + + return tiles_to_draw + + end + + + +end diff --git a/scrabble.rb b/scrabble.rb index 5dc2edec..36102831 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -3,5 +3,6 @@ module Scrabble #require the class Scoring from scoring.rb require_relative './lib/scoring.rb' require_relative './lib/player.rb' + require_relative './lib/tilebag.rb' end diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb new file mode 100644 index 00000000..a723596a --- /dev/null +++ b/specs/tilebag_spec.rb @@ -0,0 +1,17 @@ +require_relative './spec_helper' +require_relative '../scrabble.rb' + +describe Tilebag do #this is testing to make sure Tilebag exists + it "will not be nil" do + Tilebag.wont_be_nil + end +end + +#this tests to make sure the initialize method exists + describe "Tilebag#new" do + it "does the class initialize a collection of default tiles" do + my_bag = Tilebag.new + my_bag.tiles_in_bag.wont_be_nil + + end +end From 40afe0e0bf4c0439d0a3ec7577870a4f40cd2969 Mon Sep 17 00:00:00 2001 From: Ania Gonzalez Date: Fri, 11 Mar 2016 12:57:46 -0800 Subject: [PATCH 17/19] Created an array with all tiles available, including repeating letters. Subtracted used tiles from the bag. And corresponding tests. --- lib/tilebag.rb | 20 ++++++++++++++++++-- specs/tilebag_spec.rb | 21 +++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 60cdfdf3..ad400636 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -18,13 +18,29 @@ def initialize def draw_tiles(num) + #Build new array to consider all available letters to sample from + + #Raise an error if num is larger than 7 + array = [] + @tiles_in_bag.each do |key, value| + array << (key * value).split("") + array.flatten! + end + + # If number of tiles requested is larger than number of tiles in bag + # num should equal tiles left. + - tiles_to_draw = tiles_in_bag.keys.sample(num) + + + tiles_to_draw = array.sample(num) tiles_to_draw.each do |letter| - tiles_in_bag[letter] = tiles_in_bag[letter] - 1 + @tiles_in_bag[letter] = @tiles_in_bag[letter] - 1 end + @tiles_in_bag.delete_if {|key, value| value < 1 } + return tiles_to_draw end diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb index a723596a..d0f3ff85 100644 --- a/specs/tilebag_spec.rb +++ b/specs/tilebag_spec.rb @@ -8,10 +8,27 @@ end #this tests to make sure the initialize method exists - describe "Tilebag#new" do +describe "Tilebag#new" do it "does the class initialize a collection of default tiles" do my_bag = Tilebag.new my_bag.tiles_in_bag.wont_be_nil - end end + +# test that it takes correct number of tiles + describe "Tilebag#draw_tiles(num)" do + it "samples a given number of tiles from bag" do + my_bag = Tilebag.new + my_bag.draw_tiles(5).length.must_equal(5) + end + end + +# test the tiles left in bag is correct + describe "Tilebag#draw_tiles(num)" do + it "gives the correct number of tiles left in bag" do + my_bag = Tilebag.new + my_bag.draw_tiles(5) + result = my_bag.tiles_in_bag.values.reduce(0) { |sum, value| sum + value } + result.must_equal(93) + end + end From c329b60e4a5e47be2bed0ea31dd0e144b9bb3bfc Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Fri, 11 Mar 2016 13:29:29 -0800 Subject: [PATCH 18/19] we created the tiles remaining method --- lib/tilebag.rb | 19 +++++++++++++------ specs/tilebag_spec.rb | 32 +++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index ad400636..d315f9e5 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -20,18 +20,14 @@ def initialize def draw_tiles(num) #Build new array to consider all available letters to sample from - #Raise an error if num is larger than 7 + #Raise an error if num is larger than 7??? + array = [] @tiles_in_bag.each do |key, value| array << (key * value).split("") array.flatten! end - # If number of tiles requested is larger than number of tiles in bag - # num should equal tiles left. - - - tiles_to_draw = array.sample(num) @@ -46,5 +42,16 @@ def draw_tiles(num) end + def tiles_remaining + array = [] + @tiles_in_bag.each do |key, value| + array << (key * value).split("") + array.flatten! + end + + return array.length + end + + end diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb index d0f3ff85..f97d48e1 100644 --- a/specs/tilebag_spec.rb +++ b/specs/tilebag_spec.rb @@ -23,7 +23,7 @@ end end -# test the tiles left in bag is correct +# test the number of tiles left in bag is correct describe "Tilebag#draw_tiles(num)" do it "gives the correct number of tiles left in bag" do my_bag = Tilebag.new @@ -32,3 +32,33 @@ result.must_equal(93) end end + + + # test that if # of tiles requested is more than in the bag, will return the # of tiles left in bag + describe "Tilebag#draw_tiles(num)" do + it "gives the # of tiles left in bag without throwing an error when more tiles are requested than are in bag" do + my_bag = Tilebag.new + my_bag.draw_tiles(100) + result = my_bag.tiles_in_bag.values.reduce(0) { |sum, value| sum + value } + result.must_equal(0) + end + end + + # test that if # of tiles requested is more than in bag, will return the # of tiles availble without an error + describe "Tilebag#draw_tiles(num)" do + it "gives the number of tiles the player recieves, even if the number requested is more than the number in the bag, without throwing an error " do + my_bag = Tilebag.new + result = my_bag.draw_tiles(100) + result.length.must_equal(98) + end + end + + + #test that the remaining number of tiles is correct + describe "Tilebag#tiles_remaining" do + it "gives the remaining number of tiles left in bag after a certain number has been requested" do + my_bag = Tilebag.new + my_bag.draw_tiles(10) + my_bag.tiles_remaining.must_equal(88) + end + end From 845d2eb4b4a2d4e6d55fd6f2f6b69f8d7fb4ddca Mon Sep 17 00:00:00 2001 From: Mindy Carson Date: Fri, 11 Mar 2016 16:56:52 -0800 Subject: [PATCH 19/19] we finished ^_^ --- lib/player.rb | 30 +++++++++++++++++++++++++++--- specs/player_spec.rb | 31 +++++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index cd85b2a4..c7858e0a 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,9 +1,9 @@ class Player -attr_accessor :name, :words_played +attr_accessor :name, :words_played, :tiles def initialize (name) @name = name @words_played = [] - #@total_score = + @tiles = [] end @@ -11,13 +11,31 @@ def plays return @words_played end + # def have_letters? #WE WERE GOING TO DO THIS BUT DIDNT FINISH YET: NOT IN REQUIREMENTS ^_^ + + # word_letters = @word_played.split("") + # temp_tiles = @tiles + + # word_letters.each do |letter| #this checks to be sure we have the letters that are in the word we are trying to play + # if temp_tiles.include?(letter) + # temp_tiles.delete_at(tiles.index(letter) || tiles.length) + # else + # return false + # end + # end + # @tiles = temp_tiles + # return true + # end + + def play(word) if won? == true return false end + @words_played << word - return Scoring.score(word) + return Scoring.score(word) end @@ -51,4 +69,10 @@ def highest_word_score end + def draw_tiles(tile_bag) + x = 7 - @tiles.length + @tiles.concat(tile_bag.draw_tiles(x)) + end + + end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index d74a719c..e8c396fc 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -1,14 +1,14 @@ require_relative './spec_helper' require_relative '../scrabble.rb' -describe Player do #this is testing to make sure Player exists +describe Player do #this is testing to make sure Player exists it "will not be nil" do Player.wont_be_nil end end -#this tests to make sure the initialize method exists - describe "Player#new(name)" do + + describe "Player#new(name)" do #this tests to make sure the initialize method exists it "does the class initialize a name" do Player.new(name).wont_be_nil @@ -17,19 +17,19 @@ describe "Player#play(word)" do - mindy = Player.new("mindy") + mindy = Player.new("mindy") #this is creating a new instance - it "should return the score of the word played" do + it "should return the score of the word played" do #this is testing that the score of the word played is correct mindy.play("cat").must_equal(5) end end - describe "Player#plays" do + describe "Player#plays" do #this is creating a new instance mindy = Player.new("mindy") mindy.play("cat") it "should return the array of words played with the new word added" do - mindy.plays.must_equal(["cat"]) + mindy.plays.must_equal(["cat"]) #this is testing that the word played was added to the array end end @@ -38,7 +38,7 @@ mindy = Player.new("mindy") mindy.play("cat") - it "should return the sum of scores" do + it "should return the sum of scores" do #this is testing that the sum of scores is correct mindy.total_score.must_equal(5) end @@ -113,3 +113,18 @@ mindy.highest_word_score.must_equal(61) end end + + describe "Player#draw_tiles" do #this is testing to make sure draw_tiles exists + it "will not be nil" do + Player.draw_tiles.wont_be_nil + end + + + describe "Player#draw_tiles" do #this is testing that the new instance of bag will have the right number of tiles (7) + ania = Player.new("ania") + my_bag = Tilebag.new + ania.draw_tiles(my_bag) + it "should return the correct number of tiles" do + ania.tiles.length.must_equal(7) + end + end