Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrabble wave 3 #36

Open
wants to merge 10 commits into
base: ashbmk/master
Choose a base branch
from
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -71,14 +71,13 @@ 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.


<!--
## Wave 3

### 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:
Expand Down Expand Up @@ -119,4 +118,3 @@ Beginning Tile Quantities:
- Create a `Dictionary` class that includes a method for searching a list of words to determine if a given word is a valid word.
- Create a `Board` class that has a matrix (array of arrays) of tile places. Check if a word can be played on a given tile place in a certain direction.
- Include a minimum of 20 specs between the `Dictionary` and `Board` classes.
-->
12 changes: 12 additions & 0 deletions SPEC/dictionary_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require "./lib/scrabble_module"

describe Scrabble::Dictionary do
describe "valid_word?" do
it "checks to see if aardvark is a valid word (is included in the dictionary)" do
expect(Scrabble::Dictionary.valid_word?("aardvark")).to eq true
end
it "checks to see if dfskldfj is not a valid word (is not included in the dictionary)" do
expect(Scrabble::Dictionary.valid_word?("dfskldfj")).to eq false
end
end
end
41 changes: 29 additions & 12 deletions SPEC/player_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "./lib/player.rb"
require "./lib/scrabble_module"

describe Scrabble::Player do
before :each do
Expand Down Expand Up @@ -67,17 +67,6 @@
end
end

describe "highest_scoring_word" do
before :each do
@player.play("star")
@player.play("suns")
@player.play("dog")
end
it "returns dog as the highest scoring word when star, suns, dog are played" do
expect(@player.highest_scoring_word).to eq "dog"
end
end

describe "highest_scoring_word" do
before :each do
@player.play("zoo")
Expand All @@ -89,6 +78,17 @@
end
end

describe "highest word score" do
before :each do
@player.play("star")
@player.play("suns")
@player.play("dog")
end
it "returns 5" do
expect(@player.highest_word_score).to eq 5
end
end

describe "highest_word_score" do
before :each do
@player.play("zoo")
Expand All @@ -99,4 +99,21 @@
expect(@player.highest_word_score).to eq 16
end
end

describe "tiles and draw_tiles(tile_bag)" do
before :each do
@tile_bag = Scrabble::TileBag.new
end
it "fills tiles array to 7 letters when tile array is empty" do
@player.draw_tiles(@tile_bag)
expect(@player.tiles.length).to eq 7
end
it "adds 5 tiles to tile array when tile array has 2 letters" do
@player.tiles.push("a")
@player.tiles.push("p")
@player.draw_tiles(@tile_bag)
expect(@player.tiles.length).to eq 7
end
end

end
2 changes: 1 addition & 1 deletion SPEC/scrabble_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "./lib/scrabble.rb"
require "./lib/scrabble_module"

describe Scrabble::Scrabble do

Expand Down
37 changes: 37 additions & 0 deletions SPEC/tilebag_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require "./lib/scrabble_module"

describe Scrabble::TileBag do
before :each do
@tilebag = Scrabble::TileBag.new
end


describe "TileBag.new" do
it "creates a new instance of TileBag" do
expect(@tilebag).to be_an_instance_of Scrabble::TileBag
end
end

describe "draw_tiles(num)" do
it "returns 7 random tiles" do
expect(@tilebag.draw_tiles(7).length).to eq 7
end

it "takes away 7 tiles from the tilebag" do
num_tiles_in_bag = @tilebag.tilebag.length
@tilebag.draw_tiles(7)
expect(@tilebag.tilebag.length).to eq (num_tiles_in_bag - 7)
end
end

describe "tiles_remaining" do
it "returns the remaining number of tiles in the bag at beginning of game" do
expect(@tilebag.tiles_remaining).to eq 98
end

it "returns the remaining number of tiles in the bag after drawing 7" do
@tilebag.draw_tiles(7)
expect(@tilebag.tiles_remaining).to eq 91
end
end
end
12 changes: 12 additions & 0 deletions lib/scrabble/dictionary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require "./lib/scrabble_module"
module Scrabble
class Dictionary
def self.valid_word?(word)
File.open("./lib/scrabble/dictionary.txt") do |f|
f.any? do |line|
line.include?(word.upcase)
end
end
end
end
end
Loading