-
Notifications
You must be signed in to change notification settings - Fork 27
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
Katrina and Hayden's Adagrams #17
base: master
Are you sure you want to change the base?
Changes from all commits
6cf68b8
f696fe6
a2b390c
b32c24d
e4ab05a
ad200b2
25a19be
cd46fb6
5bb9752
80a3ac2
09000de
7557152
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
|
||
require 'csv' | ||
|
||
# require_relative '../assets/dictionary-english.csv' | ||
|
||
def draw_letters | ||
letter_pool = %w( | ||
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 | ||
) | ||
|
||
player_hand = letter_pool.sample(10) | ||
|
||
return player_hand | ||
end | ||
|
||
|
||
def uses_available_letters?(input, letters_in_hand) | ||
letter_match_counter = 0 | ||
temp_letters_in_hand = letters_in_hand.dup | ||
|
||
input.chars.each do |letter| | ||
if temp_letters_in_hand.include?(letter.upcase) | ||
temp_letters_in_hand.delete_at(temp_letters_in_hand.index(letter.upcase)) | ||
letter_match_counter += 1 | ||
end | ||
end | ||
|
||
if letter_match_counter == input.length | ||
return true | ||
else | ||
return false | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way you could shorten this set of |
||
end | ||
|
||
|
||
def score_word(word) | ||
word_score = 0 | ||
letter_score = { | ||
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"] | ||
} | ||
|
||
word.chars.each do |letter| | ||
letter_score.each do |point_value, letters| | ||
if letters.include?(letter.upcase) | ||
word_score += point_value | ||
end | ||
end | ||
end | ||
|
||
|
||
if word.length >= 7 | ||
word_score += 8 | ||
end | ||
|
||
return word_score | ||
end | ||
|
||
|
||
def highest_score_from(words) | ||
highest_points_word = nil | ||
score = 0 | ||
|
||
words.each do |word| | ||
if score_word(word) > score | ||
highest_points_word = word | ||
score = score_word(word) | ||
|
||
elsif score_word(word) == score | ||
if word.length == 10 && word.length != highest_points_word.length | ||
highest_points_word = word | ||
elsif word.length < highest_points_word.length && highest_points_word.length != 10 | ||
highest_points_word = word | ||
end | ||
end | ||
end | ||
|
||
winning_word = {word: highest_points_word, score: score} | ||
return winning_word | ||
|
||
end | ||
|
||
|
||
def is_in_english_dict?(input) | ||
dictionary = CSV.read("assets/dictionary-english.csv") | ||
verify = false | ||
|
||
dictionary.each do |word| | ||
if word.include?(input) | ||
verify = true | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to a comment above but... "Vague thing" to think about...While you iterate through Remember, when you use the |
||
|
||
return verify | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,4 +168,30 @@ | |
expect(best_word[:score]).must_equal 18 | ||
end | ||
end | ||
|
||
describe 'is_in_english_dict? method' do | ||
it 'verifies that valid input matches an entry in the dictionary CSV file' do | ||
input = "codeine" | ||
|
||
expect(is_in_english_dict?(input)).must_equal true | ||
end | ||
|
||
it 'verifies that invalid word input returns false' do | ||
input = "poopydiscoopscoopdiddywhoopwhoopdiscoopdipoop" | ||
|
||
expect(is_in_english_dict?(input)).must_equal false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
end | ||
|
||
it 'verifies that first entry in the dictionary CSV file is read properly' do | ||
input = "Word" | ||
|
||
expect(is_in_english_dict?(input)).must_equal true | ||
end | ||
|
||
it 'verifies that first entry in the dictionary CSV file is read properly' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. me being nitpicky: this test is not named accurately! |
||
input = "zwitterion" | ||
|
||
expect(is_in_english_dict?(input)).must_equal true | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever way of realizing that counting all "successful matches" with
letter_match_counter
should be the same size as theinput
!I'll leave this as a "vague thing" to think about... I think that while you iterate through
input.chars
, you can actually determine thatuses_available_letters?
canreturn false
before the loop finishes.Remember, when you use the
return
keyword, it will kick the program execution out of the method early, and return whatever value you give it.