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

SetharikaSok_Adagrams_Atlanta #107

Open
wants to merge 1 commit into
base: main
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
125 changes: 121 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,128 @@
import random
def draw_letters():
pass
letters = {
'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
}

drawn_letter = []
all_list = letters.items()
mynew_list = list(all_list)

while len(drawn_letter) < 10:
random_number = random.randrange(0,len(mynew_list))
Comment on lines +32 to +37

Choose a reason for hiding this comment

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

Small comment here, so in the project description it says that certain letters should have a higher probability of being chosen than other letters. For example, E should have the highest probability to be chosen since the LETTER_POOL says that there are 12 of them (line 8). What you have on lines 33-34 don't necessarily take those weights into account. All letters have an equal chance of being chosen. A solution that considers those weights could look like this:

def draw_letters():
   drawn_letters = []
   letters = []
   for letter in LETTER_POOL.keys():
       letters += letter * LETTER_POOL[letter]

   while True:
    if len(drawn_letters) == 10: break

    index = random.randint(0,len(letters) - 1)
    chosen_letter = letters[index]

    if drawn_letters.count(chosen_letter) < LETTER_POOL[chosen_letter]:
        drawn_letters.append(chosen_letter)

   return drawn_letters

In the beginning of the function we loop through the keys in LETTER_POOL to create a list with their appropriate weights. letters += 'S' * 4 --> letters = ['S', 'S', 'S', 'S']

letter_tuples = mynew_list[random_number]
key = letter_tuples[0]
value = letter_tuples[1]
count_key_in_list = drawn_letter.count(key)

if count_key_in_list < value:
drawn_letter.append(key)

print(drawn_letter)
return drawn_letter

def uses_available_letters(word, letter_bank):
pass

found_count = 0
for i in letter_bank:
for j in word.upper():
Comment on lines +52 to +53

Choose a reason for hiding this comment

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

Great job Rika on implementing a nested loop! This shows me that you are showing proficiency in them! An alternative way you could have implemented this is:

def uses_available_letters(word, letter_bank):
    cap_word = word.upper()

    for letter in cap_word:
       if letter not in letter_bank: return False

       if cap_word.count(letter) > letter_bank.count(letter): return False
    
    return True

Python has a method for iterables called count and what it does is count the instances of the value passed to it inside of the iterable it is being called on. That way we don't have to create another loop to compare each letter in word to each element in letter_bank.

if i == j:
found_count +=1
break

if found_count == len(word):
return True
else:
return False

def score_word(word):
pass

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

count_point = 0
for key_word in word.upper():
count_point += points_dict[key_word]

if len(word) in range(7, 11):
count_point += 8

return count_point

Choose a reason for hiding this comment

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

Great work on this function! Very concise and easy to follow! ⭐️


def get_highest_word_score(word_list):
pass

winner_word = ""
winner_score = 0

winner_dict = {}

for word in word_list:

Choose a reason for hiding this comment

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

One suggestion I have for you is maybe handling the determination of winner_score in this loop here, that way you don't have to worry about it when implementing the tiebreaker logic. We could do something like this here:

 highest_score = 0
    winning_words = []

    for word in word_list:
       score = score_word(word)
       
       if score > highest_score:
          highest_score = score
          winning_words = [word]
       elif score == highest_score:
          winning_words.append(word)

With this implementation we filter out words whose score is lower than the winning_score. That way when we get to the tie breaking logic we only have to worry about the length of words and not the score. This is because all the words found inside of winning_words all have a score equal to highest_score. But again, nothing is wrong with how you implemented your solution, this is just an alternative approach. Nonetheless, good job!

score = score_word(word)
winner_dict[word] = score

for word, score in winner_dict.items():
if winner_score < score:
winner_score = score
winner_word = word
elif winner_score == score and len(word) == 10 and len(winner_word) != 10:
winner_score = score
winner_word = word
elif winner_score == score and len(word) < len(winner_word) and len(winner_word) != 10:
winner_score = score
winner_word = word

return (winner_word, winner_score)



Choose a reason for hiding this comment

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

Great work, Rika! You are really showing some proficiency! Please feel free to contact me if you need any clarification about the comments I left! I can't wait to see more of your code in the future! 🤩