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

Kunzite: G Quinn #109

Open
wants to merge 2 commits into
base: main
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
124 changes: 120 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,127 @@
import random

Choose a reason for hiding this comment

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

Good idea to add a line break between the imports and functions in a file like this.

def draw_letters():
pass
letters =[]
LETTER_POOL = {

Choose a reason for hiding this comment

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

This dictionary could be moved outside this function into the main scope of the module so that draw_letters doesn't need to recreate this dictionary every time the function is run.

'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
}
while len(letters) <10:
letter = random.choice(list(LETTER_POOL))
if LETTER_POOL[letter] > 0:
LETTER_POOL[letter] -= 1
else:

Choose a reason for hiding this comment

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

One suggestion - rather than have an else block that skips the append operation on line 39, why not just append within the if block?

continue
letters.append(letter)
return letters





def uses_available_letters(word, letter_bank):
pass
new_word=word.upper()

Choose a reason for hiding this comment

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

Careful with the spacing, should have space on either side of the equals sign in Python variable assignments:

new_word = word.upper()

letter_bank_copy =list(letter_bank)
for letter in new_word:

Choose a reason for hiding this comment

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

This works perfectly well, but could be simplified a bit:

    for letter in word.upper():
        if letter in letter_bank_copy:
            letter_bank_copy.remove(letter)
        else:
            return False


    return True

if letter not in letter_bank_copy:
return False
elif letter in letter_bank_copy:
letter_bank_copy.remove(letter)
return True





def score_word(word):
pass
points =[]
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
}
new_word=word.upper()
for letter in new_word:
if letter in score_chart:
points.append(score_chart[letter])
total= sum(points)
if len(new_word) ==7 or len(new_word)==8 or len(new_word)==9 or len(new_word)==10:
total+=8
return total

def get_highest_word_score(word_list):
pass
scores_dict={}
maximum = 0
max_key = None
word_list.sort(key=len)
for word in word_list:
score = score_word(word)
scores_dict[word] = score
for scores in scores_dict :
if scores_dict[scores] > maximum:
maximum = scores_dict[scores]
max_key = scores
#Line 111 & 112 doesn't work if there are 3 or more words that are the same length

Choose a reason for hiding this comment

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

Still, this is close and passes the tests. Great job identifying where code can be improved.

elif len(word_list[-1]) == len(word_list[-2]) and score ==maximum:
max_key = word_list[-2]
elif len(word_list[-1]) == 10 and score == maximum:
max_key = word_list[-1]
return (max_key, maximum)

# how can I do this using max()?
# I originally had this but didn't how how to break ties according to len() using max().

Choose a reason for hiding this comment

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

You'd probably need some additional conditional logic to make use of max in that way. There are a lot of different ways to accomplish the same solution, you'll see that time and again in programming!

#
# def get_highest_word_score(word_list):
# word_list.sort(key=len)
# score_dict={}
# for word in word_list:
# score = score_word(word)
# score_dict[word]=score
# winner = max(score_dict, key=score_dict.get)
# return(winner, score_dict[winner])