Conversation
spitsfire
left a comment
There was a problem hiding this comment.
Heck yeah, Jeannie and Jande! This was short and sweet! I only had one or two suggestions for y'all to consider, but that's it.
Another thing we discussed in class was how to imitate the probability of grabbing more common tiles versus rarer ones. Some things you could think about is creating a list of all tiles and their duplicates (ie, ['A','A','A','B','B'] and so on) to choose from.
A more advanced solution might be using the random.choice method, but with more than one param. Here's an example of how you can "weigh" your list: https://www.geeksforgeeks.org/how-to-get-weighted-random-choice-in-python/
| player_hand = [] | ||
| random_letter = "" | ||
| while len(player_hand) < 10: | ||
| random_letter = random.choice(string.ascii_uppercase) |
|
|
||
| def uses_available_letters(word, letter_bank): | ||
| pass | ||
| list_of_letters = letter_bank[:] |
There was a problem hiding this comment.
Great reason to make a copy in this context. Let's say, for example, you are removing tiles from the original letter_bank, but the function returns False, meaning the word can't be made. Well, if you remove all the tiles from the list, now the player's hand is bare! and they can't play the round anymore.
| bool_set = set() | ||
| for letter in word.upper(): | ||
| if letter in list_of_letters: | ||
| bool_set.add(True) | ||
| list_of_letters.remove(letter) | ||
| else: | ||
| bool_set.add(False) | ||
|
|
||
|
|
||
| if bool_set == {True}: | ||
| return True | ||
| else: | ||
| return False |
There was a problem hiding this comment.
Cool idea to use flags to check over each letter in the word to see if it has a tile to match. If you were worried, though, about taking up memory space, what could we do instead?
Maybe check if the list_of_letters is empty before the for loop ends or the moment you hit an else statement which means a letter wasn't in the list_of_letters, you can return False immediately
| else: | ||
| return False | ||
|
|
||
| def score_word(word): |
adagrams/game.py
Outdated
| elif len(word) == 10: | ||
| winning_word = word | ||
| elif len(word) < len(winning_word): | ||
| winning_word = word |
There was a problem hiding this comment.
since these two conditional statements duplicate the exact same line winning_word = word, we should think about combining them into a compound conditional
No description provided.