From 377e105fc1acb0186fea3190b6e06cf0951e8d4c Mon Sep 17 00:00:00 2001 From: kristina Date: Tue, 21 Sep 2021 11:21:06 -0400 Subject: [PATCH 01/10] wave 1 all tests passed --- adagrams/game.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..87a59bfa 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,11 +1,59 @@ +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 + + # use a dictionary with the letter as the key and the number of instances/tiles as the value + # make a copy of LETTER_POOL (shallow/deep) + all_letters = LETTER_POOL.copy() + # initialize an empty array to hold strings (letters) + drawn_letters = [] + # continue loop until the list has ten values + while len(drawn_letters) < 10: + # use random module to choose a random key + letter = random.choice(list(all_letters)) + # if the value associated with the key is greater than 1, append letter to list and decrease value by 1 + if all_letters[letter] >= 1: + drawn_letters.append(letter) + all_letters[letter] -= 1 + + return drawn_letters def uses_available_letters(word, letter_bank): + pass def score_word(word): pass def get_highest_word_score(word_list): - pass \ No newline at end of file + pass + From 8b80e40ede1c0c3d13e7efe283a0ce4bc8763153 Mon Sep 17 00:00:00 2001 From: Faith Date: Tue, 21 Sep 2021 12:11:03 -0700 Subject: [PATCH 02/10] Faith's version with no code at all, committing so git will let me pull --- adagrams/game.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..b8e43219 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,6 +1,5 @@ def draw_letters(): - pass - + def uses_available_letters(word, letter_bank): pass From 0f265ce7e402c78d3b841d7554ea8107f4b1b553 Mon Sep 17 00:00:00 2001 From: kristina Date: Tue, 21 Sep 2021 18:13:44 -0400 Subject: [PATCH 03/10] wave 2 and 3 passing --- adagrams/game.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 87a59bfa..b1c5ec0d 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -48,12 +48,42 @@ def draw_letters(): return drawn_letters def uses_available_letters(word, letter_bank): + # make a copy of the letter bank + available_letters = letter_bank.copy() + # loop through the letters in word and if the letter is in the list, remove it + # if a letter is not in the list, return False + for letter in word: + if letter in available_letters: + available_letters.remove(letter) + continue + else: + return False + return True - pass def score_word(word): - pass + total = 0 + point_dict = { + 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 get_highest_word_score(word_list): - pass + lower_word = word.lower() + + for key, value in point_dict.items(): + for letter in lower_word: + if letter in value: + total += key + + if len(word) >= 7: + total += 8 + return total + +def get_highest_word_score(word_list): + pass From a2db0bc056a769fa06b41a889b2e9c142f9f61ba Mon Sep 17 00:00:00 2001 From: Faith Date: Wed, 22 Sep 2021 13:40:17 -0700 Subject: [PATCH 04/10] Faith's functions for Wave 2/2, passing all tests --- adagrams/game.py | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index acf9db18..d12d070a 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -47,11 +47,48 @@ def draw_letters(): return drawn_letters def uses_available_letters(word, letter_bank): - - pass + letter_bank_copy = letter_bank.copy() + word_list = [] + for letter in word: + if letter in letter_bank_copy: + letter_bank_copy.remove(letter) + word_list.append(letter) + if len(word_list)== len(word): + return True + else: + return False + def score_word(word): - pass + word = word.upper() + one_point = ['A','E','I','O', 'U', 'L', 'N','R','S','T'] + two_point = ['D','G'] + three_point = ['B','C','M','P'] + four_point = ['F','H','V','W','Y'] + five_point = ['K'] + eight_point = ['J','X'] + ten_point = ['Q', 'Z'] + word_score = 0 + if len(word)>=7 and len(word)<11: + word_score += 8 + + for letter in word: + if letter in one_point: + word_score += 1 + elif letter in two_point: + word_score += 2 + elif letter in three_point: + word_score += 3 + elif letter in four_point: + word_score += 4 + elif letter in five_point: + word_score += 5 + elif letter in eight_point: + word_score += 8 + elif letter in ten_point: + word_score += 10 + return word_score + def get_highest_word_score(word_list): pass From 3343060a902f01122c2b8dfbe1b01083b731126e Mon Sep 17 00:00:00 2001 From: kristina Date: Wed, 22 Sep 2021 17:05:29 -0400 Subject: [PATCH 05/10] superficial changes --- adagrams/game.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index b1c5ec0d..ffa4b6f9 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,4 +1,5 @@ import random +import math LETTER_POOL = { 'A': 9, @@ -86,4 +87,5 @@ def score_word(word): return total def get_highest_word_score(word_list): - pass + + pass \ No newline at end of file From ecb5df726a10c3d761bb592b8daa0b570d7a641c Mon Sep 17 00:00:00 2001 From: kristina Date: Wed, 22 Sep 2021 18:46:11 -0400 Subject: [PATCH 06/10] wave 4 passing all tests --- adagrams/game.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 416e4066..d6d6ec58 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -47,8 +47,6 @@ def draw_letters(): return drawn_letters - - def score_word(word): word = word.upper() one_point = ['A','E','I','O', 'U', 'L', 'N','R','S','T'] @@ -93,8 +91,32 @@ def uses_available_letters(word, letter_bank): return True +def get_highest_word_score(word_list): + words_and_scores = {} + score_list = [] + + for word in word_list: + score = score_word(word) + words_and_scores[word] = score + score_list.append(score) + + # find the max score + max_score = max(score_list) -def get_highest_word_score(word_list): + words = [k for k, v in words_and_scores.items() if v == max_score] + print(words) + + for word in words: + if len(words) == 1: + return word, max_score + elif len(word) == 10: + return word, max_score + else: + return min(words, key=len), max_score + - pass \ No newline at end of file + + + + From 7d87a6e562023c57587f3d0cada78b251b6b3e27 Mon Sep 17 00:00:00 2001 From: kristina Date: Wed, 22 Sep 2021 18:49:46 -0400 Subject: [PATCH 07/10] deleted print statement --- adagrams/game.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index d6d6ec58..e4ec2c69 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -105,7 +105,6 @@ def get_highest_word_score(word_list): max_score = max(score_list) words = [k for k, v in words_and_scores.items() if v == max_score] - print(words) for word in words: if len(words) == 1: From 34ae6b4811ebc02d2ac3b54646789d9b36667bdf Mon Sep 17 00:00:00 2001 From: kristina Date: Wed, 22 Sep 2021 18:50:42 -0400 Subject: [PATCH 08/10] deleted unnecessary module --- adagrams/game.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index e4ec2c69..168ab52b 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,5 +1,4 @@ import random -import math LETTER_POOL = { 'A': 9, @@ -95,7 +94,6 @@ def get_highest_word_score(word_list): words_and_scores = {} score_list = [] - for word in word_list: score = score_word(word) words_and_scores[word] = score From 7b85413166a4990de8997a983f99ef228e7121cd Mon Sep 17 00:00:00 2001 From: Faith Date: Sat, 25 Sep 2021 00:52:24 -0700 Subject: [PATCH 09/10] added probability functionality for wave1, commented all functions, passing all tests --- adagrams/game.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 168ab52b..6fac5e71 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -37,9 +37,16 @@ def draw_letters(): drawn_letters = [] # continue loop until the list has ten values while len(drawn_letters) < 10: - # use random module to choose a random key - letter = random.choice(list(all_letters)) - # if the value associated with the key is greater than 1, append letter to list and decrease value by 1 + # random choices takes a weights key that weights probability for each corresponding item + # in the list being chosen from. Used list of all_letters values to get correct weights + # especially cool is that as dict values are reduced as letters are drawn, the weights + # change accordingly, so the probability remains completely accurate + letter_list = random.choices(list(all_letters), weights=list(all_letters.values())) + # random choices has to return a list, in this case, list of only one item, but need + # to access that one item with [0] + letter = letter_list[0] + # if the value associated with the key is greater than 1, append letter to list and + # decrease value in dict by 1 if all_letters[letter] >= 1: drawn_letters.append(letter) all_letters[letter] -= 1 @@ -47,7 +54,9 @@ def draw_letters(): return drawn_letters def score_word(word): + # change all letters to uppercase to match dict word = word.upper() + # create lists representing points and which letters receive those points one_point = ['A','E','I','O', 'U', 'L', 'N','R','S','T'] two_point = ['D','G'] three_point = ['B','C','M','P'] @@ -55,10 +64,13 @@ def score_word(word): five_point = ['K'] eight_point = ['J','X'] ten_point = ['Q', 'Z'] + # create variable word_score and start at 0 word_score = 0 + # if word fits these conditions, gets extra points if len(word)>=7 and len(word)<11: word_score += 8 - + # check each letter in word and find which list it is in + # then assign appropriate amount of points for letter in word: if letter in one_point: word_score += 1 @@ -91,9 +103,11 @@ def uses_available_letters(word, letter_bank): def get_highest_word_score(word_list): + # create new dict that will store word as key and score as value words_and_scores = {} + # list will track just scores score_list = [] - + # populate both list and dict with data from word_list for word in word_list: score = score_word(word) words_and_scores[word] = score @@ -101,14 +115,17 @@ def get_highest_word_score(word_list): # find the max score max_score = max(score_list) - + # this is list comprehension, loops through dict, if max_score is found as a value, it returns + # the key, which is a word string. Now have a list of any possible tying words words = [k for k, v in words_and_scores.items() if v == max_score] - + # check each word in the tied words list (words) check conditionals and apply results for word in words: if len(words) == 1: return word, max_score elif len(word) == 10: return word, max_score + # each final returned pair will be a tuple. Python automatically converts a comma separated + # pair of values into a tuple else: return min(words, key=len), max_score From 9ea7fa543c78ff3ae04e746dbb4f52b7a92b8906 Mon Sep 17 00:00:00 2001 From: kristina Date: Sun, 26 Sep 2021 20:45:15 -0400 Subject: [PATCH 10/10] docstrings added to all functions --- adagrams/game.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/adagrams/game.py b/adagrams/game.py index 6fac5e71..6e21cf22 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -30,6 +30,11 @@ } def draw_letters(): + ''' + Draws 10 random letters from a dictionary of letters. + The letters are are weighted depending on the frequency as dictated in the values. + Returns a list of letters. + ''' # use a dictionary with the letter as the key and the number of instances/tiles as the value # make a copy of LETTER_POOL (shallow/deep) all_letters = LETTER_POOL.copy() @@ -54,6 +59,9 @@ def draw_letters(): return drawn_letters def score_word(word): + ''' + Scores the word and returns the score. + ''' # change all letters to uppercase to match dict word = word.upper() # create lists representing points and which letters receive those points @@ -89,6 +97,9 @@ def score_word(word): return word_score def uses_available_letters(word, letter_bank): + ''' + Checks to make sure the user only submits words using the letters they drew. + ''' # make a copy of the letter bank available_letters = letter_bank.copy() # loop through the letters in word and if the letter is in the list, remove it @@ -103,6 +114,11 @@ def uses_available_letters(word, letter_bank): def get_highest_word_score(word_list): + ''' + Finds the words with the highest point value and returns the winning words and the score in a tuple. + For ties, words equal to ten win, else the shorter words wins. + If both of the words are the same length, the first word submitted wins. + ''' # create new dict that will store word as key and score as value words_and_scores = {} # list will track just scores