-
Notifications
You must be signed in to change notification settings - Fork 135
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
Moyo_Ruby_adagrams #114
base: main
Are you sure you want to change the base?
Moyo_Ruby_adagrams #114
Conversation
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.
Excellent job! I left some comments for you below on places where the code could be cleaner/simpler. Consider adding commits more often!
import random | ||
|
||
# Function to draw 10 random letters from the letter pool | ||
|
||
def draw_letters(): |
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.
Excellent job!
def draw_letters(): | ||
pass | ||
LETTER_POOL = { |
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.
Since this dictionary is never changed, it would be good to have it declared outside of the function so that it doesn't have to be recreated each time the function is called.
# Create a list of letters with the frequency as specified in the pool | ||
letter_list = [] | ||
for letter, count in LETTER_POOL.items(): | ||
letter_list.extend([letter] * count) |
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.
Nice!
|
||
return hand | ||
|
||
# Function to check if the given word can be formed using the available letters | ||
def uses_available_letters(word, letter_bank): |
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.
Excellent, very concise code!
return False | ||
|
||
# If all letters are in the letter bank copy, the word is valid | ||
return True | ||
|
||
def score_word(word): |
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.
Excellent!
|
||
def score_word(word): | ||
pass | ||
word = word.upper() | ||
letter_scores = { |
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.
Similar to the letter pool above, this dictionary can be declared outside of the function.
# If the scores are equal, apply tie-breaking rules: | ||
score == highest_word[1] and ( | ||
# If the current word has 10 letters and the highest_word doesn't, choose the current word | ||
(len(word) == 10 and len(highest_word[0]) != 10) or | ||
# If neither word has 10 letters, choose the word with fewer letters | ||
(len(highest_word[0]) != 10 and len(word) < len(highest_word[0])) | ||
) | ||
): | ||
# Update the highest_word with the current word and its score | ||
highest_word = (word, score) | ||
# If the scores are equal and the word lengths are also equal, use the order in the supplied list | ||
elif score == highest_word[1] and len(word) == len(highest_word[0]): | ||
# Check the index of the current word and highest_word in the original list | ||
# If the index of the current word is lower, update highest_word with the current word and its score | ||
highest_word = (word_list.index(word) < word_list.index(highest_word[0])) and (word, score) or highest_word |
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.
These statements are a bit hard to read. For the sake of keeping the code readable, it might be worth it to have if and elif statements here to lay out the logic rather than trying to get everything together with and
s and or
s.
OMG this was so hard