Skip to content
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

Whales - Alexa Coffman and Uyen Vong #36

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 103 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,110 @@
from random import randint
from copy import deepcopy

LETTER_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"
]


def draw_letters():
pass
# create a copy of letter pool so we don't alter original list
letter_pool_copy = deepcopy(LETTER_POOL)
drawn_letters = []

# until the length of drawn_letters is 10, keep generating
# a random index to pop off from the letter pool
# and append popped element to drawn_letters
while len(drawn_letters) < 10:
rand_index = randint(0, len(letter_pool_copy)-1)
drawn_letters.append(letter_pool_copy.pop(rand_index))
Comment on lines +42 to +44

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting way to randomly pick a letter! I also love that you modeled your LETTER_POOL list to contain the correct frequency of letters in a bag. Great work!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But also...what if the instructors were feeling ~ chaotic ~ and said there were 100,000 tiles in the pool in total? Could you have programmatically made the LETTER_POOL list? (I'm sure you could have!)

return drawn_letters


def uses_available_letters(word, letter_bank):
pass
# create a copy of letter bank so we don't alter original list
letter_bank_copy = deepcopy(letter_bank)
word = word.upper()
valid_word = True

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is soooo pythonic! 🐍 I adore how y'all set a boolean for valid_word at the top of the function and reassign on L56 depending on the condition, then return this boolean only once in L60! While the following is acceptable:

if [valid conditional]:
    return True
else:
    return False

What y'all did (set a boolean variable to have only one return statement at the end of the function, like below) is a Pythonista's dream! Great work!

valid = True
if [not valid conditional]:
    valid = False
return valid

# check all letters in word are available in correct quantity
for letter in word:
if letter not in letter_bank_copy:
valid_word = False
else:
letter_bank_copy.remove(letter)

return valid_word

def score_word(word):
pass

letter_dict = {
'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,
}

word_score = 0

if word == None:
return None
Comment on lines +77 to +78

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great validation check!

else:
word = word.upper()
for letter in word:
word_score += letter_dict[letter]
if len(word) >= 7:
word_score += 8
return word_score

def get_highest_word_score(word_list):
pass

best_word = {
"word" : "",
"score" : 0
}
Comment on lines +89 to +92

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the organization of best word and score as a dictionary! 🤩


for word in word_list:
score = score_word(word)
if score > best_word["score"]:
update_best_word(best_word, word, score)
# check for ties using word length guidelines
elif score == best_word["score"]:
if len(word) == 10 and len(best_word["word"]) != 10:
update_best_word(best_word, word, score)
elif len(word) < len(best_word["word"]) and len(best_word["word"]) != 10:
update_best_word(best_word, word, score)

return (best_word["word"], best_word["score"])

def update_best_word(best_word, word, score):
best_word["score"] = score
best_word["word"] = word
Comment on lines +107 to +109

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely helper function! 💯

return best_word

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python (and most languages, if I think of it) likes it when you have a newline at the end of the file. (Why? Because it's one of those Just Unix/Computer Things, I guess?)