From fe37811e805393ebd8355a0b367ef49e8fb1c1ca Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Sat, 18 Mar 2023 01:37:22 -0700 Subject: [PATCH 01/20] Added project credit source, name, and date to README.md file. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index cfaa5310..91acfc1d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # AdaGrams +Project Credit: Ada Developers Academy
+Name: Linh Huynh
+Date: March 16, 2023
## Skills Assessed From ea1c8a6abdb73f2d5f767814e88c142792b52c16 Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Sat, 18 Mar 2023 02:17:15 -0700 Subject: [PATCH 02/20] Iterated through LETTER_POOL dictionary to append each letter quantity as individual elements within an empty list for easier selection later down the line. --- adagrams/game.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..208bd548 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,5 +1,41 @@ +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 +} + +LETTER_POOL_LIST = [] + def draw_letters(): - pass + hand = [] + for key, value in LETTER_POOL.items(): + LETTER_POOL_LIST.append([key]*value) + return LETTER_POOL_LIST + #print(LETTER_POOL_LIST) +#draw_letters() def uses_available_letters(word, letter_bank): pass From d7183c0b84ec9ecbd80272f30ffbbb07f5778e73 Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Sat, 18 Mar 2023 03:33:13 -0700 Subject: [PATCH 03/20] Added code to randomly select 10 letters. Assigned these letters as a list under the variable hand --- adagrams/game.py | 76 ++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 208bd548..5b07b5ce 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,41 +1,53 @@ +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 + '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 } +temp_list = [] LETTER_POOL_LIST = [] +hand = [] +hand_quantity = 10 def draw_letters(): - hand = [] - for key, value in LETTER_POOL.items(): - LETTER_POOL_LIST.append([key]*value) - return LETTER_POOL_LIST - #print(LETTER_POOL_LIST) -#draw_letters() + + # Create a comprehensive list which includes the total quanity of each available letter from the LETTER_POOL dictionary as individual elements. + for key, value in LETTER_POOL.items(): + temp_list.append([key] * value) + + for sublist in temp_list: + for letter in sublist: + LETTER_POOL_LIST.append(letter) + #print(LETTER_POOL_LIST) + + # Choose 10 random letters as hand, excluding the ones that are already chosen. + return random.sample(LETTER_POOL_LIST, hand_quantity) + #print(random.sample(LETTER_POOL_LIST, hand_quantity)) def uses_available_letters(word, letter_bank): pass From 741ab2d233d2a511ad11bc10991b155dcca4ad17 Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Sun, 19 Mar 2023 01:12:36 -0700 Subject: [PATCH 04/20] Wrote function that checks whether the letters in a word exist within a collection (or hand) of drawn letters. --- adagrams/game.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5b07b5ce..ecae7db3 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -50,7 +50,14 @@ def draw_letters(): #print(random.sample(LETTER_POOL_LIST, hand_quantity)) def uses_available_letters(word, letter_bank): - pass + for letter in word: + if letter in letter_bank: + return True + else: + return False + + + def score_word(word): pass From 7295e64d02f3daaf9fd30a77f5a047d03073bb1e Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Sun, 19 Mar 2023 02:17:01 -0700 Subject: [PATCH 05/20] Updated uses_available_letters() function to account for instances when a letter in the selected word is not present in the available collection (or hand) of letters. --- adagrams/game.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index ecae7db3..b1de5609 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -50,12 +50,20 @@ def draw_letters(): #print(random.sample(LETTER_POOL_LIST, hand_quantity)) def uses_available_letters(word, letter_bank): + word_verification = [] for letter in word: if letter in letter_bank: - return True + #print("True") + word_verification.append("True") else: - return False + #print("False") + word_verification.append("False") + #print(word_verification) + if "False" in word_verification: + return False + else: + return True From ea5cd6cbdad408f64e5c3a1401c3d6940ad0fb8b Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Tue, 21 Mar 2023 17:39:57 -0700 Subject: [PATCH 06/20] Added code under the uses_available_letters to account for instances where user overuses a letter beyond the available amount. --- adagrams/game.py | 49 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index b1de5609..72c77c80 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -49,23 +49,42 @@ def draw_letters(): return random.sample(LETTER_POOL_LIST, hand_quantity) #print(random.sample(LETTER_POOL_LIST, hand_quantity)) -def uses_available_letters(word, letter_bank): - word_verification = [] - for letter in word: - if letter in letter_bank: - #print("True") - word_verification.append("True") +def uses_available_letters(word, letter_bank): + word_verification = [] + hand_letter_count = {} + word_letter_count = {} + count = 0 + + for letter in letter_bank: + if letter not in hand_letter_count: + count = 1 + hand_letter_count[letter] = count + #print(hand_letter_count) + else: + count += 1 + hand_letter_count[letter] = count + #print(hand_letter_count) + + for letter in word: + letter_quantity = word.count(letter) + word_letter_count[letter] = letter_quantity + #print(word_letter_count) + + if letter in letter_bank and word_letter_count[letter] <= hand_letter_count[letter]: + + word_verification.append("True") + #print(word_verification) + else: + word_verification.append("False") + #print(word_verification) + + if "False" in word_verification: + return False + #print("False") else: - #print("False") - word_verification.append("False") - #print(word_verification) + return True + #print("True") - if "False" in word_verification: - return False - else: - return True - - def score_word(word): pass From 1cc20dbee788bb285ada2afbd423edf15816842c Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Tue, 21 Mar 2023 18:23:36 -0700 Subject: [PATCH 07/20] Added code to capitalize any lowercase letter input from player. --- adagrams/game.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 72c77c80..0ae4dd44 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -54,6 +54,7 @@ def uses_available_letters(word, letter_bank): hand_letter_count = {} word_letter_count = {} count = 0 + capitalized_word = word.upper() for letter in letter_bank: if letter not in hand_letter_count: @@ -65,13 +66,12 @@ def uses_available_letters(word, letter_bank): hand_letter_count[letter] = count #print(hand_letter_count) - for letter in word: - letter_quantity = word.count(letter) + for letter in capitalized_word: + letter_quantity = capitalized_word.count(letter) word_letter_count[letter] = letter_quantity #print(word_letter_count) if letter in letter_bank and word_letter_count[letter] <= hand_letter_count[letter]: - word_verification.append("True") #print(word_verification) else: From a72b4b799b78ea57552dc816affca52bfce68ff4 Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Wed, 22 Mar 2023 14:53:29 -0700 Subject: [PATCH 08/20] Added code under the score_word function to accurately score the total points for inputted words. Sorry, I need to learn how to write more succinct git notes. --- adagrams/game.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 0ae4dd44..ce158402 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -29,6 +29,35 @@ 'Z': 1 } +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 +} + temp_list = [] LETTER_POOL_LIST = [] hand = [] @@ -87,7 +116,16 @@ def uses_available_letters(word, letter_bank): def score_word(word): - pass + word_score = {} + for letter in word: + if letter in SCORE_CHART: + #letter_point = SCORE_CHART[letter] + #word_score.append(letter_point) + word_score[letter] = SCORE_CHART[letter] + #print(word_score) + + return sum(word_score.values()) + def get_highest_word_score(word_list): pass \ No newline at end of file From 8f2f693510f87dace234b08da9bcbcd5ab4c700c Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Thu, 23 Mar 2023 01:17:35 -0700 Subject: [PATCH 09/20] Made word scoring process case insensitive. --- adagrams/game.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index ce158402..d4623afe 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -58,6 +58,35 @@ 'Z': 10 } +SCORE_CHART_LOWERCASE = { + '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 +} + temp_list = [] LETTER_POOL_LIST = [] hand = [] @@ -119,9 +148,9 @@ def score_word(word): word_score = {} for letter in word: if letter in SCORE_CHART: - #letter_point = SCORE_CHART[letter] - #word_score.append(letter_point) word_score[letter] = SCORE_CHART[letter] + elif letter in SCORE_CHART_LOWERCASE: + word_score[letter] = SCORE_CHART_LOWERCASE[letter] #print(word_score) return sum(word_score.values()) From 454cdead76c49e4e3c4fafab2ee2a68ed51e7788 Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Thu, 23 Mar 2023 01:25:34 -0700 Subject: [PATCH 10/20] Accounted for empty word input scenarios in the score calculation process. --- adagrams/game.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adagrams/game.py b/adagrams/game.py index d4623afe..e19489d6 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -146,6 +146,10 @@ def uses_available_letters(word, letter_bank): def score_word(word): word_score = {} + + if word == "": + word_score["empty"] = 0 + for letter in word: if letter in SCORE_CHART: word_score[letter] = SCORE_CHART[letter] From 9279bb5dd57bcbf4c17ec6513ae25178d3feca1f Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Thu, 23 Mar 2023 18:11:21 -0700 Subject: [PATCH 11/20] Unified indentation across all functions. --- adagrams/game.py | 56 +++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index e19489d6..c5f70d8c 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -89,24 +89,24 @@ temp_list = [] LETTER_POOL_LIST = [] -hand = [] -hand_quantity = 10 def draw_letters(): + hand = [] + hand_quantity = 10 - # Create a comprehensive list which includes the total quanity of each available letter from the LETTER_POOL dictionary as individual elements. - for key, value in LETTER_POOL.items(): - temp_list.append([key] * value) + # Create a comprehensive list which includes the total quanity of each available letter from the LETTER_POOL dictionary as individual elements. + for key, value in LETTER_POOL.items(): + temp_list.append([key] * value) - for sublist in temp_list: - for letter in sublist: - LETTER_POOL_LIST.append(letter) - #print(LETTER_POOL_LIST) - - # Choose 10 random letters as hand, excluding the ones that are already chosen. - return random.sample(LETTER_POOL_LIST, hand_quantity) - #print(random.sample(LETTER_POOL_LIST, hand_quantity)) - + for sublist in temp_list: + for letter in sublist: + LETTER_POOL_LIST.append(letter) + #print(LETTER_POOL_LIST) + + # Choose 10 random letters as hand, excluding the ones that are already chosen. + return random.sample(LETTER_POOL_LIST, hand_quantity) + #print(random.sample(LETTER_POOL_LIST, hand_quantity)) + def uses_available_letters(word, letter_bank): word_verification = [] hand_letter_count = {} @@ -123,7 +123,7 @@ def uses_available_letters(word, letter_bank): count += 1 hand_letter_count[letter] = count #print(hand_letter_count) - + for letter in capitalized_word: letter_quantity = capitalized_word.count(letter) word_letter_count[letter] = letter_quantity @@ -135,30 +135,38 @@ def uses_available_letters(word, letter_bank): else: word_verification.append("False") #print(word_verification) - + if "False" in word_verification: return False #print("False") else: return True #print("True") - + def score_word(word): word_score = {} if word == "": - word_score["empty"] = 0 + word_score["empty"] = 0 for letter in word: - if letter in SCORE_CHART: - word_score[letter] = SCORE_CHART[letter] - elif letter in SCORE_CHART_LOWERCASE: - word_score[letter] = SCORE_CHART_LOWERCASE[letter] + if letter in SCORE_CHART: + word_score[letter] = SCORE_CHART[letter] + elif letter in SCORE_CHART_LOWERCASE: + word_score[letter] = SCORE_CHART_LOWERCASE[letter] #print(word_score) + while 7 <= len(word) <= 10: + word_score["bonus"] = 8 + return sum(word_score.values()) - def get_highest_word_score(word_list): - pass \ No newline at end of file + best_word = () + score_dict = {} + + for word in word_list: + score = score_word(word) + score_dict[word] = score + #print(score_dict) From 761597d9eaf53b173ed18690f389d105e8fbf9b4 Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Thu, 23 Mar 2023 19:05:29 -0700 Subject: [PATCH 12/20] Corrected score_word(word) function to properly add points for letters that appear more than once in a word. --- adagrams/game.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index c5f70d8c..5ac96f9a 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -145,16 +145,34 @@ def uses_available_letters(word, letter_bank): def score_word(word): + # word_score = {} + + # if word == "": + # word_score["empty"] = 0 + + # for letter in word: + # if letter in SCORE_CHART: + # word_score[letter] = SCORE_CHART[letter] + # elif letter in SCORE_CHART_LOWERCASE: + # word_score[letter] = SCORE_CHART_LOWERCASE[letter] + # #print(word_score) + word_score = {} if word == "": - word_score["empty"] = 0 + word_score["empty"] = 0 for letter in word: if letter in SCORE_CHART: - word_score[letter] = SCORE_CHART[letter] + if letter not in word_score: + word_score[letter] = SCORE_CHART[letter] + else: + word_score[letter] = word_score[letter] + SCORE_CHART[letter] elif letter in SCORE_CHART_LOWERCASE: - word_score[letter] = SCORE_CHART_LOWERCASE[letter] + if letter not in word_score: + word_score[letter] = SCORE_CHART_LOWERCASE[letter] + else: + word_score[letter] = word_score[letter] + SCORE_CHART_LOWERCASE[letter] #print(word_score) while 7 <= len(word) <= 10: From 76a5651b1ba76333b8e9c18fc12fadff56d3bcf7 Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Thu, 23 Mar 2023 19:54:45 -0700 Subject: [PATCH 13/20] Added code underget_highest_word_score function to determine and output highest word score. --- adagrams/game.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5ac96f9a..d109f8bd 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -145,18 +145,6 @@ def uses_available_letters(word, letter_bank): def score_word(word): - # word_score = {} - - # if word == "": - # word_score["empty"] = 0 - - # for letter in word: - # if letter in SCORE_CHART: - # word_score[letter] = SCORE_CHART[letter] - # elif letter in SCORE_CHART_LOWERCASE: - # word_score[letter] = SCORE_CHART_LOWERCASE[letter] - # #print(word_score) - word_score = {} if word == "": @@ -167,12 +155,12 @@ def score_word(word): if letter not in word_score: word_score[letter] = SCORE_CHART[letter] else: - word_score[letter] = word_score[letter] + SCORE_CHART[letter] + word_score[letter] += SCORE_CHART[letter] elif letter in SCORE_CHART_LOWERCASE: if letter not in word_score: word_score[letter] = SCORE_CHART_LOWERCASE[letter] else: - word_score[letter] = word_score[letter] + SCORE_CHART_LOWERCASE[letter] + word_score[letter] += SCORE_CHART_LOWERCASE[letter] #print(word_score) while 7 <= len(word) <= 10: @@ -181,10 +169,19 @@ def score_word(word): return sum(word_score.values()) def get_highest_word_score(word_list): - best_word = () score_dict = {} for word in word_list: score = score_word(word) score_dict[word] = score - #print(score_dict) + print(score_dict) + + for score in score_dict.values(): + winning_word = max(score_dict) + highest_word_score = score_dict[winning_word] + #print(winning_word) + #print(highest_word_score) + + best_word = (winning_word, highest_word_score) + print(best_word) + return best_word \ No newline at end of file From d431e32125503408f2c4edf98847edc565381043 Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Thu, 23 Mar 2023 22:26:04 -0700 Subject: [PATCH 14/20] Refactored score_word(word) function to approach word case sensitivity in a cleaner, more succinct manner by getting rid of unnecessary for loop iterations and eliminating the need of a SCORE_CHART_LOWERCASE dictionary. --- adagrams/game.py | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index d109f8bd..d973ba53 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -58,35 +58,6 @@ 'Z': 10 } -SCORE_CHART_LOWERCASE = { - '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 -} - temp_list = [] LETTER_POOL_LIST = [] @@ -150,20 +121,15 @@ def score_word(word): if word == "": word_score["empty"] = 0 - for letter in word: + for letter in word.upper(): if letter in SCORE_CHART: if letter not in word_score: word_score[letter] = SCORE_CHART[letter] else: word_score[letter] += SCORE_CHART[letter] - elif letter in SCORE_CHART_LOWERCASE: - if letter not in word_score: - word_score[letter] = SCORE_CHART_LOWERCASE[letter] - else: - word_score[letter] += SCORE_CHART_LOWERCASE[letter] #print(word_score) - while 7 <= len(word) <= 10: + if 7 <= len(word) <= 10: word_score["bonus"] = 8 return sum(word_score.values()) From aab97218407c4294b62d0f874506b0446036896f Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Fri, 24 Mar 2023 00:17:29 -0700 Subject: [PATCH 15/20] Updated get_highest_word_score function to account for scenarios with unsorted word lists. --- adagrams/game.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index d973ba53..bdbb853d 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -136,18 +136,20 @@ def score_word(word): def get_highest_word_score(word_list): score_dict = {} + highest_score = 0 for word in word_list: score = score_word(word) score_dict[word] = score - print(score_dict) - - for score in score_dict.values(): - winning_word = max(score_dict) - highest_word_score = score_dict[winning_word] + #print(f"score dictionary: {score_dict}") + + for word, score in score_dict.items(): + if score > highest_score: + highest_score = score + winning_word = word #print(winning_word) - #print(highest_word_score) + #print(highest_score) - best_word = (winning_word, highest_word_score) - print(best_word) + best_word = (winning_word, highest_score) + #print(best_word) return best_word \ No newline at end of file From 9ae92f6332a0556fcae6c4c600bbc1168a9809b7 Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Fri, 24 Mar 2023 02:35:44 -0700 Subject: [PATCH 16/20] Updated get_highest_word_score function to select highest scoring word with fewest letters in the event of a tie. --- adagrams/game.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index bdbb853d..dad1bc59 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,4 +1,5 @@ import random +from collections import Counter LETTER_POOL = { 'A': 9, @@ -136,6 +137,8 @@ def score_word(word): def get_highest_word_score(word_list): score_dict = {} + score_list = [] + matching_scores_dict = {} highest_score = 0 for word in word_list: @@ -144,12 +147,26 @@ def get_highest_word_score(word_list): #print(f"score dictionary: {score_dict}") for word, score in score_dict.items(): + score_list.append(score) + #print(score_list) if score > highest_score: highest_score = score winning_word = word - #print(winning_word) - #print(highest_score) + + matching_scores = [k for k,v in Counter(score_list).items() if v>1] + #print(matching_scores) + for word, score in score_dict.items(): + if score in matching_scores: + matching_scores_dict[word] = score + #print(matching_scores_dict) + + for word, score in matching_scores_dict.items(): + if score == highest_score and len(word) < len(winning_word): + highest_score = score + winning_word = word + break + best_word = (winning_word, highest_score) #print(best_word) return best_word \ No newline at end of file From 67c23d06f5517f97cd05c967b0d8a8f13bd6cf0a Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Fri, 24 Mar 2023 03:04:52 -0700 Subject: [PATCH 17/20] Updated get_highest_word_score to prefer the first word with highest tied score (for both scenarios where the winning word should have the fewest letters or 10 letters). --- adagrams/game.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index dad1bc59..358d89d4 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -162,9 +162,15 @@ def get_highest_word_score(word_list): #print(matching_scores_dict) for word, score in matching_scores_dict.items(): - if score == highest_score and len(word) < len(winning_word): + if score == highest_score and len(word) == 10: highest_score = score winning_word = word + #print(winning_word) + break + elif score == highest_score and len(word) < len(winning_word): + highest_score = score + winning_word = word + #print(winning_word) break best_word = (winning_word, highest_score) From fae638d70013478959da3ee75fd29941f5bd20bd Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Fri, 24 Mar 2023 06:29:42 -0700 Subject: [PATCH 18/20] Practice forking the URL for my Adagrams submission for grading --- adagrams/game.py | 22 ++++++++++++---------- tests/test_wave_01.py | 3 +++ tests/test_wave_02.py | 4 ++++ tests/test_wave_03.py | 3 +++ tests/test_wave_04.py | 9 +++++++++ 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 358d89d4..f008b958 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -59,25 +59,27 @@ 'Z': 10 } -temp_list = [] LETTER_POOL_LIST = [] +temp_list = [] def draw_letters(): - hand = [] - hand_quantity = 10 - # Create a comprehensive list which includes the total quanity of each available letter from the LETTER_POOL dictionary as individual elements. - for key, value in LETTER_POOL.items(): - temp_list.append([key] * value) - + # Creates a comprehensive list which includes the total quanity of each available letter from the LETTER_POOL dictionary as individual elements. + for letter, quantity in LETTER_POOL.items(): + temp_list.append([letter] * quantity) + for sublist in temp_list: for letter in sublist: LETTER_POOL_LIST.append(letter) #print(LETTER_POOL_LIST) - # Choose 10 random letters as hand, excluding the ones that are already chosen. - return random.sample(LETTER_POOL_LIST, hand_quantity) - #print(random.sample(LETTER_POOL_LIST, hand_quantity)) + # Chooses 10 random letters as hand, excluding the ones that are already chosen. + hand = random.sample(LETTER_POOL_LIST, 10) + + #print(hand) + return hand + +#draw_letters() def uses_available_letters(word, letter_bank): word_verification = [] diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index ef48e03b..6d776100 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -38,6 +38,7 @@ def test_draw_letters_draws_ten(): # Assert assert len(letters) == 10 +#@pytest.mark.skip(reason="no way of currently testing this") def test_draw_letters_is_list_of_letter_strings(): # Arrange/Act letters = draw_letters() @@ -49,6 +50,7 @@ def test_draw_letters_is_list_of_letter_strings(): assert type(elem) == str assert len(elem) == 1 +#@pytest.mark.skip(reason="no way of currently testing this") def test_letter_not_selected_too_many_times(): for i in range(1000): @@ -66,6 +68,7 @@ def test_letter_not_selected_too_many_times(): for letter in letters: assert letter_freq[letter] <= LETTER_POOL[letter] +#@pytest.mark.skip(reason="no way of currently testing this") def test_draw_letters_returns_different_hands(): # Arrange/Act hand1 = draw_letters() diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index a5170d8a..a9a9759d 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -13,6 +13,7 @@ def test_uses_available_letters_true_word_in_letter_bank(): # Assert assert is_valid == True +#@pytest.mark.skip(reason="no way of currently testing this") def test_uses_available_letters_false_word_in_letter_bank(): # Arrange letters = ["D", "O", "X", "X", "X", "X", "X", "X", "X", "X"] @@ -24,6 +25,7 @@ def test_uses_available_letters_false_word_in_letter_bank(): # Assert assert is_valid == False +#@pytest.mark.skip(reason="no way of currently testing this") def test_uses_available_letters_false_word_overuses_letter(): # Arrange letters = ["A", "X", "X", "X", "X", "X", "X", "X", "X", "X"] @@ -35,6 +37,7 @@ def test_uses_available_letters_false_word_overuses_letter(): # Assert assert is_valid == False +#@pytest.mark.skip(reason="no way of currently testing this") def test_uses_available_letters_does_not_change_letter_bank(): # Arrange letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"] @@ -48,6 +51,7 @@ def test_uses_available_letters_does_not_change_letter_bank(): assert is_valid == True assert letters == letters_copy +#pytest.mark.skip(reason="no way of currently testing this") def test_uses_available_letters_ignores_case(): # Arrange letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"] diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 5473db39..85fff889 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -8,16 +8,19 @@ def test_score_word_accurate(): assert score_word("DOG") == 5 assert score_word("WHIMSY") == 17 +#@pytest.mark.skip(reason="no way of currently testing this") def test_score_word_accurate_ignores_case(): # Assert assert score_word("a") == 1 assert score_word("dog") == 5 assert score_word("wHiMsY") == 17 +#@pytest.mark.skip(reason="no way of currently testing this") def test_score_zero_for_empty(): # Assert assert score_word("") == 0 +#@pytest.mark.skip(reason="no way of currently testing this") def test_score_extra_points_for_seven_or_longer(): # Assert assert score_word("XXXXXXX") == 64 diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index e586621c..b04b3ac1 100644 --- a/tests/test_wave_04.py +++ b/tests/test_wave_04.py @@ -14,6 +14,7 @@ def test_get_highest_word_score_accurate(): assert best_word[0] == "XXXX" assert best_word[1] == 32 +#@pytest.mark.skip(reason="no way of currently testing this") def test_get_highest_word_score_accurate_unsorted_list(): # Arrange words = ["XXX", "XXXX", "XX", "X"] @@ -25,6 +26,7 @@ def test_get_highest_word_score_accurate_unsorted_list(): assert best_word[0] == "XXXX" assert best_word[1] == 32 +#@pytest.mark.skip(reason="no way of currently testing this") def test_get_highest_word_tie_prefers_shorter_word(): # Arrange words = ["MMMM", "WWW"] @@ -38,6 +40,7 @@ def test_get_highest_word_tie_prefers_shorter_word(): assert best_word[0] == "WWW" assert best_word[1] == 12 +#@pytest.mark.skip(reason="no way of currently testing this") def test_get_highest_word_tie_prefers_shorter_word_unsorted_list(): # Arrange words = ["WWW", "MMMM"] @@ -51,6 +54,7 @@ def test_get_highest_word_tie_prefers_shorter_word_unsorted_list(): assert best_word[0] == "WWW" assert best_word[1] == 12 +#@pytest.mark.skip(reason="no way of currently testing this") def test_get_highest_word_tie_prefers_ten_letters(): # Arrange words = ["AAAAAAAAAA", "BBBBBB"] @@ -62,6 +66,7 @@ def test_get_highest_word_tie_prefers_ten_letters(): assert best_word[0] == "AAAAAAAAAA" assert best_word[1] == 18 +#@pytest.mark.skip(reason="no way of currently testing this") def test_get_highest_word_tie_prefers_ten_letters_unsorted_list(): # Arrange words = ["BBBBBB", "AAAAAAAAAA"] @@ -73,6 +78,7 @@ def test_get_highest_word_tie_prefers_ten_letters_unsorted_list(): assert best_word[0] == "AAAAAAAAAA" assert best_word[1] == 18 +#@pytest.mark.skip(reason="no way of currently testing this") def test_get_highest_word_tie_same_length_prefers_first(): # Arrange words = ["AAAAAAAAAA", "EEEEEEEEEE"] @@ -86,6 +92,7 @@ def test_get_highest_word_tie_same_length_prefers_first(): assert best_word[0] == words[0] assert best_word[1] == 18 +#@pytest.mark.skip(reason="no way of currently testing this") def test_get_highest_word_many_ties_pick_first_ten_letters(): # Arrange words = ["JQ", "FHQ", "AAAAAAAAAA", "BBBBBB", "TTTTTTTTTT"] @@ -97,6 +104,7 @@ def test_get_highest_word_many_ties_pick_first_ten_letters(): assert best_word[0] == "AAAAAAAAAA" assert best_word[1] == 18 +#@pytest.mark.skip(reason="no way of currently testing this") def test_get_highest_word_many_ties_pick_shortest(): # Arrange words = ["BBBBBB", "AAAAAAAAD", "JQ", "KFHK"] @@ -108,6 +116,7 @@ def test_get_highest_word_many_ties_pick_shortest(): assert best_word[0] == "JQ" assert best_word[1] == 18 +#@pytest.mark.skip(reason="no way of currently testing this") def test_get_highest_word_does_not_return_early_after_first_tiebreaker(): # Arrange words = ["WWW", "MMMM", "BBBBBB", "AAAAAAAAD", "JQ", "KFHK"] From 90bd3d2ac57bfdda4f69b1890d53aa9b975b8588 Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Fri, 24 Mar 2023 09:06:03 -0700 Subject: [PATCH 19/20] Updated draw_letters function to remove randomly selected letters in the user hand from the letter pool. --- adagrams/game.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index f008b958..14dadc8e 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -71,15 +71,24 @@ def draw_letters(): for sublist in temp_list: for letter in sublist: LETTER_POOL_LIST.append(letter) - #print(LETTER_POOL_LIST) # Chooses 10 random letters as hand, excluding the ones that are already chosen. - hand = random.sample(LETTER_POOL_LIST, 10) + #hand = random.sample(LETTER_POOL_LIST, 10) + + hand = [] + while len(hand) < 10: + random_letter = random.choice(LETTER_POOL_LIST) + random_letter_index = LETTER_POOL_LIST.index(random_letter) + LETTER_POOL_LIST.pop(random_letter_index) + # print(random_letter) + # print(random_letter_index) + hand.append(random_letter) #print(hand) + #print(LETTER_POOL_LIST) return hand -#draw_letters() +draw_letters() def uses_available_letters(word, letter_bank): word_verification = [] From 9ea3722599261b361e76713320706ea63c5b404b Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Fri, 24 Mar 2023 09:15:25 -0700 Subject: [PATCH 20/20] Removed all print statements. --- adagrams/game.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 14dadc8e..a393f812 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -80,12 +80,8 @@ def draw_letters(): random_letter = random.choice(LETTER_POOL_LIST) random_letter_index = LETTER_POOL_LIST.index(random_letter) LETTER_POOL_LIST.pop(random_letter_index) - # print(random_letter) - # print(random_letter_index) hand.append(random_letter) - #print(hand) - #print(LETTER_POOL_LIST) return hand draw_letters() @@ -101,30 +97,23 @@ def uses_available_letters(word, letter_bank): if letter not in hand_letter_count: count = 1 hand_letter_count[letter] = count - #print(hand_letter_count) else: count += 1 hand_letter_count[letter] = count - #print(hand_letter_count) for letter in capitalized_word: letter_quantity = capitalized_word.count(letter) word_letter_count[letter] = letter_quantity - #print(word_letter_count) if letter in letter_bank and word_letter_count[letter] <= hand_letter_count[letter]: word_verification.append("True") - #print(word_verification) else: word_verification.append("False") - #print(word_verification) if "False" in word_verification: return False - #print("False") else: return True - #print("True") def score_word(word): @@ -139,7 +128,6 @@ def score_word(word): word_score[letter] = SCORE_CHART[letter] else: word_score[letter] += SCORE_CHART[letter] - #print(word_score) if 7 <= len(word) <= 10: word_score["bonus"] = 8 @@ -155,35 +143,28 @@ def get_highest_word_score(word_list): for word in word_list: score = score_word(word) score_dict[word] = score - #print(f"score dictionary: {score_dict}") for word, score in score_dict.items(): score_list.append(score) - #print(score_list) if score > highest_score: highest_score = score winning_word = word matching_scores = [k for k,v in Counter(score_list).items() if v>1] - #print(matching_scores) for word, score in score_dict.items(): if score in matching_scores: matching_scores_dict[word] = score - #print(matching_scores_dict) for word, score in matching_scores_dict.items(): if score == highest_score and len(word) == 10: highest_score = score winning_word = word - #print(winning_word) break elif score == highest_score and len(word) < len(winning_word): highest_score = score winning_word = word - #print(winning_word) break best_word = (winning_word, highest_score) - #print(best_word) return best_word \ No newline at end of file