diff --git a/README.md b/README.md index cfaa5310..75eaa5ea 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ ## Skills Assessed -- Following directions and reading comprehension - Reading tests - Using git to maintain code - Manipulating and processing data in lists and strings @@ -22,9 +21,7 @@ In this version of _Adagrams_, we will only be working with the English alphabet Follow these directions once, at the beginning of your project: -1. Navigate to your projects folder named `projects`. - -If you followed Ada's recommended file system structure from the Intro to Dev Environment lesson in Learn, you can navigate to your projects folder with the following command: +1. Navigate to your folder which where this project will be cloned. Example below is named projects. ```bash $ cd ~/Developer/projects @@ -145,7 +142,7 @@ $ pytest $ pytest -s ``` -## Project Write-Up: How to Complete and Submit +## Notes The goal of this project is to write code in `game.py` so each of the functions meet the requirements outlined in the Project Directions below. @@ -154,18 +151,9 @@ Go through the waves one-by-one and build the features of this game. You will use play-testing and unit tests to drive your development. -At submission time, no matter where you are, submit the project via Learn. - -This will let us give feedback on what you've finished so that you can be better prepared for the next project. ## Project Directions -### Get Familiar - -Take time to read through the Wave 1 implementation requirements and the tests for Wave 1. Write down your questions, and spend some time going through your understanding of the requirements and tests. Make sure you can run `$ pytest` and see the tests fail. - -If, after you have taken some time to think through the problem and would like direction for how to dissect the problem, or if you need clarity on the terms/vocabulary we used in this project, you can check out [a small hint we've provided](./project_docs/hints.md). - ### Wave 1: draw_letters Your first task is to build a hand of 10 letters for the user. To do so, implement the function `draw_letters` in `game.py`. This method should have the following properties: diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..9982a594 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,11 +1,108 @@ +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 + hand = [] + copy_letter_pool = LETTER_POOL.copy() + while len(hand) < 10: + random_letter = random.choices( + list(copy_letter_pool), weights=copy_letter_pool.values(), k=1) + str_random_letter = random_letter[0] + + if copy_letter_pool[str_random_letter] > 0: + hand.append(str_random_letter) + copy_letter_pool[str_random_letter] -= 1 + return hand + def uses_available_letters(word, letter_bank): - pass + word_upper = word.upper() + for letter in word_upper: + if word_upper.count(letter) != letter_bank.count(letter): + return False + return True + def score_word(word): - pass + score = 0 + 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, + } + + for letter in word.upper(): + if letter in score_chart: + score += score_chart[letter] + if len(word) >= 7: + score += 8 + return score + def get_highest_word_score(word_list): - pass \ No newline at end of file + highest_score = 0 + winner = None + + for word in word_list: + word_score = score_word(word) + if word_score > highest_score: + highest_score = word_score + winner = (word, word_score) + elif word_score == highest_score: + if len(word) == 10: + return (word, word_score) + elif len(word) < len(winner[0]): + winner = (word, word_score) + return winner