forked from AdaGold/adagrams
-
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
SHERMAN and FAHMY Adagrams #6
Open
Peacegypsy
wants to merge
12
commits into
Ada-C10:master
Choose a base branch
from
Peacegypsy:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
55086ff
added draw_letters method
jfahmy b207dc3
added uses_available_letters def, passed tests
732e086
add score_word method with passing tests
jfahmy e66a579
shortened if statement in score word method
jfahmy 0e254ed
fixes the if statement bug caused by last commit
jfahmy 3562f7e
added variable to handle a tie for best word
75cf2c7
refactored score_word method, tests passed
jfahmy 9a724ec
handles ties for highest score from method, tests passed
jfahmy 5b09bfc
Adjusted spacing
jfahmy cedee69
Added option Wave 5 to check dictionary in csv file
cc32e4e
adjusted wave 3 code so that we are not deleting from the original array
jfahmy ea1a9d9
removed extraneous csv test file
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
require 'csv' | ||
|
||
def draw_letters | ||
alphabet = { | ||
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 | ||
} | ||
|
||
hand = [] | ||
tiles_drawn = 0 | ||
until tiles_drawn == 10 | ||
letter = alphabet.keys.sample | ||
if alphabet[letter] > 0 | ||
alphabet[letter] -= 1 | ||
hand << letter.to_s | ||
tiles_drawn += 1 | ||
end | ||
end | ||
hand | ||
|
||
end | ||
|
||
def uses_available_letters?(input, letter_in_hand) | ||
new_letters = letter_in_hand.map { |i| i } | ||
input.split("").each do |letter| | ||
if !new_letters.include? letter | ||
return 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. Good job returning when you know the outcome! |
||
elsif new_letters.include? letter | ||
index = new_letters.find_index(letter) | ||
new_letters.delete_at(index) | ||
end | ||
end | ||
return true | ||
end | ||
|
||
def score_word(word) | ||
word_score = 0 | ||
|
||
word.split("").each do |letter| | ||
letter = letter.upcase.to_sym | ||
case letter | ||
when :A, :E, :I, :O, :U, :L, :N, :R, :S, :T | ||
word_score += 1 | ||
when :D, :G | ||
word_score += 2 | ||
when :B, :C, :M, :P | ||
word_score += 3 | ||
when :F, :H, :V, :W, :Y | ||
word_score += 4 | ||
when :K | ||
word_score += 5 | ||
when :J, :X | ||
word_score += 8 | ||
when :Q, :Z | ||
word_score += 10 | ||
end | ||
end | ||
|
||
word_score += 8 if (7..10).include?(word.length) | ||
|
||
return word_score | ||
end | ||
|
||
def highest_score_from(words) | ||
best_word = {word: nil, score: 0} | ||
words.each do |word| | ||
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. ONE LOOP I LOVE IT |
||
if score_word(word) > best_word[:score] | ||
best_word[:score] = score_word(word) | ||
best_word[:word] = word | ||
elsif score_word(word) == best_word[:score] | ||
if word.length == 10 && best_word[:word].length != 10 | ||
best_word[:word] = word | ||
elsif word.length < best_word[:word].length && best_word[:word].length != 10 | ||
best_word[:word] = word | ||
end | ||
end | ||
end | ||
best_word | ||
end | ||
|
||
|
||
def is_in_english_dict?(input) | ||
csv_file = 'assets/dictionary-english.csv' | ||
CSV.read(csv_file, "r").each do |line| | ||
return true if line.include? input.downcase | ||
end | ||
return false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require 'csv' | ||
require_relative 'lib/adagrams' | ||
|
||
def display_welcome_message | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using a hash with sample gives an equal 1/26 chance to each letter, instead we need the chances to be weighted.