Skip to content
117 changes: 113 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,120 @@
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
}

SCORE_CHART = {
'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,
}
def draw_letters():
pass
letter_list = []
hand = []

for letter in LETTER_POOL.keys():
Copy link

Choose a reason for hiding this comment

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

In Python, looping over a dictionary this way uses its keys by default, so no need to call .keys(), you can just write

for letter in LETTER_POOL:

for num in range(LETTER_POOL[letter]):
letter_list.append(letter)

for draw in range(10):
Copy link

Choose a reason for hiding this comment

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

Good job with this one! Since draw isn't being used, consider a while loop with a condition that looks at len(letter_list)

index = random.randint(0, (len(letter_list) -1))
hand.append(letter_list[index])
letter_list.pop(index)

return hand

def uses_available_letters(word, letter_bank):
pass
try:
formatted_word = word.upper()
except AttributeError:
Copy link

Choose a reason for hiding this comment

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

Good job handling a case where, I believe, the parameter word isn't a string! A guard clause would be my suggestion to validate that word is a string, rather than catching the exception

return False

for letter in formatted_word:
if formatted_word.count(letter) > letter_bank.count(letter):
return False
return True

def score_word(word):
pass
formatted_word = word.upper()
score = 0

for letter in formatted_word:
score += SCORE_CHART[letter]

if len(word) >= 7:
Copy link

Choose a reason for hiding this comment

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

Nice job with this function!

Copy link

Choose a reason for hiding this comment

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

Per the README, the 8 bonus points should be awarded when a word is 7, 8, 9, or 10 letters long so we'll also want to have a check that the length of the word is < 11.

score += 8

return score

def get_highest_word_score(word_list):
pass
winning_word = word_list[0]
winning_score = score_word(winning_word)

for word in word_list:
current_score = score_word(word)
if current_score > winning_score:
winning_word = word
winning_score = current_score
elif current_score == winning_score:
winning_word = tie_breaker(winning_word, word)
winning_score = score_word(winning_word)

return (winning_word, winning_score)

def tie_breaker(first, second):
for word in [first, second]:
if len(word) == 10:
return word
if len(first) < len(second):
Copy link

Choose a reason for hiding this comment

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

Good job handling the tie cases!

return first
elif len(second) < len(first):
return second
return first