Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
bca89f7
Finishing baseline.
annamm77 Mar 8, 2016
6fc9a9d
adding simplecov to spechelper.
cotarg Mar 8, 2016
ea4aefd
setting up the basics
cotarg Mar 8, 2016
63bd384
wrote skeleton of first spec
cotarg Mar 8, 2016
befe81a
wrote beginning of scoring class.
cotarg Mar 8, 2016
9a69def
Rake file is now functional :)
annamm77 Mar 8, 2016
7810173
moved letter points constant to module since it will be used for more…
cotarg Mar 8, 2016
2ebf6a4
commiting and pushing to trade drivers
cotarg Mar 8, 2016
8bc6f70
Updated scoring_spec to include TEST_CASES and testing loop. Need to …
annamm77 Mar 8, 2016
dda5e5d
wrote a self.bonus method to calculate if there's a bingo bonus, comm…
cotarg Mar 8, 2016
455472f
wrote a method to iterate through letters and find their score value.
cotarg Mar 8, 2016
c47469b
required relative scoring.rb.
cotarg Mar 8, 2016
79170f5
fixed merge issuesgit status
cotarg Mar 8, 2016
9f69ae2
Updated instances of Scoring to Scrabble::Scoring, which fixed some e…
annamm77 Mar 8, 2016
7371c3a
we managed to go from errored out tests to failing tests...YAY PROGRE…
cotarg Mar 8, 2016
8ce7063
WE HAVE PASSING TESTS
cotarg Mar 8, 2016
839e236
Made a test for highest_score_from(array).
annamm77 Mar 8, 2016
56f936f
Set up Scrabble::Sorting.highest_score_from method. Ready to add logic.
annamm77 Mar 8, 2016
a4bbf83
Added logic to highest_score_from. Method test currently fails, more …
annamm77 Mar 8, 2016
2933db6
GREEN TEST FOR SMALLEST WORD IN THE ARRAY HECK YEAH
cotarg Mar 8, 2016
7db59d9
look at these beautiful tests. including some fun edge cases.
cotarg Mar 9, 2016
cba7c16
Edited a conditional into one line for highest_Score_from(array_of_wo…
annamm77 Mar 9, 2016
e48d0d1
I changed this and then changed it back before making an intermediate…
cotarg Mar 9, 2016
2712c0b
I added some more edge cases and have a lovely wall of green.
cotarg Mar 9, 2016
e74a8e1
Added Scrabble::Player class and began working on initialize. Wrote s…
annamm77 Mar 9, 2016
14e93d6
Scaffolded in methods using requirements for assignment, commented wi…
cotarg Mar 10, 2016
6d0ba9b
Defined some methods and passed some tests (:total_score, jerk code p…
cotarg Mar 10, 2016
f22a0a2
Wrote some tests for returning a score and playing a word.
cotarg Mar 10, 2016
59d86bc
Added scoring file to player.rb. Began working on play method for Scr…
annamm77 Mar 10, 2016
6867452
added pushing to the plays array and updating total score to play met…
cotarg Mar 10, 2016
386e482
Tests to see if play method returns correct value, if total score upd…
cotarg Mar 10, 2016
f82ef62
added won? method. this whole thing really needs a refactor\!
cotarg Mar 10, 2016
28fd5ac
Wrote highest_scoring_word method.
annamm77 Mar 10, 2016
12654b1
Working on highest_word_score test, at the moment. Go team.
annamm77 Mar 10, 2016
4fa88fd
wrote out explicit highest scoring word and highest word score method…
cotarg Mar 10, 2016
50a87b7
wrote a test to make sure highest word score and highest scoring word…
cotarg Mar 10, 2016
5fd090c
Forgot to save before commit, recomitting.
cotarg Mar 10, 2016
d8f9ae2
Wokred on play method to check if player has won or not.
annamm77 Mar 10, 2016
ee1b10f
In the middle of adding TEST_PLAYERS
annamm77 Mar 10, 2016
357964d
Committing specifically to revert to previous version.
cotarg Mar 10, 2016
3d6cf86
Committing specifically to revert to previous version.
cotarg Mar 10, 2016
e11f856
playing with let and trying to figure out how to make it work
cotarg Mar 11, 2016
ebc570c
I changed something in here. no idea what.
cotarg Mar 11, 2016
4629ae7
these tests dont work yet
cotarg Mar 11, 2016
f2ba179
manual merge
cotarg Mar 11, 2016
c8f1a47
these tests now work
cotarg Mar 11, 2016
e268512
these tests now work.
cotarg Mar 11, 2016
2d4d65e
these tests are SO broken. they're commented out so they don't stop u…
cotarg Mar 11, 2016
24c7182
Added DEFAULT_TILES constant.
annamm77 Mar 11, 2016
5acc05b
Created Tilebag Class. Need to have default tiles letterr constant co…
annamm77 Mar 11, 2016
52de6fb
In the middle of testing for tilebag having the correct default letters.
annamm77 Mar 11, 2016
8e70bbd
Forgot to save tilebag... my bad....
annamm77 Mar 11, 2016
4af33e3
set initializer to shuffle tiles on creation, wrote beginning of tile…
cotarg Mar 11, 2016
0fe76a4
our tests for the tilebag are failing again because we need to refact…
cotarg Mar 11, 2016
fe263c8
draw_tiles(num) seems functional.
annamm77 Mar 11, 2016
8507b9f
all tests are passing at the moment
annamm77 Mar 11, 2016
f1b150a
wrote a tiles_remaining method
cotarg Mar 11, 2016
4bb34c5
removed remaining reader for variable that was removed.
cotarg Mar 11, 2016
2fae99d
wrote a test to ensure that remaining tiles method works
cotarg Mar 11, 2016
e6c3fc2
Added draw_tiles method to Player. Still in progress.
annamm77 Mar 11, 2016
de1159d
Trying to get will fill tiles when tiles are drawn to work
annamm77 Mar 11, 2016
e5c3292
finished draw tiles method and tiles accessor.
cotarg Mar 11, 2016
d1d3300
tests that instance responds to query for tiles, and that draw_tiles …
cotarg Mar 11, 2016
dcbdcc3
removed some magic numbers and replaced with a constant
cotarg Mar 11, 2016
c2a65f1
set MAX_TILES == 7, since 7 is the standard max number of tiles.
cotarg Mar 11, 2016
b50f0d3
Edited tests to remove some magic numbers, and make some tests more m…
cotarg Mar 11, 2016
fe3b7fe
Condensed a couple of lines of code, reorganized a method so the comm…
cotarg Mar 11, 2016
59eaba6
edited player to condense some more code after checking the coverage …
cotarg Mar 11, 2016
fe74255
condensed some code to a single line expression since it's more expre…
cotarg Mar 11, 2016
4b4f487
amended specs to test scores against an array of tile play quantities.
cotarg Mar 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Scrabble
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3.0
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
56 changes: 56 additions & 0 deletions lib/player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require_relative '../scrabble'
require_relative './scoring'

class Scrabble::Player
attr_reader :name, :plays, :tiles
attr_accessor :total_score

# set up with empty plays array and score as instance variable
def initialize(name, score = 0)
@name = name
@total_score = score
@plays = []
@tiles = []
end

def play(word)
# requirement: return false if player's score > 100
return false if won?

# Adds the input word to the plays Array
self.plays << word

# add score for word to @score
self.total_score += Scrabble::Scoring.score(word)

# Returns the score of the word
Scrabble::Scoring.score(word)
end

def won?
# If the player has over 100 points returns true
return true if self.total_score > 100
end

def highest_scoring_word(array_of_words)
highest_score = ""
array_of_words.each do |word|
highest_score = word if Scrabble::Scoring.score(word) > Scrabble::Scoring.score(highest_score)
end
return highest_score
end

def highest_word_score
highest_score = ""
plays.each do |word|
highest_score = word if Scrabble::Scoring.score(word) > Scrabble::Scoring.score(highest_score)
end
return Scrabble::Scoring.score(highest_score)
end

def draw_tiles(tile_bag)
tiles << tile_bag.draw_tiles(Scrabble::MAX_TILES - tiles.length)
tiles.flatten!
end

end
68 changes: 68 additions & 0 deletions lib/scoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# possibly require Scrabble module
# require 'enumerable'
require_relative '../scrabble'

class Scrabble::Scoring # declare this as Scrabble::Scoring during cleanup.

def self.score(word)
self.scoring_math(word)
end

def self.highest_score_from(array_of_words)
highest_score = ""
array_of_words.each do |word|
if self.score(word) > self.score(highest_score)
highest_score = word
elsif self.score(word) == self.score(highest_score)
highest_score = word if word.length < highest_score.length
end
end
return highest_score
end

private # hiding the mess even from ourselves!!

def self.scoring_math(word)
# iterate over the letters in the word (after downcasing the word to ensure it matches up
# against our CONSTANT for checking)
# figure out what word[index] is worth
# add to running total
total_score = 0

word = word.downcase

for index in 0..word.length - 1
if Scrabble::LETTER_POINT_VALUES[1].include? word[index]
total_score += 1
elsif Scrabble::LETTER_POINT_VALUES[2].include? word[index]
total_score += 2
elsif Scrabble::LETTER_POINT_VALUES[3].include? word[index]
total_score += 3
elsif Scrabble::LETTER_POINT_VALUES[4].include? word[index]
total_score += 4
elsif Scrabble::LETTER_POINT_VALUES[5].include? word[index]
total_score += 5
elsif Scrabble::LETTER_POINT_VALUES[8].include? word[index]
total_score += 8
elsif Scrabble::LETTER_POINT_VALUES[10].include? word[index]
total_score += 10
end
end

# check if the word gets a bingo bonus
if self.bonus?(word)
total_score += 50
end

return total_score
end

# this will check if the word gets a bingo bonus!
# it should be a huh? method
def self.bonus?(word)
if word.length >= 7
return true
end
end

end
20 changes: 20 additions & 0 deletions lib/tilebag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require_relative '../scrabble'

class Scrabble::Tilebag
attr_reader :tiles

def initialize
@tiles = Scrabble::DEFAULT_TILES.shuffle
end

def draw_tiles(num)
tiles_drawn = []
tiles_drawn << tiles.pop until tiles_drawn.length == num
return tiles_drawn
end

def tiles_remaining
tiles.length
end

end
43 changes: 43 additions & 0 deletions scrabble.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# require_relative './lib/scoring'

module Scrabble

# fill in this array of hashes as a lookup table
LETTER_POINT_VALUES = { 1 => ["a", "e", "i", "o", "u", "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"]}

DEFAULT_TILES = ["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"]

MAX_TILES = 7

end
Binary file added specs/.DS_Store
Binary file not shown.
80 changes: 80 additions & 0 deletions specs/player_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require_relative './spec_helper'
require_relative '../scrabble'
require_relative '../lib/player'
require_relative '../lib/tilebag'

describe Scrabble::Player do
before do
@testbag = Scrabble::Tilebag.new

@jane = Scrabble::Player.new("Jane")


@bob = Scrabble::Player.new("bob")
@bob.total_score

@fred = Scrabble::Player.new("fred")
@fred.play("cupcake")
@fred.play("abalone")
end



it "exists" do
Scrabble::Player.wont_be_nil
end

# this test works because a proc is an objct that holds the code and runs it at testing and returns the value
it "has a name" do
proc { Scrabble::Player.new() }.must_raise(ArgumentError)
end

it "has a readable name instance variable" do
@jane.must_respond_to(:name)
end

it "will return a value when total score is queried" do
@jane.must_respond_to(:total_score)
end

it "will return the score when a play is made" do
@jane.play("cat").must_equal(Scrabble::Scoring.score("cat"))
end

it "will increase total_score when a word is played" do
score = @jane.total_score
@jane.play("elephant")
@jane.total_score.must_equal(score + Scrabble::Scoring.score("elephant"))
end

it "will push a word into the plays array" do
@jane.play("cat")
@jane.plays.must_include("cat")
end

it "will return true if total score is >100" do
@fred.won?.must_equal(true)
end

it "will return false if a winner tries to make a play" do
@fred.play("cat").must_equal(false)
end

it "selects the highest value word in the array" do
@fred.highest_scoring_word(@fred.plays).must_equal("cupcake")
end

it "selects the highest value word in the array and shows score value" do
@fred.highest_word_score.must_equal(Scrabble::Scoring.score(@fred.highest_scoring_word(@fred.plays)))
end

it "will return the tiles when queried" do
@bob.must_respond_to(:tiles)
end

it "will fill tiles when tiles are drawn" do
@bob.draw_tiles(@testbag)
@bob.tiles.length.must_equal(Scrabble::MAX_TILES)
end

end
79 changes: 79 additions & 0 deletions specs/sandbox_player_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#require_relative './spec_helper'
#require_relative '../scrabble'
#require_relative '../lib/player'
#
#describe Scrabble::Player do
# let(:jane) { jane = Scrabble::Player.new("Jane")
# jane.play("cat")
# return jane
# }
#
#
# let(:bob) { Scrabble::Player.new("bob")
# }
#
#
# let(:fred) { Scrabble::Player.new("fred")
# # fred.play("cupcake")
# # fred.play("abalone")
# # return fred
# }
#
#
#
#
#
#
# it "exists" do
# Scrabble::Player.wont_be_nil
# end
#
# # this test works because a proc is an objct that holds the code and runs it at testing and returns the value
# it "has a name(sb)" do
# proc { Scrabble::Player.new() }.must_raise(ArgumentError)
# end
#
# it "(sb)returns the name when queried" do
# jane.name.must_equal("Jane")
# end
#
# it "(sb)will return a value when total score is queried" do
# jane.total_score.wont_be_nil
# end
#
# it "(sb)will return the score when a play is made" do
# jane.play("cat").must_equal(5)
# end
#
# it "(sb)will push a word into the plays array" do
# jane.play("sat")
# jane.plays.must_include("sat")
# end
#
# # this test is meaningful because it tests if the score increases.
# # we use a word we know the score of to test if the total_score increases by that much.
# it "(sb)will increase total_score when a word is played" do
# jane.total_score.must_equal(score + 5)
# end
#
# it "(sb)will return true if total score is > 100" do
# fred.won?.must_equal(true)
# end
#
# it "(sb)will return false if total score is < 100" do
# bob.won?.must_equal(false)
# end
#
# it "(sb)returns highest scoring word in an array" do
# fred.highest_scoring_word(fred.plays).must_equal("cupcake")
# end
#
# it "(sb)returns the score for highest scoring word" do
# fred.highest_word_score.must_equal(67)
# end
#
# it "(sb)will return false if a winner tries to make a play" do
# fred.play("cat").must_equal(false)
# end
#end
#
Loading