-
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
New Pull request for final submission! #130
base: main
Are you sure you want to change the base?
Changes from all commits
71eab8a
abc2e8b
9e1af57
925d291
ec516de
9750c40
2a75177
133f16d
577f939
021aa80
0b56c2e
e255e53
86cd71f
b393f40
7d1f6e6
2a19949
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,108 @@ | ||
import random | ||
|
||
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 | ||
} | ||
|
||
|
||
def draw_letters(): | ||
pass | ||
hand = [] | ||
copy_letter_pool = LETTER_POOL.copy() | ||
while len(hand) < 10: | ||
random_letter = random.choices( | ||
list(copy_letter_pool), weights=copy_letter_pool.values(), k=1) | ||
str_random_letter = random_letter[0] | ||
|
||
if copy_letter_pool[str_random_letter] > 0: | ||
hand.append(str_random_letter) | ||
copy_letter_pool[str_random_letter] -= 1 | ||
return hand | ||
|
||
|
||
def uses_available_letters(word, letter_bank): | ||
pass | ||
word_upper = word.upper() | ||
for letter in word_upper: | ||
if word_upper.count(letter) != letter_bank.count(letter): | ||
return False | ||
return True | ||
|
||
|
||
def score_word(word): | ||
pass | ||
score = 0 | ||
score_chart = { | ||
"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, | ||
} | ||
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 dictionary could be moved to outside the functions as a global constant just in case we wanted to expand this project and use the score_chart elsewhere! |
||
|
||
for letter in word.upper(): | ||
if letter in score_chart: | ||
score += score_chart[letter] | ||
if len(word) >= 7: | ||
score += 8 | ||
return 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. This function looks great! |
||
|
||
|
||
def get_highest_word_score(word_list): | ||
pass | ||
highest_score = 0 | ||
winner = None | ||
|
||
for word in word_list: | ||
word_score = score_word(word) | ||
if word_score > highest_score: | ||
highest_score = word_score | ||
winner = (word, word_score) | ||
elif word_score == highest_score: | ||
if len(word) == 10: | ||
return (word, word_score) | ||
elif len(word) < len(winner[0]): | ||
winner = (word, word_score) | ||
return winner | ||
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. I like what you did here, separating each part out into their separate pieces! One challenge I have for you would be to see if you can do the comparisons in place. This would require just one for loop and a few conditionals to compare the different words and their scores! There are a few examples on code reviews for reference! |
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.
I love the way you used the random.choices function here to account for the different weights of each letter! You were one of just a few people to catch onto this! Overall this works really well and you've accounted for several different possibilities!