From 20e463038ee4b76ff4bc7221dfacf8d20a049371 Mon Sep 17 00:00:00 2001 From: Nadine Date: Mon, 7 Mar 2016 17:00:28 -0800 Subject: [PATCH 01/29] first rev of scrabble --- scrabble.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 scrabble.rb diff --git a/scrabble.rb b/scrabble.rb new file mode 100644 index 00000000..051bb930 --- /dev/null +++ b/scrabble.rb @@ -0,0 +1,3 @@ +class Scrabble + +end \ No newline at end of file From ead7d521655be83ed738baf9cfe564a5de5330d3 Mon Sep 17 00:00:00 2001 From: Nadine Date: Tue, 8 Mar 2016 09:48:00 -0800 Subject: [PATCH 02/29] first rev of files --- lib/player.rb | 0 lib/scoring.rb | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/player.rb create mode 100644 lib/scoring.rb 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 From 423c01efb74ae5340c5ed78930ee0be6d61f5838 Mon Sep 17 00:00:00 2001 From: Nadine Date: Tue, 8 Mar 2016 09:48:12 -0800 Subject: [PATCH 03/29] first rev of files --- specs/.DS_Store | Bin 0 -> 6148 bytes specs/player_spec.rb | 2 ++ specs/scoring_spec.rb | 2 ++ specs/spec_helper.rb | 11 +++++++++++ 4 files changed, 15 insertions(+) create mode 100644 specs/.DS_Store create mode 100644 specs/player_spec.rb create mode 100644 specs/scoring_spec.rb create mode 100644 specs/spec_helper.rb diff --git a/specs/.DS_Store b/specs/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Tue, 8 Mar 2016 09:48:45 -0800 Subject: [PATCH 04/29] first rev of files --- RakeFile | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 RakeFile diff --git a/RakeFile b/RakeFile new file mode 100644 index 00000000..f45f7fcf --- /dev/null +++ b/RakeFile @@ -0,0 +1,10 @@ +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 \ No newline at end of file From 3a9074f6744b520b037ae8f69274b69d1552ee63 Mon Sep 17 00:00:00 2001 From: Suzanne Harrison Date: Tue, 8 Mar 2016 10:04:03 -0800 Subject: [PATCH 05/29] passed first test --- scrabble.rb | 8 +++++--- specs/scoring_spec.rb | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/scrabble.rb b/scrabble.rb index 051bb930..9cfa7207 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,3 +1,5 @@ -class Scrabble - -end \ No newline at end of file +module Scrabble + class Scoring + #some sort of data structure to store the individual letter scores + end +end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 05f53a80..4518fbd6 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -1,2 +1,8 @@ require_relative "./spec_helper" require_relative "../scrabble" + +describe Scrabble::Scoring do + it "it is an object we have acccess to" do + Scrabble::Scoring.wont_be_nil + end +end From 200726e120faeb728d084ce2d1acfc88419c3ca4 Mon Sep 17 00:00:00 2001 From: Nadine Date: Tue, 8 Mar 2016 10:22:25 -0800 Subject: [PATCH 06/29] Added 2 tests on scoring_spec and score chart and first two methods in wave one for file scrabble --- specs/scoring_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 4518fbd6..66e960de 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -5,4 +5,14 @@ it "it is an object we have acccess to" do Scrabble::Scoring.wont_be_nil end + + TEST_SCORE = { + "zebra" => 16 + } + + TEST_SCORE.each do |word, score| + it "should return score for the word" do + Scoring.score(word).must_equal(score) + end + end end From b2f92a9ab30172f517b8149ce03be1e8deb2ff26 Mon Sep 17 00:00:00 2001 From: Nadine Date: Tue, 8 Mar 2016 10:23:41 -0800 Subject: [PATCH 07/29] forgot to save scrabble file --- scrabble.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scrabble.rb b/scrabble.rb index 9cfa7207..cd83a189 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,5 +1,23 @@ module Scrabble class Scoring #some sort of data structure to store the individual letter scores + SCORE_CHART = { + 1 => ["a", "e", "i", "u", "o", "l", "n", "r", "s", "t"] + 2 => ["d", "g"] + 3 => ["b", "c", "m", "p"] + 4 => ["f", "h", "v", "w", "y"] + 5 => ["k"] + 8 => ["j", "x"] + 10 => ["q", "z"] + } + def self.score(word) + #returns score value for given word. word input as string. + #seven letter word get 50point bonus + end + + def self.highest_score_from(array_of_words) + end + + end end From 8641558e46417d69f1940396527e9bb48edfe604 Mon Sep 17 00:00:00 2001 From: Suzanne Harrison Date: Tue, 8 Mar 2016 10:56:24 -0800 Subject: [PATCH 08/29] added to score method in scrabble.rb but now need to start putting this class Scoring into the scroring.rb --- scrabble.rb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/scrabble.rb b/scrabble.rb index cd83a189..d083dc4c 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -2,16 +2,23 @@ module Scrabble class Scoring #some sort of data structure to store the individual letter scores SCORE_CHART = { - 1 => ["a", "e", "i", "u", "o", "l", "n", "r", "s", "t"] - 2 => ["d", "g"] - 3 => ["b", "c", "m", "p"] - 4 => ["f", "h", "v", "w", "y"] - 5 => ["k"] - 8 => ["j", "x"] - 10 => ["q", "z"] - } + "A"=>1, "B"=>3, "C"=>3, "D"=>2, + "E"=>1, "F"=>4, "G"=>2, "H"=>4, + "I"=>1, "J"=>8, "K"=>5, "L"=>1, + "M"=>3, "N"=>1, "O"=>1, "P"=>3, + "Q"=>10, "R"=>1, "S"=>1, "T"=>1, + "U"=>1, "V"=>4, "W"=>4, "X"=>8, + "Y"=>4, "Z"=>10 + } def self.score(word) - #returns score value for given word. word input as string. + word_array = word.split("").upcase + + word_score = 0 + + word_array.each do |letter| + word_score += SCORE_CHART[letter] + #returns score value for given word. word input as string. + #word is input as a string (case insensitive). #seven letter word get 50point bonus end From 822a1945c57bf737eaf1a9242513c0f915db0d85 Mon Sep 17 00:00:00 2001 From: Suzanne Harrison Date: Tue, 8 Mar 2016 13:11:21 -0800 Subject: [PATCH 09/29] added connection from scrabble to lib folder. passed first test for scoring word --- lib/scoring.rb | 28 ++++++++++++++++++++++++++++ scrabble.rb | 30 +++++------------------------- specs/scoring_spec.rb | 3 ++- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index e69de29b..8fdc38df 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -0,0 +1,28 @@ +class Scoring + #some sort of data structure to store the individual letter scores + SCORE_CHART = { + "A"=>1, "B"=>3, "C"=>3, "D"=>2, + "E"=>1, "F"=>4, "G"=>2, "H"=>4, + "I"=>1, "J"=>8, "K"=>5, "L"=>1, + "M"=>3, "N"=>1, "O"=>1, "P"=>3, + "Q"=>10, "R"=>1, "S"=>1, "T"=>1, + "U"=>1, "V"=>4, "W"=>4, "X"=>8, + "Y"=>4, "Z"=>10 + } + def self.score(word) + word_array = word.upcase.split("") + + word_score = 0 + raise ArgumentError unless word.length < 8 + + word_array.each do |letter| + word_score += SCORE_CHART[letter] + #returns score value for given word. word input as string. + end + #seven letter word get 50point bonus + return word_score + end + + def self.highest_score_from(array_of_words) + end +end diff --git a/scrabble.rb b/scrabble.rb index d083dc4c..d06dce98 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,30 +1,10 @@ +require_relative "./lib/player.rb" +require_relative "./lib/scoring.rb" + module Scrabble class Scoring - #some sort of data structure to store the individual letter scores - SCORE_CHART = { - "A"=>1, "B"=>3, "C"=>3, "D"=>2, - "E"=>1, "F"=>4, "G"=>2, "H"=>4, - "I"=>1, "J"=>8, "K"=>5, "L"=>1, - "M"=>3, "N"=>1, "O"=>1, "P"=>3, - "Q"=>10, "R"=>1, "S"=>1, "T"=>1, - "U"=>1, "V"=>4, "W"=>4, "X"=>8, - "Y"=>4, "Z"=>10 - } - def self.score(word) - word_array = word.split("").upcase - - word_score = 0 - - word_array.each do |letter| - word_score += SCORE_CHART[letter] - #returns score value for given word. word input as string. - #word is input as a string (case insensitive). - #seven letter word get 50point bonus - end - - def self.highest_score_from(array_of_words) - end - + end + class Player end end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 66e960de..9314529d 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -1,6 +1,7 @@ require_relative "./spec_helper" require_relative "../scrabble" + describe Scrabble::Scoring do it "it is an object we have acccess to" do Scrabble::Scoring.wont_be_nil @@ -11,7 +12,7 @@ } TEST_SCORE.each do |word, score| - it "should return score for the word" do + it "should return #{ score } score for the #{ word }" do Scoring.score(word).must_equal(score) end end From b767359f3d55fe244b234170e17b8786d0617746 Mon Sep 17 00:00:00 2001 From: Nadine Date: Tue, 8 Mar 2016 13:37:27 -0800 Subject: [PATCH 10/29] Excluded words with greater than 7 letters from score calculation. Added 50 point bonus for 7 letter word in self.score method. --- lib/scoring.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 8fdc38df..b374ebbf 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -13,16 +13,19 @@ def self.score(word) word_array = word.upcase.split("") word_score = 0 - raise ArgumentError unless word.length < 8 - - word_array.each do |letter| - word_score += SCORE_CHART[letter] + + if word.length <= 7 + word_array.each do |letter| + word_score += SCORE_CHART[letter] #returns score value for given word. word input as string. - end + end #seven letter word get 50point bonus + word.length == 7 ? word_score += 50 : word_score + end return word_score end def self.highest_score_from(array_of_words) + end end From bbda4ebbeb75ad863a94e746161e2d36b32137e3 Mon Sep 17 00:00:00 2001 From: Nadine Date: Tue, 8 Mar 2016 13:39:41 -0800 Subject: [PATCH 11/29] added specs for the newly updated methods. --- specs/scoring_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 9314529d..2d598357 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -8,11 +8,13 @@ end TEST_SCORE = { - "zebra" => 16 + "zebra" => 16, + "xylophone" => 0, + "develop" => 63 } TEST_SCORE.each do |word, score| - it "should return #{ score } score for the #{ word }" do + it "should return #{ score } for '#{ word }'" do Scoring.score(word).must_equal(score) end end From 42bc78e8d136cbaaa314d698366311d5874f9283 Mon Sep 17 00:00:00 2001 From: Suzanne Harrison Date: Tue, 8 Mar 2016 14:18:08 -0800 Subject: [PATCH 12/29] added highest score method without tiebreaking rules --- lib/scoring.rb | 10 ++++++++-- specs/scoring_spec.rb | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index b374ebbf..7d467ca5 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -13,7 +13,7 @@ def self.score(word) word_array = word.upcase.split("") word_score = 0 - + if word.length <= 7 word_array.each do |letter| word_score += SCORE_CHART[letter] @@ -26,6 +26,12 @@ def self.score(word) end def self.highest_score_from(array_of_words) - + array_of_scores = [] + array_of_words.each do |word| + x = self.score(word) + array_of_scores.push(x) + end + return array_of_scores.max + end end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 2d598357..ea5b54e3 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -7,15 +7,15 @@ Scrabble::Scoring.wont_be_nil end - TEST_SCORE = { - "zebra" => 16, - "xylophone" => 0, - "develop" => 63 - } + TEST_SCORE = { + "zebra" => 16, + "xylophone" => 0, + "develop" => 63 + } - TEST_SCORE.each do |word, score| - it "should return #{ score } for '#{ word }'" do - Scoring.score(word).must_equal(score) - end - end + TEST_SCORE.each do |word, score| + it "should return #{ score } for '#{ word }'" do + Scoring.score(word).must_equal(score) + end + end end From 4b1df58361eec82bab28224df6b1bc9b1ae14b61 Mon Sep 17 00:00:00 2001 From: Nadine Date: Tue, 8 Mar 2016 14:54:29 -0800 Subject: [PATCH 13/29] Added test to find word with highest value --- lib/scoring.rb | 4 +++- specs/scoring_spec.rb | 30 ++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 7d467ca5..931ae6cb 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -9,6 +9,7 @@ class Scoring "U"=>1, "V"=>4, "W"=>4, "X"=>8, "Y"=>4, "Z"=>10 } + def self.score(word) word_array = word.upcase.split("") @@ -31,7 +32,8 @@ def self.highest_score_from(array_of_words) x = self.score(word) array_of_scores.push(x) end - return array_of_scores.max + highest_score = array_of_scores.max + return array_of_words[array_of_scores.index(highest_score)] end end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index ea5b54e3..a44b4622 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -7,15 +7,37 @@ Scrabble::Scoring.wont_be_nil end - TEST_SCORE = { - "zebra" => 16, + TEST_SCORE = { + "zebra" => 16, "xylophone" => 0, - "develop" => 63 + "develop" => 63, + "pigsty" => 12, + "doggies" => 60, + "zenith" => 18 } + ARRAY_OF_WORDS = [ + "zebra", + "xylophone", + "develop", + "pigsty", + "doggies", + "zenith" + ] + describe "Scoring#score" do TEST_SCORE.each do |word, score| it "should return #{ score } for '#{ word }'" do - Scoring.score(word).must_equal(score) + Scoring.score(word).must_equal(score) end end + end + + describe "Scoring#highest_score_from" do + + it "should return the word with the highest score" do + array = TEST_SCORE.max_by{|word,score| score} + best_word = array[0] + Scoring.highest_score_from(ARRAY_OF_WORDS).must_equal(best_word) + end + end end From b70aa649620e382c685b3ba4cb4e89376d43726f Mon Sep 17 00:00:00 2001 From: Suzanne Harrison Date: Tue, 8 Mar 2016 16:33:24 -0800 Subject: [PATCH 14/29] sorted the tied words,add tie breaking features. --- lib/scoring.rb | 29 ++++++++++++++++++++++++++++- specs/scoring_spec.rb | 14 ++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 931ae6cb..267c4d9a 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -27,13 +27,40 @@ def self.score(word) end def self.highest_score_from(array_of_words) + array_of_tied_words = [] array_of_scores = [] + array_of_word_lengths =[] + array_of_words.each do |word| x = self.score(word) array_of_scores.push(x) end + highest_score = array_of_scores.max - return array_of_words[array_of_scores.index(highest_score)] + array_of_scores.each do |score| + if score == highest_score + array_of_tied_words << array_of_words[array_of_scores.index(score)] + end + end + + array_of_tied_words = array_of_tied_words.sort_by {|word| word.length} + + if array_of_tied_words.count > 2 && + return array_of_tied_words[0] + + array_of_tied_words.each do |tied_word| + if array_of_tied_words.length == 7 + return tied_word + end + + + return array_of_tied_words[0] + + else array_of_tied_words[1].length + + array_of_tied_words[1] + + #return array_of_words[array_of_scores.index(highest_score)] end end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index a44b4622..ded1ffe9 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -12,17 +12,21 @@ "xylophone" => 0, "develop" => 63, "pigsty" => 12, - "doggies" => 60, - "zenith" => 18 + "doggies" => 60, + "zenith" => 18, + "cramps" => 12, + "naysays" => 63 } ARRAY_OF_WORDS = [ - "zebra", + "zebra", "xylophone", "develop", "pigsty", "doggies", - "zenith" + "zenith", + "cramps", + "naysays" ] describe "Scoring#score" do TEST_SCORE.each do |word, score| @@ -38,6 +42,8 @@ array = TEST_SCORE.max_by{|word,score| score} best_word = array[0] Scoring.highest_score_from(ARRAY_OF_WORDS).must_equal(best_word) + + it "should return the word with fewest" end end end From 164693e1ecf38ec653f0b0beb19a570b640053fe Mon Sep 17 00:00:00 2001 From: Nadine Date: Tue, 8 Mar 2016 16:54:01 -0800 Subject: [PATCH 15/29] Found bugs. Working on tiebreaker test. --- lib/scoring.rb | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index 267c4d9a..f48eba49 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -30,6 +30,7 @@ def self.highest_score_from(array_of_words) array_of_tied_words = [] array_of_scores = [] array_of_word_lengths =[] + 7_letter_words = [] array_of_words.each do |word| x = self.score(word) @@ -43,22 +44,18 @@ def self.highest_score_from(array_of_words) end end - array_of_tied_words = array_of_tied_words.sort_by {|word| word.length} + array_of_word_lengths = array_of_tied_words.sort_by {|word| word.length} - if array_of_tied_words.count > 2 && - return array_of_tied_words[0] + if array_of_tied_words != 7 - array_of_tied_words.each do |tied_word| - if array_of_tied_words.length == 7 - return tied_word - end + + #y=0 + #until array_of_tied_words[y].length == 7 + # y +=1 + #end - return array_of_tied_words[0] - - else array_of_tied_words[1].length - - array_of_tied_words[1] + #return array_of_tied_words[y] #return array_of_words[array_of_scores.index(highest_score)] From ae7cddce53b3e2cdbb18262d09777afaadd5efd5 Mon Sep 17 00:00:00 2001 From: Nadine Date: Wed, 9 Mar 2016 10:03:10 -0800 Subject: [PATCH 16/29] Finished tiebreaker section. Untested. --- lib/scoring.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/scoring.rb b/lib/scoring.rb index f48eba49..37b9e8d9 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -37,17 +37,25 @@ def self.highest_score_from(array_of_words) array_of_scores.push(x) end + index = 0 + highest_score = array_of_scores.max array_of_scores.each do |score| if score == highest_score array_of_tied_words << array_of_words[array_of_scores.index(score)] + array_of_word_lengths << array_of_tied_words[index] + index += 1 end end - array_of_word_lengths = array_of_tied_words.sort_by {|word| word.length} - - if array_of_tied_words != 7 + if array_of_word_lengths.count(7) >= 1 + winner_index = array_of_word_lengths.find_index(7) + return array_of_tied_words[winner_index] + else + return array_of_tied_words.min_by {|win_word| win_word.length} + end + #array_of_word_lengths = array_of_tied_words.sort_by {|word| word.length} #y=0 From 5fa1eacf1c3e5f49cab0749e69741fffc29963ad Mon Sep 17 00:00:00 2001 From: Suzanne Harrison Date: Wed, 9 Mar 2016 11:33:58 -0800 Subject: [PATCH 17/29] specs added word jogged --- specs/scoring_spec.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index ded1ffe9..d646bdec 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -8,6 +8,7 @@ end TEST_SCORE = { + "jogged" => 16, "zebra" => 16, "xylophone" => 0, "develop" => 63, @@ -15,10 +16,12 @@ "doggies" => 60, "zenith" => 18, "cramps" => 12, - "naysays" => 63 + "naysays" => 63, + "mixup" => 16 } ARRAY_OF_WORDS = [ + "jogged", "zebra", "xylophone", "develop", @@ -26,7 +29,8 @@ "doggies", "zenith", "cramps", - "naysays" + "naysays", + "mixup" ] describe "Scoring#score" do TEST_SCORE.each do |word, score| @@ -38,12 +42,16 @@ describe "Scoring#highest_score_from" do - it "should return the word with the highest score" do - array = TEST_SCORE.max_by{|word,score| score} + array = TEST_SCORE.max_by{|word, score| score} best_word = array[0] + it "should return the #{best_word} with the highest score" do Scoring.highest_score_from(ARRAY_OF_WORDS).must_equal(best_word) - it "should return the word with fewest" + #it "should return the word with fewest tiles" do + + + + end end end From 5901076330b012848566292530d3e1edd8cb393a Mon Sep 17 00:00:00 2001 From: Nadine Date: Wed, 9 Mar 2016 16:24:44 -0800 Subject: [PATCH 18/29] added hash words for tiebreaker test --- specs/.DS_Store | Bin 6148 -> 6148 bytes specs/scoring_spec.rb | 32 ++++++++++---------------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/specs/.DS_Store b/specs/.DS_Store index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..b0fb372c3ec661d92dcf93e449f26ba7042951cc 100644 GIT binary patch delta 213 zcmZoMXfc=|&e%RNQEZ}~q9_vs0|O%ig8&0VDnk)NJVP-<0YmD0LTLA1sera9nX*f)Sm+~7^n}M-ZN-= tf!vLmf7vD*h_Gzt=HTIAY~Pspoq009h@v3KSqea$0K{Oh*-_*$GXQ9YF<}4z delta 71 zcmZoMXfc=|&Zs)EP;8=}A_oHyFfuR*Y!+nv#x_}jao1*c4gn5ERUrR6^JIPzMM0n} SLjp({5P;YXn;k_CGXnr4oDIzY diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index d646bdec..3cf80b1c 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -20,18 +20,11 @@ "mixup" => 16 } - ARRAY_OF_WORDS = [ - "jogged", - "zebra", - "xylophone", - "develop", - "pigsty", - "doggies", - "zenith", - "cramps", - "naysays", - "mixup" - ] + HASH_WORDS = { + "jogged" => ["jogged"], + "zebra" => ["jogged", "zebra", "pigsty", "mixup", "cramps"], + "develop" => ["jogged", "zebra", "develop", "pigsty", "doggies", "naysays", "mixup", "cramps", "zenith"] + } describe "Scoring#score" do TEST_SCORE.each do |word, score| it "should return #{ score } for '#{ word }'" do @@ -41,17 +34,12 @@ end describe "Scoring#highest_score_from" do + HASH_WORDS.each do |word,array| + it "should return #{word} with the highest score and tiebreaker" do + Scoring.highest_score_from(array).must_equal(word) - array = TEST_SCORE.max_by{|word, score| score} - best_word = array[0] - it "should return the #{best_word} with the highest score" do - Scoring.highest_score_from(ARRAY_OF_WORDS).must_equal(best_word) - - #it "should return the word with fewest tiles" do - - - - + #it "should return the word with fewest tiles" do end + end end end From 659a4080a775b4b1148e4116251c037b790486b3 Mon Sep 17 00:00:00 2001 From: Nadine Date: Thu, 10 Mar 2016 11:17:51 -0800 Subject: [PATCH 19/29] Started over with tiebreaking conditions and finished. Moving to wave 2 after this commit. --- lib/.DS_Store | Bin 0 -> 6148 bytes lib/scoring.rb | 49 ++++++++++++------------------------------ specs/.DS_Store | Bin 6148 -> 6148 bytes specs/scoring_spec.rb | 5 +++-- 4 files changed, 17 insertions(+), 37 deletions(-) create mode 100644 lib/.DS_Store diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2e8e514c1596b15c45e294fea119b31b4cc5d64d GIT binary patch literal 6148 zcmeHKO-lnY5PhjVw0h}Hk2#5#S}Uk{k)_sxAiWgtx^0ol;+B3KyzPJR2iG^rP+Y4A zJxGz6W#&zinQZd1Y!U#jvmCX727nq>uu`Y_LZn@ELn>NRCA!eZ7&9DG)7xw#+A6k@ z0a?2`rpWM!SA1B%e3)i=%2xR_deoy;5PHBq<`^R9N>A{DCwR1RjwVitP3k4>2`=dA z*HG&1iaoqh-D)MB{j|5~BE4JA7c*ua;+`XsQP0srpK}<65sg{8#u@FDZ8@G9GsGf9 z4d~4nnexe4-=dw+Z~bZ{eI3c}Cq}}&WpXCQfH7bUY#{^Ovqfrq5zQI{#(*)fWl(l89!F0b`)dz)mbSWdFbU{{CN1vXU`i4E!qwT(vvsb~q*7TQ?>r ud#$HFP(>uJh`3In6SiW;%2s?p4Z?aa4lz+IBC>{J2Z2C?8Drp28F&XCSxiF! literal 0 HcmV?d00001 diff --git a/lib/scoring.rb b/lib/scoring.rb index 37b9e8d9..d4adc785 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -27,45 +27,24 @@ def self.score(word) end def self.highest_score_from(array_of_words) - array_of_tied_words = [] - array_of_scores = [] - array_of_word_lengths =[] - 7_letter_words = [] + win_score = 0 + win_word = array_of_words[0] - array_of_words.each do |word| - x = self.score(word) - array_of_scores.push(x) - end - - index = 0 - highest_score = array_of_scores.max - array_of_scores.each do |score| - if score == highest_score - array_of_tied_words << array_of_words[array_of_scores.index(score)] - array_of_word_lengths << array_of_tied_words[index] - index += 1 + array_of_words.each do |word| + score_inst = self.score(word) + #checks if current winning score is less than or equal + #to the current word's score, then uses the tiebreaker + #conditions to determine winning word and score + if score_inst > win_score + win_score = score_inst + win_word = word + elsif score_inst == win_score && word.length < win_word.length + win_word = word + win_score = score_inst end end - - - if array_of_word_lengths.count(7) >= 1 - winner_index = array_of_word_lengths.find_index(7) - return array_of_tied_words[winner_index] - else - return array_of_tied_words.min_by {|win_word| win_word.length} - end - #array_of_word_lengths = array_of_tied_words.sort_by {|word| word.length} - - #y=0 - - #until array_of_tied_words[y].length == 7 - # y +=1 - #end - - #return array_of_tied_words[y] - - #return array_of_words[array_of_scores.index(highest_score)] + return win_word end end diff --git a/specs/.DS_Store b/specs/.DS_Store index b0fb372c3ec661d92dcf93e449f26ba7042951cc..5347773661d7b17d6c90f27e553990b4962b28b3 100644 GIT binary patch delta 348 zcma)2y$-=p7(KTL79|mr1dENffhYYNsJt25R=?| z|L1%^cc<>uV@i^u?keRLb0Xw+>RwiC1-(NCJ*u~2NHo+2aD!~pBb1|lqz`I&4sXEM)Y*}Q>y9@A!a4t@@xqRk7L WzcWwf7cpdHm~6u%y*Wl?1v3D7R1%N? diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index 3cf80b1c..b60b06e6 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -22,9 +22,12 @@ HASH_WORDS = { "jogged" => ["jogged"], + "mixup" => ["mixup", "jogged", "pigsty", "zebra", "cramps"], "zebra" => ["jogged", "zebra", "pigsty", "mixup", "cramps"], + "zenith" => ["jogged", "zebra", "pigsty", "mixup", "cramps", "zenith"], "develop" => ["jogged", "zebra", "develop", "pigsty", "doggies", "naysays", "mixup", "cramps", "zenith"] } + describe "Scoring#score" do TEST_SCORE.each do |word, score| it "should return #{ score } for '#{ word }'" do @@ -37,8 +40,6 @@ HASH_WORDS.each do |word,array| it "should return #{word} with the highest score and tiebreaker" do Scoring.highest_score_from(array).must_equal(word) - - #it "should return the word with fewest tiles" do end end end From fe8e1903a86d72c1727b96901c721ee27e5a3193 Mon Sep 17 00:00:00 2001 From: Nadine Date: Thu, 10 Mar 2016 13:27:24 -0800 Subject: [PATCH 20/29] Started on wave 2, player files. --- lib/player.rb | 26 ++++++++++++++++++++++++++ specs/player_spec.rb | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/lib/player.rb b/lib/player.rb index e69de29b..56a16fb7 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -0,0 +1,26 @@ +class Player + attr_accessor :name + + def initialize (name) + @name = name + end + + ARRAY = { + "Suzanne" => ["cramps", "develop", "mixup", "doggies"], + "Jeremy" => ["zebra", "naysays", "pigsty"] +} + + def plays + played_words = [] + ARRAY.each do |name, words| + if @name == name + played_words = words + end + end + return played_words + end + + def total_score + + +end \ No newline at end of file diff --git a/specs/player_spec.rb b/specs/player_spec.rb index 46471a2d..9913bbc3 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -1,2 +1,42 @@ require_relative "./spec_helper" -require_relative "../scrabble" \ No newline at end of file +require_relative "../scrabble" + +#ARRAY = { +# "Suzanne" => ["cramps", "develop", "mixup", "dogs"] +# "Jeremy" => ["zebra", "naysays", "pigsty", "doggies"] +#} +describe Scrabble::Player do + it "it is an object we have acccess to" do + Scrabble::Player.wont_be_nil + end + + describe "Player#name" do + suzanne = Player.new("Suzanne") + it "should return Suzanne" do + suzanne.name.must_equal("Suzanne") + end + end + + describe "Player#plays" do + suzanne = Player.new("Suzanne") + it "should return words:" do + suzanne.plays.must_equal(["cramps", "develop", "mixup", "dogs"]) + end + end + + #describe "Player#play(word)" do + # it "adds input word to the array" + # suzanne.play("spider").must_equal(9) + #end + + describe "Player#total_score" do + it " return sum of scores of played words" + suzanne.total_score.must_equal(151) + end + end + + describe "Player#won?" do + it "return true for player with >100 points" + + +end \ No newline at end of file From ff334a8e8775b4bdae917f190beb8a61bbeb06ae Mon Sep 17 00:00:00 2001 From: Suzanne Harrison Date: Thu, 10 Mar 2016 15:34:01 -0800 Subject: [PATCH 21/29] touble with adding total_score method --- lib/player.rb | 35 ++++++++++++++++++++++++++--------- lib/scoring.rb | 4 ++-- specs/player_spec.rb | 23 ++++++++++++----------- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 56a16fb7..faf5848d 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,18 +1,22 @@ -class Player +require File.expand_path('../scoring.rb',__FILE__) + +class Player < Scoring attr_accessor :name def initialize (name) @name = name end - ARRAY = { - "Suzanne" => ["cramps", "develop", "mixup", "doggies"], - "Jeremy" => ["zebra", "naysays", "pigsty"] -} - + def hash_players + hash_players = { + "Suzanne" => ["cramps", "develop", "mixup", "doggies"], + "Jeremy" => ["zebra", "naysays", "pigsty"] + } + end + def plays played_words = [] - ARRAY.each do |name, words| + hash_players.each do |name, words| if @name == name played_words = words end @@ -20,7 +24,20 @@ def plays return played_words end - def total_score + def self.score(word) + super + end + # def total_score + # total_array_values = 0 + # hash_players.each do |name, array| + # if @name == name + # array.each do |word| + # total_array_values += Scoring.score(word) + # end + # end + # end + # return total_array_values + # end -end \ No newline at end of file +end diff --git a/lib/scoring.rb b/lib/scoring.rb index d4adc785..cda748b5 100644 --- a/lib/scoring.rb +++ b/lib/scoring.rb @@ -33,8 +33,8 @@ def self.highest_score_from(array_of_words) array_of_words.each do |word| score_inst = self.score(word) - #checks if current winning score is less than or equal - #to the current word's score, then uses the tiebreaker + #checks if current winning score is less than or equal + #to the current word's score, then uses the tiebreaker #conditions to determine winning word and score if score_inst > win_score win_score = score_inst diff --git a/specs/player_spec.rb b/specs/player_spec.rb index 9913bbc3..efeace26 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -1,6 +1,7 @@ require_relative "./spec_helper" require_relative "../scrabble" + #ARRAY = { # "Suzanne" => ["cramps", "develop", "mixup", "dogs"] # "Jeremy" => ["zebra", "naysays", "pigsty", "doggies"] @@ -10,6 +11,7 @@ Scrabble::Player.wont_be_nil end + describe "Player#name" do suzanne = Player.new("Suzanne") it "should return Suzanne" do @@ -20,7 +22,7 @@ describe "Player#plays" do suzanne = Player.new("Suzanne") it "should return words:" do - suzanne.plays.must_equal(["cramps", "develop", "mixup", "dogs"]) + suzanne.plays.must_equal(["cramps", "develop", "mixup", "doggies"]) end end @@ -29,14 +31,13 @@ # suzanne.play("spider").must_equal(9) #end - describe "Player#total_score" do - it " return sum of scores of played words" - suzanne.total_score.must_equal(151) - end - end - - describe "Player#won?" do - it "return true for player with >100 points" - + # describe "Player#total_score" do + # suzanne = Player.new("Suzanne") + # it "should return sum of scores of played words" + # suzanne.total_score.must_equal(151) + # end + # end -end \ No newline at end of file + # describe "Player#won?" do + # it "return true for player with >100 points" +end From 2a604760842254f39825e216a12668e661ad8bcc Mon Sep 17 00:00:00 2001 From: Suzanne Harrison Date: Thu, 10 Mar 2016 15:34:59 -0800 Subject: [PATCH 22/29] scrabble file slightly changed with require relative --- scrabble.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scrabble.rb b/scrabble.rb index d06dce98..13dd2cb2 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -5,6 +5,6 @@ module Scrabble class Scoring end - class Player + class Player < Scoring end end From ead84d8e5201375e011cc08e27997f8776bf768d Mon Sep 17 00:00:00 2001 From: Nadine Date: Thu, 10 Mar 2016 16:54:03 -0800 Subject: [PATCH 23/29] Finished wave 2 --- lib/player.rb | 66 +++++++++++++++++++++++++++++++---------- scrabble.rb | 10 ++----- specs/player_spec.rb | 69 ++++++++++++++++++++++++++++++------------- specs/scoring_spec.rb | 4 +-- 4 files changed, 104 insertions(+), 45 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index faf5848d..4c873517 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,6 +1,4 @@ -require File.expand_path('../scoring.rb',__FILE__) - -class Player < Scoring +class Player attr_accessor :name def initialize (name) @@ -10,7 +8,8 @@ def initialize (name) def hash_players hash_players = { "Suzanne" => ["cramps", "develop", "mixup", "doggies"], - "Jeremy" => ["zebra", "naysays", "pigsty"] + "Jeremy" => ["zebra", "naysays", "pigsty"], + "Nadine" => ["mice"] } end @@ -18,7 +17,7 @@ def plays played_words = [] hash_players.each do |name, words| if @name == name - played_words = words + played_words += words end end return played_words @@ -28,16 +27,51 @@ def self.score(word) super end - # def total_score - # total_array_values = 0 - # hash_players.each do |name, array| - # if @name == name - # array.each do |word| - # total_array_values += Scoring.score(word) - # end - # end - # end - # return total_array_values - # end + def play(word) + if won? == true + return false + else + hash_players.each do |name, words| + if @name == name + words << word + end + end + return Scoring.score(word) + end + end + + def total_score + total_array_values = 0 + hash_players.each do |name, array| + if @name == name + array.each do |word| + total_array_values += Scoring.score(word) + end + end + end + return total_array_values + end + + def won? + if total_score >100 + return true + else + return false + end + end + + def highest_scoring_word + win_word = "" + hash_players.each do |name,array| + if @name == name + win_word = Scoring.highest_score_from(array) + end + end + return win_word + end + def highest_word_score + highest_score = 0 + highest_score = Scoring.score(highest_scoring_word) + end end diff --git a/scrabble.rb b/scrabble.rb index 13dd2cb2..df7e7b85 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -1,10 +1,6 @@ -require_relative "./lib/player.rb" -require_relative "./lib/scoring.rb" -module Scrabble - class Scoring - end - class Player < Scoring - end +module Scrabble + require_relative "./lib/scoring.rb" + require_relative "./lib/player.rb" end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index efeace26..08e6ab7c 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -2,15 +2,11 @@ require_relative "../scrabble" -#ARRAY = { -# "Suzanne" => ["cramps", "develop", "mixup", "dogs"] -# "Jeremy" => ["zebra", "naysays", "pigsty", "doggies"] -#} -describe Scrabble::Player do +describe Player do it "it is an object we have acccess to" do - Scrabble::Player.wont_be_nil + Player.wont_be_nil end - +end describe "Player#name" do suzanne = Player.new("Suzanne") @@ -26,18 +22,51 @@ end end - #describe "Player#play(word)" do - # it "adds input word to the array" - # suzanne.play("spider").must_equal(9) - #end + describe "Player#play(word)" do + suzanne = Player.new("Suzanne") + nadine = Player.new("Nadine") + it "adds input word to the array" do + suzanne.play("spider").must_equal(false) + end + it "adds input word to the array" do + nadine.play("cat").must_equal(5) + end + end + + describe "Player#total_score" do + suzanne = Player.new("Suzanne") + it "should return 151 for Suzanne" do + suzanne.total_score.must_equal(151) + end + end + + describe "Player#won?" do + suzanne = Player.new("Suzanne") + it "return true for player with >100 points" do + suzanne.won?.must_equal(true) + end + end + + describe "Player#highest_scoring_word" do + suzanne = Player.new("Suzanne") + nadine = Player.new("Nadine") + jeremy = Player.new("Jeremy") + it "should return highest scoring played word" do + suzanne.highest_scoring_word.must_equal("develop") + end + it "should return highest scoring played word" do + nadine.highest_scoring_word.must_equal("mice") + end + it "should return highest scoring played word" do + jeremy.highest_scoring_word.must_equal("naysays") + end + end + + describe "Player#highest_word_score" do + suzanne = Player.new("Suzanne") + it "should return highest word score" do + suzanne.highest_word_score.must_equal(63) + end + end - # describe "Player#total_score" do - # suzanne = Player.new("Suzanne") - # it "should return sum of scores of played words" - # suzanne.total_score.must_equal(151) - # end - # end - # describe "Player#won?" do - # it "return true for player with >100 points" -end diff --git a/specs/scoring_spec.rb b/specs/scoring_spec.rb index b60b06e6..d0ce5613 100644 --- a/specs/scoring_spec.rb +++ b/specs/scoring_spec.rb @@ -2,9 +2,9 @@ require_relative "../scrabble" -describe Scrabble::Scoring do +describe Scoring do it "it is an object we have acccess to" do - Scrabble::Scoring.wont_be_nil + Scoring.wont_be_nil end TEST_SCORE = { From 2b8c1675feadd1033aa81cbfd0fd0e02f66ee876 Mon Sep 17 00:00:00 2001 From: Suzanne Harrison Date: Fri, 11 Mar 2016 10:43:00 -0800 Subject: [PATCH 24/29] started tilebag. trying to initialize and get full hash of tiles available --- lib/.DS_Store | Bin 6148 -> 6148 bytes lib/tilebag.rb | 12 ++++++++++++ specs/tilebag_spec.rb | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 lib/tilebag.rb create mode 100644 specs/tilebag_spec.rb diff --git a/lib/.DS_Store b/lib/.DS_Store index 2e8e514c1596b15c45e294fea119b31b4cc5d64d..34c7db24400791b85fd739315e7606041dfe1d27 100644 GIT binary patch delta 72 zcmZoMXfc=|#>CJzu~2NHo+2aT!~knX#>qTPrkl%{C$emAVBX5KnVo~51E^$kA@g_U a$^0U^oQw<%3B)qu~2NHo+2a5!~pA!7aACWj2_c^afV`sWQKf(B8E(cJce`z1qMR~ zGX`A-BOt8{#FjwPfWaKd(gUhV^32IkPRhwoVqjnp0Af2Jo(#l{|NjF?1_lyMD=4W? z@+mDYDFSL$V+aL0B^78%F@rvXA44KT3fM`hK%O&$DUd7x%H=a;0o5cklz>$Q16f5t zl}SLD0~FT>l9@oZKG9Cmg!`9, "b"=>2, "c"=>2, "d"=>4, "e"=>12, "f"=>2, "g"=>3, "h"=>2, "i"=>9, + "j"=>1, "k"=>1, "l"=>4, "m"=>2, "n"=>6, "o"=>8, "p"=>2, "q"=>1, "r"=>6, + "s"=>4, "t"=>6, "u"=>4, "v"=>2, "w"=>2, "x"=>1, "y"=>2, "z"=>1} +end diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb new file mode 100644 index 00000000..27d3bd63 --- /dev/null +++ b/specs/tilebag_spec.rb @@ -0,0 +1,21 @@ +require_relative "./spec_helper" +require_relative "../scrabble" + +describe Tilebag do + it "is an object we have access to" do + Tilebag.wont_be_nil + end +end + +# TILEBAG = { +# "a"=>9, "b"=>2, "c"=>2, "d"=>4, "e"=>12, "f"=>2, "g"=>3, "h"=>2, "i"=>9, +# "j"=>1, "k"=>1, "l"=>4, "m"=>2, "n"=>6, "o"=>8, "p"=>2, "q"=>1, "r"=>6, +# "s"=>4, "t"=>6, "u"=>4, "v"=>2, "w"=>2, "x"=>1, "y"=>2, "z"=>1 +# } + +# describe "Tilebag#tilebag" do +# bag = Tilebag.new +# it "should give an array with all tiles" do +# bag.must_equal(TILEBAG) +# end +end From 66b30b1ac7ea8b78adc8abbb859bac520cb83c2a Mon Sep 17 00:00:00 2001 From: Nadine Date: Fri, 11 Mar 2016 11:24:45 -0800 Subject: [PATCH 25/29] Started wave 3 --- lib/tilebag.rb | 14 ++++++++++++++ scrabble.rb | 1 + specs/.DS_Store | Bin 6148 -> 6148 bytes specs/tilebag_spec.rb | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 78a5d835..d4b6287e 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -9,4 +9,18 @@ def initialize "a"=>9, "b"=>2, "c"=>2, "d"=>4, "e"=>12, "f"=>2, "g"=>3, "h"=>2, "i"=>9, "j"=>1, "k"=>1, "l"=>4, "m"=>2, "n"=>6, "o"=>8, "p"=>2, "q"=>1, "r"=>6, "s"=>4, "t"=>6, "u"=>4, "v"=>2, "w"=>2, "x"=>1, "y"=>2, "z"=>1} + + def self.draw_tiles(num) + + + return + end + + def self.tiles_remaining + self.draw_tiles + + @tilebag.each do |letter, number| + remaining += number + end + return (remaining-) end diff --git a/scrabble.rb b/scrabble.rb index df7e7b85..e88cf6c2 100644 --- a/scrabble.rb +++ b/scrabble.rb @@ -3,4 +3,5 @@ module Scrabble require_relative "./lib/scoring.rb" require_relative "./lib/player.rb" + require_relative "./lib/tilebag.rb" end diff --git a/specs/.DS_Store b/specs/.DS_Store index 5347773661d7b17d6c90f27e553990b4962b28b3..1d8b7d6f88a34f3ce08c7eda57cbf80e10c93b7f 100644 GIT binary patch delta 62 zcmZoMXfc@J&&akhU^gQp+h!i7nT-7W3?&Si3^@#`3`q=$4C#|)nB;gEgBTbXH2#CZ P=7r3fESuRm{_+C=5RelF delta 32 ocmZoMXfc@J&&awlU^gQp>t-INnT(sCF)Ol6Y;fGn&heKY0H>u2O#lD@ diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb index 27d3bd63..d314dce2 100644 --- a/specs/tilebag_spec.rb +++ b/specs/tilebag_spec.rb @@ -13,9 +13,28 @@ # "s"=>4, "t"=>6, "u"=>4, "v"=>2, "w"=>2, "x"=>1, "y"=>2, "z"=>1 # } +#LEFTOVERS = { +# 7 => +#} + # describe "Tilebag#tilebag" do # bag = Tilebag.new # it "should give an array with all tiles" do # bag.must_equal(TILEBAG) # end + + describe "Tilebag#draw_tiles(num)" do + it "should return a number of random tiles" do + Tilebag.draw_tiles(7).must_equal(7) + end + end + + describe "Tilebag#tiles_remaining" do + it "should return number of tiles remaining" do + Tilebag.tiles_remaining.must_equal(91) + end + end + + + end From 9ecbd814afb9038521ab1463d34267dae868a828 Mon Sep 17 00:00:00 2001 From: Suzanne Harrison Date: Fri, 11 Mar 2016 13:39:30 -0800 Subject: [PATCH 26/29] added methods for tiles_remaining and tiles_drawn. --- lib/tilebag.rb | 22 ++++++++++++++----- specs/tilebag_spec.rb | 50 +++++++++++++++++-------------------------- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index d4b6287e..3b3d379f 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -11,16 +11,28 @@ def initialize "s"=>4, "t"=>6, "u"=>4, "v"=>2, "w"=>2, "x"=>1, "y"=>2, "z"=>1} def self.draw_tiles(num) + keys = [] + letters = [] + keys = (@tilebag.keys).shuffle + puts keys + count = 0 + until count == num do + letter = keys[count] + if @tilebag[letter] >= 1 + @tilebag[letter] = @tilebag[letter] - 1 + letters << letter + count = count + 1 + end + end + return letters - - return end def self.tiles_remaining - self.draw_tiles - + remaining = 0 @tilebag.each do |letter, number| remaining += number end - return (remaining-) + return remaining + end end diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb index d314dce2..5f926486 100644 --- a/specs/tilebag_spec.rb +++ b/specs/tilebag_spec.rb @@ -7,34 +7,24 @@ end end -# TILEBAG = { -# "a"=>9, "b"=>2, "c"=>2, "d"=>4, "e"=>12, "f"=>2, "g"=>3, "h"=>2, "i"=>9, -# "j"=>1, "k"=>1, "l"=>4, "m"=>2, "n"=>6, "o"=>8, "p"=>2, "q"=>1, "r"=>6, -# "s"=>4, "t"=>6, "u"=>4, "v"=>2, "w"=>2, "x"=>1, "y"=>2, "z"=>1 -# } - -#LEFTOVERS = { -# 7 => -#} - -# describe "Tilebag#tilebag" do -# bag = Tilebag.new -# it "should give an array with all tiles" do -# bag.must_equal(TILEBAG) -# end - - describe "Tilebag#draw_tiles(num)" do - it "should return a number of random tiles" do - Tilebag.draw_tiles(7).must_equal(7) - end - end - - describe "Tilebag#tiles_remaining" do - it "should return number of tiles remaining" do - Tilebag.tiles_remaining.must_equal(91) - end - end - - - +describe "Tilebag#tiles_remaining" do + it "should return the tiles remaining in the game" do + Tilebag.tiles_remaining.must_equal(98) + end + it "should return the tiles remaining in the game" do + Tilebag.draw_tiles(7) + Tilebag.tiles_remaining.must_equal(91) + end end + + # TILEBAG = { + # "a"=>9, "b"=>2, "c"=>2, "d"=>4, "e"=>12, "f"=>2, "g"=>3, "h"=>2, "i"=>9, + # "j"=>1, "k"=>1, "l"=>4, "m"=>2, "n"=>6, "o"=>8, "p"=>2, "q"=>1, "r"=>6, + # "s"=>4, "t"=>6, "u"=>4, "v"=>2, "w"=>2, "x"=>1, "y"=>2, "z"=>1 + # } + # + # describe "Tilebag#tilebag" do + # bag = Tilebag.new + # it "should give an array with all tiles" do + # bag.must_equal(TILEBAG) + # end From b43291ae0bb0029701fe9efe8e162da6a3488f34 Mon Sep 17 00:00:00 2001 From: Nadine Date: Fri, 11 Mar 2016 15:27:21 -0800 Subject: [PATCH 27/29] Finished Tilebag methods and specs --- lib/tilebag.rb | 35 +++++++++++++++++++---------------- specs/tilebag_spec.rb | 34 +++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 3b3d379f..ed1a4e18 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -2,37 +2,40 @@ class Tilebag attr_reader :tilebag def initialize - @tilebag = {} - end - - @tilebag = { + #@tilebag = {} + @tilebag = { "a"=>9, "b"=>2, "c"=>2, "d"=>4, "e"=>12, "f"=>2, "g"=>3, "h"=>2, "i"=>9, "j"=>1, "k"=>1, "l"=>4, "m"=>2, "n"=>6, "o"=>8, "p"=>2, "q"=>1, "r"=>6, "s"=>4, "t"=>6, "u"=>4, "v"=>2, "w"=>2, "x"=>1, "y"=>2, "z"=>1} - def self.draw_tiles(num) + end + + def draw_tiles(num) keys = [] letters = [] - keys = (@tilebag.keys).shuffle - puts keys count = 0 - until count == num do - letter = keys[count] - if @tilebag[letter] >= 1 + + if self.tiles_remaining >= num + while count < num + keys = (@tilebag.keys).shuffle + letter = keys[0] + if @tilebag[letter] > 0 @tilebag[letter] = @tilebag[letter] - 1 letters << letter count = count + 1 end end - return letters + return letters + else + return "Out of tiles" + end + end - def self.tiles_remaining - remaining = 0 - @tilebag.each do |letter, number| - remaining += number - end + def tiles_remaining + values = @tilebag.values + remaining = values.inject(0) { |sum, item| sum + item } return remaining end end diff --git a/specs/tilebag_spec.rb b/specs/tilebag_spec.rb index 5f926486..dcf468ab 100644 --- a/specs/tilebag_spec.rb +++ b/specs/tilebag_spec.rb @@ -7,16 +7,40 @@ end end +describe "Tilebag#tdraw_tiles" do + nadine_bag = Tilebag.new + it "should return out of tiles" do + nadine_bag.draw_tiles(100).must_equal("Out of tiles") + end +end + describe "Tilebag#tiles_remaining" do - it "should return the tiles remaining in the game" do - Tilebag.tiles_remaining.must_equal(98) + nadine_bag = Tilebag.new + it "should return the 98 tiles remaining in the game" do + nadine_bag.tiles_remaining.must_equal(98) + end +end + +describe "Tilebag#tiles_remaining2" do + suzanne_bag= Tilebag.new + it "should return the 91 tiles remaining in the game" do + suzanne_bag.draw_tiles(7) + suzanne_bag.tiles_remaining.must_equal(91) end - it "should return the tiles remaining in the game" do - Tilebag.draw_tiles(7) - Tilebag.tiles_remaining.must_equal(91) +end + +describe "Tilebag#tiles_remaining3" do + jeremy_bag=Tilebag.new + it "should return the 0 tiles remaining in the game" do + jeremy_bag.draw_tiles(98) + jeremy_bag.tiles_remaining.must_equal(0) end end + + + + # TILEBAG = { # "a"=>9, "b"=>2, "c"=>2, "d"=>4, "e"=>12, "f"=>2, "g"=>3, "h"=>2, "i"=>9, # "j"=>1, "k"=>1, "l"=>4, "m"=>2, "n"=>6, "o"=>8, "p"=>2, "q"=>1, "r"=>6, From 2be5fc46835d0d249f2991400cbced79a0654fa7 Mon Sep 17 00:00:00 2001 From: Nadine Date: Fri, 11 Mar 2016 15:48:04 -0800 Subject: [PATCH 28/29] Started on wave 3 player modification --- lib/player.rb | 14 ++++++++++++++ lib/tilebag.rb | 1 + specs/player_spec.rb | 14 ++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/lib/player.rb b/lib/player.rb index 4c873517..edb58c1a 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -74,4 +74,18 @@ def highest_word_score highest_score = 0 highest_score = Scoring.score(highest_scoring_word) end + + tiles = [] + + def tiles + + return player_tiles + end + + def draw_tiles(tile_bag) + tiles = self.tiles + tiles_needed = 7 - tiles.length + tiles = Tilebag.draw_tiles(tiles_needed) + end + end diff --git a/lib/tilebag.rb b/lib/tilebag.rb index ed1a4e18..ef87bf4f 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -38,4 +38,5 @@ def tiles_remaining remaining = values.inject(0) { |sum, item| sum + item } return remaining end + end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index 08e6ab7c..4462b0de 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -69,4 +69,18 @@ end end + # describe "Player#tiles" do + # suzanne = Player.new("Suzanne") + # it "should return a collection of letters can play (max 7)" do + # suzanne.tiles.must_equal + # end + # end + + describe "Player#draw_tiles(tile_bag)" do + suzanne = Player.new("Suzanne") + it "should fill tiles array until it has 7 letters" do + suzanne.draw_tiles().must_equal() + end + end + From 2341f0e033a3f7061d1ef22563739377672a7f0d Mon Sep 17 00:00:00 2001 From: Suzanne Harrison Date: Fri, 11 Mar 2016 16:24:02 -0800 Subject: [PATCH 29/29] tests and code for PLayer enhancement --- lib/player.rb | 10 +++++----- lib/tilebag.rb | 4 ++-- specs/player_spec.rb | 17 ++++++++--------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index edb58c1a..66161c10 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -36,7 +36,7 @@ def play(word) words << word end end - return Scoring.score(word) + return Scoring.score(word) end end @@ -63,7 +63,7 @@ def won? def highest_scoring_word win_word = "" hash_players.each do |name,array| - if @name == name + if @name == name win_word = Scoring.highest_score_from(array) end end @@ -78,11 +78,11 @@ def highest_word_score tiles = [] def tiles - - return player_tiles + self.draw_tiles + return tiles end - def draw_tiles(tile_bag) + def draw_tiles tiles = self.tiles tiles_needed = 7 - tiles.length tiles = Tilebag.draw_tiles(tiles_needed) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index ef87bf4f..117b5ecb 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -26,10 +26,10 @@ def draw_tiles(num) end end return letters - else + else return "Out of tiles" end - + end diff --git a/specs/player_spec.rb b/specs/player_spec.rb index 4462b0de..e7966cac 100644 --- a/specs/player_spec.rb +++ b/specs/player_spec.rb @@ -69,18 +69,17 @@ end end - # describe "Player#tiles" do - # suzanne = Player.new("Suzanne") - # it "should return a collection of letters can play (max 7)" do - # suzanne.tiles.must_equal - # end - # end + describe "Player#tiles" do + suzanne = Player.new("Suzanne") + it "should return a collection of letters can play (max 7)" do + suzanne.tiles.must_equal.Array + end + end describe "Player#draw_tiles(tile_bag)" do suzanne = Player.new("Suzanne") it "should fill tiles array until it has 7 letters" do - suzanne.draw_tiles().must_equal() + suzanne.draw_tiles + suzanne.tiles.length.must_equal(7) end end - -