From 890bdc9b2fd235509b31c251c50852300a21cef7 Mon Sep 17 00:00:00 2001 From: Lilly Date: Mon, 20 Sep 2021 19:17:52 -0700 Subject: [PATCH 01/10] adding work so far --- adagrams/game.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..ba574056 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,4 +1,36 @@ +import random + def draw_letters(): + import random + +letter_bank = {'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} + + +new_dict = {} +for k, v in letter_bank.items(): + new_dict[k] = v + + +for x in range(10): + letter = random.choice(list(new_dict.keys())) + new_dict[letter] - 1 + +for key in letter_bank: + if key in letter: + letter_bank[key] + +print(new_dict) + +# def draw_letters(): +# letter_bank = ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'C', 'C', 'D', 'D', 'D', 'D', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'F', 'F', 'G', 'G', 'G', 'H', 'H', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'J', 'K', 'L', 'L', 'L', 'L', 'M', 'M', 'N', 'N', 'N', 'N', 'N', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'P', 'P', 'Q', 'R', 'R', 'R', 'R', 'R', 'R', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'T', 'T', 'T', 'U', 'U', 'U', 'U', 'V', 'V', 'W', 'W', 'X', 'Y', 'Y', 'Z'] + +# array_letter = [] +# for ten_letters in range(10): + + +# array_letter.append(random.choice(letter_bank)) +# return letter_bank_modfied +# print(draw_letters()) pass def uses_available_letters(word, letter_bank): From 85269198514a6cdabdb43ac863d2f96d6e127b19 Mon Sep 17 00:00:00 2001 From: Lilly Date: Tue, 21 Sep 2021 10:26:15 -0700 Subject: [PATCH 02/10] changed wave 1 function --- adagrams/game.py | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index ba574056..a7971e79 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,37 +1,20 @@ import random def draw_letters(): - import random - -letter_bank = {'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} - - -new_dict = {} -for k, v in letter_bank.items(): - new_dict[k] = v - - -for x in range(10): - letter = random.choice(list(new_dict.keys())) - new_dict[letter] - 1 - -for key in letter_bank: - if key in letter: - letter_bank[key] - -print(new_dict) - -# def draw_letters(): -# letter_bank = ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'C', 'C', 'D', 'D', 'D', 'D', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'F', 'F', 'G', 'G', 'G', 'H', 'H', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'J', 'K', 'L', 'L', 'L', 'L', 'M', 'M', 'N', 'N', 'N', 'N', 'N', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'P', 'P', 'Q', 'R', 'R', 'R', 'R', 'R', 'R', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'T', 'T', 'T', 'U', 'U', 'U', 'U', 'V', 'V', 'W', 'W', 'X', 'Y', 'Y', 'Z'] - -# array_letter = [] -# for ten_letters in range(10): - - -# array_letter.append(random.choice(letter_bank)) -# return letter_bank_modfied -# print(draw_letters()) - pass + letter_bank = {'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} + tile_bag = [] + for k, v in letter_bank.items(): + for each_letter in range(v): + tile_bag.append(k) + + tile_list = [] + for ten_letters in range(10): + letter = random.choice(tile_bag) + tile_list.append(letter) + tile_bag.remove(letter) + + return tile_list + def uses_available_letters(word, letter_bank): pass From 3173894181ee95ba043f18a9f7c8ff6ce7dddad7 Mon Sep 17 00:00:00 2001 From: exitexit Date: Tue, 21 Sep 2021 10:32:49 -0700 Subject: [PATCH 03/10] another way for wave1 --- adagrams/game.py | 52 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index ba574056..d3c6cdf4 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,25 +1,45 @@ import random +# from tests.test_wave_01 import LETTER_POOL def draw_letters(): - import random + -letter_bank = {'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} - - -new_dict = {} -for k, v in letter_bank.items(): - new_dict[k] = v - - -for x in range(10): - letter = random.choice(list(new_dict.keys())) - new_dict[letter] - 1 + letters={'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} + # for key,values in letter_bank.items(): + # new_list.append(random.choice(key)) + + new_list=[] + freq_dict=letters + array_letter=[] + for key,values in freq_dict.items(): + for letters in range(values): + new_list.append(random.choice(key)) + for ten_letters in range(10): + array_letter.append(random.choice(new_list)) + for letter in array_letter: + new_list.remove(letter) + if letter in freq_dict: + freq_dict[letter] -= 1 + else: + freq_dict[letter] = 1 + + + return array_letter + +# new_dict = {} +# for k, v in letter_bank.items(): +# new_dict[k] = v + + +# for x in range(10): +# letter = random.choice(list(new_dict.keys())) +# new_dict[letter] - 1 -for key in letter_bank: - if key in letter: - letter_bank[key] +# for key in letter_bank: +# if key in letter: +# letter_bank[key] -print(new_dict) +# print(new_dict) # def draw_letters(): # letter_bank = ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'C', 'C', 'D', 'D', 'D', 'D', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'F', 'F', 'G', 'G', 'G', 'H', 'H', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'J', 'K', 'L', 'L', 'L', 'L', 'M', 'M', 'N', 'N', 'N', 'N', 'N', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'P', 'P', 'Q', 'R', 'R', 'R', 'R', 'R', 'R', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'T', 'T', 'T', 'U', 'U', 'U', 'U', 'V', 'V', 'W', 'W', 'X', 'Y', 'Y', 'Z'] From ec0c011b4b5149dc7f70be51bc72d30d9211af3b Mon Sep 17 00:00:00 2001 From: Lilly Date: Tue, 21 Sep 2021 18:45:06 -0700 Subject: [PATCH 04/10] wave 2 function added --- adagrams/game.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index a7971e79..70c0d57d 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -17,7 +17,22 @@ def draw_letters(): def uses_available_letters(word, letter_bank): - pass + letter_list = [letter for letter in letter_bank if letter in word] + if len(letter_list) == len(word): + return True + return False + + # let_list =[] + # for letter in letter_bank: + # if letter in word: + # n = letter_bank[letter_bank.index(letter)] + # let_list.append(n) + # if len(let_list) == len(word): + # return True + # return False + + + def score_word(word): pass From c852fbd474ca94fc6895b7af0475d00ece61fec7 Mon Sep 17 00:00:00 2001 From: exitexit Date: Tue, 21 Sep 2021 19:11:55 -0700 Subject: [PATCH 05/10] correction to wave2, all tests passed --- adagrams/game.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 4abfeb8d..c9e037d1 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -21,36 +21,28 @@ def uses_available_letters(word, letter_bank): freq_dict={} counter_word={} - for letter in letter_bank: - if letter in freq_dict: - freq_dict[letter]+=1 - else: - freq_dict[letter]=1 + for one_letter in word: if one_letter not in letter_bank: return False - # for one_letter in counter_word: else: if one_letter in counter_word: counter_word[one_letter] += 1 else: counter_word[one_letter] = 1 - - if freq_dict[letter]>= counter_word[one_letter]: - one_letter=True + for letter in letter_bank: + if letter in freq_dict: + freq_dict[letter]+=1 else: - one_letter=False + freq_dict[letter]=1 + if freq_dict[one_letter]>= counter_word[one_letter]: + one_letter=True + else: + one_letter=False return one_letter - - - # for letter in word: - # if letter not in letter_bank: - # return False - # break - # return True def score_word(word): From 2f1298274ef152382234bfd0dc239efbe6790061 Mon Sep 17 00:00:00 2001 From: exitexit Date: Tue, 21 Sep 2021 20:32:10 -0700 Subject: [PATCH 06/10] wave3 first attempt --- adagrams/game.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index f07050d2..6fabca18 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -36,9 +36,6 @@ def uses_available_letters(word, letter_bank): # freq_dict={} # counter_word={} - - - # for one_letter in word: # if one_letter not in letter_bank: # return False @@ -62,7 +59,34 @@ def uses_available_letters(word, letter_bank): def score_word(word): - pass + total=0 + modified_word=word.upper() + value1=["A","E","I","O","U","L","N", "R", "S", "T"] + value_2=["D", "G"] + value_3=["B", "C", "M", "P"] + value_4=["F", "H", "V", "W", "Y"] + value_5=["K"] + value_8=["J", "X"] + value_10=["Q", "Z"] + + for letter in modified_word: + if letter in value1: + total+=1 + elif letter in value_2: + total+=2 + elif letter in value_3: + total+=3 + elif letter in value_4: + total+=4 + elif letter in value_5: + total+=5 + elif letter in value_8: + total+=8 + elif letter in value_10: + total+=10 + if len(modified_word)>=7: + total+=8 + return(total) def get_highest_word_score(word_list): pass \ No newline at end of file From f7f92f9a4dd8d8ab81a43fffe9e70af206ced1e2 Mon Sep 17 00:00:00 2001 From: Lilly Date: Tue, 21 Sep 2021 21:14:48 -0700 Subject: [PATCH 07/10] wave four --- adagrams/game.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 6fabca18..86991ee0 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -89,4 +89,27 @@ def score_word(word): return(total) def get_highest_word_score(word_list): - pass \ No newline at end of file + word_dict = {} + for word in word_list: + word_dict[word] = score_word(word) + + max_key = max(word_dict, key=word_dict.get) + + return max_key, word_dict[max_key] + + # Dictionayr = {key word, value points} + +# for word in word_list +# score_word(word) add to dictionary as k, v + + + +# max = find the max with dictionary +# tie breaking rules +# prefer the word with the fewest letters... + +# ...unless one word has 10 letters. If the top score is tied between multiple words and one is 10 letters long, choose the one with 10 letters over the one with fewer tiles +# If the there are multiple words that are the same score and the same length, pick the first one in the supplied list + +# retrun highest score (word, points) +# pass \ No newline at end of file From dc901f69bdcb763880931edc130030f14e923050 Mon Sep 17 00:00:00 2001 From: Lilly Date: Wed, 22 Sep 2021 17:06:57 -0700 Subject: [PATCH 08/10] wave 4 --- adagrams/game.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 86991ee0..d7f40f02 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -91,25 +91,31 @@ def score_word(word): def get_highest_word_score(word_list): word_dict = {} for word in word_list: - word_dict[word] = score_word(word) + word_dict[word] = score_word(word) - max_key = max(word_dict, key=word_dict.get) - - return max_key, word_dict[max_key] - - # Dictionayr = {key word, value points} - -# for word in word_list -# score_word(word) add to dictionary as k, v + + max_value = max(word_dict.values()) + max_values = [k for k, v in word_dict.items() if v == max_value] + min_word_length = min(len(k) for k, v in word_dict.items()) + max_key = max(word_dict, key=word_dict.get) -# max = find the max with dictionary -# tie breaking rules -# prefer the word with the fewest letters... + if len(max_values) > 1: -# ...unless one word has 10 letters. If the top score is tied between multiple words and one is 10 letters long, choose the one with 10 letters over the one with fewer tiles -# If the there are multiple words that are the same score and the same length, pick the first one in the supplied list + for k ,v in word_dict.items(): + tie_breaker = [] + if len(k) == 10: + tie_breaker.append(k) + tie_breaker.append(v) + return tuple(tie_breaker) + elif len(k) == min_word_length and len(k) != 10: + tie_breaker.append(k) + tie_breaker.append(v) -# retrun highest score (word, points) -# pass \ No newline at end of file + return tuple(tie_breaker) + else: + return max_key, word_dict[max_key] + + + # return tuple(tie_breaker) \ No newline at end of file From f2a896acc49a47e59e5f75e8bc836f349585f4d3 Mon Sep 17 00:00:00 2001 From: Lilly Date: Wed, 22 Sep 2021 18:33:41 -0700 Subject: [PATCH 09/10] final draft --- adagrams/game.py | 86 +++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 56 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index d7f40f02..a670ca54 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -2,12 +2,16 @@ # from tests.test_wave_01 import LETTER_POOL def draw_letters(): + #creating a dictionary of letter pool letter_bank = {'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} + + #get all of all possible letters tile_bag = [] - for k, v in letter_bank.items(): - for each_letter in range(v): - tile_bag.append(k) + for letter, freq in letter_bank.items(): + for each_letter in range(freq): + tile_bag.append(letter) + #creates ten tiles from string from the list of letters tile_list = [] for ten_letters in range(10): letter = random.choice(tile_bag) @@ -18,49 +22,18 @@ def draw_letters(): def uses_available_letters(word, letter_bank): + #verifies if word is in letterbank and if there are enough tiles letter_list = [letter for letter in letter_bank if letter in word] if len(letter_list) == len(word): return True return False - - # let_list =[] - # for letter in letter_bank: - # if letter in word: - # n = letter_bank[letter_bank.index(letter)] - # let_list.append(n) - # if len(let_list) == len(word): - # return True - # return False - - - - # freq_dict={} - # counter_word={} - # for one_letter in word: - # if one_letter not in letter_bank: - # return False - # else: - # if one_letter in counter_word: - # counter_word[one_letter] += 1 - # else: - # counter_word[one_letter] = 1 - # for letter in letter_bank: - # if letter in freq_dict: - # freq_dict[letter]+=1 - # else: - # freq_dict[letter]=1 - # if freq_dict[one_letter]>= counter_word[one_letter]: - # one_letter=True - # else: - # one_letter=False - # return one_letter - - - + def score_word(word): + #creates empty variable for total/makes input all upper case total=0 modified_word=word.upper() + #Creates tile scores value1=["A","E","I","O","U","L","N", "R", "S", "T"] value_2=["D", "G"] value_3=["B", "C", "M", "P"] @@ -69,6 +42,7 @@ def score_word(word): value_8=["J", "X"] value_10=["Q", "Z"] + #Assigns score for each letter in word, and gets total updating it for letter in modified_word: if letter in value1: total+=1 @@ -89,33 +63,33 @@ def score_word(word): return(total) def get_highest_word_score(word_list): + #Get word dictionary with words and point value word_dict = {} for word in word_list: word_dict[word] = score_word(word) - + #gets the max value in dictionary max_value = max(word_dict.values()) + #get duplicates if present max_values = [k for k, v in word_dict.items() if v == max_value] - + #gets min word length min_word_length = min(len(k) for k, v in word_dict.items()) + #gets name of the max key max_key = max(word_dict, key=word_dict.get) - if len(max_values) > 1: - - for k ,v in word_dict.items(): - tie_breaker = [] - if len(k) == 10: - tie_breaker.append(k) - tie_breaker.append(v) - return tuple(tie_breaker) - elif len(k) == min_word_length and len(k) != 10: - tie_breaker.append(k) - tie_breaker.append(v) - - return tuple(tie_breaker) + #loopping over dictionary to find tie breaking winner + tie_breaker = [] + for word , points in word_dict.items(): + #if ever see word with 10 instant winner + if len(word) == 10: + tie_breaker = (word, points) + return tie_breaker + #if if there is no word with 10 it will print the word with the fewest letters + elif len(word) == min_word_length: + tie_breaker = (word, points) + return tie_breaker + # if no duplicates print single winner else: return max_key, word_dict[max_key] - - - # return tuple(tie_breaker) \ No newline at end of file + \ No newline at end of file From faf68ac640dfff768136f5ff30985a67ecc31b53 Mon Sep 17 00:00:00 2001 From: exitexit Date: Wed, 22 Sep 2021 18:36:54 -0700 Subject: [PATCH 10/10] Final 18 tests passed --- adagrams/game.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index a670ca54..0151ec55 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,6 +1,4 @@ import random -# from tests.test_wave_01 import LETTER_POOL - def draw_letters(): #creating a dictionary of letter pool letter_bank = {'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}