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

Created skeleton of directory requirements. #1

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0b9406d
Created skeleton of directory requirements.
rpavilanis Aug 29, 2016
1f16bb3
Added helper file
rpavilanis Aug 30, 2016
7fc99b3
Added file to specs folder
rpavilanis Aug 30, 2016
0f9cf0f
Made scoring class file
rpavilanis Aug 30, 2016
d4e0c52
renamed spec file
rpavilanis Aug 30, 2016
5cc1928
Added LETTER_HASH to module.rb
rpavilanis Aug 30, 2016
bb0f694
Added class and initialize/self.score methods
rpavilanis Aug 30, 2016
0eb00db
Added test to scoring_spec.rb file
rpavilanis Aug 30, 2016
bdbbc07
Rachel and I created test cases for scoring of words such as 'bad', '…
Trishthedish Aug 30, 2016
6b7e3a8
Fixed the calling of class instance methods which needed to include o…
Trishthedish Aug 30, 2016
26b9e55
Added method for doing total score
rpavilanis Aug 30, 2016
3f09013
Created a working class method highest_score_from(array_of_words). Us…
Trishthedish Aug 30, 2016
e6fd830
Started to look at how to deal with ties. Moving on to having Rachel …
Trishthedish Aug 30, 2016
02f0150
Added notes.md file
rpavilanis Aug 30, 2016
ed3700f
added notes for test cases
rpavilanis Aug 30, 2016
c31ae58
Created more test case scenarios that would hadle much of the logic t…
Trishthedish Aug 30, 2016
3d24e00
Added outline to notes for a solution re: self.highest_score_from. Co…
rpavilanis Aug 31, 2016
ae768a4
Accomplished Wave1 requirements. Made test more accuately describe wh…
Trishthedish Aug 31, 2016
1286452
Added skeleton of class Player and wrote pseudocode for various methods.
rpavilanis Aug 31, 2016
e8c3d61
added test cases to player_spec.rb
rpavilanis Aug 31, 2016
d0017c7
Tackled properly creating tests for play and play methods. Continued …
Trishthedish Aug 31, 2016
f4e0542
Finished writing total_score, won?, highest_scoring_word, and highest…
rpavilanis Aug 31, 2016
323561f
Created a plan for conquering wave 3, set up our plans
Trishthedish Aug 31, 2016
5866c47
Added letters to tile bag in 2-d array. Added note to add a test for …
rpavilanis Aug 31, 2016
892eb71
Started out creating the logic for default tile bag and then had to s…
Trishthedish Aug 31, 2016
f8a3655
Added test and commented out for Player.rb - verifying name.
rpavilanis Aug 31, 2016
b78ffc4
Merge Changes
Trishthedish Aug 31, 2016
3004fc9
fixed the madness.Thanks Chris
Trishthedish Aug 31, 2016
acf0f65
Continued work on Wave3. Created tests and variable names within the …
Trishthedish Aug 31, 2016
764ace9
Added an additional test and notes for two other tests we need to cre…
rpavilanis Aug 31, 2016
653978a
Added a few extra comments to Scoring.rb class. Add in some logic ar…
rpavilanis Sep 1, 2016
2432a92
put two ideas from Chris about tests.
rpavilanis Sep 1, 2016
0c7a025
Finished draw_tiles and tiles_remaining methods. Finished tests for t…
rpavilanis Sep 1, 2016
8c4468b
Added test for player method that test if enought tiles were used. Al…
Trishthedish Sep 1, 2016
eca8d4c
Added working draw_tiles method to Player class, adjusted tests for P…
rpavilanis Sep 2, 2016
ee5579b
added method for navigating through and deleting tiles from @picked_t…
rpavilanis Sep 2, 2016
6ec0091
After everything to work properly we built a really not dry test case…
Trishthedish Sep 2, 2016
dd768a5
Created test sceanio that is long winded.
Trishthedish Sep 2, 2016
1b33069
Cleaned up code & made sure MVP was officially met. COMPLETED THE MVP…
Trishthedish Sep 2, 2016
91dd570
started to work with wave2
Trishthedish Nov 18, 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
18 changes: 17 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,37 @@
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/

# Used by dotenv library to load environment variables.
# .env

## Specific to RubyMotion:
.dat*
.repl_history
build/
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/

## Specific to RubyMotion (use of CocoaPods):
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# vendor/Pods/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

## Environment normalisation:
## Environment normalization:
/.bundle/
/vendor/bundle
/lib/bundler/man/
Expand All @@ -33,3 +48,4 @@ build/

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
.DS_Store
13 changes: 13 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs = ["lib", "specs"]
t.warning = false
t.verbose = false
t.test_files = FileList['specs/*_spec.rb']
puts "Running TestTask"
end

task default: :test do
puts "Running my Rakefile"
end
80 changes: 80 additions & 0 deletions lib/Player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require_relative "../module"
require_relative "../lib/TileBag"
require_relative "../lib/Scoring"
# :: module reference

class Scrabble::Player

attr_reader :name, :total_score, :picked_tiles, :tilebag1

def initialize(name)
@name = name
@word_score = 0
@total_score = 0
@words_by_player = []
@picked_tiles = []

end

def plays
# returns Array of words played
return @words_by_player
end

def play(word)
# play(word): Function: adds the input word to words_by_player
# returns false if player has already won, otherwise return @word_score
if won?
return false
else
word.each_char do |letter|
if picked_tiles.include? letter
@picked_tiles.delete_at(@picked_tiles.index(letter))
end
end
@words_by_player << word
@word_score = Scrabble::Scoring.score(word)
return @word_score
end
end

def total_score
# Returns the sum of scores of played words: @total_score
@words_by_player.each do |word|
@total_score += Scrabble::Scoring.score(word)
end
return @total_score
end

def won?
# If the player has over 100 points, returns true, otherwise returns false
if @total_score >= 100
return true
else
return false
end
end

def highest_scoring_word
# Returns the highest scoring played word
return Scrabble::Scoring.highest_score_from(@words_by_player)
end

def highest_word_score
# Returns the highest_scoring_word's score
# proudest moment for Rachel lol
high_score_word = highest_scoring_word
highest_score = Scrabble::Scoring.score(high_score_word)
return highest_score
end
def tiles
return @picked_tiles
end

def draw_tiles(tile_bag)
# fills the tile array until it has 7 letters from the given tile bag
@picked_tiles << tile_bag.draw_tiles(7 - @picked_tiles.length)
return @picked_tiles.flatten!
end
# class end
end
55 changes: 55 additions & 0 deletions lib/Scoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require_relative "../module"

class Scrabble::Scoring

attr_reader :word
attr_accessor :total

def self.score(word)
# create an array of strings (letters) from word
# loop through letters array in order to determine total score (by referencing LETTER_HASH)

return 0 if word.nil? || word.empty?

letters = word.upcase.split('')

letters.length >= 7 ? total = 50 : total = 0

letters.each do |letter|
total += Scrabble::LETTER_HASH[letter]

end

return total

end

def self.highest_score_from(array_of_words)
# initialize two variables in order to hold max_score and max_scoring_word
# iterate through the array_of_words and use if statements to determine when the word and score are stored in the local variables
# use tie-breaking logic in if statements to determine when to score word/score into variable
max_score = 0
max_scoring_word = ""

array_of_words.each do |word|

if score(word).to_i > max_score
max_score = score(word)
max_scoring_word = word

elsif score(word).to_i == max_score
if word.chars.count >= 7
max_score = score(word)
max_scoring_word = word

elsif word.chars.count < max_scoring_word.chars.count
max_score = score(word)
max_scoring_word = word

end
end
end
return max_scoring_word
end
#class end.
end
51 changes: 51 additions & 0 deletions lib/TileBag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require_relative '../lib/Scoring'
require_relative '../module'
require 'awesome_print'

class Scrabble::TileBag

attr_reader :picked_tiles

def initialize
# called When you use TileBag.new sets up an instance with a collection of default tiles.
@default_tile_bag = [
["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", "V", "V"], ["W", "W"],
["X"], ["Y", "Y"], ["Z"]
]

@flattened_default_tile_bag = @default_tile_bag.flatten
@picked_tiles = []

end

def draw_tiles(num)
# Purpose: returns a number (num) of random tiles, removes those tiles from default set. if statement for number of tiles left in bag! Throw error if try to draw more tiles than are left in bag: "There are only #{num_tiles_remain} left in the bag!"
@flattened_default_tile_bag.shuffle!

if @flattened_default_tile_bag.length < num || num > 7 || num + picked_tiles.length > 7
raise ArgumentError, "This is a friendly reminder that you're terminal."
else
picked_tiles << @flattened_default_tile_bag.pop(num)
return picked_tiles.flatten!
end

end

def tiles_remaining
# returns the numbers of tiles remaining in the bag.
num_tiles_remain = @flattened_default_tile_bag.length
return num_tiles_remain

end

end
13 changes: 13 additions & 0 deletions module.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# module.rb

module Scrabble
LETTER_HASH = {
"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
}
end
75 changes: 75 additions & 0 deletions notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
_____________
CURRENT IDEA:
1. create a variable for max_score and max_scoring_word
max_score = 0
max_scoring_word = ""
2. iterate through array_of_words ( array_of_words.each do |word|
) and within that put if/elsif statements
3. For the if/elsif statements within loop ("if score(word).to_i > max_score", and then also "if score(word).to_i == max_score")
4. ONLY if they are equal, do if statements below

____________
FOR TIE-BREAKER IF STATEMENTS
1. word.chars.count >= 7 and then also word.chars.count < max_scoring_word.chars.count (so this deals with a couple of the tests we wrote earlier - basically just wrote this based on what we generated earlier)
then put this for both: max_score = score(word)
max_scoring_word = word

This SHOULD account for the tie-breaker situations we wrote tests for earlier. I forgot about the .chars method that you can call on a string - it just looks at the characters and then the .count method counts them up!
____________
OLD IDEAS:
1. when looping through array of words, assign key as word (as string) and value as total amount
2. sort hash.values.sort.reverse -> will give us array of sorted values (highest to lowest)

3. are there any repeating values :.map same as .collect : goes through array or hash and does whatever you ask it to do -> then sticks answer into an array
4. only keep highest repeating values (delete others)
5. if there are highest repeating values THEN continue:
6. create array of key lengths of remaining repeating values
hash = { "Cat" => 7, "Doggy" => 15, "Joe" => 5 }
array = []

hash.each do |k, v|

array << k.length
end

puts array
_________
OLD CODE:
def self.highest_score_from(array_of_words)
# output is word in array with highest_score_from
scored_words_array = []
array_of_words.each do |word|
scored_words_array << score(word).to_i
end
return scored_words_array.max
end
________________
Ideas:
if max_scores_array has length of 1 - then DONE and return word that wins
else
iterate through this
tie breaker method with ifs (compare with arrays, and then to return word refer to corresponding index)
end

if statements:
.min_by - Enumerables: array.min_by { |word| word.length } - will help with tied with 3 or 2 words when we return the one with fewer letters

if tie with two words of same length and value -> return max_scoring_words.first

word.index[word]
_______________________

test cases ->
# tied with 2
# two thirty point words (frizzy and mezuzah both = 30) and two others
["frizzy", "mezuzah", "cat", "milk"]

[30, 30, 5, 6]
# tied with 3
# three twenty point words (boxwood, chintz, bozeman) and three others
["boxwood", "chintz", "bozeman" "dog", "litter", "bike"]

# tie with one 7-letter word and one with fewer letters
["acardia", "abyss", "dog", "cat"]
# tie with two words of same length and value
["nuzzle", "nozzle", "dog", "cat"]
11 changes: 11 additions & 0 deletions specs/Spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Spec_helper.rb

require 'simplecov'
SimpleCov.start

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

Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
5 changes: 5 additions & 0 deletions specs/coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"result": {
"covered_percent": 100.0
}
}
7 changes: 7 additions & 0 deletions specs/coverage/.resultset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"RSpec": {
"coverage": {
},
"timestamp": 1472667020
}
}
Empty file.
Loading