From c0db591739493a793762145606f4fca8454d86c2 Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Wed, 22 Mar 2023 22:29:42 -0600 Subject: [PATCH 01/13] Passes tests for wave 1 --- adagrams/game.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..bd590951 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,11 +1,60 @@ +"""doc string""" + +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 + """Build a hand of 10 letters for the user""" + letter_pool_copy = LETTER_POOL.copy() + letters = [] + + + while len(letters) < 10: + letter_key = random.choice(list(letter_pool_copy.keys())) + + if letter_pool_copy[letter_key] != 0: + letter_pool_copy[letter_key] -= 1 + letters.append(letter_key) + + return letters + def uses_available_letters(word, letter_bank): + """ doc string """ pass def score_word(word): + """ doc string """ pass def get_highest_word_score(word_list): + """ doc string """ pass \ No newline at end of file From ece24a832c6621f37caecc91ac2407194782b277 Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Wed, 22 Mar 2023 23:34:03 -0600 Subject: [PATCH 02/13] Wave 2 tests 1-3 pass --- adagrams/game.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index bd590951..de8ef323 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -46,10 +46,30 @@ def draw_letters(): return letters +# word = "doNkey" +# word = "eele" +# word = "men" + +# letter_bank = ['d', 'o', 'k', 'n', 'e', 'e', 'y', 'a'] def uses_available_letters(word, letter_bank): - """ doc string """ - pass + """ docstring """ + letter_bank_copy = letter_bank + # for element in letter_bank: + # letter_bank_copy.append(element.casefold()) + + # print(letter_bank_copy) + + for letter in word: + if letter in letter_bank_copy: + letter_bank_copy.remove(letter) + # print(letter_bank_copy) + else: + return False + + return True + +# print(uses_available_letters(word, letter_bank)) def score_word(word): """ doc string """ From 65d6e15be5ecbdece77cb2a404794400de589bd6 Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Wed, 22 Mar 2023 23:43:48 -0600 Subject: [PATCH 03/13] Wave 2 tests 1-4 passed --- adagrams/game.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index de8ef323..1f496882 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -54,11 +54,7 @@ def draw_letters(): def uses_available_letters(word, letter_bank): """ docstring """ - letter_bank_copy = letter_bank - # for element in letter_bank: - # letter_bank_copy.append(element.casefold()) - - # print(letter_bank_copy) + letter_bank_copy = letter_bank.copy() for letter in word: if letter in letter_bank_copy: From c3f8a919f1378c5c263191b223f22af19e65b5c6 Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Wed, 22 Mar 2023 23:51:27 -0600 Subject: [PATCH 04/13] Wave 2 all tests pass --- adagrams/game.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 1f496882..6698b132 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -31,12 +31,12 @@ 'Z': 1 } + def draw_letters(): """Build a hand of 10 letters for the user""" letter_pool_copy = LETTER_POOL.copy() letters = [] - while len(letters) < 10: letter_key = random.choice(list(letter_pool_copy.keys())) @@ -46,20 +46,16 @@ def draw_letters(): return letters -# word = "doNkey" -# word = "eele" -# word = "men" - -# letter_bank = ['d', 'o', 'k', 'n', 'e', 'e', 'y', 'a'] def uses_available_letters(word, letter_bank): """ docstring """ letter_bank_copy = letter_bank.copy() - - for letter in word: - if letter in letter_bank_copy: - letter_bank_copy.remove(letter) - # print(letter_bank_copy) + letter_bank_case = [element.upper() for element in letter_bank_copy] + + for letter in word.upper(): + letter.upper() + if letter in letter_bank_case: + letter_bank_case.remove(letter) else: return False @@ -67,10 +63,12 @@ def uses_available_letters(word, letter_bank): # print(uses_available_letters(word, letter_bank)) + def score_word(word): """ doc string """ pass + def get_highest_word_score(word_list): """ doc string """ - pass \ No newline at end of file + pass From 0b7ac547bcdebaa82fde4ae8b57ae3ce0c2d7f1c Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Thu, 23 Mar 2023 00:31:34 -0600 Subject: [PATCH 05/13] Wave 3 all tests pass --- adagrams/game.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 6698b132..c13dc898 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -48,7 +48,7 @@ def draw_letters(): def uses_available_letters(word, letter_bank): - """ docstring """ + """take word input and compare to letter bank.""" letter_bank_copy = letter_bank.copy() letter_bank_case = [element.upper() for element in letter_bank_copy] @@ -61,12 +61,28 @@ def uses_available_letters(word, letter_bank): return True -# print(uses_available_letters(word, letter_bank)) - - def score_word(word): - """ doc string """ - pass + """assign a point value to the input word""" + letter_value = { + 1: ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'], + 2: ['D', 'G'], + 3: ['B', 'C', 'M', 'P'], + 4: ['F', 'H', 'V', 'W', 'Y'], + 5: ['K'], + 8: ['J', 'X'], + 10: ['Q', 'Z'] + } + + current_score = 0 + for letter in word: + letter = letter.upper() + for key, val in letter_value.items(): + if letter in val: + current_score += key + if 6 < len(word) < 10: + current_score += 8 + + return current_score def get_highest_word_score(word_list): From d1e8b527d4e81a9d203926a7d6715b16843ba2a4 Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Thu, 23 Mar 2023 01:07:01 -0600 Subject: [PATCH 06/13] Wave 4 get word and score into a dictionary --- adagrams/game.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index c13dc898..4f4a1b85 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,4 +1,4 @@ -"""doc string""" +"""adagrams: it's really scrabble""" import random @@ -31,7 +31,6 @@ 'Z': 1 } - def draw_letters(): """Build a hand of 10 letters for the user""" letter_pool_copy = LETTER_POOL.copy() @@ -46,9 +45,8 @@ def draw_letters(): return letters - def uses_available_letters(word, letter_bank): - """take word input and compare to letter bank.""" + """Take word input and compare to letter bank.""" letter_bank_copy = letter_bank.copy() letter_bank_case = [element.upper() for element in letter_bank_copy] @@ -62,7 +60,7 @@ def uses_available_letters(word, letter_bank): return True def score_word(word): - """assign a point value to the input word""" + """Assign a point value to the input word""" letter_value = { 1: ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'], 2: ['D', 'G'], @@ -84,7 +82,18 @@ def score_word(word): return current_score - +word_list = ['graze', 'ferment', 'add', 'sex', 'tenletters', 'branxzorfl'] def get_highest_word_score(word_list): - """ doc string """ - pass + """Return the highest scoring word as a tuple: ('string', word_score)""" + # initiate empty dictionary + word_score_dict = {} + + # for each word in the list, produce a score and assign + # word/score to dictionary + for word in word_list: + score = score_word(word) + print(f'word: {word}, score: {score}') + word_score_dict.update({word: score}) + print(word_score_dict) + +print(get_highest_word_score(word_list)) From 4b594512e28b998496e1d7368eb959bc4361c730 Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Thu, 23 Mar 2023 21:49:26 -0600 Subject: [PATCH 07/13] Wave 4 get word and score into a dictionary --- adagrams/game.py | 50 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 4f4a1b85..3725ff83 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -82,18 +82,50 @@ def score_word(word): return current_score -word_list = ['graze', 'ferment', 'add', 'sex', 'tenletters', 'branxzorfl'] -def get_highest_word_score(word_list): - """Return the highest scoring word as a tuple: ('string', word_score)""" - # initiate empty dictionary +words_list = ['graze', 'ferment', 'add', 'sex', 'tenletters', 'branxzorfl'] +def get_word_scores(word_list): + """Create a list of words and their scores based on the hand drawn.""" word_score_dict = {} - # for each word in the list, produce a score and assign - # word/score to dictionary for word in word_list: score = score_word(word) - print(f'word: {word}, score: {score}') word_score_dict.update({word: score}) - print(word_score_dict) + score_list = list(word_score_dict.items()) + + return score_list + +def get_highest_word_score(word_list): + """Return the highest scoring word as a tuple: ('string', word_score)""" + # word_score_dict = {} + + # for word in word_list: + # score = score_word(word) + # word_score_dict.update({word: score}) + # score_list = list(word_score_dict.items()) + word_scores = get_word_scores(word_list) + + high_score = 0 + highest_score_words = [] + + for tupl in word_scores: + idx = tupl[1] + if idx > high_score: + high_score = idx + highest_score_words.append(tupl) + + + + + + + + print(word_scores) + print(high_score) + print(highest_score_words) + + + # return tuple of the word with the highest score + return None + -print(get_highest_word_score(word_list)) +print(get_highest_word_score(words_list)) From f4f7a851d3d292e53a50a7064b8a82d0aa652d16 Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Thu, 23 Mar 2023 21:53:02 -0600 Subject: [PATCH 08/13] Returns a tuple of winning score and word --- adagrams/game.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 3725ff83..45950125 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -113,19 +113,12 @@ def get_highest_word_score(word_list): high_score = idx highest_score_words.append(tupl) + # print(word_scores) + # print(high_score) + # print(highest_score_words) - - - - - - print(word_scores) - print(high_score) - print(highest_score_words) - - # return tuple of the word with the highest score - return None + return highest_score_words[-1] print(get_highest_word_score(words_list)) From 27e61614fda3a7724745ad57ad33516e6802709e Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Thu, 23 Mar 2023 23:19:55 -0600 Subject: [PATCH 09/13] Returns tuple of word and highest score --- adagrams/game.py | 66 ++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 45950125..69bde0a9 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -31,6 +31,17 @@ 'Z': 1 } +letter_value = { + 1: ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'], + 2: ['D', 'G'], + 3: ['B', 'C', 'M', 'P'], + 4: ['F', 'H', 'V', 'W', 'Y'], + 5: ['K'], + 8: ['J', 'X'], + 10: ['Q', 'Z'] +} + + def draw_letters(): """Build a hand of 10 letters for the user""" letter_pool_copy = LETTER_POOL.copy() @@ -38,15 +49,16 @@ def draw_letters(): while len(letters) < 10: letter_key = random.choice(list(letter_pool_copy.keys())) - if letter_pool_copy[letter_key] != 0: letter_pool_copy[letter_key] -= 1 letters.append(letter_key) return letters + def uses_available_letters(word, letter_bank): """Take word input and compare to letter bank.""" + letter_bank_copy = letter_bank.copy() letter_bank_case = [element.upper() for element in letter_bank_copy] @@ -59,17 +71,9 @@ def uses_available_letters(word, letter_bank): return True + def score_word(word): """Assign a point value to the input word""" - letter_value = { - 1: ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'], - 2: ['D', 'G'], - 3: ['B', 'C', 'M', 'P'], - 4: ['F', 'H', 'V', 'W', 'Y'], - 5: ['K'], - 8: ['J', 'X'], - 10: ['Q', 'Z'] - } current_score = 0 for letter in word: @@ -82,43 +86,21 @@ def score_word(word): return current_score -words_list = ['graze', 'ferment', 'add', 'sex', 'tenletters', 'branxzorfl'] -def get_word_scores(word_list): - """Create a list of words and their scores based on the hand drawn.""" - word_score_dict = {} - - for word in word_list: - score = score_word(word) - word_score_dict.update({word: score}) - score_list = list(word_score_dict.items()) - - return score_list def get_highest_word_score(word_list): """Return the highest scoring word as a tuple: ('string', word_score)""" - # word_score_dict = {} - # for word in word_list: - # score = score_word(word) - # word_score_dict.update({word: score}) - # score_list = list(word_score_dict.items()) - word_scores = get_word_scores(word_list) + highest_score = 0 + winning_word = "" - high_score = 0 - highest_score_words = [] - - for tupl in word_scores: - idx = tupl[1] - if idx > high_score: - high_score = idx - highest_score_words.append(tupl) - - # print(word_scores) - # print(high_score) - # print(highest_score_words) + for word in word_list: + # if the score of the word is higher than highest_score: + if score_word(word) > highest_score: + # that word's score becomes the high schore + highest_score = score_word(word) + winning_word = word # that word becomes the winning word - # return tuple of the word with the highest score - return highest_score_words[-1] + return (winning_word, highest_score) -print(get_highest_word_score(words_list)) +print(get_highest_word_score(word_list)) From f673807cd6bb9af423a2742b478ac70c9be27617 Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Thu, 23 Mar 2023 23:31:54 -0600 Subject: [PATCH 10/13] Revert "Wave 4 get word and score into a dictionary" This reverts commit d1e8b527d4e81a9d203926a7d6715b16843ba2a4. --- adagrams/game.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 69bde0a9..05050e87 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,4 +1,4 @@ -"""adagrams: it's really scrabble""" +"""doc string""" import random @@ -56,6 +56,7 @@ def draw_letters(): return letters + def uses_available_letters(word, letter_bank): """Take word input and compare to letter bank.""" From 3729cfa519605a547bd23a5afdb9f589d65935a5 Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Fri, 24 Mar 2023 01:02:49 -0600 Subject: [PATCH 11/13] Wave 4 passes 6/10 tests --- adagrams/game.py | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 05050e87..2426ee0c 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -56,7 +56,6 @@ def draw_letters(): return letters - def uses_available_letters(word, letter_bank): """Take word input and compare to letter bank.""" @@ -87,7 +86,7 @@ def score_word(word): return current_score - +words_list = ['QQQQ', 'JJJJJ', 'add', 'sex', 'tenletters', 'branxzorfd', 'branxzorfl'] def get_highest_word_score(word_list): """Return the highest scoring word as a tuple: ('string', word_score)""" @@ -95,13 +94,34 @@ def get_highest_word_score(word_list): winning_word = "" for word in word_list: - # if the score of the word is higher than highest_score: - if score_word(word) > highest_score: - # that word's score becomes the high schore - highest_score = score_word(word) - winning_word = word # that word becomes the winning word + score = score_word(word) + + if score > highest_score: + if len(word) == 10: + highest_score = score + winning_word = word + elif len(word) < 10: + highest_score = score + winning_word = word + elif score == highest_score: + if len(word) == 10: + highest_score = score + winning_word = word + elif len(word) < 10 and len(word) < len(winning_word): + highest_score = score + winning_word = word + + return (winning_word, highest_score) +print(get_highest_word_score(words_list)) + +# for each word in the supplied list, + # if there is one word with the highest score: + # that word is the winner ***CHECK*** -print(get_highest_word_score(word_list)) + # elif more than 1 word has the same highest score: + # the word with 10 letters wins + # elif: + # the word with the fewest letters wins \ No newline at end of file From 4bdb4924bf142c2f715008b4bd7ae6a2762a123b Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Fri, 24 Mar 2023 09:30:43 -0600 Subject: [PATCH 12/13] All tests pass, waves 1-4 --- adagrams/game.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 2426ee0c..9d6ade16 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -81,12 +81,13 @@ def score_word(word): for key, val in letter_value.items(): if letter in val: current_score += key - if 6 < len(word) < 10: + if 6 < len(word) <= 10: current_score += 8 return current_score -words_list = ['QQQQ', 'JJJJJ', 'add', 'sex', 'tenletters', 'branxzorfd', 'branxzorfl'] +words = ["AAAAAAAAAA", "EEEEEEEEEE"] + def get_highest_word_score(word_list): """Return the highest scoring word as a tuple: ('string', word_score)""" @@ -95,33 +96,23 @@ def get_highest_word_score(word_list): for word in word_list: score = score_word(word) - + print(f'word: {word}, score: {score}') if score > highest_score: if len(word) == 10: highest_score = score winning_word = word - elif len(word) < 10: + elif len(word) < 10 and len(winning_word) != 10: highest_score = score winning_word = word elif score == highest_score: - if len(word) == 10: + if len(word) == 10 and len(winning_word) != 10: highest_score = score winning_word = word - elif len(word) < 10 and len(word) < len(winning_word): + elif len(winning_word) != 10 and len(word) < 10 and len(word) < len(winning_word): highest_score = score winning_word = word - - return (winning_word, highest_score) -print(get_highest_word_score(words_list)) - -# for each word in the supplied list, - # if there is one word with the highest score: - # that word is the winner ***CHECK*** +print(get_highest_word_score(words)) - # elif more than 1 word has the same highest score: - # the word with 10 letters wins - # elif: - # the word with the fewest letters wins \ No newline at end of file From 734dc44a70ea870136169f26eed1cb8bd3f53e85 Mon Sep 17 00:00:00 2001 From: Amber Shay Date: Fri, 24 Mar 2023 09:47:46 -0600 Subject: [PATCH 13/13] Updates docstrings and cleans up white space --- adagrams/game.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 9d6ade16..a13e772d 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,4 +1,4 @@ -"""doc string""" +"""Adagrams: It's really scrabble""" import random @@ -43,7 +43,9 @@ def draw_letters(): - """Build a hand of 10 letters for the user""" + """Output a list of ten strings, where each string is a letter of + len(1) as defined in LETTER_POOL.""" + letter_pool_copy = LETTER_POOL.copy() letters = [] @@ -57,7 +59,8 @@ def draw_letters(): def uses_available_letters(word, letter_bank): - """Take word input and compare to letter bank.""" + """Each letter in the word 1) is not case-sensitive and 2) is not + utilized more than the available frequency outlined in LETTER_POOL.""" letter_bank_copy = letter_bank.copy() letter_bank_case = [element.upper() for element in letter_bank_copy] @@ -73,7 +76,7 @@ def uses_available_letters(word, letter_bank): def score_word(word): - """Assign a point value to the input word""" + """Assign point value to the word as outlined in letter_value.""" current_score = 0 for letter in word: @@ -86,10 +89,11 @@ def score_word(word): return current_score -words = ["AAAAAAAAAA", "EEEEEEEEEE"] def get_highest_word_score(word_list): - """Return the highest scoring word as a tuple: ('string', word_score)""" + """Return the highest scoring word. For ties: the first + 10-letter word wins. If there are no 10-letter words, the + shortest word wins.""" highest_score = 0 winning_word = "" @@ -113,6 +117,3 @@ def get_highest_word_score(word_list): winning_word = word return (winning_word, highest_score) - -print(get_highest_word_score(words)) -