Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lions - Nancy L. #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,62 @@
import random

def draw_letters():
pass
#available letters should be in a dictionary
available_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
}
Comment on lines +5 to +15

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart to include dictionary here!

# start with an empty list of available letters to use
hand_available = []
"""
THIS IS WHAT THE INSTRUCTOR HELPED ME TO ACOMPLISH
for _ in range(10):
letters = []
for letter, quantity in available_letters.items():
for _ in range(quantity):
letters.append(letter)

selection = random.choice(letters)
hand_available.append(selection)
available_letters[selection] = available_letters[selection] - 1
Comment on lines +20 to +28

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well! Nice use of a list of all the available letters to make random.choice work.

"""

# iterate through the length of dictionary of letters/quantity available (key:value)
for letter, quantity in available_letters.items():
# # randomly choose a letter in the dictionary using keys
# selection = random.choice(list(available_letters.keys()) -I was unable to get this to work in the loop-
selection = random.choice(letter)
# if the user list has < 10 letters
if len(hand_available) < 10:
# # if the quantity of the letter is not 0 (value)
if quantity != 0:
# # add the letter to the empty list
hand_available.append(selection)
# # subtract that number from the amounts available
quantity -= 1
Comment on lines +31 to +43

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea here, but it unfortunately doesn't quite work. Here we're looking at the letters one at a time in the order they appeared in the dictionary. Because we're just looking at one letter at a time, random.choice doesn't actually choose anything randomly - it will just choose the one letter that we're looking at.


return hand_available


def uses_available_letters(word, letter_bank):
pass
for letter in word:
if letter in letter_bank:
return True
elif letter not in letter_bank or len(word) > len(letter_bank):
return False
Comment on lines 48 to +53

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is on the right track! There are two main issues:

  • It can return too early. If the first letter is in the letter bank, it will immediately return True, without considering whether any of the other letters match. This is because the return statement on line 51 immediately ends our function, not letting the rest of the loop run.
  • It doesn't consider duplicate letters. If our word has two As, but the letter bank only allows one, line 52 will not properly catch that we've used a letter too many times.


# if every letter in the word is found in the letter_bank:
# return True
# if every letter in the word is not in the letter_bank or
# exceedes the len() of the letter_bank:
# return False

def score_word(word):
pass
Expand Down