Skip to content

New Pull request for final submission! #130

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Changes from 8 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
120 changes: 116 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,123 @@
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
}


def draw_letters():
pass
hand = []
copy_letter_pool = LETTER_POOL.copy()
while len(hand) < 10:
random_letter = random.choices(list(copy_letter_pool), weights = copy_letter_pool.values(), k=1)
str_random_letter = random_letter[0]

if copy_letter_pool[str_random_letter] > 0:
hand.append(str_random_letter)
copy_letter_pool[str_random_letter] += -1
return hand

Choose a reason for hiding this comment

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

I love the way you used the random.choices function here to account for the different weights of each letter! You were one of just a few people to catch onto this! Overall this works really well and you've accounted for several different possibilities!


def uses_available_letters(word, letter_bank):
pass
quantity_available = {}
validate_enough_available = {}
for letter in letter_bank:
available_count = letter_bank.count(letter)
quantity_available[letter] = available_count

Choose a reason for hiding this comment

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

Since you never use available_count again, you could merge this line with the one above to save a little space.


for character in word.upper():
amount_needed_for_word = (word.upper()).count(character)
if character in quantity_available and (amount_needed_for_word <= quantity_available[character]):
validate_enough_available[character] = True
else:
validate_enough_available[character] = False

if False in validate_enough_available.values():
return False
else:
return True

Choose a reason for hiding this comment

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

It took me a second, but this is a very unique way to write this function! If you wanted to cut this down just a bit, you could make a copy of your letter_bank. From there, you can loop through your word and check to see if each letter is in the copy of the letter_bank. If it is, you can remove it from the letter bank and if it isn't you can immediately return False and terminate the loop and function early! Any chance to terminate a function early is a great idea!

def score_word(word):
pass
score = 0
score_chart = {
"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,
}

Choose a reason for hiding this comment

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

This dictionary could be moved to outside the functions as a global constant just in case we wanted to expand this project and use the score_chart elsewhere!


for letter in word.upper():
if letter in score_chart:
score += score_chart[letter]
if len(word) >= 7:
score += 8
return score

Choose a reason for hiding this comment

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

This function looks great!


def get_highest_word_score(word_list):
pass
player_scores = {}
top_players = []
for word in word_list:
word_score = score_word(word)
player_scores[word] = word_score

highest_score = max(player_scores.values())
for key, value in player_scores.items():
if value >= highest_score:
top_players.append((key, value))

winner = top_players[0]
for word, score in top_players:
if len(word) >= 10:
winner = (word, score)
return winner
elif len(word) < len(winner[0]) and len(winner[0]) != 10:
winner = (word, score)
return winner

Choose a reason for hiding this comment

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

I like what you did here, separating each part out into their separate pieces! One challenge I have for you would be to see if you can do the comparisons in place. This would require just one for loop and a few conditionals to compare the different words and their scores! There are a few examples on code reviews for reference!