From 065c19429e3c87c27cfa3fe14172bfb39aaa139d Mon Sep 17 00:00:00 2001 From: Reyna Diaz Date: Wed, 28 Sep 2022 10:13:07 -0400 Subject: [PATCH 1/8] "adds draw_letters(), test_wave_01 passing" --- adagrams/game.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..3bda7e42 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,5 +1,19 @@ def draw_letters(): - pass + 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 +} + + letters_not_drawn = list(LETTER_POOL.keys()) + letters_drawn = [] + letter_count = 0 + + for letter in letters_not_drawn: + if letter not in letters_drawn and len(letters_drawn) < 10: + letters_drawn.append(letter) + letter_count += 1 + return letters_drawn def uses_available_letters(word, letter_bank): pass From d01531375dabf2e04fff19e1bebfa0d1a978a2e5 Mon Sep 17 00:00:00 2001 From: Reyna Diaz Date: Wed, 28 Sep 2022 11:23:34 -0400 Subject: [PATCH 2/8] "test_wave_02 in progress, 3/5 tests passing" --- adagrams/game.py | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 3bda7e42..3ff61812 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,10 +1,10 @@ -def draw_letters(): - LETTER_POOL = { +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(): letters_not_drawn = list(LETTER_POOL.keys()) letters_drawn = [] letter_count = 0 @@ -15,8 +15,50 @@ def draw_letters(): letter_count += 1 return letters_drawn +### Wave 2: use_available_letters + +# Next, you need a way to check if an input word (a word a player submits) only uses characters that are contained within a collection (or hand) of drawn letters. Essentially, you need a way to check if the word is an anagram of some or all of the given letters in the hand. + +# To do so, implement the function called `uses_available_letters` in `game.py`. This function should have the following properties: + +# - Has two parameters: +# - `word`, the first parameter, describes some input word, and is a string +# - `letter_bank`, the second parameter, describes an array of drawn letters in a hand. You can expect this to be an array of ten strings, with each string representing a letter +# - Returns either `True` or `False` +# - Returns `True` if every letter in the `input` word is available (in the right quantities) in the `letter_bank` +# - Returns `False` if not; if there is a letter in `input` that is not present in the `letter_bank` or has too much of compared to the `letter_bank` + + def uses_available_letters(word, letter_bank): - pass + # word = word.upper() + word_dict = {} + letter_count = 0 + is_valid = False + + for letter in word: + if letter in letter_bank and letter_count <= LETTER_POOL[letter]: + word_dict[letter] = True + letter_count += 1 + is_valid = True + elif not letter in letter_bank: + word_dict[letter] = False + is_valid = False + return is_valid + # else: + # return True + + # def build_word_dict(snowman_word): + # """This function takes snowman_word as input and returns + # a dictionary with a key-value pair for each letter in + # snowman_word where the key is the letter and the value is `False`. + # """ + # snowman_word_dict = {} + # for letter in snowman_word: + # snowman_word_dict[letter] = False + # return snowman_word_dict + + # if not snowman_dict[letter] + def score_word(word): pass From cd6549f031f0d16d8895472fe7be51b62a5f5413 Mon Sep 17 00:00:00 2001 From: misha-joy Date: Wed, 28 Sep 2022 09:28:29 -0700 Subject: [PATCH 3/8] adds wave 2 functions, passes wave2 tests --- adagrams/game.py | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 3bda7e42..37da145d 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,10 +1,10 @@ -def draw_letters(): - LETTER_POOL = { +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(): letters_not_drawn = list(LETTER_POOL.keys()) letters_drawn = [] letter_count = 0 @@ -15,8 +15,41 @@ def draw_letters(): letter_count += 1 return letters_drawn +### Wave 2: use_available_letters + +# Next, you need a way to check if an input word (a word a player submits) +# only uses characters that are contained within a collection (or hand) of drawn letters. +# Essentially, you need a way to check if the word is an anagram of some or all of the given +# letters in the hand. + +# To do so, implement the function called `uses_available_letters` in `game.py`. +# This function should have the following properties: + +# - Has two parameters: +# - `word`, the first parameter, describes some input word, and is a string +# - `letter_bank`, the second parameter, describes an array of drawn letters in a hand. +# You can expect this to be an array of ten strings, with each string representing a letter +# - Returns either `True` or `False` +# - Returns `True` if every letter in the `input` word is available (in the right quantities) +# in the `letter_bank` +# - Returns `False` if not; if there is a letter in `input` that is not present in the +# `letter_bank` or has too much of compared to the `letter_bank` + def uses_available_letters(word, letter_bank): - pass + word = word.upper() + word_dict = {} + is_valid = False + letter_count = 0 + + for letter in word: + if letter in letter_bank and letter_count <= LETTER_POOL[letter] and word.count(letter) <= letter_bank.count(letter): + word_dict[letter] = True + letter_count += 1 + is_valid = True + elif not letter in letter_bank: + word_dict[letter] = False + is_valid = False + return is_valid def score_word(word): pass From 25f8a65ce2d11707a4439ef7d881e552c1caf85d Mon Sep 17 00:00:00 2001 From: misha-joy Date: Thu, 29 Sep 2022 07:15:05 -0700 Subject: [PATCH 4/8] adds wave3 function --- adagrams/game.py | 66 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 37da145d..fc582f44 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -15,25 +15,6 @@ def draw_letters(): letter_count += 1 return letters_drawn -### Wave 2: use_available_letters - -# Next, you need a way to check if an input word (a word a player submits) -# only uses characters that are contained within a collection (or hand) of drawn letters. -# Essentially, you need a way to check if the word is an anagram of some or all of the given -# letters in the hand. - -# To do so, implement the function called `uses_available_letters` in `game.py`. -# This function should have the following properties: - -# - Has two parameters: -# - `word`, the first parameter, describes some input word, and is a string -# - `letter_bank`, the second parameter, describes an array of drawn letters in a hand. -# You can expect this to be an array of ten strings, with each string representing a letter -# - Returns either `True` or `False` -# - Returns `True` if every letter in the `input` word is available (in the right quantities) -# in the `letter_bank` -# - Returns `False` if not; if there is a letter in `input` that is not present in the -# `letter_bank` or has too much of compared to the `letter_bank` def uses_available_letters(word, letter_bank): word = word.upper() @@ -42,7 +23,8 @@ def uses_available_letters(word, letter_bank): letter_count = 0 for letter in word: - if letter in letter_bank and letter_count <= LETTER_POOL[letter] and word.count(letter) <= letter_bank.count(letter): + if letter in letter_bank and \ + word.count(letter) <= letter_bank.count(letter): word_dict[letter] = True letter_count += 1 is_valid = True @@ -52,7 +34,47 @@ def uses_available_letters(word, letter_bank): return is_valid def score_word(word): - pass + score = 0 + word = word.upper() + points = { + 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"] + } + + for letter in word: + for key, value in points.items(): + if letter in value: + score += key + + if len(word) >= 7: + score += 8 + return score + def get_highest_word_score(word_list): - pass \ No newline at end of file + pass +# word list is a list of strings +# 1. use score_word() to get the score of each word in word list: + # for word in word_list: + #word_score = score_word(word) -- + # ~~ do we want to append this to a list of word scores? + # ~~ or make a dict with word : score as the key, value pair? + +# 2. get highest score using list or dict w/ highest scores + # for score in scores: + # something +# 3. if tie: + # if len(tied_word) > len(other_tied_word): + # tied_word wins! + # unless len(other_tied_word) > 10 + # then 10 letter word wins + # if len(tied_word) == len(other_tied_word): + # first one wins + # ? ???? ? + # +# return: tuple with two elements, ([highest scoring word], [score]) \ No newline at end of file From a5985fa89d1e9ced4b1b1cd57345a26505f8faa3 Mon Sep 17 00:00:00 2001 From: Reyna Diaz Date: Thu, 29 Sep 2022 10:45:43 -0400 Subject: [PATCH 5/8] "wave2 refactor" --- adagrams/game.py | 51 ++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 3ff61812..480dd8a7 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -15,28 +15,14 @@ def draw_letters(): letter_count += 1 return letters_drawn -### Wave 2: use_available_letters - -# Next, you need a way to check if an input word (a word a player submits) only uses characters that are contained within a collection (or hand) of drawn letters. Essentially, you need a way to check if the word is an anagram of some or all of the given letters in the hand. - -# To do so, implement the function called `uses_available_letters` in `game.py`. This function should have the following properties: - -# - Has two parameters: -# - `word`, the first parameter, describes some input word, and is a string -# - `letter_bank`, the second parameter, describes an array of drawn letters in a hand. You can expect this to be an array of ten strings, with each string representing a letter -# - Returns either `True` or `False` -# - Returns `True` if every letter in the `input` word is available (in the right quantities) in the `letter_bank` -# - Returns `False` if not; if there is a letter in `input` that is not present in the `letter_bank` or has too much of compared to the `letter_bank` - - def uses_available_letters(word, letter_bank): - # word = word.upper() + word = word.upper() word_dict = {} letter_count = 0 is_valid = False for letter in word: - if letter in letter_bank and letter_count <= LETTER_POOL[letter]: + if letter in letter_bank and word.count(letter) <= letter_bank.count(letter): word_dict[letter] = True letter_count += 1 is_valid = True @@ -44,21 +30,30 @@ def uses_available_letters(word, letter_bank): word_dict[letter] = False is_valid = False return is_valid - # else: - # return True - # def build_word_dict(snowman_word): - # """This function takes snowman_word as input and returns - # a dictionary with a key-value pair for each letter in - # snowman_word where the key is the letter and the value is `False`. - # """ - # snowman_word_dict = {} - # for letter in snowman_word: - # snowman_word_dict[letter] = False - # return snowman_word_dict +### Wave 3: score_word + +# Now you need a function returns the score of a given word as defined by the Adagrams game. + +# Implement the function `score_word` in `game.py`. This method should have the following properties: + +# - Has one parameter: `word`, which is a string of characters +# - Returns an integer representing the number of points +# - Each letter within `word` has a point value. The number of points of each letter is summed up to represent the total score of `word` +# - Each letter's point value is described in the table below +# - If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points - # if not snowman_dict[letter] +# #### Score chart +# |Letter | Value| +# |:----------------------------:|:----:| +# |A, E, I, O, U, L, N, R, S, T | 1 | +# |D, G | 2 | +# |B, C, M, P | 3 | +# |F, H, V, W, Y | 4 | +# |K | 5 | +# |J, X | 8 | +# |Q, Z | 10 | def score_word(word): pass From 288649273b41292b62c4c3c4292d556aeed4f3a3 Mon Sep 17 00:00:00 2001 From: Reyna Diaz Date: Thu, 29 Sep 2022 10:54:35 -0400 Subject: [PATCH 6/8] wave 2 refactor --- adagrams/game.py | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 480dd8a7..c0f3351b 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -30,31 +30,7 @@ def uses_available_letters(word, letter_bank): word_dict[letter] = False is_valid = False return is_valid - -### Wave 3: score_word - -# Now you need a function returns the score of a given word as defined by the Adagrams game. - -# Implement the function `score_word` in `game.py`. This method should have the following properties: - -# - Has one parameter: `word`, which is a string of characters -# - Returns an integer representing the number of points -# - Each letter within `word` has a point value. The number of points of each letter is summed up to represent the total score of `word` -# - Each letter's point value is described in the table below -# - If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points - -# #### Score chart - -# |Letter | Value| -# |:----------------------------:|:----:| -# |A, E, I, O, U, L, N, R, S, T | 1 | -# |D, G | 2 | -# |B, C, M, P | 3 | -# |F, H, V, W, Y | 4 | -# |K | 5 | -# |J, X | 8 | -# |Q, Z | 10 | - + def score_word(word): pass From 1106dd64d2006a9c715b50362dfe979d98d55710 Mon Sep 17 00:00:00 2001 From: Reyna Diaz Date: Thu, 29 Sep 2022 11:00:29 -0400 Subject: [PATCH 7/8] "adds wave3 again again" --- adagrams/game.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 0fc15703..5362c559 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -32,7 +32,26 @@ def uses_available_letters(word, letter_bank): return is_valid def score_word(word): - pass + score = 0 + word = word.upper() + points = { + 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"] + } + + for letter in word: + for key, value in points.items(): + if letter in value: + score += key + + if len(word) >= 7: + score += 8 + return score def get_highest_word_score(word_list): pass From ca93d023f2586a9e4124b48e0a0faf0e2d9d2d63 Mon Sep 17 00:00:00 2001 From: Reyna Diaz Date: Fri, 30 Sep 2022 11:05:50 -0400 Subject: [PATCH 8/8] "added wave4 function, all tests passing" Co-authored-by: misha-joy --- adagrams/game.py | 56 ++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5362c559..bcfa0d59 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -20,7 +20,6 @@ def uses_available_letters(word, letter_bank): word_dict = {} is_valid = False letter_count = 0 - for letter in word: if letter in letter_bank and word.count(letter) <= letter_bank.count(letter): word_dict[letter] = True @@ -48,30 +47,41 @@ def score_word(word): for key, value in points.items(): if letter in value: score += key - if len(word) >= 7: score += 8 return score def get_highest_word_score(word_list): - pass -# word list is a list of strings -# 1. use score_word() to get the score of each word in word list: - # for word in word_list: - #word_score = score_word(word) -- - # ~~ do we want to append this to a list of word scores? - # ~~ or make a dict with word : score as the key, value pair? - -# 2. get highest score using list or dict w/ highest scores - # for score in scores: - # something -# 3. if tie: - # if len(tied_word) > len(other_tied_word): - # tied_word wins! - # unless len(other_tied_word) > 10 - # then 10 letter word wins - # if len(tied_word) == len(other_tied_word): - # first one wins - # ? ???? ? - # -# return: tuple with two elements, ([highest scoring word], [score]) \ No newline at end of file + scores_dict = {} + for word in word_list: + scores_dict[word] = score_word(word) + highest_score = max(scores_dict.values()) + highest_scoring_words = [] + for word, score in scores_dict.items(): + if score == highest_score: + highest_scoring_words.append(word) + longest_word = max(highest_scoring_words, key=len) + shortest_word = min(highest_scoring_words, key=len) + winning_word = [] + if len(longest_word) >= 10: + winning_word.append(longest_word) + winning_word.append(score_word(longest_word)) + else: + winning_word.append(shortest_word) + winning_word.append(score_word(shortest_word)) + return tuple(winning_word) + + + + + + + + + + + + + + +