-
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
Maple- Shay & Sabrina #35
base: master
Are you sure you want to change the base?
Changes from all commits
8abaaff
e7d16c9
72bdc8f
5a87dd2
b6a004c
b6407bf
81c2ca0
8d8cffd
48cffec
dbdb78f
ea04acc
ff15f62
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,85 @@ | ||||||||||||||||
import random | ||||||||||||||||
|
||||||||||||||||
LETTERS_DICT = {'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} | ||||||||||||||||
|
||||||||||||||||
''' | ||||||||||||||||
We generated LETTERS_POOL from LETTERS_DICT using the following code so that we | ||||||||||||||||
would not have to run it every time draw_letters is called since the pool of | ||||||||||||||||
letters will be a constant | ||||||||||||||||
LETTERS_POOL = [] | ||||||||||||||||
for letter in LETTERS_DICT: | ||||||||||||||||
letters_string = letter * LETTERS_DICT[letter] | ||||||||||||||||
for letter in letters_string: | ||||||||||||||||
LETTERS_POOL.append(letter) | ||||||||||||||||
''' | ||||||||||||||||
LETTERS_POOL = ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'C', \ | ||||||||||||||||
'C', 'D', 'D', 'D', 'D', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', \ | ||||||||||||||||
'E', 'E', 'F', 'F', 'G', 'G', 'G', 'H', 'H', 'I', 'I', 'I', 'I', 'I', 'I', \ | ||||||||||||||||
'I','I', 'I', 'J', 'K', 'L', 'L', 'L', 'L', 'M', 'M', 'N', 'N', 'N', 'N', 'N', \ | ||||||||||||||||
'N', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'P', 'P', 'Q', 'R', 'R', 'R', 'R', \ | ||||||||||||||||
'R', 'R', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'T', 'T', 'T', 'U', 'U', 'U', 'U', \ | ||||||||||||||||
'V', 'V', 'W', 'W', 'X', 'Y', 'Y', 'Z'] | ||||||||||||||||
|
||||||||||||||||
SCORES = {"A": 1, "C": 3, "B": 3, "E": 1, "D": 2, "G": 2, | ||||||||||||||||
"F": 4, "I": 1, "H": 4, "K": 5, "J": 8, "M": 3, | ||||||||||||||||
"L": 1, "O": 1, "N": 1, "Q": 10, "P": 3, "S": 1, | ||||||||||||||||
"R": 1, "U": 1, "T": 1, "W": 4, "V": 4, "Y": 4, | ||||||||||||||||
"X": 8, "Z": 10} | ||||||||||||||||
|
||||||||||||||||
def draw_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. 👍 short and sweet! love it! |
||||||||||||||||
pass | ||||||||||||||||
''' | ||||||||||||||||
Returns a hand of 10 letters drawn randomly without replacement from the | ||||||||||||||||
letter pool | ||||||||||||||||
''' | ||||||||||||||||
return random.sample(LETTERS_POOL, 10) | ||||||||||||||||
|
||||||||||||||||
def uses_available_letters(word, letter_bank): | ||||||||||||||||
pass | ||||||||||||||||
''' | ||||||||||||||||
Checks if word uses only letters in the letter_bank (hand) and does not use | ||||||||||||||||
a letter more times than it appears in the letter_bank | ||||||||||||||||
Returns True or False | ||||||||||||||||
''' | ||||||||||||||||
temp_letter_bank = letter_bank.copy() | ||||||||||||||||
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. 👍 good job reducing side effects! |
||||||||||||||||
for letter in word: | ||||||||||||||||
if letter in temp_letter_bank: | ||||||||||||||||
temp_letter_bank.remove(letter) | ||||||||||||||||
else: | ||||||||||||||||
return False | ||||||||||||||||
return True | ||||||||||||||||
|
||||||||||||||||
def score_word(word): | ||||||||||||||||
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. 👍 |
||||||||||||||||
pass | ||||||||||||||||
''' | ||||||||||||||||
Returns score of word based on letter values in SCORES. If the length of the | ||||||||||||||||
word is 7, 8, 9, or 10, then the word gets an additional 8 points. | ||||||||||||||||
''' | ||||||||||||||||
total = 0 | ||||||||||||||||
if len(word) >= 7: | ||||||||||||||||
total += 8 | ||||||||||||||||
total += sum(SCORES[letter] for letter in word.upper()) | ||||||||||||||||
return total | ||||||||||||||||
Comment on lines
+57
to
+61
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. ohh interesting doing the +8 points first, then using |
||||||||||||||||
|
||||||||||||||||
def get_highest_word_score(word_list): | ||||||||||||||||
pass | ||||||||||||||||
''' | ||||||||||||||||
input: word_list | ||||||||||||||||
output: (winning_word, score) | ||||||||||||||||
Finds word in word_list with highest score. If there is a tie, will pick word | ||||||||||||||||
with fewest letters unless one word has 10 letters, then will choose word | ||||||||||||||||
with 10 letters. If multiple words have same score and length, picks the word | ||||||||||||||||
supplied first. | ||||||||||||||||
''' | ||||||||||||||||
winning_word = None | ||||||||||||||||
highest_score = 0 | ||||||||||||||||
for word in word_list: | ||||||||||||||||
if score_word(word) > highest_score: | ||||||||||||||||
winning_word = word | ||||||||||||||||
highest_score = score_word(word) | ||||||||||||||||
Comment on lines
+75
to
+77
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. maybe we can dry this up a bit, so we only use
Suggested change
|
||||||||||||||||
elif score_word(word) == highest_score: | ||||||||||||||||
if len(word) == 10 and len(word) != len(winning_word): | ||||||||||||||||
winning_word = word | ||||||||||||||||
highest_score = score_word(word) | ||||||||||||||||
Comment on lines
+78
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. now that we have the |
||||||||||||||||
elif len(word) < len(winning_word) and len(winning_word) != 10: | ||||||||||||||||
winning_word = word | ||||||||||||||||
highest_score = score_word(word) | ||||||||||||||||
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. here too! |
||||||||||||||||
return winning_word, highest_score |
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.
this works! Though I think since you put in the effort of coding the algorithm out, you should show it off! Maybe we can do something like this:
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.
this way, if the letter scores or availability change, then you only need to change the original dictionary!