-
Notifications
You must be signed in to change notification settings - Fork 89
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
C18 Yun and Intesar #76
base: master
Are you sure you want to change the base?
Changes from all commits
7abbbc3
4457635
e05bc49
c6bb6da
ef2520e
19c50a0
8710579
f2a9685
769622e
e0fe174
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,166 @@ | ||
def draw_letters(): | ||
pass | ||
import random | ||
import string | ||
from collections import Counter | ||
|
||
def draw_letters(): | ||
#create a pool for all the letters, using a list | ||
#import random | ||
# use random.choices to randomly generate 10 letters from the letter pool | ||
LETTER_POOL_COUNT = { | ||
'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 | ||
} | ||
hand = [] | ||
while len(hand) < 10: | ||
random_letter = random.choice(string.ascii_uppercase) | ||
if hand.count(random_letter) < LETTER_POOL_COUNT[random_letter]: | ||
hand.append(random_letter) | ||
continue | ||
else: | ||
continue | ||
|
||
return hand | ||
|
||
def uses_available_letters(word, letter_bank): | ||
pass | ||
word_case = word.upper() | ||
letter_count_dict = Counter(letter_bank) | ||
for letter in word_case: | ||
if letter in letter_count_dict and letter_count_dict[letter] > 0: | ||
letter_count_dict[letter] -= 1 | ||
continue | ||
else: | ||
return False | ||
|
||
|
||
return True | ||
Comment on lines
48
to
+59
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 use of Also, the |
||
|
||
|
||
def score_word(word): | ||
pass | ||
LETTER_SCORE = {'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} | ||
word_upper = word.upper() | ||
score = 0 | ||
|
||
for letter in word_upper: | ||
if letter in LETTER_SCORE: | ||
score += LETTER_SCORE[letter] | ||
if len(word_upper) >= 7 and len(word_upper) <= 10: | ||
score += 8 | ||
return score | ||
|
||
#CODED_BY_YUN: | ||
def get_highest_word_score(word_list): | ||
pass | ||
sorted_word_list = sorted(word_list, key=len) | ||
score_list = [] | ||
word_score_dict = {} | ||
for word in sorted_word_list: | ||
word_score = score_word(word) | ||
score_list.append(word_score) | ||
word_score_dict[word] = word_score | ||
|
||
highest_word_score = max(set(score_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. The |
||
highest_word_dict = {} | ||
for word, score in word_score_dict.items(): | ||
if score == highest_word_score: | ||
highest_word_dict[word] = score | ||
for word, score in highest_word_dict.items(): | ||
if len(word) == 10: | ||
winning_tuple = (word, score) | ||
break | ||
else: | ||
winning_tuple = list(highest_word_dict.items())[0] | ||
Comment on lines
+90
to
+95
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. Line 95 repeatedly converts the items in a dictionary to a list. Can you think of a way to avoid this? |
||
return winning_tuple | ||
|
||
##CODED_BY_IS## | ||
# def get_highest_word_score(word_list): | ||
# word_to_score_dict = {} | ||
# for word in word_list: | ||
# word_score = score_word(word) | ||
# word_to_score_dict[word] = word_score | ||
Comment on lines
+100
to
+103
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 score dictionary! |
||
# winning_words = [] | ||
# highest_scoring_word = () | ||
# highest_scoring_word = (word, word_score) | ||
Comment on lines
+100
to
+106
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. Line 106 will start us with the last word in the data, which is likely not what we want because earlier words should win tiebreaks. |
||
|
||
# for word, word_score in word_to_score_dict.items(): | ||
# if highest_scoring_word == (): | ||
# highest_scoring_word = (word, word_score) | ||
# continue | ||
# if word_score > highest_scoring_word[1]: | ||
# highest_scoring_word = (word, word_score) | ||
# winning_words.append(highest_scoring_word) | ||
|
||
# if word_score == highest_scoring_word[1]: | ||
# if len(highest_scoring_word[0]) == 10: | ||
# winning_words.append(highest_scoring_word) | ||
# return highest_scoring_word | ||
|
||
# if len(word) == 10 and len(highest_scoring_word[0]) <= len(word): | ||
# highest_scoring_word = (word, word_to_score_dict[word]) | ||
# winning_words.append(highest_scoring_word) | ||
# return highest_scoring_word | ||
# if len(highest_scoring_word[0]) > len(word): | ||
# highest_scoring_word = (word, word_to_score_dict[word]) | ||
# elif len(highest_scoring_word[0]) == len(word): | ||
# highest_scoring_word = (word, word_to_score_dict[word]) | ||
|
||
# winning_words.append(highest_scoring_word) | ||
# return highest_scoring_word | ||
Comment on lines
+108
to
+131
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. There's a lot of great logic here! I think the main issue this code has is the return statements being inside the |
||
|
||
# Sept 30, Yun: Hey Intersar. I tried to fix the bugs but followed your idea of using only tuple | ||
# \and only iterate over once in the highest_scoring_word dict. | ||
# \please see below code and I believe it should work now, for Wave 4. | ||
|
||
# word_to_score_dict = {} | ||
# for word in word_list: | ||
# word_score = score_word(word) | ||
# word_to_score_dict[word] = word_score | ||
|
||
# highest_scoring_word = list(word_to_score_dict.items())[0] | ||
|
||
# for word, word_score in word_to_score_dict.items(): | ||
# if word_score > highest_scoring_word[1]: | ||
# highest_scoring_word = (word, word_score) | ||
|
||
# elif word_score == highest_scoring_word[1]: | ||
# if len(highest_scoring_word[0]) == 10 and len(word) <= 10: | ||
# continue | ||
# elif len(word) == 10 and len(highest_scoring_word[0]) <= 10: | ||
# highest_scoring_word = (word, word_score) | ||
# elif len(word) < len(highest_scoring_word[0]): | ||
# highest_scoring_word = (word, word_score) | ||
# elif len(highest_scoring_word[0]) < len(word): | ||
# continue | ||
# return highest_scoring_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.
Nice logic! We can slightly simplify things be removing lines 43-44, they are unneeded.