-
Notifications
You must be signed in to change notification settings - Fork 57
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
Spruce - Mary Tian #52
base: master
Are you sure you want to change the base?
Changes from all commits
fa003b2
58cde09
58e4683
ede8403
d22f5b3
41eac74
578b283
8f264ab
9489155
9569f75
8e30f04
692d319
7f1428d
b091b4a
c1f82c3
19f5d56
1f82866
8b1289b
d8e63cf
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 | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,11 +1,89 @@ | ||||||||||||||||||||||||||||||
import random | ||||||||||||||||||||||||||||||
# module will let us randomly choose characters in specified sample range | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
def draw_letters(): | ||||||||||||||||||||||||||||||
pass | ||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||
Build a hand of 10 letters for the user. Returns an array of strings, one letter long. | ||||||||||||||||||||||||||||||
The num of strings included in the array | ||||||||||||||||||||||||||||||
cannot be more than the num alloted in the letter table | ||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||
LETTER_POOL = { | ||||||||||||||||||||||||||||||
'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 | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
letter_to_draw = list(LETTER_POOL.keys()) | ||||||||||||||||||||||||||||||
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.
Suggested change
We can omit |
||||||||||||||||||||||||||||||
letters_drawn = [] | ||||||||||||||||||||||||||||||
letter_count = {} | ||||||||||||||||||||||||||||||
for letter in random.sample(letter_to_draw, 10): | ||||||||||||||||||||||||||||||
if letter not in letters_drawn: | ||||||||||||||||||||||||||||||
letters_drawn.append(letter) | ||||||||||||||||||||||||||||||
letter_count[letter] = 1 | ||||||||||||||||||||||||||||||
elif letter_count[letter] < LETTER_POOL[letter]: | ||||||||||||||||||||||||||||||
letters_drawn.append(letter) | ||||||||||||||||||||||||||||||
letter_count[letter] += 1 | ||||||||||||||||||||||||||||||
Comment on lines
+18
to
+24
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 the use of a frequency map to keep track of the letters being drawn! 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. We could also use letters_drawn = random.sample(LETTER_POOL.keys(), counts=LETTER_POOL.values(), k=10) Here's the |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return letters_drawn | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
def uses_available_letters(word, letter_bank): | ||||||||||||||||||||||||||||||
pass | ||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||
If letters in user's word are not in letter_bank, or if user uses more letters | ||||||||||||||||||||||||||||||
than in hand, the function returns False. | ||||||||||||||||||||||||||||||
Function returns False if user enters empty word. Else, it returns True. | ||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||
for letter in word: | ||||||||||||||||||||||||||||||
if letter not in letter_bank or word.count(letter) > letter_bank.count(letter): | ||||||||||||||||||||||||||||||
is_valid = False | ||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||
is_valid = True | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return is_valid | ||||||||||||||||||||||||||||||
Comment on lines
+35
to
+41
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. Great use of a guard clause here. We can make the code even neater by getting rid of the
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
def score_word(word): | ||||||||||||||||||||||||||||||
pass | ||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||
Calculate user's score for their entered word. | ||||||||||||||||||||||||||||||
Ignore lettercase, account for empty word, and give extra points for longer words. | ||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||
LETTER_POINTS = { | ||||||||||||||||||||||||||||||
'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1, 'J': 8, | ||||||||||||||||||||||||||||||
'K': 5, 'L': 1, 'M': 3, 'N': 1, 'O': 1, 'P': 3, 'Q': 10, 'R': 1, 'S': 1, 'T': 1, 'U': 1, | ||||||||||||||||||||||||||||||
'V': 4, 'W': 4, 'X': 8, 'Y': 4, 'Z': 10 | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+49
to
+53
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 my feedback on |
||||||||||||||||||||||||||||||
bonus_range = [7, 8, 9, 10] | ||||||||||||||||||||||||||||||
total = sum([LETTER_POINTS[letter] for letter in word.upper()]) | ||||||||||||||||||||||||||||||
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. LOVELY use of list comprehension here! |
||||||||||||||||||||||||||||||
if len(word) in bonus_range: | ||||||||||||||||||||||||||||||
total += 8 | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return total | ||||||||||||||||||||||||||||||
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. This function is so neat, great work! |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
def get_highest_word_score(word_list): | ||||||||||||||||||||||||||||||
pass | ||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||
Score the words in word_list. Returns tuple of word with highest score. | ||||||||||||||||||||||||||||||
If tie score, word with 10 letters or word with least letters wins. | ||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||
words_scored_dict = {user_word: score_word( | ||||||||||||||||||||||||||||||
user_word) for user_word in word_list} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
highest_word_score = max(words_scored_dict.values()) | ||||||||||||||||||||||||||||||
smallest_word_len = min((len(key) for key in words_scored_dict.keys())) | ||||||||||||||||||||||||||||||
largest_word_len = max((len(key) for key in words_scored_dict.keys())) | ||||||||||||||||||||||||||||||
Comment on lines
+71
to
+72
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.
Suggested change
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. Really cool use of dictionary and list comprehensions!! |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
for user_word, score in words_scored_dict.items(): | ||||||||||||||||||||||||||||||
if largest_word_len == 10: | ||||||||||||||||||||||||||||||
if len(user_word) != 10: | ||||||||||||||||||||||||||||||
continue | ||||||||||||||||||||||||||||||
elif len(user_word) == 10: | ||||||||||||||||||||||||||||||
winning_word = user_word | ||||||||||||||||||||||||||||||
highest_word_score = score | ||||||||||||||||||||||||||||||
break | ||||||||||||||||||||||||||||||
Comment on lines
+76
to
+81
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. We can take out
Suggested change
|
||||||||||||||||||||||||||||||
elif score == highest_word_score and len( | ||||||||||||||||||||||||||||||
user_word) == smallest_word_len: | ||||||||||||||||||||||||||||||
winning_word = user_word | ||||||||||||||||||||||||||||||
break | ||||||||||||||||||||||||||||||
elif score == highest_word_score: | ||||||||||||||||||||||||||||||
winning_word = user_word | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return winning_word, highest_word_score | ||||||||||||||||||||||||||||||
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. Great work! |
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.
Long chunks of data like letter_bank tend to clutter functions and require more scrolling to see the rest of the function body. Consider moving this dictionary outside of this function (or in a new file) as a constant variable to be referenced in draw_letters.