-
Notifications
You must be signed in to change notification settings - Fork 50
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
C22 Tami Gaertner #37
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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 | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,11 +1,95 @@ | ||||||
|
||||||
from random import randint | ||||||
from .data import LETTER_POOL | ||||||
from .score_chart import score_of_letters | ||||||
# wave 1 | ||||||
def draw_letters(): | ||||||
pass | ||||||
|
||||||
hand =[] | ||||||
letter_counts = LETTER_POOL.copy() | ||||||
|
||||||
while len(hand)< 10: | ||||||
|
||||||
available_letters =[] | ||||||
|
||||||
for letter, count in letter_counts.items(): | ||||||
if count > 0: | ||||||
available_letters.append(letter) | ||||||
if not available_letters: | ||||||
break | ||||||
Comment on lines
+18
to
+19
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. Will we ever reach a situation where |
||||||
|
||||||
index = randint(0, len(available_letters) -1) | ||||||
choose_letter = available_letters[index] | ||||||
letter_counts[choose_letter] -= 1 | ||||||
hand.append(choose_letter) | ||||||
|
||||||
return hand | ||||||
|
||||||
# wave 2 | ||||||
|
||||||
def uses_available_letters(word, letter_bank): | ||||||
pass | ||||||
word = word.lower() | ||||||
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 don't typically want to reassign parameter variables in case we ever need to access the original value that was passed in. It's okay to create a new variable in this case like |
||||||
|
||||||
for letter in word: | ||||||
|
||||||
letter_found = False | ||||||
|
||||||
for bank_letter in letter_bank: | ||||||
if letter == bank_letter.lower(): | ||||||
letter_found = True | ||||||
break | ||||||
Comment on lines
+39
to
+40
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. Since we break on line 47 right after changing |
||||||
if not letter_found: | ||||||
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. I like the early exit as soon as we find something invalid. |
||||||
word_count = word.count(letter) | ||||||
|
||||||
bank_count = 0 | ||||||
|
||||||
for bank_letter in letter_bank: | ||||||
|
||||||
if letter == bank_letter.lower(): | ||||||
bank_count += 1 | ||||||
if word_count > bank_count: | ||||||
return False | ||||||
return True | ||||||
|
||||||
# wave 3 | ||||||
def score_word(word): | ||||||
pass | ||||||
|
||||||
if not word: | ||||||
return 0 | ||||||
|
||||||
total_score = 0 | ||||||
|
||||||
word = word.upper() | ||||||
|
||||||
for letter in word: | ||||||
|
||||||
if letter.upper() in score_of_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. Nice check to let us keep scoring if we have something like a hyphenated word! |
||||||
letter_score = score_of_letters[letter.upper()] | ||||||
total_score += letter_score | ||||||
if len(word) >= 7 : | ||||||
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
|
||||||
total_score += 8 | ||||||
|
||||||
return total_score | ||||||
|
||||||
# wave 4 | ||||||
def get_highest_word_score(word_list): | ||||||
pass | ||||||
|
||||||
highest_score = (None, 0) | ||||||
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 idea to use a tuple from the start so you have your return value ready to go by the end of the loop! |
||||||
|
||||||
for word in word_list: | ||||||
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 approach to tie break in a single loop over |
||||||
new_score = score_word(word) | ||||||
if new_score > highest_score[1]: | ||||||
highest_score = (word, new_score) | ||||||
elif new_score == highest_score[1]: | ||||||
if len(word) == 10 and len(highest_score[0]) != 10: | ||||||
highest_score = (word, new_score) | ||||||
elif len(highest_score[0]) != 10 and len(word) < len(highest_score[0]): | ||||||
highest_score = (word, new_score) | ||||||
return highest_score | ||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
score_of_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. Since we're treating this data structure like a constant, we should follow constant variable naming conventions and use all capital letters like: |
||
'A': 1, | ||
'E': 1, | ||
'I': 1, | ||
'O': 1, | ||
'U': 1, | ||
'L': 1, | ||
'N': 1, | ||
'R': 1, | ||
'S': 1, | ||
'T': 1, | ||
'D': 2, | ||
'G': 2, | ||
'B': 3, | ||
'C': 3, | ||
'M': 3, | ||
'P': 3, | ||
'F': 4, | ||
'H': 4, | ||
'V': 4, | ||
'W': 4, | ||
'Y': 4, | ||
'K': 5, | ||
'J': 8, | ||
'X': 8, | ||
'Q': 10, | ||
'Z': 10 | ||
} |
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 thought to separate out data from our implementation code. In larger projects, especially when the data is shared by multiple functions or files, this makes a lot of sense.
There is a little bit of a tradeoff happening when only one function uses the data. By placing the data in a larger scope, more code has access to and could potentially change the values in the data structure. If only one function will ever use the data, it can make sense to place the data inside the function. That way the data is only created when the function is called, and only the code that need access to the data has the ability to see or change it.