From 663254adcdf0c907222e803d585375a99708d844 Mon Sep 17 00:00:00 2001 From: Cecily Date: Tue, 21 Sep 2021 15:38:44 -0400 Subject: [PATCH 1/9] wave 1 pseudo --- adagrams/game.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..c3ad560f 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,5 +1,14 @@ def draw_letters(): - pass + # create a data structure for the distribution of letters + # while len of new data structure - list "letters" is < 10 + # note to self - double check length of 10 actually means 10 + # use random() to pull a random letter + # check if random letter is in our dataset + # check if quantity is > 0 + # if yes then return letter to list "letters" as single letter strings + # qty value of letter decrease by 1 + # if not - continue + def uses_available_letters(word, letter_bank): pass From 773282a133c6f03023297aba060b148c4d818aa4 Mon Sep 17 00:00:00 2001 From: Angela Date: Wed, 22 Sep 2021 08:16:22 -0700 Subject: [PATCH 2/9] draw letters update test --- adagrams/game.py | 59 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index c3ad560f..e8978404 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,14 +1,63 @@ +import random + def draw_letters(): + 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_drawn = [] + + letter_pool_list = [] + for key in letter_pool: + for idx in range(letter_pool[key]): + letter_pool_list.append(key) + + while len(letters_drawn) != 10: + random_entry = random.choice(letter_pool_list) + letters_drawn.append(random_entry) + return letters_drawn + + + + + # * is array a list or dictionary which includes the qty + letters + + # create a data structure for the distribution of letters # while len of new data structure - list "letters" is < 10 # note to self - double check length of 10 actually means 10 # use random() to pull a random letter # check if random letter is in our dataset - # check if quantity is > 0 - # if yes then return letter to list "letters" as single letter strings - # qty value of letter decrease by 1 - # if not - continue - + # # check if quantity is > 0 + # # if yes then return letter to list "letters" as single letter strings + # # qty value of letter decrease by 1 + # # if not - continue + # return list of drawn letters def uses_available_letters(word, letter_bank): pass From 6f3b604b500baa146a63d115a53c2edff8450161 Mon Sep 17 00:00:00 2001 From: Cecily Date: Wed, 22 Sep 2021 11:17:53 -0400 Subject: [PATCH 3/9] update function uses_available_letters --- adagrams/game.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index c3ad560f..dddba0b2 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -8,12 +8,63 @@ def draw_letters(): # if yes then return letter to list "letters" as single letter strings # qty value of letter decrease by 1 # if not - continue - + pass def uses_available_letters(word, letter_bank): - pass + # check if input word uses some or all of the given letters in the hand + # if a letter in word is in the letter bank + # remove the letter from a copy of the letter bank + # consider how to exit loop (word length) + # return boolean + # True if every letter in the word is available + # false if a letter is not in the list or is not available + + is_letter_in_letter_bank = True + letters_copy = letter_bank.copy() + # we have to make a copy of the letter bank because the list is mutable + # we don't want to have a side effect of changing the list outside of this function + word_length = len(word) + + while is_letter_in_letter_bank == True and word_length > 0: + for letter in word: + if letter in letters_copy: + letters_copy.remove(letter) + word_length -= 1 + else: + is_letter_in_letter_bank = False + break + return is_letter_in_letter_bank + +# # ALTERNATE OPTION +# try: +# while word_length > 0: +# for letter in word: +# if letter in letters_copy: +# letters_copy.remove(letter) +# word_length -= 1 +# else: +# raise ValueError +# return True +# except ValueError: +# return False def score_word(word): + # return a score (int) of inputted word + # create score chart data structure + # dictionary with score int as the key and a list of string letters as the values + #for each letter in the word + # find the letter in the score chart + # will need to access the list of letters + # for each score value (key) + # access the letter which is the value and a list + # iteratre thru the list to flag if the letter exists + # add up the points from each letter in word + # define var for total points (count) + # for letter in word + # what is the value of the letter + # count values + # count length of word + # if length 7 -10 letters long, add 8 pts pass def get_highest_word_score(word_list): From b500d905f147a766c51bdc82a4a0efc9544ca16a Mon Sep 17 00:00:00 2001 From: cecily-916 Date: Wed, 22 Sep 2021 12:56:17 -0400 Subject: [PATCH 4/9] update first function --- adagrams/game.py | 58 +++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index c0e10c2b..4db7fe27 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -40,6 +40,8 @@ def draw_letters(): while len(letters_drawn) != 10: random_entry = random.choice(letter_pool_list) letters_drawn.append(random_entry) + letter_pool_list.remove(random_entry) + return letters_drawn @@ -74,28 +76,28 @@ def uses_available_letters(word, letter_bank): # we don't want to have a side effect of changing the list outside of this function word_length = len(word) - while is_letter_in_letter_bank == True and word_length > 0: - for letter in word: - if letter in letters_copy: - letters_copy.remove(letter) - word_length -= 1 - else: - is_letter_in_letter_bank = False - break - return is_letter_in_letter_bank + # while is_letter_in_letter_bank == True and word_length > 0: + # for letter in word: + # if letter in letters_copy: + # letters_copy.remove(letter) + # word_length -= 1 + # else: + # is_letter_in_letter_bank = False + # break + # return is_letter_in_letter_bank -# # ALTERNATE OPTION -# try: -# while word_length > 0: -# for letter in word: -# if letter in letters_copy: -# letters_copy.remove(letter) -# word_length -= 1 -# else: -# raise ValueError -# return True -# except ValueError: -# return False +# ALTERNATE OPTION + try: + while word_length > 0: + for letter in word: + if letter in letters_copy: + letters_copy.remove(letter) + word_length -= 1 + else: + raise ValueError + return True + except ValueError: + return False def score_word(word): # return a score (int) of inputted word @@ -107,14 +109,20 @@ def score_word(word): # for each score value (key) # access the letter which is the value and a list # iteratre thru the list to flag if the letter exists - # add up the points from each letter in word + # perhaps use continue?? when letter is found + # add up the points from each letter in word # define var for total points (count) - # for letter in word - # what is the value of the letter - # count values # count length of word # if length 7 -10 letters long, add 8 pts pass def get_highest_word_score(word_list): + # returns a tuple (winning_word, score) + # must be able to return multiple tuples for any ties + # create data structure of the higheset scoring words (tuples) + # iterate over the highest scoring words tuple data structure + # conditional for fewest letters in word (index 0 of tuple) + # elif one word == 10 letters this one gets chosen + # if 3 way tie of same len, pick 1st in word_list + pass \ No newline at end of file From ace0c1aa2ec41be01e0d46f15770e4973607350f Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 23 Sep 2021 08:30:13 -0700 Subject: [PATCH 5/9] score_words complete --- adagrams/game.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index e8978404..ee7eaf91 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -40,6 +40,7 @@ def draw_letters(): while len(letters_drawn) != 10: random_entry = random.choice(letter_pool_list) letters_drawn.append(random_entry) + letter_pool_list.remove(random_entry) return letters_drawn @@ -62,8 +63,63 @@ def draw_letters(): def uses_available_letters(word, letter_bank): pass -def score_word(word): +# return a score (int) of inputted word + # create score chart data structure + # dictionary with score int as the key and a list of string letters as the values + #for each letter in the word + # find the letter in the score chart + # will need to access the list of letters + # for each score value (key) + # access the letter which is the value and a list + # iteratre thru the list to flag if the letter exists + # perhaps use continue?? when letter is found + # add up the points from each letter in word + # define var for total points (count) + # count length of word + # if length 7 -10 letters long, add 8 pts pass +def score_word(word): + + 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 + } + + word = word.upper() + total_points = 0 + + for letter in word: + total_points += score_chart[letter] + if len(word) >= 7 and len(word) <= 10: + total_points += 8 + + return total_points + def get_highest_word_score(word_list): pass \ No newline at end of file From b58b0adc85c3d6e4deb1603a8f2a12e9adcbe2ac Mon Sep 17 00:00:00 2001 From: cecily-916 Date: Thu, 23 Sep 2021 12:01:43 -0400 Subject: [PATCH 6/9] update get_highest_word_score --- adagrams/game.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 4db7fe27..c106f8c9 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -125,4 +125,16 @@ def get_highest_word_score(word_list): # elif one word == 10 letters this one gets chosen # if 3 way tie of same len, pick 1st in word_list - pass \ No newline at end of file + highest_scoring_word = [("",0)] + for word in word_list: + score = score_word(word) + if score >= highest_scoring_word[1]: + if len(word) >= 10: + highest_scoring_word[0][0] = word + highest_scoring_word[0][1] = score + elif len(word)< len(highest_scoring_word[0]): + highest_scoring_word[0][0] = word + highest_scoring_word[0][1] = score + if score == highest_scoring_word[0][1]: + highest_scoring_word.append((word, score)) + return highest_scoring_word[0] From 01a02dcfa20e9635db03945b31b2d83d5a555a12 Mon Sep 17 00:00:00 2001 From: cecily-916 Date: Thu, 23 Sep 2021 14:29:02 -0400 Subject: [PATCH 7/9] refactored get_highest_word_score --- adagrams/game.py | 77 +++++++++--------------------------------------- 1 file changed, 14 insertions(+), 63 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index a35b441d..6aa253ed 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -44,35 +44,11 @@ def draw_letters(): return letters_drawn - - - # * is array a list or dictionary which includes the qty + letters - - - # create a data structure for the distribution of letters - # while len of new data structure - list "letters" is < 10 - # note to self - double check length of 10 actually means 10 - # use random() to pull a random letter - # check if random letter is in our dataset - # # check if quantity is > 0 - # # if yes then return letter to list "letters" as single letter strings - # # qty value of letter decrease by 1 - # # if not - continue - # return list of drawn letters - def uses_available_letters(word, letter_bank): - # check if input word uses some or all of the given letters in the hand - # if a letter in word is in the letter bank - # remove the letter from a copy of the letter bank - # consider how to exit loop (word length) - # return boolean - # True if every letter in the word is available - # false if a letter is not in the list or is not available - - is_letter_in_letter_bank = True + + # is_letter_in_letter_bank = True letters_copy = letter_bank.copy() - # we have to make a copy of the letter bank because the list is mutable - # we don't want to have a side effect of changing the list outside of this function + word_length = len(word) # while is_letter_in_letter_bank == True and word_length > 0: @@ -98,22 +74,6 @@ def uses_available_letters(word, letter_bank): except ValueError: return False -# return a score (int) of inputted word - # create score chart data structure - # dictionary with score int as the key and a list of string letters as the values - #for each letter in the word - # find the letter in the score chart - # will need to access the list of letters - # for each score value (key) - # access the letter which is the value and a list - # iteratre thru the list to flag if the letter exists - # perhaps use continue?? when letter is found - # add up the points from each letter in word - # define var for total points (count) - # count length of word - # if length 7 -10 letters long, add 8 pts - pass - def score_word(word): score_chart = { @@ -157,28 +117,19 @@ def score_word(word): return total_points def get_highest_word_score(word_list): - # returns a tuple (winning_word, score) - # must be able to return multiple tuples for any ties - # create data structure of the higheset scoring words (tuples) - # iterate over the highest scoring words tuple data structure - # conditional for fewest letters in word (index 0 of tuple) - # elif one word == 10 letters this one gets chosen - # if 3 way tie of same len, pick 1st in word_list - - highest_scoring_word = [("",0)] + + highest_scoring_word = ("",0) for word in word_list: score = score_word(word) - if score > highest_scoring_word[0][1]: - highest_scoring_word[0]= (word, score) - elif score == highest_scoring_word[0][1]: - if len(word) == len(highest_scoring_word[0][0]): - continue - if len(highest_scoring_word[0][0]) >= 10: + if score > highest_scoring_word[1]: + highest_scoring_word = (word, score) + elif score == highest_scoring_word[1]: + if len(word) == len(highest_scoring_word[0]) \ + or len(highest_scoring_word[0]) >= 10: continue - elif len(word) >= 10: - highest_scoring_word[0]= (word, score) - elif len(word)< len(highest_scoring_word[0][0]): - highest_scoring_word[0]= (word, score) + if len(word) >= 10 \ + or len(word)< len(highest_scoring_word[0]): + highest_scoring_word = (word, score) - return highest_scoring_word[0] + return highest_scoring_word From 3be533f098517a27cb55086bd32ebd6b1e793320 Mon Sep 17 00:00:00 2001 From: cecily-916 Date: Thu, 23 Sep 2021 17:15:50 -0400 Subject: [PATCH 8/9] Merge branch 'master' of https://github.com/cecily-916/adagrams-py --- adagrams/game.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 6aa253ed..74ae3182 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -31,8 +31,8 @@ def draw_letters(): } letters_drawn = [] - letter_pool_list = [] + for key in letter_pool: for idx in range(letter_pool[key]): letter_pool_list.append(key) @@ -43,25 +43,11 @@ def draw_letters(): letter_pool_list.remove(random_entry) return letters_drawn - def uses_available_letters(word, letter_bank): - # is_letter_in_letter_bank = True letters_copy = letter_bank.copy() - word_length = len(word) - # while is_letter_in_letter_bank == True and word_length > 0: - # for letter in word: - # if letter in letters_copy: - # letters_copy.remove(letter) - # word_length -= 1 - # else: - # is_letter_in_letter_bank = False - # break - # return is_letter_in_letter_bank - -# ALTERNATE OPTION try: while word_length > 0: for letter in word: From e2f2c9ff735899ad0c701ff2bf95f6f34c5dd12a Mon Sep 17 00:00:00 2001 From: cecily-916 Date: Thu, 23 Sep 2021 17:21:49 -0400 Subject: [PATCH 9/9] submitting final version --- adagrams/game.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 74ae3182..a3272539 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -63,7 +63,6 @@ def uses_available_letters(word, letter_bank): def score_word(word): score_chart = { - 'A': 1, 'B': 3, 'C': 3,