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

Nicole and Yasmin #6

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8f4f07f
Baseline
yasminor Aug 29, 2016
d4a34f7
first spec passed
nurlywhirly Aug 30, 2016
5cdfd2e
three tests in initialize method pass
nurlywhirly Aug 30, 2016
47a440b
Five passing tests
yasminor Aug 30, 2016
87ba82a
WiP - Before lunch
nurlywhirly Aug 30, 2016
a216a28
Added self.score method
yasminor Aug 30, 2016
810adf3
got rid of collecting all word bc we weren't supposed to
nurlywhirly Aug 31, 2016
048ec4e
Added three tests for #highest_score_from_array class method
yasminor Aug 31, 2016
09977de
We think we understand you can only test inputs and outputs of methods
nurlywhirly Aug 31, 2016
c4302e6
WiP - lecture interrupting our building of a scored words hash
nurlywhirly Aug 31, 2016
56319bd
Added .gitignore
nurlywhirly Aug 31, 2016
84d33f1
WIP: building our scored hash in #highest_score_from_array
yasminor Aug 31, 2016
960941c
highest_score_from_array success
nurlywhirly Aug 31, 2016
9f3427c
nine tests running green on Scoring.rb
nurlywhirly Aug 31, 2016
ed2667d
Started Player class
yasminor Aug 31, 2016
58db8b8
Now testing to make sure #highest_score_from_array is returning the c…
yasminor Sep 1, 2016
4deaabd
WiP lunchtime commit. More player tests finished.
nurlywhirly Sep 1, 2016
af607ff
Finished Wave II
yasminor Sep 1, 2016
4bc6730
Began Tilebag class
yasminor Sep 1, 2016
4c361ec
Finished wave 3 yay
nurlywhirly Sep 1, 2016
d268ddd
Finished wave 3 requirement to tie tilebag to player
nurlywhirly Sep 2, 2016
5bbdd58
Fixed problem of drawing negative tiles
nurlywhirly Sep 2, 2016
3b046f7
This is the best that you get
yasminor Sep 2, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
*.rbc
/.config
/coverage/
/specs/coverage
/InstalledFiles
/pkg/
/spec/reports/
/test/tmp/
/test/version_tmp/
/tmp/
/specs/.DS_Store
.DS_Store

## Specific to RubyMotion:
.dat*
Expand Down
76 changes: 76 additions & 0 deletions Player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require_relative 'scoring'
require_relative 'tilebag'

module Scrabble
class Player
attr_accessor :name, :score_array
attr_reader :word_array, :tiles

def initialize(name)
@name = name
@word_array = []
@score_array = []
@tile_bag = Scrabble::Tilebag.new
@tiles = []
end

def plays
return @word_array
end

def play(word)
raise ArgumentError.new("invalid input type") unless word.is_a?(String)
@word_array << word
score = Scrabble::Scoring.score(word)
@score_array << score
if won? == true
puts "You won!"
return false
else
return score
end
end

def total_score
@score_array.reduce(:+)
end

def won?
if total_score >= 100
return true
else
return false
end
end

def highest_scoring_word
Scrabble::Scoring.highest_score_from_array(@word_array)
end

def highest_word_score
word = highest_scoring_word
return Scrabble::Scoring.score(word)
end

def draw_tiles(tile_bag)
raise ArgumentError.new("you cannot draw more than 7 or less than 1") if (tile_bag > 7 || tile_bag < 1)

draw_array = []
draw_array = @tile_bag.tb_draw_tiles(tile_bag)


raise ArgumentError.new("you cannot have more than 7 in your hand") if @tiles.length + draw_array.length > 7

draw_array.each do |tile|
@tiles << tile
end


end

def tiles
return @tiles
end

end
end
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.test_files = FileList['specs/*_spec.rb']
end

task default: :test
92 changes: 92 additions & 0 deletions Scoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
module Scrabble
class Scoring
attr_accessor :array_of_words, :word, :length, :score
attr_reader

SCORE_CHART = {
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"]
}

def initialize
@array_of_words = array_of_words
end

def collect_word_from_user(word)
@word = word
end

# # nope
# def store_all_game_words(word)
# @array_of_words << word
# end

def self.score(word)
raise ArgumentError.new("invalid input type") unless word.is_a?(String)

letter_array = word.upcase.split(//)
single_word_score = []

letter_array.each do |i|
Scrabble::Scoring::SCORE_CHART.each do |letter_score, letters|
if letters.include?(i)
single_word_score << letter_score
break
end
end
end

if letter_array.length == 7
single_word_score.reduce(:+) + 50
else
return single_word_score.reduce(:+)
end
end

def self.highest_score_from_array(array_of_words)
raise ArgumentError.new("invalid input type") unless array_of_words.is_a?(Array)

array_of_words.each do |word|
raise ArgumentError.new("invalid input type") unless word.is_a?(String)
end

scored_hash = {}

array_of_words.each do |word|
word_score = Scrabble::Scoring.score(word)
scored_hash[word_score] = Array.new
end

array_of_words.each do |word|
word_score = Scrabble::Scoring.score(word)
scored_hash[word_score] << word
end

high_scores = scored_hash.max[1]
high_scores_lengths = []

if high_scores.length == 1
return high_scores[0]
else
high_scores.each do |word|
length = word.length
high_scores_lengths << length
end
lowest = high_scores_lengths.min

high_scores.each do |word|
if word.length == lowest
return word
end
end

end
end

end
end
33 changes: 33 additions & 0 deletions just for help.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe Card do
# What class you're testing

describe "#initialize" do
# Here we put the methods in "#method" format
card = Card.new("suit",1)
# So you don't have to keep writing the above line over and over again in the following "describes"

it "can create a new instance of Card" do
# Make this as specific to the test it can be, aka it really describes what the test is testing
card.must_be_instance_of(Card)
# We "run the method" here, aka def initialize is also Card.new(parameters)
end

it "should have a suit property" do
# Note: these tests will be run in random order
card.must_respond_to(:suit)
end

it "should have a value property" do
card.must_respond_to(:value)
end

it "first initialize parameter must be \"suit\"" do
card.suit.must_equal("suit")
# the first "suit" in above line is the instance variable
end

it "second initialize parameter must be \"1\"" do
card.value.must_equal(1)
end
end
end
Binary file added specs/.DS_Store
Binary file not shown.
70 changes: 70 additions & 0 deletions specs/Scoring_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require_relative 'spec_helper'
require_relative '../Scoring.rb'

describe Scrabble::Scoring do

it "should have a scoring chart" do
Scrabble::Scoring::SCORE_CHART.wont_be_nil
end

describe "#initialize" do

it "should create a new instance of Scoring" do
Scrabble::Scoring.new.must_be_instance_of(Scrabble::Scoring)
end

end

describe "#collect_word_from_user" do
it "should pull in a parameter that is the player's word choice" do
Scrabble::Scoring.new.must_respond_to(:word)
end

it "should call the store_all_game_words method" do
Scrabble::Scoring.new.must_respond_to(:store_all_game_words)
end
end

describe "#self.score" do
it "should raise an error if the input is not a string" do
proc { Scrabble::Scoring.score(1) }.must_raise(ArgumentError)
end

it "should output something, not nothing" do
Scrabble::Scoring.score("word").wont_be_nil
end

it "should output something has a class of Fixnum" do
Scrabble::Scoring.score("word").must_be_kind_of Fixnum
end

#A test to check if it scores a (particular) word correctly (fox = 13)
it "should score fox as 13" do
Scrabble::Scoring.score("fox").must_equal(13)
end

end

describe "self.highest_score_from_array(array_of_words)" do

it "should raise an error when something that isn't an array is passed in" do
proc { Scrabble::Scoring.highest_score_from_array({}) }.must_raise(ArgumentError)
end

it "should raise an error when an element inside of the input array isn't a string" do
proc { Scrabble::Scoring.highest_score_from_array( [1] )}.must_raise(ArgumentError)
end

it "should output something has a class of String" do
Scrabble::Scoring.highest_score_from_array(["sdf","sdfds"]).must_be_kind_of String
end

it "should return the first word in a tie" do
test_array = ["J", "X"] #J and X are both worth 8 points
Scrabble::Scoring.highest_score_from_array(test_array).must_equal("J")
end
end

end

# Scrabble::Scoring.new("word").collect_word("word")
Loading