Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f4357fb
Added all necessary files
dri19tcc Mar 8, 2016
8a27d61
Shaving Yaks! AKA, more setup.
JBoshart Mar 8, 2016
6ac0e09
Updated tests to include score method
dri19tcc Mar 8, 2016
14ab14e
Discovered octothorp necessity in calling methods with tdd. Tests are…
JBoshart Mar 8, 2016
3b71c0c
updated our TDD to pass in a word and see if the word is split. Made…
dri19tcc Mar 8, 2016
e0a32d0
Added scoring chart hash, and test cases hash. Began working on test …
JBoshart Mar 8, 2016
1dcaea8
Wrote out loop to test all of our test cases. Started making our cod…
dri19tcc Mar 8, 2016
fee8843
Now that we are certain that the split portion of our score method is…
JBoshart Mar 8, 2016
91a7fe0
Made a loop in scoring.rb that goes through each letter and assigns a…
dri19tcc Mar 8, 2016
62acc10
YAY! Score method now adds the letter values.
JBoshart Mar 9, 2016
5fd0c05
Added te 50 point bonus. Added a ternary conditional. Updated tests…
dri19tcc Mar 9, 2016
42f8e55
Removed 'if it exists' tests as we do not need them. Started work on …
JBoshart Mar 9, 2016
c4454f3
Updated scoring-spec so that ARRAY_CASES contained hashes. Made sure…
dri19tcc Mar 9, 2016
5ad6fce
Added back in scoring test cases for single letters, as they are stil…
JBoshart Mar 9, 2016
7e5b99b
Changed error message in scoring-spec. Started tests in player-spec …
dri19tcc Mar 10, 2016
c1dcba2
Added name instance, and test for name instance being returned. Added…
JBoshart Mar 10, 2016
dd2426d
Added extra tests to make sure all our methods would be there. Start…
dri19tcc Mar 10, 2016
adaa5ee
Working on plays method, seeing if it returns an array.
JBoshart Mar 10, 2016
6864903
Tested and changed code to see if we can check if our plays method re…
dri19tcc Mar 10, 2016
1ae1b7c
Commented out passing tests from scoring-spec so that we had less to …
JBoshart Mar 10, 2016
dad7fae
Created a new instance variable called @words that was set to an empt…
dri19tcc Mar 10, 2016
8eba8c6
Got play(word) to push test case words to array contained within the …
JBoshart Mar 10, 2016
d8f2fa9
Added a new test that is also testing played(word) method, but also t…
dri19tcc Mar 11, 2016
8a34bdd
corrected the test to test what we actually wanted to test, not the o…
JBoshart Mar 11, 2016
05db6b8
Took out an empty line
dri19tcc Mar 11, 2016
8601484
Added a WIN_CONDITION
dri19tcc Mar 11, 2016
da71203
Added the method total_score. Started the test for total score
dri19tcc Mar 11, 2016
4f5f316
Got total_score working.
JBoshart Mar 11, 2016
0a1518e
Added a test for won? method. Then made the won? method return true …
dri19tcc Mar 11, 2016
7c244bb
Started working on highest_scoring_word method. Doing our best to use…
JBoshart Mar 11, 2016
4f47d6c
Made highest_scoring_word method return highest scoring word by utili…
JBoshart Mar 11, 2016
6eb6d07
Finished highest_score_word method and tests, finished highest_word_s…
dri19tcc Mar 11, 2016
23c08db
Added a test to see if the TileBag class exists. Made that test pass…
dri19tcc Mar 11, 2016
35f6e79
Added a test for number of tiles method
dri19tcc Mar 11, 2016
af0759f
Added a test for the draw_tiles(num) method. Added the method and got…
dri19tcc Mar 11, 2016
eafd864
Got stalled out on how to test the second part of the draw_tiles(num)…
JBoshart Mar 11, 2016
18e3c66
Made a test for tiles_remaining, added it's corresponding method and …
dri19tcc Mar 12, 2016
6aab539
Uncommented out our passing tests that we had previously commented ou…
JBoshart Mar 12, 2016
227b781
In working on ScrabbleSinatra I found that I wanted a method to check…
JBoshart Apr 7, 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
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['spec/*-spec.rb']
end

task default: :test
62 changes: 62 additions & 0 deletions lib/player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
class Player
attr_reader :name, :word
WIN_CONDITION = 100

def initialize(name)
@name = name
@words = []
@word_score = 0
end

def plays
return @words
end

def play(word)
if self.won? == true
return false
end
@word_score = Scoring.score(word)
@words << word
return @word_score
end

def total_score
tally = 0
@words.each do |word|
tally += Scoring.score(word)
end
return tally
end

def won?
if total_score > WIN_CONDITION
return true
end
return false
end

def highest_scoring_word
words_and_scores = { }
most = []
@words.each do |word|
words_and_scores[word] = (Scoring.score(word))
end
most = words_and_scores.max_by do |key, value|
value
end
return most[0]
end

def highest_word_score
words_and_scores = { }
most = []
@words.each do |word|
words_and_scores[Scoring.score(word)] = word
end
most = words_and_scores.max_by do |key, value|
key
end
return most[0]
end
end
43 changes: 43 additions & 0 deletions lib/scoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Scoring
SCORE_CHART = {
"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.check_if_letters(word)
!word.match(/[^A-Za-z]/)
end

def self.score(word)
arr = word.downcase.split(//)
arr.length == 7 ? tally = 50 : tally = 0
arr.each do |i|
value = SCORE_CHART[i]
tally = value + tally
end
return tally
end

def self.highest_score_from(array_of_words)
high_word = ""
high_score = 0
array_of_words.each do |word|
self.score(word)
if self.score(word) > high_score
high_word = word
high_score = self.score(word)
elsif self.score(word) == high_score
if word.length < high_word.length
high_word = word
high_score = self.score(word)
end
end
end
return high_word
end
end
40 changes: 40 additions & 0 deletions lib/tilebag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class TileBag
attr_reader :total_tiles
def initialize
@default_tiles = {
"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,
}
@total_tiles = 98
end

def draw_tiles(num)
your_tiles = []
until your_tiles.length == num do
tiles_picked = @default_tiles.keys.sample
your_tiles << tiles_picked
value = @default_tiles[tiles_picked]
new_value = value - 1
@default_tiles[tiles_picked] = new_value
end


#subtract tiles from @default_tiles
# sample = h.keys.sample example?
# h.select { |k,v| k == sample }
return your_tiles
end

def tiles_remaining
@total_tiles -= self.draw_tiles(num).length
return @total_tiles
end

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

module Scrabble
class Scoring
end

class Player
end

class TileBag
end
end
97 changes: 97 additions & 0 deletions spec/player-spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
require_relative './spec_helper'
require_relative '../lib/player'

TEST_CASES = ["word", "butt", "fart", "red"]
WIN_CASE = ["cazique", "mezquit"]
WINNING = 100


describe Player do
it "Does the Player Class exist test?" do
Player.wont_be_nil
end

describe "Player#new(name)" do
it "Does the class initialize with a name" do
Player.new(name).wont_be_nil
end
end

describe "#plays" do
test_player = Player.new(name)
it "Does it contain an array" do
test_player.plays.must_be_kind_of Array
end
end

describe "#play(word)" do

test_player = Player.new(name)

# TEST_CASES.each do |played_word|
it "Does it add the played word?" do
test_player.play("word")
test_player.plays.must_equal(["word"])
end
# end
end

describe "#play(word)" do

test_player = Player.new(name)

TEST_CASES.each do |played_word|
it "Does it return the score of the word" do
test_player.play(played_word).must_equal(Scoring.score(played_word))
end
end
end

describe "#total_score" do

test_player = Player.new(name)

it "Does it return the total score" do
TEST_CASES.each do |word|
test_player.play(word)
end
test_player.total_score.must_equal(25)
end
end

describe "#won?" do

test_player = Player.new(name)

it "Does it return true if the player won?" do
WIN_CASE.each do |word|
test_player.play(word)
end
assert test_player.won? == true
end
end

describe "#highest_scoring_word" do

test_player = Player.new(name)

it "Does it return the highest scoring WORD" do
TEST_CASES.each do |word|
test_player.play(word)
end
test_player.highest_scoring_word.must_equal("word")
end
end

describe "#highest_word_score" do

test_player = Player.new(name)

it "Does it return the highest word SCORE" do
TEST_CASES.each do |word|
test_player.play(word)
end
test_player.highest_word_score.must_equal(8)
end
end
end
52 changes: 52 additions & 0 deletions spec/scoring-spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require_relative './spec_helper'
require_relative '../lib/scoring'

describe Scoring do
it "Does the Scoring Class exist?" do
Scoring.wont_be_nil
end

describe "Scoring#score(word)" do
HASH_CASES = {
"cat" => 5,
"CAT" => 5,
"BOX" => 12,
"box" => 12,
"googles" => 59,
"GOOgles" => 59,
"m" => 3,
"f" => 4,
"v" => 4,
"k" => 5,
"j" => 8,
"z" => 10
}

HASH_CASES.each do |letters, score|
it "Does it assign a score number to each letter" do
Scoring.score(letters).must_equal(score)
end
end
end

describe "Scoring#highest_score_from(array_of_words)" do
ARRAY_CASES = {
"cat" => ["cat"],
"box" => ["cat", "box"],
"box" => ["phone", "box", "cat"],
"purple" => ["purple", "farts", "hands", "butts"],
"hands" => ["hands", "violet"],
"hands" => ["violet", "hands"],
"jukebox" => ["jukebox", "cazique", "mezquit"],
"mezquit" => ["mezquit", "jukebox", "cazique"],
"buzzcut" => ["jukebox", "buzzcut"],
"buzzcut" => ["buzzcut", "jukebox"]
}

ARRAY_CASES.each do |key, value|
it "Does it return the highest score" do
Scoring.highest_score_from(value).must_equal(key)
end
end
end
end
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'simplecov'
SimpleCov.start

require 'minitest'
require 'minitest/spec'
require 'minitest/autorun'
require 'minitest/reporters'

# give us some really pretty output :)
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
36 changes: 36 additions & 0 deletions spec/tilebag-spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require_relative './spec_helper'
require_relative '../lib/tilebag'


describe TileBag do
it "Does the TileBag Class exist test?" do
TileBag.wont_be_nil
end

describe "#draw_tiles" do
it "Does it return number of random tiles" do
test_tiles = TileBag.new
tile_list = test_tiles.draw_tiles(7)
tile_list.length.must_equal(7)
end
end

describe "#tiles_remaining" do
it "Does it return tiles remaining" do
test_tiles = TileBag.new
test_tiles.tiles_remaining.must_equal(91)
end
end
end



#TRYING TO FIGURE OUT IF IT IS SUBTRACTING CORRECT TILES. CURRENTLY UNABLE TO MAKE IT WORK. WILL COME BACK.
# describe "#draw_tiles" do
#
# it "Does it subtract the correct tiles from tile chosen?" do
# test_tiles = TileBag.new
# test_tiles.draw_tiles(2).must_equal(3)
#
# end
# end