From 0522bc9c4fceeb19794357e086f8fa0fc697a57e Mon Sep 17 00:00:00 2001 From: Genesis Quinn Date: Fri, 24 Mar 2023 03:56:25 -0400 Subject: [PATCH 1/2] Completed Adagrams --- adagrams/game.py | 127 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 123 insertions(+), 4 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..315461ce 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,11 +1,130 @@ +import random def draw_letters(): - pass + letters =[] + 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 +} + while len(letters) <10: + letter = random.choice(list(LETTER_POOL)) + if LETTER_POOL[letter] > 0: + LETTER_POOL[letter] -= 1 + else: + continue + letters.append(letter) + return letters + + + + def uses_available_letters(word, letter_bank): - pass + new_word=word.upper() + letter_bank_copy =list(letter_bank) + for letter in new_word: + if letter not in letter_bank_copy: + return False + elif letter in letter_bank_copy: + letter_bank_copy.remove(letter) + return True + + + + def score_word(word): - pass + points =[] + 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 +} + new_word=word.upper() + for letter in new_word: + if letter in score_chart: + points.append(score_chart[letter]) + total= sum(points) + if len(new_word) ==7 or len(new_word)==8 or len(new_word)==9 or len(new_word)==10: + total+=8 + else: + total+=0 + return total def get_highest_word_score(word_list): - pass \ No newline at end of file + scores_dict={} + maximum = 0 + max_key = None + word_list.sort(key=len) + for word in word_list: + puntos = score_word(word) + scores_dict[word] = puntos + for scores in scores_dict : + if scores_dict[scores] > maximum: + maximum = scores_dict[scores] + max_key = scores + elif len(word_list[-1]) == len(word_list[0]) and puntos == maximum: + max_key = (word_list[0]) + elif len(word_list[-1]) == len(word_list[-2]) and puntos ==maximum: + max_key = word_list[-2] + elif len(word_list[-1]) == 10 and puntos == maximum: + max_key = word_list[-1] + return (max_key, maximum) + +# how can I do this using max()? +# I originally had this but didn't how how to break ties according to len() using max(). +# +# def get_highest_word_score(word_list): +# word_list.sort(key=len) +# score_dict={} +# for word in word_list: +# puntos = score_word(word) +# score_dict[word]=puntos +# winner = max(score_dict, key=score_dict.get) +# return(winner, score_dict[winner]) \ No newline at end of file From 6a86681e587fb88a4799726710a06b1575dfee38 Mon Sep 17 00:00:00 2001 From: Genesis Quinn Date: Fri, 24 Mar 2023 14:27:03 -0400 Subject: [PATCH 2/2] Adagrams Revisions --- adagrams/game.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 315461ce..7d7166d5 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -93,8 +93,6 @@ def score_word(word): total= sum(points) if len(new_word) ==7 or len(new_word)==8 or len(new_word)==9 or len(new_word)==10: total+=8 - else: - total+=0 return total def get_highest_word_score(word_list): @@ -103,17 +101,16 @@ def get_highest_word_score(word_list): max_key = None word_list.sort(key=len) for word in word_list: - puntos = score_word(word) - scores_dict[word] = puntos + score = score_word(word) + scores_dict[word] = score for scores in scores_dict : if scores_dict[scores] > maximum: maximum = scores_dict[scores] max_key = scores - elif len(word_list[-1]) == len(word_list[0]) and puntos == maximum: - max_key = (word_list[0]) - elif len(word_list[-1]) == len(word_list[-2]) and puntos ==maximum: +#Line 111 & 112 doesn't work if there are 3 or more words that are the same length + elif len(word_list[-1]) == len(word_list[-2]) and score ==maximum: max_key = word_list[-2] - elif len(word_list[-1]) == 10 and puntos == maximum: + elif len(word_list[-1]) == 10 and score == maximum: max_key = word_list[-1] return (max_key, maximum) @@ -124,7 +121,7 @@ def get_highest_word_score(word_list): # word_list.sort(key=len) # score_dict={} # for word in word_list: -# puntos = score_word(word) -# score_dict[word]=puntos +# score = score_word(word) +# score_dict[word]=score # winner = max(score_dict, key=score_dict.get) # return(winner, score_dict[winner]) \ No newline at end of file