forked from AdaGold/adagrams
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Sockets - Carla & Rosalyn #18
Open
ranuseh
wants to merge
6
commits into
Ada-C11:master
Choose a base branch
from
ranuseh: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
6 commits
Select commit
Hold shift + click to select a range
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,177 @@ | ||
require "csv" | ||
|
||
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) | ||
|
||
def display_welcome_message | ||
puts "Welcome to Adagrams!" | ||
end | ||
|
||
def draw_letters | ||
drawn_letters = LETTER_POOL.sample(10) | ||
return drawn_letters | ||
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. Love how easy this is to read. |
||
end | ||
|
||
def display_drawn_letters(letters) | ||
puts "You have drawn the letters:" | ||
puts letters.join(', ') | ||
end | ||
|
||
def display_game_instructions | ||
puts "Please input your submission for the longest anagram you can come up with" | ||
end | ||
|
||
def display_needs_valid_input_message | ||
puts "You entered in a word that contains characters not in the letter bank" | ||
display_game_instructions | ||
end | ||
|
||
def display_retry_instructions | ||
puts "Should we play another round?" | ||
puts "Enter y to replay" | ||
puts "Enter n to quit" | ||
end | ||
|
||
def display_not_in_letter_bank_message | ||
puts "You entered in a word that contains characters not in the letter bank" | ||
display_game_instructions | ||
end | ||
|
||
def display_score(score) | ||
puts "Your submitted anagram scored #{score} points" | ||
end | ||
|
||
def display_highest_score(high_score_hash) | ||
puts "Thanks for playing Adagrams!" | ||
puts "The highest score from this game was #{high_score_hash[:word]}, which was worth #{high_score_hash[:score]} points" | ||
end | ||
|
||
def display_goodbye_message | ||
puts "Goodbye!" | ||
end | ||
|
||
# Wave 2 | ||
|
||
def get_user_input | ||
gets.chomp.upcase | ||
end | ||
|
||
def uses_available_letters?(input, letters_in_hand) | ||
letters = input.upcase.split('') | ||
letters_in_hand.each do |l| | ||
i = letters.index(l) | ||
next if i.nil? | ||
letters.delete_at(i) | ||
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 work using |
||
return true if letters.empty? | ||
end | ||
false | ||
end | ||
|
||
# Wave 3 | ||
|
||
def score_word (word) | ||
score = 0 | ||
word.upcase.split('').each do |letter| | ||
case letter | ||
when "A", "E", "I", "O", "U", "L", "N", "R", "S", "T" | ||
score += 1 | ||
when "D", "G" | ||
score += 2 | ||
when "B", "C", "M", "P" | ||
score += 3 | ||
when "F", "H", "G", "W", "Y" | ||
score += 4 | ||
when "K" | ||
score += 5 | ||
when "J", "X" | ||
score += 8 | ||
when "Q", "Z" | ||
score += 10 | ||
else | ||
score += 0 | ||
end | ||
end | ||
if word.length >= 7 && word.length <= 10 | ||
score += 8 | ||
end | ||
return score | ||
end | ||
|
||
# Wave 4 | ||
|
||
def highest_score_from(words) | ||
best_word = { | ||
word: '', | ||
score: 0 | ||
} | ||
words.each do |word| | ||
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 best_word[:word].length < word.length && word.length == 10 | ||
best_word[:word] = word | ||
best_word[:score] = score_word(word) | ||
|
||
elsif best_word[:word].length > word.length && best_word[:word].length < 10 | ||
best_word[:word] = word | ||
best_word[:score] = score_word(word) | ||
end | ||
end | ||
end | ||
return best_word | ||
end | ||
|
||
# Wave 5 | ||
# Curently able to read the file but unable to check with user word | ||
# def is_in_english_dict? (input) | ||
# dictionary = '' | ||
# CSV.foreach(File.path("dictionary-english.csv")) do |row| | ||
# dictionary = row | ||
# puts dictionary | ||
# end | ||
# if dictionary.include?(input) | ||
# puts "true" | ||
# else | ||
# puts "false" | ||
# end | ||
# end | ||
|
||
def run_game | ||
played_words = [] | ||
|
||
display_welcome_message | ||
|
||
should_continue = true | ||
|
||
while should_continue | ||
puts "Let's draw 10 letters from the letter pool..." | ||
|
||
letter_bank = draw_letters | ||
display_drawn_letters(letter_bank) | ||
|
||
display_game_instructions | ||
|
||
user_input_word = get_user_input | ||
|
||
while ( !(uses_available_letters?(user_input_word, letter_bank)) ) | ||
display_needs_valid_input_message | ||
user_input_word = get_user_input | ||
end | ||
|
||
score = score_word(user_input_word) | ||
played_words << user_input_word | ||
|
||
display_score(score) | ||
|
||
display_retry_instructions | ||
should_continue = get_user_input == "Y" | ||
end | ||
|
||
display_highest_score(highest_score_from(played_words)) | ||
display_goodbye_message | ||
end | ||
|
||
run_game |
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.
This works, but I think we can agree it's hard to read and hard to check. Is there a way to generate this from a more readable format?