From dc8ff52a48a55b42c616abab6bddcfab3e7abbea Mon Sep 17 00:00:00 2001 From: Abby Castillo Date: Sun, 26 Mar 2023 21:02:53 -0700 Subject: [PATCH 1/2] completed waves 1 and 2 for real this time --- adagrams/game.py | 74 +++++++++++++++++++++++++++++++++++++-- project_docs/dev-notes.md | 57 ++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 project_docs/dev-notes.md diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..b17f15c5 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,11 +1,79 @@ +# initializations +print("") +print("*** INITIALIZATIONS ***") + +import random + +LETTERS_TUPLE = ( {'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_dict = LETTERS_TUPLE[0] +# print(f"letters_dict is {letters_dict}") + +# helper functions + +def make_letter_pool_list(letter_frequencies): + letter_pool_list = [] + for letter in letter_frequencies: + for i in range(letter_frequencies[letter]): + letter_pool_list.append(letter) + return letter_pool_list + +# print(f"random number: {random.randint(0, 100)}") +# wave functions + def draw_letters(): - pass + letter_pool = make_letter_pool_list(letters_dict) + hand = [] + while len(hand) < 10: + letter_selection = random.randint(0, len(letter_pool) - 1) + hand.append(letter_pool[letter_selection]) + del letter_pool[letter_selection] + return hand def uses_available_letters(word, letter_bank): - pass + hand = list(letter_bank) + word = word.upper() + for letter in word: + if letter not in hand: + return False + elif letter in hand: + hand.remove(letter) + print(f"letter_bank: {letter_bank}") + print(f"hand: {hand}") + return True def score_word(word): pass def get_highest_word_score(word_list): - pass \ No newline at end of file + pass + +print("") +print("*** FUNCTION CALL BEGINS: draw_letters()") +hand = draw_letters() +uses_available_letters('sandwich', hand) \ No newline at end of file diff --git a/project_docs/dev-notes.md b/project_docs/dev-notes.md new file mode 100644 index 00000000..1decbe75 --- /dev/null +++ b/project_docs/dev-notes.md @@ -0,0 +1,57 @@ +so i might want to start with a dictionary. wrap it inside a tuple to be safe. + +letters_tuple = ( {A: 9, + B: 2, + N: 2, + etc}) + +then in the code, you run a loop that creates a list full of all the letters. + +def make_letter_string(letters_tuple): + letters_dict = letters_tuple[0] + for letter, frequency in letters_dict.items: + +.... + +OK! + +so. + +in your draw_letters() function. + +initialize a hand variable. + (so... hand = []) +take the letter_pool_list. + +*** LOOP BEGINS *** +return a random number based on the length of that list, set to a variable. + (so... letter_selection = random.randint(0, len(letter_pool_list))) +then pick the letter item based on the random number, add it to hand + (so... hand.append(letter_pool_list[letter_selection])) +then remove that letter from the letter_pool_list. + (so... del letter_pool_list[letter_selection]) + +OK.... + +## WAVE 2 !!! + +here you are going to do stuff with sets. + +begin by turning word into a list. you do this with a loop. + +so, first, initialize the list. + (so... word_letters = []) +then, iterate through the string. +so... +for letter in word: + word_letters.append[letter] + +oh. no. +do it this way: + +for letter in word: + if letter not in letter_bank: + return False + elif letter in letter_bank: + letter_bank.remove(letter) +return True \ No newline at end of file From a54be5a98860f4924ecc19495f19000d1cb79c94 Mon Sep 17 00:00:00 2001 From: Abby Castillo Date: Sun, 7 May 2023 22:01:42 -0700 Subject: [PATCH 2/2] added wave 3 --- adagrams/game.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index b17f15c5..c34996de 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -63,17 +63,17 @@ def uses_available_letters(word, letter_bank): return False elif letter in hand: hand.remove(letter) - print(f"letter_bank: {letter_bank}") - print(f"hand: {hand}") return True def score_word(word): - pass + score = 0 + for letter in word: + score += LETTERS_TUPLE[0][letter] + + return score def get_highest_word_score(word_list): pass -print("") -print("*** FUNCTION CALL BEGINS: draw_letters()") hand = draw_letters() uses_available_letters('sandwich', hand) \ No newline at end of file