From 39b3afbdcb1d0ac9d667b90c1e8cfba639026e6f Mon Sep 17 00:00:00 2001 From: Charles Ellis Date: Wed, 14 Oct 2015 14:49:00 -0700 Subject: [PATCH 01/12] Remove confusion from saying self.new instead of initialize --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 07088686..f2e224ae 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Create a `Scrabble` class with a minimum of 8 specs. The class should have the f ### Primary Requirements Create a `Player` class with a minimum of 11 specs. The class should have the following class and instance methods: -- `self.new(name)`: creates a new instance with the instance variable `name` assigned +- `#initialize(name)`: Called when you use `Player.new`, sets up an instance with the instance variable `name` assigned - `#name`: returns the `@name` instance variable - `#plays`: returns an Array of the words played by the player - `#play(word)`: Adds the input word to the `plays` Array From de7e4585173cc5f3a6078d343c1ac773c098d5ee Mon Sep 17 00:00:00 2001 From: Charles Ellis Date: Thu, 15 Oct 2015 14:08:45 -0700 Subject: [PATCH 02/12] Add Wave 3 requirements --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index f2e224ae..0626c76d 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,6 @@ Create a `Player` class with a minimum of 11 specs. The class should have the fo - `#highest_word_score`: Returns the `highest_scoring_word` score. - From ea00f9938f47169870904229e9195b4a433c9d19 Mon Sep 17 00:00:00 2001 From: Charles Ellis Date: Thu, 15 Oct 2015 14:14:11 -0700 Subject: [PATCH 03/12] Say initialize instead of self.new, use better parameter name --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0626c76d..a23da7e9 100644 --- a/README.md +++ b/README.md @@ -76,8 +76,8 @@ Create a `Player` class with a minimum of 11 specs. The class should have the fo ### Primary Requirements Create a `TileBag` class with a minimum of 5 specs. It should have the following class and instance methods: -- `self.new` creates an instance with a collection of default tiles -- `#draw_tiles(n)` returns n number of random tiles, removes the tiles from the default set. +- `#initialize` Called when you use `TileBag.new`, sets up an instance with a collection of default tiles +- `#draw_tiles(num)` returns `num` number of random tiles, removes the tiles from the default set. - `#tiles_remaining` returns the number of tiles remaining in the bag Create specs for (minimum 2) and add to the `Player` class the following instance methods: From 8d293ab6409bcb5f6e1252037687da84b1697d8f Mon Sep 17 00:00:00 2001 From: Desiree Date: Thu, 15 Oct 2015 15:00:04 -0700 Subject: [PATCH 04/12] Condense code for #won? method --- lib/player.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 424077f8..d7ee2c9b 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -32,11 +32,7 @@ def highest_word_score end def won? - if @total > 100 - true - else - false - end + @total > 100 end end From 8a14237cd9ef278a44afc93551b22da2ec8d82cd Mon Sep 17 00:00:00 2001 From: Desiree Date: Thu, 15 Oct 2015 15:36:07 -0700 Subject: [PATCH 05/12] Add TileBag.rb and tilebag_spec.rb files --- lib/tilebag.rb | 4 ++++ spec/tilebag_spec.rb | 1 + 2 files changed, 5 insertions(+) create mode 100644 lib/tilebag.rb create mode 100644 spec/tilebag_spec.rb diff --git a/lib/tilebag.rb b/lib/tilebag.rb new file mode 100644 index 00000000..8d93f851 --- /dev/null +++ b/lib/tilebag.rb @@ -0,0 +1,4 @@ +module Scrabble + class TileBag + end +end diff --git a/spec/tilebag_spec.rb b/spec/tilebag_spec.rb new file mode 100644 index 00000000..617a1a0e --- /dev/null +++ b/spec/tilebag_spec.rb @@ -0,0 +1 @@ +require "./lib/tilebag" From f9aa315637a18d6cab5e4940e18bdd7de6fa2ec9 Mon Sep 17 00:00:00 2001 From: Desiree Date: Thu, 15 Oct 2015 16:52:07 -0700 Subject: [PATCH 06/12] Start spec for #draw_tiles and start its method --- lib/tilebag.rb | 9 +++++++++ spec/player_spec.rb | 3 +-- spec/tilebag_spec.rb | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 8d93f851..2b3edd92 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -1,4 +1,13 @@ module Scrabble class TileBag + attr_reader :tile_quantities + def initialize + @tile_quantities = {"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} + end + + def draw_tiles(num) + end end end diff --git a/spec/player_spec.rb b/spec/player_spec.rb index ab453dfc..3a9b4bf4 100644 --- a/spec/player_spec.rb +++ b/spec/player_spec.rb @@ -10,7 +10,6 @@ @player2.play("toast") # toast = 5 @player2.play("hand") # hand = 8 @player3.total = 101 - end describe ".new" do @@ -72,7 +71,7 @@ describe "#highest_word_score" do it "returns the highest scoring word score" do - expect(@player2.highest_word_score).to eq 8 + expect(@player2.highest_word_score).to eq 8 end end diff --git a/spec/tilebag_spec.rb b/spec/tilebag_spec.rb index 617a1a0e..73289b6d 100644 --- a/spec/tilebag_spec.rb +++ b/spec/tilebag_spec.rb @@ -1 +1,25 @@ require "./lib/tilebag" + +describe Scrabble::TileBag do + before :each do + @tilebag1 = Scrabble::TileBag.new + end + + describe "#initialize" do + it "sets up an instance of the TileBag class" do + expect(@tilebag1).to be_an_instance_of Scrabble::TileBag + end + it "sets up an instance with a collection of default tiles" do + expect(@tilebag1.tile_quantities["W"]).to eq 2 + expect(@tilebag1.tile_quantities["L"]).to eq 4 + end + end + + describe "#draw_tiles" do + it "returns the specifed number of random tiles" do + expect(@tilebag1.draw_tiles(4).length).to eq 4 + end + end + + +end From 15a466a7e1878f2bb84065ad6d112844a5d2c275 Mon Sep 17 00:00:00 2001 From: Desiree Date: Fri, 16 Oct 2015 09:51:37 -0700 Subject: [PATCH 07/12] Change tile_quantities from hash to array and changed test for it --- lib/tilebag.rb | 12 +++++++++--- spec/player_spec.rb | 2 +- spec/tilebag_spec.rb | 17 ++++++++++------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 2b3edd92..50fbe053 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -2,12 +2,18 @@ module Scrabble class TileBag attr_reader :tile_quantities def initialize - @tile_quantities = {"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} + #@tile_quantities = {"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} + @tile_quantities = %w{A A A A A A A A A B B C C D D D D + E E E E E E E E E E E E F F G G G H H I I I I I I I I I J K + L L L L M M N N N N N N O O O O O O O O P P Q R R R R R R S S + S S T T T T T T U U U U V V W W X Y Y Z} + end def draw_tiles(num) + [] end end end diff --git a/spec/player_spec.rb b/spec/player_spec.rb index 3a9b4bf4..493f9563 100644 --- a/spec/player_spec.rb +++ b/spec/player_spec.rb @@ -38,7 +38,7 @@ it "adds the input word to the plays array" do expect(@player2.plays).to eq ["love", "toast", "hand"] end - it "returns false is player has already won" do + it "returns false if player has already won" do expect(@player3.play("word")).to eq false end end diff --git a/spec/tilebag_spec.rb b/spec/tilebag_spec.rb index 73289b6d..1ae852c7 100644 --- a/spec/tilebag_spec.rb +++ b/spec/tilebag_spec.rb @@ -10,16 +10,19 @@ expect(@tilebag1).to be_an_instance_of Scrabble::TileBag end it "sets up an instance with a collection of default tiles" do - expect(@tilebag1.tile_quantities["W"]).to eq 2 - expect(@tilebag1.tile_quantities["L"]).to eq 4 + expect(@tilebag1.tile_quantities).to_not be_empty + expect(@tilebag1.tile_quantities.length).to eq 98 + #test length to eq 100 + #expect(@tilebag1.tile_quantities["W"]).to eq 2 + #expect(@tilebag1.tile_quantities["L"]).to eq 4 end end - describe "#draw_tiles" do - it "returns the specifed number of random tiles" do - expect(@tilebag1.draw_tiles(4).length).to eq 4 - end - end + # describe "#draw_tiles" do + # it "returns the specifed number of random tiles" do + # expect(@tilebag1.draw_tiles(4).length).to eq 4 + # end + # end end From 215be957d58e28e9d7a8262b3f61189e8525dcde Mon Sep 17 00:00:00 2001 From: Desiree Date: Fri, 16 Oct 2015 10:21:03 -0700 Subject: [PATCH 08/12] Add code for draw_tiles(num) and test and code for tiles_remaining --- lib/tilebag.rb | 21 +++++++++++---------- spec/tilebag_spec.rb | 22 ++++++++++++++-------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 50fbe053..756eb862 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -1,19 +1,20 @@ module Scrabble class TileBag - attr_reader :tile_quantities - def initialize - #@tile_quantities = {"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} - @tile_quantities = %w{A A A A A A A A A B B C C D D D D - E E E E E E E E E E E E F F G G G H H I I I I I I I I I J K - L L L L M M N N N N N N O O O O O O O O P P Q R R R R R R S S - S S T T T T T T U U U U V V W W X Y Y Z} + STARTING_TILES = %w{A A A A A A A A A B B C C D D D D +E E E E E E E E E E E E F F G G G H H I I I I I I I I I J K +L L L L M M N N N N N N O O O O O O O O P P Q R R R R R R S S +S S T T T T T T U U U U V V W W X Y Y Z} + attr_reader :tile_quantities, :tiles_remaining + def initialize + @tile_quantities = STARTING_TILES.shuffle! + @tiles_remaining = @tile_quantities.length end def draw_tiles(num) - [] + drawn_tiles = @tile_quantities.pop(num) + return drawn_tiles end + end end diff --git a/spec/tilebag_spec.rb b/spec/tilebag_spec.rb index 1ae852c7..61485231 100644 --- a/spec/tilebag_spec.rb +++ b/spec/tilebag_spec.rb @@ -12,17 +12,23 @@ it "sets up an instance with a collection of default tiles" do expect(@tilebag1.tile_quantities).to_not be_empty expect(@tilebag1.tile_quantities.length).to eq 98 - #test length to eq 100 - #expect(@tilebag1.tile_quantities["W"]).to eq 2 - #expect(@tilebag1.tile_quantities["L"]).to eq 4 end end - # describe "#draw_tiles" do - # it "returns the specifed number of random tiles" do - # expect(@tilebag1.draw_tiles(4).length).to eq 4 - # end - # end + describe "#draw_tiles" do + it "returns the specifed number of random tiles" do + expect(@tilebag1.draw_tiles(4).length).to eq 4 + end + it "removes the tiles from the default set" do + expect(@tilebag1.tile_quantities.length).to eq 94 + end + end + + describe "#tiles_remaining" do + it " returns the number of tiles remaining in the bag" do + expect(@tilebag1.tiles_remaining).to eq 94 + end + end end From 74c2e313d8f2454d6c1d390565bca3b75ee1c6a5 Mon Sep 17 00:00:00 2001 From: Desiree Date: Fri, 16 Oct 2015 10:31:33 -0700 Subject: [PATCH 09/12] fix total score method in Player class --- lib/player.rb | 11 ++++++----- lib/tilebag.rb | 1 - spec/player_spec.rb | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index d7ee2c9b..14fc04d9 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,11 +1,11 @@ module Scrabble class Player attr_reader :name, :plays - attr_accessor :total + def initialize(name) @name = name @plays = [] - @total = 0 + end def play(word) @@ -17,10 +17,11 @@ def play(word) end def total_score + total = 0 @plays.each do |word| - @total += Scrabble.score(word) + total += Scrabble.score(word) end - return @total + return total end def highest_scoring_word @@ -32,7 +33,7 @@ def highest_word_score end def won? - @total > 100 + total_score > 100 end end diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 756eb862..077405fa 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -15,6 +15,5 @@ def draw_tiles(num) drawn_tiles = @tile_quantities.pop(num) return drawn_tiles end - end end diff --git a/spec/player_spec.rb b/spec/player_spec.rb index 493f9563..df0a37c2 100644 --- a/spec/player_spec.rb +++ b/spec/player_spec.rb @@ -9,7 +9,7 @@ @player2.play("love") # love = 7 @player2.play("toast") # toast = 5 @player2.play("hand") # hand = 8 - @player3.total = 101 + @player3.play("zzzzzzzzzzz") # = 110 end describe ".new" do @@ -58,7 +58,7 @@ expect(@player2.won?).to eq false end it "returns false if player does not have over 100 points" do - @player4.total = 100 + @player4.play("zzzzzzzzzz") expect(@player4.won?).to eq false end end From 5fb9235b90c2c148755164fe2372c48ef85365ef Mon Sep 17 00:00:00 2001 From: Desiree Date: Fri, 16 Oct 2015 12:19:23 -0700 Subject: [PATCH 10/12] Add test for Player class #draw_tiles --- lib/player.rb | 15 +++++++++++++-- lib/tilebag.rb | 1 + spec/player_spec.rb | 20 +++++++++++++++++++- spec/tilebag_spec.rb | 7 ++++--- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 14fc04d9..7c3577c7 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,13 +1,15 @@ module Scrabble class Player - attr_reader :name, :plays + attr_reader :name, :plays, :tiles, :bag def initialize(name) @name = name @plays = [] - + @tiles = [] + @bag = nil end + def play(word) if won? == true return false @@ -36,5 +38,14 @@ def won? total_score > 100 end + def draw_tiles(tile_bag) + @bag = tile_bag + until @tiles.length == 7 + drawn_tile = @bag.draw_tiles(1) + @tiles.push(drawn_tile) + end + return @tiles + end + end end diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 077405fa..9c1e03b9 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -15,5 +15,6 @@ def draw_tiles(num) drawn_tiles = @tile_quantities.pop(num) return drawn_tiles end + end end diff --git a/spec/player_spec.rb b/spec/player_spec.rb index df0a37c2..4bdef57a 100644 --- a/spec/player_spec.rb +++ b/spec/player_spec.rb @@ -6,6 +6,7 @@ @player2 = Scrabble::Player.new("andre") @player3 = Scrabble::Player.new("batman") @player4 = Scrabble::Player.new("spiderman") + @player5 = Scrabble::Player.new("superman") @player2.play("love") # love = 7 @player2.play("toast") # toast = 5 @player2.play("hand") # hand = 8 @@ -58,7 +59,7 @@ expect(@player2.won?).to eq false end it "returns false if player does not have over 100 points" do - @player4.play("zzzzzzzzzz") + @player4.play("zzzzzzzzzz") #word = 100 points exactly expect(@player4.won?).to eq false end end @@ -75,6 +76,23 @@ end end + describe "#tiles" do + it "returns the collection of letters that the player can play" do + expect(@player5.tiles).to be_an_instance_of Array + end + it "contains a maximum of 7 tiles" do + expect(@player5.tiles.length).to be <= 7 + end + end + + describe "#draw_tiles(tile_bag)" do + it "fills tiles array until it has 7 letters from the given tile bag" do + @tilebag = TileBag.new + @player5.draw_tiles(@tilebag) + expect(@player5.tiles.length).to eq 7 + end + end + end diff --git a/spec/tilebag_spec.rb b/spec/tilebag_spec.rb index 61485231..faae1934 100644 --- a/spec/tilebag_spec.rb +++ b/spec/tilebag_spec.rb @@ -3,6 +3,7 @@ describe Scrabble::TileBag do before :each do @tilebag1 = Scrabble::TileBag.new + @tilebag2 = Scrabble::TileBag.new end describe "#initialize" do @@ -17,16 +18,16 @@ describe "#draw_tiles" do it "returns the specifed number of random tiles" do - expect(@tilebag1.draw_tiles(4).length).to eq 4 + expect(@tilebag2.draw_tiles(4).length).to eq 4 end it "removes the tiles from the default set" do - expect(@tilebag1.tile_quantities.length).to eq 94 + expect(@tilebag2.tile_quantities.length).to eq 94 end end describe "#tiles_remaining" do it " returns the number of tiles remaining in the bag" do - expect(@tilebag1.tiles_remaining).to eq 94 + expect(@tilebag2.tiles_remaining).to eq 94 end end From 54d06dfa104f05cde7c932f76a2d8d469433ed8c Mon Sep 17 00:00:00 2001 From: Desiree Date: Fri, 16 Oct 2015 13:50:59 -0700 Subject: [PATCH 11/12] Clean up some code --- lib/tilebag.rb | 7 +++---- spec/player_spec.rb | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/tilebag.rb b/lib/tilebag.rb index 9c1e03b9..e618bc44 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -7,13 +7,12 @@ class TileBag attr_reader :tile_quantities, :tiles_remaining def initialize - @tile_quantities = STARTING_TILES.shuffle! - @tiles_remaining = @tile_quantities.length + @tile_quantities = STARTING_TILES.shuffle! + @tiles_remaining = @tile_quantities.length end def draw_tiles(num) - drawn_tiles = @tile_quantities.pop(num) - return drawn_tiles + @tile_quantities.pop(num) end end diff --git a/spec/player_spec.rb b/spec/player_spec.rb index 4bdef57a..5fe97380 100644 --- a/spec/player_spec.rb +++ b/spec/player_spec.rb @@ -87,7 +87,7 @@ describe "#draw_tiles(tile_bag)" do it "fills tiles array until it has 7 letters from the given tile bag" do - @tilebag = TileBag.new + @tilebag = Scrabble::TileBag.new @player5.draw_tiles(@tilebag) expect(@player5.tiles.length).to eq 7 end From baae4ce241398c2c753a7a8e5450f417ca9114b6 Mon Sep 17 00:00:00 2001 From: Desiree Date: Fri, 16 Oct 2015 14:05:27 -0700 Subject: [PATCH 12/12] Fix the code to pass all tests --- lib/player.rb | 2 +- lib/tilebag.rb | 17 ++++++++++------- spec/tilebag_spec.rb | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/player.rb b/lib/player.rb index 7c3577c7..ad0b9c83 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -40,7 +40,7 @@ def won? def draw_tiles(tile_bag) @bag = tile_bag - until @tiles.length == 7 + until @tiles.length == 7 do drawn_tile = @bag.draw_tiles(1) @tiles.push(drawn_tile) end diff --git a/lib/tilebag.rb b/lib/tilebag.rb index e618bc44..ddb41e18 100644 --- a/lib/tilebag.rb +++ b/lib/tilebag.rb @@ -1,19 +1,22 @@ module Scrabble class TileBag - STARTING_TILES = %w{A A A A A A A A A B B C C D D D D -E E E E E E E E E E E E F F G G G H H I I I I I I I I I J K -L L L L M M N N N N N N O O O O O O O O P P Q R R R R R R S S -S S T T T T T T U U U U V V W W X Y Y Z} - attr_reader :tile_quantities, :tiles_remaining + attr_reader :tile_quantities def initialize - @tile_quantities = STARTING_TILES.shuffle! - @tiles_remaining = @tile_quantities.length + starting_tiles = %w{A A A A A A A A A B B C C D D D D + E E E E E E E E E E E E F F G G G H H I I I I I I I I I J K + L L L L M M N N N N N N O O O O O O O O P P Q R R R R R R S S + S S T T T T T T U U U U V V W W X Y Y Z} + @tile_quantities = starting_tiles.shuffle! end def draw_tiles(num) @tile_quantities.pop(num) end + def tiles_remaining + @tile_quantities.length + end + end end diff --git a/spec/tilebag_spec.rb b/spec/tilebag_spec.rb index faae1934..92f79606 100644 --- a/spec/tilebag_spec.rb +++ b/spec/tilebag_spec.rb @@ -4,6 +4,7 @@ before :each do @tilebag1 = Scrabble::TileBag.new @tilebag2 = Scrabble::TileBag.new + @tilebag2.draw_tiles(4) end describe "#initialize" do @@ -20,7 +21,7 @@ it "returns the specifed number of random tiles" do expect(@tilebag2.draw_tiles(4).length).to eq 4 end - it "removes the tiles from the default set" do + it "Removes the tiles from the default set" do expect(@tilebag2.tile_quantities.length).to eq 94 end end